Skip to content

Commit 07d8097

Browse files
Simplified Updater and fixed bugs
The updater was remade to have a public interface simplifying interaction between client.
1 parent a14ae0b commit 07d8097

File tree

5 files changed

+39
-28
lines changed

5 files changed

+39
-28
lines changed

CSGO Font Manager/CSGO Font Manager.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@
106106
<DesignTime>True</DesignTime>
107107
<DependentUpon>Resources.resx</DependentUpon>
108108
</Compile>
109-
<Compile Include="ProtectedSettings.cs" />
110109
<Compile Include="Settings.cs" />
111110
<EmbeddedResource Include="Form1.resx">
112111
<DependentUpon>Form1.cs</DependentUpon>

CSGO Font Manager/Form1.cs

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public partial class Form1 : Form
3434

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

3839
public static Settings Settings;
3940
public static JsonManager<Settings> SettingsManager;
@@ -88,12 +89,12 @@ private void AutoFocusRunningInstance()
8889
SetForegroundWindow(runningFM[0].MainWindowHandle);
8990
Environment.Exit(0);
9091
}
91-
// Not implemented
9292
}
9393

9494
private void checkForUpdates()
9595
{
96-
/*
96+
if (Settings.HideNewUpdates) return;
97+
9798
string versionPattern = @"(\d+\.)(\d+\.?)+";
9899

99100
// Get new version
@@ -106,8 +107,6 @@ private void checkForUpdates()
106107
using(var content = response.GetResponseStream())
107108
using(var reader = new StreamReader(content)){
108109
newVersion = reader.ReadToEnd().Replace("\n","");
109-
110-
if (newVersion == Settings.HideNewVersions) return;
111110
}
112111
}
113112
catch (Exception e)
@@ -121,7 +120,7 @@ private void checkForUpdates()
121120
Console.WriteLine("New version number is in an invalid format.");
122121
return;
123122
}
124-
123+
125124
string rawLocalVersion = VersionNumber.Remove(VersionNumber.IndexOf('.') ,1).Replace(".",",").Split(' ')[0]; // Split in case version
126125
string rawNewVersion = newVersion.Remove(newVersion.IndexOf('.') ,1).Replace(".",",").Split(' ')[0]; // number contains "2.2 Alpha"
127126
// Convert to a comparable number
@@ -134,30 +133,44 @@ private void checkForUpdates()
134133

135134
if (MessageBox.Show(
136135
$"Version {newVersion} is available to download from the official GitHub Repo!\n\n" +
137-
"Do you want to continue getting update notifications?",
138-
"Update Available", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
136+
"Do you want to download the update now?",
137+
"Update Available", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
139138
{
140-
Settings.HideNewVersions = VersionNumber;
139+
// Call updater.exe
140+
string fmExe = System.Reflection.Assembly.GetExecutingAssembly().Location;
141+
var processInfo = new ProcessStartInfo
142+
{
143+
UseShellExecute = false,
144+
RedirectStandardError = true,
145+
RedirectStandardOutput = true,
146+
CreateNoWindow = true,
147+
FileName = UpdaterFile,
148+
Arguments = $"\"{VersionNumber}\" \"{fmExe}\""
149+
};
150+
Process p = Process.Start(processInfo);
151+
p.WaitForExit();
152+
153+
string output = p.StandardOutput.ReadLine();
154+
string err = p.StandardError.ReadLine();
155+
}
156+
else if (MessageBox.Show(
157+
$"Do you want to continue getting update notifications?\n" +
158+
$"You will be required to manually download the next release yourself.",
159+
"Update Notifications", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
160+
{
161+
Settings.HideNewUpdates = true;
141162
}
142163
}
143-
*/
164+
}
144165

145-
// Call updater.exe
146-
string fmExe = System.Reflection.Assembly.GetExecutingAssembly().Location;
147-
var processInfo = new ProcessStartInfo
166+
private static void ExtractUpdater()
167+
{
168+
Process[] runningFM = Process.GetProcessesByName(UpdaterExecName);
169+
if (runningFM.Length == 0)
148170
{
149-
UseShellExecute = false,
150-
RedirectStandardError = true,
151-
RedirectStandardOutput = true,
152-
CreateNoWindow = true,
153-
FileName = UpdaterFile,
154-
Arguments = $"\"{ProtectedSettings.Token}\" \"{VersionNumber}\" \"{fmExe}\""
155-
};
156-
Process p = Process.Start(processInfo);
157-
p.WaitForExit();
158-
159-
string output = p.StandardOutput.ReadLine();
160-
string err = p.StandardError.ReadLine();
171+
// Extract updater
172+
File.WriteAllBytes(UpdaterFile, Properties.Resources.updater);
173+
}
161174
}
162175

163176
private static void SetupFolderStructure()
@@ -168,8 +181,7 @@ private static void SetupFolderStructure()
168181
Directory.CreateDirectory(FontsFolder);
169182
Directory.CreateDirectory(DataPath);
170183

171-
// Extract updater
172-
File.WriteAllBytes(UpdaterFile, Properties.Resources.updater);
184+
ExtractUpdater();
173185
}
174186
else
175187
{

CSGO Font Manager/Settings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class Settings
1010
{
1111
public string CsgoPath { get; set; }
1212
public bool ProTips { get; set; } = true;
13-
public string HideNewVersions { get; set; }
13+
public bool HideNewUpdates { get; set; }
1414
public string ActiveFont { get; set; }
1515
}
1616
}
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)