Skip to content

Commit

Permalink
autoupdater and benchmark changes
Browse files Browse the repository at this point in the history
not full update, still making some changes
Updater.exe now will automatically install last version from github releases
  • Loading branch information
Prevter committed May 2, 2021
1 parent daeba5c commit 7f512c7
Show file tree
Hide file tree
Showing 16 changed files with 610 additions and 886 deletions.
26 changes: 26 additions & 0 deletions FloatToolGUI.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,42 @@ VisualStudioVersion = 16.0.30011.22
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FloatToolGUI", "FloatToolGUI\FloatToolGUI.csproj", "{A5906B52-BA1B-481C-BF4C-3028EF52A925}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Updater", "Updater\Updater.csproj", "{239C41D8-4405-461B-9706-7C03D7A87903}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A5906B52-BA1B-481C-BF4C-3028EF52A925}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A5906B52-BA1B-481C-BF4C-3028EF52A925}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A5906B52-BA1B-481C-BF4C-3028EF52A925}.Debug|x64.ActiveCfg = Debug|x64
{A5906B52-BA1B-481C-BF4C-3028EF52A925}.Debug|x64.Build.0 = Debug|x64
{A5906B52-BA1B-481C-BF4C-3028EF52A925}.Debug|x86.ActiveCfg = Debug|Any CPU
{A5906B52-BA1B-481C-BF4C-3028EF52A925}.Debug|x86.Build.0 = Debug|Any CPU
{A5906B52-BA1B-481C-BF4C-3028EF52A925}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A5906B52-BA1B-481C-BF4C-3028EF52A925}.Release|Any CPU.Build.0 = Release|Any CPU
{A5906B52-BA1B-481C-BF4C-3028EF52A925}.Release|x64.ActiveCfg = Release|x64
{A5906B52-BA1B-481C-BF4C-3028EF52A925}.Release|x64.Build.0 = Release|x64
{A5906B52-BA1B-481C-BF4C-3028EF52A925}.Release|x86.ActiveCfg = Release|Any CPU
{A5906B52-BA1B-481C-BF4C-3028EF52A925}.Release|x86.Build.0 = Release|Any CPU
{239C41D8-4405-461B-9706-7C03D7A87903}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{239C41D8-4405-461B-9706-7C03D7A87903}.Debug|Any CPU.Build.0 = Debug|Any CPU
{239C41D8-4405-461B-9706-7C03D7A87903}.Debug|x64.ActiveCfg = Debug|Any CPU
{239C41D8-4405-461B-9706-7C03D7A87903}.Debug|x64.Build.0 = Debug|Any CPU
{239C41D8-4405-461B-9706-7C03D7A87903}.Debug|x86.ActiveCfg = Debug|Any CPU
{239C41D8-4405-461B-9706-7C03D7A87903}.Debug|x86.Build.0 = Debug|Any CPU
{239C41D8-4405-461B-9706-7C03D7A87903}.Release|Any CPU.ActiveCfg = Release|Any CPU
{239C41D8-4405-461B-9706-7C03D7A87903}.Release|Any CPU.Build.0 = Release|Any CPU
{239C41D8-4405-461B-9706-7C03D7A87903}.Release|x64.ActiveCfg = Release|Any CPU
{239C41D8-4405-461B-9706-7C03D7A87903}.Release|x64.Build.0 = Release|Any CPU
{239C41D8-4405-461B-9706-7C03D7A87903}.Release|x86.ActiveCfg = Release|Any CPU
{239C41D8-4405-461B-9706-7C03D7A87903}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
287 changes: 136 additions & 151 deletions FloatToolGUI/Benchmark.Designer.cs

Large diffs are not rendered by default.

84 changes: 66 additions & 18 deletions FloatToolGUI/Benchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public enum SearchMode

