/// <summary> /// Checks if version from Output.cs is same/newer than version from VersionPath file. Also deletes possible backup of older Launcher version. /// </summary> private bool IsUpToDate() { string versionOnWeb = null; try { using (var client = new AmWebClient(3000)) versionOnWeb = client.DownloadString(c.SubElText("Paths", "VersionPath")); } catch { o.Messagebox(c.SubElText("Messages", "VersionNotVerified")); return(true); } double webVersion; if (Double.TryParse(versionOnWeb.Trim(), NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out webVersion)) { return(webVersion <= c.version); } else { o.Messagebox(c.SubElText("Messages", "VersionNotVerified")); return(true); } }
/// <summary> /// Renames Launcher's files and downloads new ones. Unzips them and restarts a Launcher. /// </summary> private void UpdateSelf() { string cwd = Directory.GetCurrentDirectory(); string exeName = cwd + "\\" + AppDomain.CurrentDomain.FriendlyName; MessageBox.Show(c.SubElText("Messages", "OutdatedLauncher")); // Clean up possible mess in the way. if (File.Exists(cwd + "\\OldLauncher.exe")) { File.Delete(cwd + "\\OldLauncher.exe"); } if (File.Exists(cwd + "\\OldLauncherConfig.xml")) { File.Delete(cwd + "\\OldLauncherConfig.xml"); } if (File.Exists(cwd + "\\OldLauncherIcon.ico")) { File.Delete(cwd + "\\OldLauncherIcon.ico"); } // Backup current files. if (File.Exists(exeName)) { File.Move(exeName, cwd + "\\OldLauncher.exe"); } if (File.Exists(cwd + "\\LauncherConfig.xml")) { File.Move(cwd + "\\LauncherConfig.xml", cwd + "\\OldLauncherConfig.xml"); } if (File.Exists(cwd + "\\LauncherIcon.ico")) { File.Move(cwd + "\\LauncherIcon.ico", cwd + "\\OldLauncherIcon.ico"); } try { if (File.Exists(cwd + "\\Launcher.zip")) { File.Delete(cwd + "\\Launcher.zip"); } // Download new Launcher. using (var client = new AmWebClient(3000)) { client.DownloadFile(c.SubElText("Paths", "LauncherPath"), cwd + "\\Launcher.zip"); } // Unzip new Launcher. Shell32.Shell objShell = new Shell32.Shell(); Shell32.Folder destinationFolder = objShell.NameSpace(cwd); Shell32.Folder sourceFile = objShell.NameSpace(cwd + "\\Launcher.zip"); foreach (var zipFile in sourceFile.Items()) { destinationFolder.CopyHere(zipFile, 4 | 16); } // Remove zip. File.Delete(cwd + "\\Launcher.zip"); // Start a new Launcher. Process.Start(exeName); newsPictureBox.CancelAsync(); Close(); } catch (Exception e) { // Return things to previous state. if (File.Exists(cwd + "\\OldLauncher.exe")) { File.Move(cwd + "\\OldLauncher.exe", exeName); } if (File.Exists(cwd + "\\OldLauncherConfig.xml")) { File.Move(cwd + "\\OldLauncherConfig.xml", cwd + "\\LauncherConfig.xml"); } if (File.Exists(cwd + "\\OldLauncherIcon.ico")) { File.Move(cwd + "\\OldLauncherIcon.ico", cwd + "\\LauncherIcon.ico"); } o.Messagebox("CouldNotBeUpdated", e); updateButt.Enabled = false; launchButt.Enabled = false; } }