private static void PerformCheck(object state) { try { CheckForCodeplexRelease(); } catch (Exception exc) { Terminals.Logging.Log.Error("Failed during CheckForCodeplexRelease.", exc); } try { string autoUpdate = Terminals.MainForm.CommandLineArgs.AutomaticallyUpdate; if (autoUpdate != null) { bool update = false; if (bool.TryParse(autoUpdate, out update) && update == true) { string url = Settings.UpdateSource; string contents = Download(url); if (!String.IsNullOrEmpty(contents)) { TerminalsUpdates updates = (TerminalsUpdates)Unified.Serialize.DeSerializeXML(contents, typeof(TerminalsUpdates)); if (updates != null) { string currentMD5 = GetMD5HashFromFile("Terminals.exe"); if (currentMD5 != null) { //get the latest build System.Data.DataRow row = updates.Tables[0].Rows[0]; string md5 = (row["MD5"] as string); if (!md5.Equals(currentMD5)) { string version = (row["version"] as string); if (!System.IO.Directory.Exists("Builds")) { System.IO.Directory.CreateDirectory("Builds"); } string finalFolder = @"Builds\" + version; if (!System.IO.Directory.Exists(finalFolder)) { System.IO.Directory.CreateDirectory(finalFolder); } string filename = string.Format("{0}.zip", version); filename = @"Builds\" + filename; bool downloaded = true; if (!System.IO.File.Exists(filename)) { downloaded = DownloadNewBuild((row["Url"] as string), filename); } if (downloaded && System.IO.File.Exists(filename)) { //ICSharpCode.SharpZipLib.Zip.FastZipEvents evts = new ICSharpCode.SharpZipLib.Zip.FastZipEvents(); ICSharpCode.SharpZipLib.Zip.FastZip fz = new ICSharpCode.SharpZipLib.Zip.FastZip(); fz.ExtractZip(filename, finalFolder, null); if (System.Windows.Forms.MessageBox.Show("A new build is available, would you like to install it now", "New Build", System.Windows.Forms.MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.OK) { System.IO.DirectoryInfo parent = FindFileInFolder(new DirectoryInfo(finalFolder), "Terminals.exe"); if (parent == null) { return; } else { finalFolder = parent.FullName; } System.IO.File.Copy("Terminals.config", System.IO.Path.Combine(finalFolder, "Terminals.config"), true); System.IO.File.Copy("ToolStrip.settings", System.IO.Path.Combine(finalFolder, "ToolStrip.settings"), true); System.IO.File.Copy("Terminals.log4net.config", System.IO.Path.Combine(finalFolder, "Terminals.log4net.config"), true); string temp = System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); string updaterExe = System.IO.Path.Combine(temp, "TerminalsUpdater.exe"); if (System.IO.File.Exists(System.IO.Path.Combine(finalFolder, "TerminalsUpdater.exe"))) { System.IO.File.Copy(System.IO.Path.Combine(finalFolder, "TerminalsUpdater.exe"), updaterExe, true); } //updaterExe = @"C:\Source\Terminals\Terminals\bin\Debug\"; if (System.IO.File.Exists(updaterExe)) { string args = "\"" + finalFolder + "\" \"" + System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\""; System.Diagnostics.Process.Start(updaterExe, args); System.Windows.Forms.Application.Exit(); } } } } } } } } } } catch (Exception exc) { Terminals.Logging.Log.Error("Failed during update.", exc); } }
private static void DownloadLatestRelease() { try { String url = Settings.Instance.UpdateSource; string contents = DownloadAsString(url); if (!String.IsNullOrEmpty(contents)) { TerminalsUpdates updates = (TerminalsUpdates)Serialize.DeSerializeXML(contents, typeof(TerminalsUpdates)); if (updates != null) { String currentMd5 = GetMd5HashFromFile("Terminals.exe"); if (currentMd5 != null) { //get the latest build System.Data.DataRow row = updates.Tables[0].Rows[0]; String md5 = (row["MD5"] as string); if (!md5.Equals(currentMd5)) { String version = (row["version"] as String); if (!Directory.Exists("Builds")) { Directory.CreateDirectory("Builds"); } String finalFolder = @"Builds\" + version; if (!Directory.Exists(finalFolder)) { Directory.CreateDirectory(finalFolder); } String filename = String.Format("{0}.zip", version); filename = @"Builds\" + filename; Boolean downloaded = true; if (!File.Exists(filename)) { string targetUrl = row["Url"] as String; downloaded = SaveHttpToFile(targetUrl, filename); } if (downloaded && File.Exists(filename)) { //ICSharpCode.SharpZipLib.Zip.FastZipEvents evts = new ICSharpCode.SharpZipLib.Zip.FastZipEvents(); FastZip fz = new FastZip(); fz.ExtractZip(filename, finalFolder, null); if (MessageBox.Show("A new build is available, would you like to install it now", "New Build", MessageBoxButtons.OKCancel) == DialogResult.OK) { DirectoryInfo parent = FindFileInFolder(new DirectoryInfo(finalFolder), "Terminals.exe"); if (parent == null) { return; } finalFolder = parent.FullName; File.Copy(FileLocations.CONFIG_FILENAME, Path.Combine(finalFolder, FileLocations.CONFIG_FILENAME), true); File.Copy("Terminals.log4net.config", Path.Combine(finalFolder, "Terminals.log4net.config"), true); String temp = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); String updaterExe = Path.Combine(temp, "TerminalsUpdater.exe"); if (File.Exists(Path.Combine(finalFolder, "TerminalsUpdater.exe"))) { File.Copy(Path.Combine(finalFolder, "TerminalsUpdater.exe"), updaterExe, true); } //updaterExe = @"C:\Source\Terminals\Terminals\bin\Debug\"; if (File.Exists(updaterExe)) { //String args = "\"" + finalFolder + "\" \"" + Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\""; String args = String.Format("\"{0}\" \"{1}\"", finalFolder, Program.Info.Location); System.Diagnostics.Process.Start(updaterExe, args); Application.Exit(); } } } } } } } } catch (Exception exc) { Logging.Error("Failed during update.", exc); } }
private static void PerformCheck(object state) { try { CheckForNewRelease(); } catch { Log.Warn("Failed during CheckForNewRelease."); return; } try { bool autoUpdate = (state as CommandLineArgs).AutomaticallyUpdate; if (autoUpdate) { { String url = Settings.UpdateSource; String contents = Download(url); if (!String.IsNullOrEmpty(contents)) { TerminalsUpdates updates = (TerminalsUpdates)Serialize.DeSerializeXml(contents, typeof(TerminalsUpdates)); if (updates != null) { String currentMD5 = GetMD5HashFromFile(AssemblyInfo.Title + ".exe"); if (currentMD5 != null) { //get the latest build DataRow row = updates.Tables[0].Rows[0]; String md5 = (row["MD5"] as string); if (!md5.Equals(currentMD5)) { String version = (row["version"] as String); if (!Directory.Exists("Builds")) { Directory.CreateDirectory("Builds"); } String finalFolder = @"Builds\" + version; if (!Directory.Exists(finalFolder)) { Directory.CreateDirectory(finalFolder); } String filename = String.Format("{0}.zip", version); filename = @"Builds\" + filename; Boolean downloaded = true; if (!File.Exists(filename)) { downloaded = DownloadNewBuild((row["Url"] as String), filename); } if (downloaded && File.Exists(filename)) { //ICSharpCode.SharpZipLib.Zip.FastZipEvents evts = new ICSharpCode.SharpZipLib.Zip.FastZipEvents(); FastZip fz = new FastZip(); fz.ExtractZip(filename, finalFolder, null); if ( MessageBox.Show( "A new build is available, would you like to install it now", "New Build", MessageBoxButtons.OKCancel) == DialogResult.OK) { DirectoryInfo parent = FindFileInFolder(new DirectoryInfo(finalFolder), AssemblyInfo.Title + ".exe"); if (parent == null) { return; } finalFolder = parent.FullName; File.Copy(Settings.CONFIG_FILE_NAME, Path.Combine(finalFolder, Settings.CONFIG_FILE_NAME), true); File.Copy(AssemblyInfo.Title + ".log4net.config", Path.Combine(finalFolder, AssemblyInfo.Title + ".log4net.config"), true); String temp = Environment.GetFolderPath( Environment.SpecialFolder.LocalApplicationData); String updaterExe = Path.Combine(temp, AssemblyInfo.Title + "Updater.exe"); if ( File.Exists(Path.Combine(finalFolder, AssemblyInfo.Title + "Updater.exe"))) { File.Copy( Path.Combine(finalFolder, AssemblyInfo.Title + "Updater.exe"), updaterExe, true); } //updaterExe = @"C:\Source\Terminals\Terminals\bin\Debug\"; if (File.Exists(updaterExe)) { //String args = "\"" + finalFolder + "\" \"" + Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\""; String args = String.Format("\"{0}\" \"{1}\"", finalFolder, AssemblyInfo.Location); Process.Start(updaterExe, args); Application.Exit(); } } } } } } } } } } catch (Exception exc) { Log.Error("Failed during update.", exc); } }