private ProtocolOptions LoadPropertiesFromDatabase() { using (Database database = DatabaseConnections.CreateInstance()) { string serializedProperties = database.GetProtocolPropertiesByFavorite(this.favorite.Id); Type propertiesType = this.favorite.protocolProperties.GetType(); return(Serialize.DeSerializeXML(serializedProperties, propertiesType) as ProtocolOptions); } }
private static ToolStripSettings LoadFromXmlString(string xmlContent) { return((ToolStripSettings)Serialize.DeSerializeXML(xmlContent, typeof(ToolStripSettings), false)); }
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); } }