Skip to content

Commit

Permalink
优化修复器的“取消比对”体验
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyaser authored and Nyaser committed Aug 29, 2024
1 parent e994ed4 commit ada48b6
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 45 deletions.
28 changes: 14 additions & 14 deletions Form.Fixer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public partial class Form_Fixer : Form
private Config? Config;
private readonly List<string> AudioList;
private static readonly ResourceManager Resources = new(typeof(Form_Fixer));
private CancellationTokenSource cancellationTokenSource = new();

public Form_Fixer(Dictionary<string, object> args)
{
Expand All @@ -28,25 +29,24 @@ private void Form_Fixer_Load(object sender, EventArgs e)
textBox_gameVersion.Text = Config.Version;
}

private bool CancellingCompare;

private void Button_Compare_Click(object sender, EventArgs e)
{
button_cancel.Enabled = !(CancellingCompare = button_compare.Enabled = button_start.Enabled = false);
Compare().GetAwaiter().OnCompleted(() =>
button_cancel.Enabled = !(button_compare.Enabled = button_start.Enabled = false);
Compare(cancellationTokenSource.Token).GetAwaiter().OnCompleted(() =>
{
GC.Collect(2, GCCollectionMode.Aggressive, true, true);
GC.WaitForFullGCComplete();
GC.Collect(2, GCCollectionMode.Aggressive, true, true); GC.WaitForFullGCComplete();
progressBar.Value = 0; progressBar.Maximum = 100; progressBar.Style = ProgressBarStyle.Continuous;
button_cancel.Enabled = !(button_compare.Enabled = button_start.Enabled = true);
});
}

private void Button_Cancel_Click(object sender, EventArgs e)
{
CancellingCompare = true;
cancellationTokenSource.Cancel(); cancellationTokenSource.Token.WaitHandle.WaitOne();
cancellationTokenSource.Dispose(); cancellationTokenSource = new CancellationTokenSource();
}

private async Task Compare()
private async Task Compare(CancellationToken token)
{
if (Config is null || Config.Channel is null) return;
groupBox_suplus.Text = Resources.GetString("groupBox_suplus.Text"); textBox_suplus.Clear();
Expand All @@ -58,10 +58,10 @@ private async Task Compare()
BaseAddress = new Uri((await API.GetAsync(Config.Channel)).main.major.res_list_url)
};
Dictionary<string, string> pkg_version = [];
pkg_version["game"] = await http.GetStringAsync($"{http.BaseAddress}/pkg_version");
pkg_version["game"] = await http.GetStringAsync($"{http.BaseAddress}/pkg_version", token);
foreach (string item in AudioList)
{
pkg_version[item] = await http.GetStringAsync($"{http.BaseAddress}/{item}_pkg_version");
pkg_version[item] = await http.GetStringAsync($"{http.BaseAddress}/{item}_pkg_version", token);
}

List<FileInfoH> online = [];
Expand Down Expand Up @@ -109,10 +109,10 @@ where j is not null
}
progressBar.Value = local.Count;
groupBox_progress.Text = $"{Resources.GetString("groupBox_progress.Text")} ({local.Count} of {items.Count})";
if (CancellingCompare) break;
if (token.IsCancellationRequested) break;
}
items.Clear();
if (CancellingCompare) return;
if (token.IsCancellationRequested) return;
List<FileInfoH> surplus = local.Except(online).ToList();
List<FileInfoH> missing = online.Except(local).ToList();
groupBox_suplus.Text = $"{Resources.GetString("groupBox_suplus.Text")} ({surplus.Count} of {local.Count})"; local.Clear();
Expand All @@ -126,7 +126,7 @@ private void Button_Start_Click(object sender, EventArgs e)
button_compare.Enabled = button_start.Enabled = false;
StartFix().GetAwaiter().OnCompleted(() =>
{
groupBox_progress.Text = $"{Resources.GetString("groupBox_progress.Text")}"; progressBar.Value = 0;
groupBox_progress.Text = Resources.GetString("groupBox_progress.Text"); progressBar.Value = 0;
groupBox_suplus.Text = Resources.GetString("groupBox_suplus.Text"); textBox_suplus.Clear();
groupBox_missing.Text = Resources.GetString("groupBox_missing.Text"); textBox_missing.Clear();
button_compare.Enabled = button_start.Enabled = true;
Expand Down Expand Up @@ -171,7 +171,7 @@ private void Timer_RAM_Tick(object sender, EventArgs e)

private void Form_Fixer_FormClosing(object sender, FormClosingEventArgs e)
{
CancellingCompare = true;
Button_Cancel_Click(sender, e);
}

private void Form_Fixer_FormClosed(object sender, FormClosedEventArgs e)
Expand Down
62 changes: 31 additions & 31 deletions Form.Fixer.resx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
Expand All @@ -26,36 +26,36 @@
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
Expand Down Expand Up @@ -117,7 +117,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="groupBox_gameVersion.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Top, Right</value>
</data>
Expand Down Expand Up @@ -235,7 +235,7 @@
<value>5</value>
</data>
<data name="button_cancel.Text" xml:space="preserve">
<value>终止比对</value>
<value>取消比对</value>
</data>
<data name="&gt;&gt;button_cancel.Name" xml:space="preserve">
<value>button_cancel</value>
Expand Down Expand Up @@ -639,12 +639,12 @@
<data name="&gt;&gt;groupBox1.ZOrder" xml:space="preserve">
<value>0</value>
</data>
<data name="timer_RAM.TrayLocation" type="System.Drawing.Point, System.Drawing">
<metadata name="timer_RAM.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</data>
<data name="$this.Localizable" type="System.Boolean, mscorlib">
</metadata>
<metadata name="$this.Localizable" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</data>
</metadata>
<data name="$this.AutoScaleDimensions" type="System.Drawing.SizeF, System.Drawing">
<value>7, 17</value>
</data>
Expand Down

0 comments on commit ada48b6

Please sign in to comment.