public void parseCraft(List<InputSkin> inputs, List<Skin> outputs, string want)
{
//List<double> results = new List<double>();
decimal wantFloat;
decimal.TryParse(want, System.Globalization.NumberStyles.Any, CultureInfo.InvariantCulture, out wantFloat);
decimal wantFloat = 1;
if (CurrentSearchMode != SearchMode.Equal)
decimal.TryParse(want, System.Globalization.NumberStyles.Any, CultureInfo.InvariantCulture, out wantFloat);

foreach (var item in outputs)
{
Expand Down Expand Up @@ -96,7 +96,7 @@ private void StartCalculation()

Stopwatch timer = Stopwatch.StartNew();

var threads = Environment.ProcessorCount;
int threads = (int)benchmarkThreadsNumericUpdown.Value;
try
{
for (int i = 0; i < threads; i++)
Expand Down Expand Up @@ -149,8 +149,10 @@ public Benchmark(string version)
cpuNameLabel.Text = mo["Name"].ToString().Trim();
Logger.Log($"[{DateTime.Now}]: CPU Name: {cpuNameLabel.Text} ({threadCountLabel.Text})");
thread1 = new Thread(runCycle);
LoadStats();

benchmarkThreadsNumericUpdown.Value = Environment.ProcessorCount;
warningPic.Image = SystemIcons.Warning.ToBitmap();
Thread t = new Thread(new ThreadStart(LoadStats));
t.Start();
}

private void startBenchmarkBtn_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -194,18 +196,22 @@ private void AddCpuToList(string cpu, string speed, string ver, bool bigMargin)
AutoSize = true,
ForeColor = foreColor
});
flowLayoutPanel1.Controls.Add(tmpPanel);
Invoke((MethodInvoker)(() =>
{
benchmarkScoreboardLayout.Controls.Add(tmpPanel);
})
);

}

private void LoadStats()
{
try
{
flowLayoutPanel1.Controls.Clear();
WebRequest request = WebRequest.Create($"{uri}getBenchmarks.php");
request.Credentials = CredentialCache.DefaultCredentials;
WebResponse response = request.GetResponse();

using (Stream dataStream = response.GetResponseStream())
{
StreamReader reader = new StreamReader(dataStream);
Expand All @@ -216,25 +222,28 @@ private void LoadStats()
{
var results = responseFromServer.Remove(responseFromServer.Length - 1).Split('&');
int index = 0;
Invoke((MethodInvoker)(() => { benchmarkScoreboardLayout.Controls.Clear(); }));
foreach (var cpu in results)
{
index++;
var items = cpu.Split('|');
AddCpuToList(items[0], items[1], items[2], index== results.Length);
AddCpuToList(items[0], items[1], items[2], index == results.Length);
}
}
}
response.Close();
}
catch(Exception ex)
{
flowLayoutPanel1.Controls.Add(new Label
{
Text = "Произошла ошибка подключения",
AutoSize = true,
ForeColor = Color.White
});

Invoke((MethodInvoker)(() => {
benchmarkScoreboardLayout.Controls.Clear();
benchmarkScoreboardLayout.Controls.Add(new Label
{
Text = "Произошла ошибка подключения",
AutoSize = true,
ForeColor = Color.White
});
}));
Logger.Log($"[{DateTime.Now}]: {{EXCEPTION}} {ex.Message}{Environment.NewLine}{ex.StackTrace}");
Logger.SaveCrashReport();
}
Expand All @@ -245,7 +254,7 @@ private void submitScoreBtn_Click(object sender, EventArgs e)
try
{
submitScoreBtn.Enabled = false;
HttpWebRequest req = (HttpWebRequest)WebRequest.Create($"{uri}addBenchmark.php?cpu={cpuNameLabel.Text} ({threadCountLabel.Text})&speed={speedLabel.Text.Split(' ')[0]}");
HttpWebRequest req = (HttpWebRequest)WebRequest.Create($"{uri}addBenchmark.php?cpu={cpuNameLabel.Text} ({benchmarkThreadsNumericUpdown.Value.ToString()})&speed={speedLabel.Text.Split(' ')[0]}");
req.UserAgent = $"FloatTool/{versionLabel2.Text}";
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
res.Close();
Expand Down Expand Up @@ -282,5 +291,44 @@ private void DragWindowMouseDown(object sender, MouseEventArgs e)
SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
}
}

private void benchmarkThreadsNumericUpdown_ValueChanged(object sender, EventArgs e)
{
if (benchmarkThreadsNumericUpdown.Value > Environment.ProcessorCount)
{
warningPic.Enabled = true;
warningPic.Visible = true;
}
else
{
warningPic.Enabled = false;
warningPic.Visible = false;
}
}

