Skip to content

Commit

Permalink
Simplified Updater and fixed bugs
Browse files Browse the repository at this point in the history
The updater was remade to have a public interface simplifying interaction between client.
  • Loading branch information
WilliamRagstad committed May 7, 2020
1 parent a14ae0b commit 07d8097
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 28 deletions.
1 change: 0 additions & 1 deletion CSGO Font Manager/CSGO Font Manager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="ProtectedSettings.cs" />
<Compile Include="Settings.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
Expand Down
64 changes: 38 additions & 26 deletions CSGO Font Manager/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public partial class Form1 : Form

private static string SettingsFile = DataPath + "settings.json";
private static string UpdaterFile = DataPath + "updater.exe";
private static string UpdaterExecName = "FontManagerUpdater";

public static Settings Settings;
public static JsonManager<Settings> SettingsManager;
Expand Down Expand Up @@ -88,12 +89,12 @@ private void AutoFocusRunningInstance()
SetForegroundWindow(runningFM[0].MainWindowHandle);
Environment.Exit(0);
}
// Not implemented
}

private void checkForUpdates()
{
/*
if (Settings.HideNewUpdates) return;

string versionPattern = @"(\d+\.)(\d+\.?)+";

// Get new version
Expand All @@ -106,8 +107,6 @@ private void checkForUpdates()
using(var content = response.GetResponseStream())
using(var reader = new StreamReader(content)){
newVersion = reader.ReadToEnd().Replace("\n","");
if (newVersion == Settings.HideNewVersions) return;
}
}
catch (Exception e)
Expand All @@ -121,7 +120,7 @@ private void checkForUpdates()
Console.WriteLine("New version number is in an invalid format.");
return;
}

string rawLocalVersion = VersionNumber.Remove(VersionNumber.IndexOf('.') ,1).Replace(".",",").Split(' ')[0]; // Split in case version
string rawNewVersion = newVersion.Remove(newVersion.IndexOf('.') ,1).Replace(".",",").Split(' ')[0]; // number contains "2.2 Alpha"
// Convert to a comparable number
Expand All @@ -134,30 +133,44 @@ private void checkForUpdates()

if (MessageBox.Show(
$"Version {newVersion} is available to download from the official GitHub Repo!\n\n" +
"Do you want to continue getting update notifications?",
"Update Available", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
"Do you want to download the update now?",
"Update Available", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
{
Settings.HideNewVersions = VersionNumber;
// Call updater.exe
string fmExe = System.Reflection.Assembly.GetExecutingAssembly().Location;
var processInfo = new ProcessStartInfo
{
UseShellExecute = false,
RedirectStandardError = true,
RedirectStandardOutput = true,
CreateNoWindow = true,
FileName = UpdaterFile,
Arguments = $"\"{VersionNumber}\" \"{fmExe}\""
};
Process p = Process.Start(processInfo);
p.WaitForExit();

string output = p.StandardOutput.ReadLine();
string err = p.StandardError.ReadLine();
}
else if (MessageBox.Show(
$"Do you want to continue getting update notifications?\n" +
$"You will be required to manually download the next release yourself.",
"Update Notifications", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
{
Settings.HideNewUpdates = true;
}
}
*/
}

// Call updater.exe
string fmExe = System.Reflection.Assembly.GetExecutingAssembly().Location;
var processInfo = new ProcessStartInfo
private static void ExtractUpdater()
{
Process[] runningFM = Process.GetProcessesByName(UpdaterExecName);
if (runningFM.Length == 0)
{
UseShellExecute = false,
RedirectStandardError = true,
RedirectStandardOutput = true,
CreateNoWindow = true,
FileName = UpdaterFile,
Arguments = $"\"{ProtectedSettings.Token}\" \"{VersionNumber}\" \"{fmExe}\""
};
Process p = Process.Start(processInfo);
p.WaitForExit();

string output = p.StandardOutput.ReadLine();
string err = p.StandardError.ReadLine();
// Extract updater
File.WriteAllBytes(UpdaterFile, Properties.Resources.updater);
}
}

private static void SetupFolderStructure()
Expand All @@ -168,8 +181,7 @@ private static void SetupFolderStructure()
Directory.CreateDirectory(FontsFolder);
Directory.CreateDirectory(DataPath);

// Extract updater
File.WriteAllBytes(UpdaterFile, Properties.Resources.updater);
ExtractUpdater();
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion CSGO Font Manager/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class Settings
{
public string CsgoPath { get; set; }
public bool ProTips { get; set; } = true;
public string HideNewVersions { get; set; }
public bool HideNewUpdates { get; set; }
public string ActiveFont { get; set; }
}
}
Binary file not shown.
Binary file not shown.

0 comments on commit 07d8097

Please sign in to comment.