Skip to content

Commit d7965a2

Browse files
committed
ModApi.UpdateManager: remove broken support for current.info
1 parent 8fa9a73 commit d7965a2

File tree

1 file changed

+39
-56
lines changed

1 file changed

+39
-56
lines changed

ModApi.UpdateManager/UpdateManager.cs

Lines changed: 39 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public static class UpdateManager
2727
public static string PathPrefix = LauncherKitUpdateUrls.First();
2828
public static string AppDataPath = Environment.ExpandEnvironmentVariables(@"%appdata%\Spore ModAPI Launcher");
2929
public static string UpdateInfoDestPath = Path.Combine(AppDataPath, "update.info");
30-
public static string CurrentInfoDestPath = Path.Combine(AppDataPath, "current.info");
3130
public static string UpdaterDestPath = Path.Combine(AppDataPath, "updater.exe");
3231
public static string UpdaterBlockPath = Path.Combine(AppDataPath, "noUpdateCheck.info");
3332
public static string UpdaterOverridePath = Path.Combine(AppDataPath, "overrideUpdatePath.info");
@@ -183,81 +182,65 @@ public static void CheckForUpdates()
183182
}
184183
}
185184

186-
if (!File.Exists(CurrentInfoDestPath))
187-
{
188-
string[] currentInfoLines = new string[]
189-
{
190-
new Version(1, 0, 0, 0).ToString(),
191-
CurrentVersion.ToString(),
192-
false.ToString(),
193-
Path.Combine(PathPrefix, "ModAPIUpdateSetup.exe")
194-
};
195-
196-
File.WriteAllLines(CurrentInfoDestPath, currentInfoLines);
197-
}
198-
199185
if (File.Exists(UpdateInfoDestPath))
200186
{
201-
if (File.ReadAllText(CurrentInfoDestPath) != File.ReadAllText(UpdateInfoDestPath))
187+
var updateInfoLines = File.ReadAllLines(UpdateInfoDestPath);
188+
if (Version.TryParse(updateInfoLines[0], out Version ModApiSetupVersion) &&
189+
ModApiSetupVersion == new Version(1, 0, 0, 0))
202190
{
203-
var updateInfoLines = File.ReadAllLines(UpdateInfoDestPath);
204-
if (Version.TryParse(updateInfoLines[0], out Version ModApiSetupVersion) &&
205-
ModApiSetupVersion == new Version(1, 0, 0, 0))
191+
if (Version.Parse(updateInfoLines[1]) > CurrentVersion)
206192
{
207-
if (Version.Parse(updateInfoLines[1]) > CurrentVersion)
208-
{
209-
string versionString = "Current version: " + CurrentVersion + "\nNew version: " + updateInfoLines[1];
193+
string versionString = "Current version: " + CurrentVersion + "\nNew version: " + updateInfoLines[1];
210194

211-
if (MessageBox.Show("An update to the Spore ModAPI Launcher Kit is now available. Would you like to install it now?\n\n" + versionString, "Update Available", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
195+
if (MessageBox.Show("An update to the Spore ModAPI Launcher Kit is now available. Would you like to install it now?\n\n" + versionString, "Update Available", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
196+
{
197+
if (bool.Parse(updateInfoLines[2]))
212198
{
213-
if (bool.Parse(updateInfoLines[2]))
214-
{
215-
Process.Start(updateInfoLines[3]);
216-
}
217-
else
218-
{
219-
var installerClient = new WebClient();
220-
installerClient.Headers.Add("User-Agent", HttpUserAgent);
199+
Process.Start(updateInfoLines[3]);
200+
}
201+
else
202+
{
203+
var installerClient = new WebClient();
204+
installerClient.Headers.Add("User-Agent", HttpUserAgent);
221205

222-
if (File.Exists(UpdaterDestPath))
223-
File.Delete(UpdaterDestPath);
206+
if (File.Exists(UpdaterDestPath))
207+
File.Delete(UpdaterDestPath);
224208

225-
installerClient.DownloadFile(updateInfoLines[3], UpdaterDestPath);
209+
installerClient.DownloadFile(updateInfoLines[3], UpdaterDestPath);
226210

227-
if (File.Exists(UpdaterDestPath))
211+
if (File.Exists(UpdaterDestPath))
212+
{
213+
if (new FileInfo(UpdaterDestPath).Length > 0)
228214
{
229-
if (new FileInfo(UpdaterDestPath).Length > 0)
230-
{
231-
var args = Environment.GetCommandLineArgs().ToList();
215+
var args = Environment.GetCommandLineArgs().ToList();
232216

233-
string currentArgs = string.Empty;
234-
foreach (string s in args)
235-
currentArgs += "\"" + s.TrimEnd('\\') + "\" ";
217+
string currentArgs = string.Empty;
218+
foreach (string s in args)
219+
currentArgs += "\"" + s.TrimEnd('\\') + "\" ";
236220

237-
string argOnePath = Directory.GetParent(System.Reflection.Assembly.GetEntryAssembly().Location).ToString().TrimEnd('\\');
238-
if (!argOnePath.EndsWith(" "))
239-
argOnePath = argOnePath + " ";
221+
string argOnePath = Directory.GetParent(System.Reflection.Assembly.GetEntryAssembly().Location).ToString().TrimEnd('\\');
222+
if (!argOnePath.EndsWith(" "))
223+
argOnePath = argOnePath + " ";
240224

241-
Process.Start(UpdaterDestPath, "\"" + argOnePath + "\" " + currentArgs);
242-
Process.GetCurrentProcess().Kill();
243-
}
244-
else
245-
{
246-
File.Delete(UpdaterDestPath);
247-
}
225+
Process.Start(UpdaterDestPath, "\"" + argOnePath + "\" " + currentArgs);
226+
Process.GetCurrentProcess().Kill();
227+
}
228+
else
229+
{
230+
File.Delete(UpdaterDestPath);
248231
}
249232
}
250233
}
251-
252234
}
235+
253236
}
254-
else
255-
ShowUnrecognizedUpdateInfoVersionMessage();
256237
}
257238
else
258-
{
259-
File.Delete(UpdateInfoDestPath);
260-
}
239+
ShowUnrecognizedUpdateInfoVersionMessage();
240+
}
241+
else
242+
{
243+
File.Delete(UpdateInfoDestPath);
261244
}
262245

263246
if (DllsUpdater.HasDllsUpdate(out var githubRelease))

0 commit comments

Comments
 (0)