private void updateBenchmarksButton_Click(object sender, EventArgs e)
{
benchmarkScoreboardLayout.Controls.Clear();

benchmarkScoreboardLayout.Controls.Add(new Panel {
Size = new Size(300, 100)
});
benchmarkScoreboardLayout.Controls.Add(new Label
{
Size = new Size(361, 19),
Text = "Загрузка бенчмарков...",
AutoSize = false,
TextAlign = ContentAlignment.MiddleCenter
});
benchmarkScoreboardLayout.Controls.Add(new PictureBox
{
Size = new Size(362, 64),
Image = Properties.Resources.loading,
SizeMode = PictureBoxSizeMode.Zoom
});

Thread t = new Thread(new ThreadStart(LoadStats));
t.Start();
}
}
}
3 changes: 3 additions & 0 deletions FloatToolGUI/Benchmark.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="ToolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>113, 17</value>
</metadata>
<metadata name="Updater.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
Expand Down
4 changes: 2 additions & 2 deletions FloatToolGUI/Calculation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ static public string craftF(List<InputSkin> ingridients, float minFloat, float m
{
arrInput[i] = Convert.ToSingle(ingridients[i].WearValue);
}
foreach (float f in arrInput)
for (int i = 0; i < 10; i++)
{
avgFloat += Convert.ToSingle(f);
avgFloat += Convert.ToSingle(arrInput[i]);
}
avgFloat /= 10;
return setprecission(((maxFloat - minFloat) * avgFloat) + minFloat, 10);
Expand Down
1 change: 1 addition & 0 deletions FloatToolGUI/FloatToolGUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@
<ItemGroup>
<Content Include="floattool.ico" />
<Content Include="FodyWeavers.xml" />
<None Include="Resources\loading.gif" />
<EmbeddedResource Include="itemData.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
Expand Down
48 changes: 24 additions & 24 deletions FloatToolGUI/Main.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 36 additions & 5 deletions FloatToolGUI/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using Microsoft.Win32;
using System.Numerics;
using Button = System.Windows.Forms.Button;
using System.Diagnostics;

namespace FloatToolGUI
{
Expand Down Expand Up @@ -104,8 +105,9 @@ static public string getSkinData(string name)
public void parseCraft(List<InputSkin> inputs, List<Skin> outputs, string want)
{
//List<double> results = new List<double>();
decimal wantFloat;
decimal.TryParse(want, System.Globalization.NumberStyles.Any, CultureInfo.InvariantCulture, out wantFloat);
decimal wantFloat = 1;
if (CurrentSearchMode != SearchMode.Equal)
decimal.TryParse(want, System.Globalization.NumberStyles.Any, CultureInfo.InvariantCulture, out wantFloat);

foreach (var item in outputs)
{
Expand Down Expand Up @@ -236,6 +238,33 @@ public void updateSearchStr()
Logger.Log($"[{DateTime.Now.ToString()}]: Changed search skin to: {search}");
}

public void AutoUpdater()
{
string ver = versionLabel.Text;
string data = CheckUpdates();
string lastver = data.Split('|')[0];
Logger.Log($"Checked version is: {lastver}{newLine}Installed: {ver}");
if (ver != lastver)
{
DialogResult result = MessageBox.Show(
$"Доступна версия {lastver}! Хотите обновить?",
"Доступно обновление",
MessageBoxButtons.YesNo,
MessageBoxIcon.Information,
MessageBoxDefaultButton.Button1,
MessageBoxOptions.DefaultDesktopOnly);

if (result == DialogResult.Yes)
{
string strExeFilePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
string strWorkPath = System.IO.Path.GetDirectoryName(strExeFilePath);
Process.Start($@"{strWorkPath}\Updater.exe", data.Split('|')[1]);
Invoke((MethodInvoker)(() => { Close(); } ));
}
}
}


RegistryKey registryData;
public FloatTool()
{
Expand Down Expand Up @@ -275,15 +304,17 @@ public FloatTool()
string ver = versionLabel.Text;
try
{
ver = CheckUpdates();
Thread updater = new Thread(AutoUpdater);
updater.Start();
//ver = CheckUpdates();
}
catch(Exception ex)
{
Logger.Log($"[{DateTime.Now}]: {{EXCEPTION}} {ex.Message}{newLine}{ex.StackTrace}");
Logger.SaveCrashReport();
}

Logger.Log($"Checked version is: {ver}{newLine}Installed: {versionLabel.Text}");
/*Logger.Log($"Checked version is: {ver}{newLine}Installed: {versionLabel.Text}");
if (ver != versionLabel.Text)
{
DialogResult result = MessageBox.Show(
Expand All @@ -296,7 +327,7 @@ public FloatTool()
if (result == DialogResult.Yes)
System.Diagnostics.Process.Start("https://github.com/Nemeshio/FloatTool-GUI/releases/latest");
}
}*/
}
Logger.Log($"[{DateTime.Now.ToString()}]: Initialized");
}
Expand Down
Loading

0 comments on commit 7f512c7

Please sign in to comment.