///<summary> /// Load settings from settings file ///</summary> public void LoadSettings() { if (UsedSettingsFile == string.Empty) { // wenn noch keine datei angelegt wurde, diese hier initial erzeugen. _settings = new UserSettings { Interval = 60, ServerPath = "", SimObjectsPath = "", Username = "" }; UsedSettingsFile = "init.xml"; SaveSettings(); } _settings = DeSerializer.Deserializer <UserSettings>(UsedSettingsFile); }
/** * Gets local version information. */ public void GetLocalData() { SettingsManager.Instance.ContinueUpdate = false; SettingsManager.Instance.ErrorPosition = ErrorPosition.Localinformation; try { _localInformation = DeSerializer.Deserializer <LocalInformation>(Path.GetFullPath(Strings.FILE_LOCAL_INFORMATION)); if (LocalInformation.UpdateServerUrl != "" && LocalInformation.UpdateServerUrl != null) { _gotLocal = true; SettingsManager.Instance.ContinueUpdate = true; } } catch { } }
public Overview GetOverviewFromFile(string overviewFile) { return(DeSerializer.Deserializer <Overview>(overviewFile)); }
public VersionInformation GetVersionInformationFromFile(string filePath) { return(DeSerializer.Deserializer <VersionInformation>(filePath)); }
/** * Get detailed remote version information. * Recursivly get all remote version information from newest avaiable down to current version. * Depends on applies to value in version information. * @param version newest version number */ public void GetVersions(string version) { // If fetching local and overview informations finished successfully continue with update. if (_gotLocal && _gotOverview) { SettingsManager.Instance.ContinueUpdate = false; SettingsManager.Instance.ErrorPosition = ErrorPosition.Remoteinformation; // Check if temporary folder for version exists. If not, create it. if (Directory.Exists(Path.GetFullPath( new StringBuilder().Append(Strings.FOLDER_UPDATE_INFORMATION) .Append(Path.DirectorySeparatorChar) .Append(version) .ToString()))) { } else { Directory.CreateDirectory(Path.GetFullPath( new StringBuilder().Append(Strings.FOLDER_UPDATE_INFORMATION) .Append(Path.DirectorySeparatorChar) .Append(version) .ToString())); } bool finishedDownloadOK = false; // Download via HTTP or HTTPS. if (LocalInformation.UpdateServerUrl.Contains(Strings.SEARCHSTRING_HTTP) || LocalInformation.UpdateServerUrl.Contains(Strings.SEARCHSTRING_HTTPS)) { Downloader overviewdownloader = new Downloader(); DownloaderState state = WebDownload(overviewdownloader, new StringBuilder() .Append(LocalInformation.UpdateServerUrl) .Append(Path.DirectorySeparatorChar) .Append(version) .Append(Path.DirectorySeparatorChar) .Append(Strings.FILE_VERSION_INFORMATION) .ToString(), new StringBuilder() .Append(Strings.FOLDER_UPDATE_INFORMATION) .Append(Path.DirectorySeparatorChar) .Append(version) .Append(Path.DirectorySeparatorChar) .Append(Strings.FILE_VERSION_INFORMATION) .ToString()); while (!overviewdownloader.DownloadFinished) { Thread.Sleep(100); Application.DoEvents(); } if (overviewdownloader.ErrorMessage != null) { MessageBox.Show(overviewdownloader.ErrorMessage); } else { finishedDownloadOK = true; } // Download from LAN or local device. } else if (LocalInformation.UpdateServerUrl.StartsWith(Strings.STARTSTRING_LAN) || LocalInformation.UpdateServerUrl.Contains(Strings.SEARCHSTRING_LOCAL)) { // use network or local path to get information Downloader overviewdownloader = new Downloader(); DownloaderState state = overviewdownloader.Download( new StringBuilder() .Append(LocalInformation.UpdateServerUrl) .Append(Path.DirectorySeparatorChar) .Append(version) .Append(Path.DirectorySeparatorChar) .Append(Strings.FILE_VERSION_INFORMATION) .ToString(), new StringBuilder() .Append(Strings.FOLDER_UPDATE_INFORMATION) .Append(Path.DirectorySeparatorChar) .Append(version) .Append(Path.DirectorySeparatorChar) .Append(Strings.FILE_VERSION_INFORMATION) .ToString(), null, null); while (!overviewdownloader.DownloadFinished) { Thread.Sleep(100); Application.DoEvents(); } if (overviewdownloader.ErrorMessage != null) { MessageBox.Show(overviewdownloader.ErrorMessage); } else { finishedDownloadOK = true; } } // If download finished try to deserialize information. if (finishedDownloadOK) { try { _remoteVersions.Add(DeSerializer.Deserializer <VersionInformation>( new StringBuilder() .Append(Strings.FOLDER_UPDATE_INFORMATION) .Append(Path.DirectorySeparatorChar) .Append(version) .Append(Path.DirectorySeparatorChar) .Append(Strings.FILE_VERSION_INFORMATION) .ToString())); SettingsManager.Instance.ContinueUpdate = true; } catch { return; } } // Check if last downloaded version matches local installation. If not, get next previous version. if (_remoteVersions[_remoteVersions.Count - 1].AppliesToVersion.ToString() == _localInformation.CurrentVersion.ToString() || !SettingsManager.Instance.ContinueUpdate) { } else { GetVersions(_remoteVersions[_remoteVersions.Count - 1].AppliesToVersion.ToString()); } } }
/** * Download overview data. * @see WebDownload() * @see LocalDownload() */ public void GetOverview() { if (_gotLocal) { SettingsManager.Instance.ContinueUpdate = false; SettingsManager.Instance.ErrorPosition = ErrorPosition.Overview; bool finishedDownloadOK = false; // Download overview via HTTP or HTTPS. if (LocalInformation.UpdateServerUrl.Contains(Strings.SEARCHSTRING_HTTP) || LocalInformation.UpdateServerUrl.Contains(Strings.SEARCHSTRING_HTTPS)) { // Instantiate new downloader. Downloader overviewdownloader = new Downloader(); DownloaderState state = WebDownload( overviewdownloader, new StringBuilder().Append(LocalInformation.UpdateServerUrl).Append(Strings.FILE_OVERVIEW).ToString(), new StringBuilder().Append(Strings.FOLDER_UPDATE_INFORMATION) .Append(Path.DirectorySeparatorChar) .Append(Strings.FILE_OVERVIEW) .ToString() ); while (!overviewdownloader.DownloadFinished) { Thread.Sleep(100); Application.DoEvents(); } if (overviewdownloader.ErrorMessage != null) { if (SettingsManager.Instance.UseGUI) { MessageBox.Show(overviewdownloader.ErrorMessage); } } else { finishedDownloadOK = true; } // Download overview from LAN or local device. } else if (LocalInformation.UpdateServerUrl.StartsWith(Strings.STARTSTRING_LAN) || LocalInformation.UpdateServerUrl.Contains(Strings.SEARCHSTRING_LOCAL)) { // use network or local path to get information Downloader overviewdownloader = new Downloader(); DownloaderState state = overviewdownloader.Download( new StringBuilder().Append(LocalInformation.UpdateServerUrl) .Append(Path.DirectorySeparatorChar) .Append(Strings.FILE_OVERVIEW) .ToString(), new StringBuilder().Append(Strings.FOLDER_UPDATE_INFORMATION) .Append(Path.DirectorySeparatorChar) .Append(Strings.FILE_OVERVIEW) .ToString(), null, null); if (overviewdownloader.ErrorMessage != null) { if (SettingsManager.Instance.UseGUI) { MessageBox.Show(overviewdownloader.ErrorMessage); } } else { finishedDownloadOK = true; } } // Try to deserialize overview data if download finished successfully. // Else return from GetOverview(). if (finishedDownloadOK) { try { _overview = DeSerializer.Deserializer <Overview>( new StringBuilder().Append(Strings.FOLDER_UPDATE_INFORMATION) .Append(Path.DirectorySeparatorChar) .Append(Strings.FILE_OVERVIEW) .ToString()); } catch { return; } } // Continues update if version information found in overview. if (_overview != null) { if (_overview.Versions.Count > 0) { _gotOverview = true; SettingsManager.Instance.ContinueUpdate = true; } } } }
public static void StartSync() { // load local catalog CustomObjectCatalog localObjects = null; try { localObjects = DeSerializer.Deserializer <CustomObjectCatalog>("localObjects.xml"); } catch { } if (localObjects == null) { bool ok = DeSerializer.Serialize <CustomObjectCatalog>(new CustomObjectCatalog(new List <CustomObject>()), "localObjects.xml"); if (ok) { localObjects = DeSerializer.Deserializer <CustomObjectCatalog>("localObjects.xml"); } } if (localObjects != null) { // ask for update // TODO: invoke message box to ask user if he realy wants to sync. // get catalog from net Nme2Ws.Nme2Ws ws = new Nme2Ws.Nme2Ws(); CustomObjectCatalog webObjects = new CustomObjectCatalog(ws.CustomObjectServiceGetAllCustomObjectsAsArray()); // compare catalog IList <LocalCustomObject> toBeDeleted = new List <LocalCustomObject>(); IList <LocalCustomObject> newItems = new List <LocalCustomObject>(); foreach (LocalCustomObject webObject in webObjects.CustomObjects) { bool exists = false; foreach (LocalCustomObject localObject in localObjects.CustomObjects) { if (webObject.Id == localObject.Id && webObject.Version == localObject.Version) { exists = true; } else if (webObject.Id == localObject.Id && webObject.Version != localObject.Version) { exists = true; if (!toBeDeleted.Contains(webObject)) { toBeDeleted.Add(localObject); } if (!newItems.Contains(webObject)) { newItems.Add(webObject); } } } if (!exists) { if (!newItems.Contains(webObject)) { newItems.Add(webObject); } } } foreach (LocalCustomObject localObject in localObjects.CustomObjects) { bool clearedForDelete = true; foreach (LocalCustomObject webObject in webObjects.CustomObjects) { if (localObject.Id == webObject.Id) { clearedForDelete = false; } } if (clearedForDelete) { if (!toBeDeleted.Contains(localObject)) { toBeDeleted.Add(localObject); } } } // delete old items string customObjectPath = Settings.Default.CustomSimObjectPath; foreach (LocalCustomObject localOject in toBeDeleted) { Directory.Delete(customObjectPath + Path.DirectorySeparatorChar + localOject.Id + "_" + localOject.Version, true); } // download new items foreach (LocalCustomObject webObject in newItems) { // extract to custom object folder WebClient client = new WebClient(); // Load new object from remot to [temp] string copysource = webObject.DownloadPath; string destinationFilename = webObject.Id + "_" + webObject.Version + ".zip"; string unzipDestination = webObject.Id + "_" + webObject.Version; string destination = "./[temp]/" + destinationFilename; System.Diagnostics.Trace.Write(copysource); //Console.ForegroundColor = Program.ConsoleOrange; System.Diagnostics.Trace.Write("Inet access for download ..."); client.DownloadFile(copysource, destination); //File.Copy(copysource, "./[temp]/" + ObjectName.Replace('.', '_') + ".zip",true); //Console.ForegroundColor = Program.ConsoleGreen; System.Diagnostics.Trace.Write("... completed"); //Console.ForegroundColor = Program.ConsoleWhite; // unzip to simobject folder string unzipdir = customObjectPath + Path.DirectorySeparatorChar + unzipDestination; Directory.CreateDirectory(unzipdir); UnZipFiles(destination, unzipdir, "", false); // delete from [temp] File.Delete(destination); } // save catalog as new local DeSerializer.Serialize(webObjects, "localObjects.xml"); } }
private static void Main(string[] args) { #region Add logging log = LogManager.GetLogger(typeof(Program)); log.Debug("Starting updater update."); #endregion #region Wait for SoftwareUpdater.exe log.Info("Waiting for software updater process."); bool wait = true; while (wait) { foreach (Process clsProcess in Process.GetProcesses()) { wait = (clsProcess.ProcessName.Contains("SoftwareUpdater") || clsProcess.ProcessName.Contains("SoftwareUpdater.vshost")); if (wait) { break; } } Thread.Sleep(500); } #endregion #region Confirm args string filelist = "", downloads = "", backup = "", basepath = "", gui = ""; if (args.Length == 5) { if (!File.Exists(args[0])) { log.Info("Error within filelist path: " + args[0]); Exit(1); } filelist = args[0]; if (!Directory.Exists(args[1])) { log.Info("Error within download path: " + args[1]); Exit(1); } downloads = args[1]; if (!Directory.Exists(args[2])) { log.Info("Error within backup path: " + args[2]); Exit(1); } backup = args[2]; if (!Directory.Exists(args[3])) { log.Info("Error within basepath: " + args[3]); Exit(1); } basepath = args[3]; if (!args[4].Contains("gui")) { log.Info("Error within gui selector: " + args[4]); Exit(1); } gui = args[4]; } else { log.Info("Wrong args count."); foreach (string arg in args) { log.Info(arg); } Exit(1); } #endregion #region Copy files // get filelist List <UpdateFile> filestocopy = DeSerializer.Deserializer <List <UpdateFile> >(filelist); // copy file from download dir try { CopyDirectory(downloads, basepath, true); log.Info("Copy of new updater software successfully finished."); } catch (Exception ex) { CopyDirectory(backup, basepath, true); log.Info(ex.Message); Exit(2); } #endregion #region Get version information string versioninfpath = backup.Replace("\\Backup", ""); VersionInformation inf = DeSerializer.Deserializer <VersionInformation>(versioninfpath + Path.DirectorySeparatorChar + "info.xml"); #endregion #region Update local information LocalInformation local = DeSerializer.Deserializer <LocalInformation>(basepath + Path.DirectorySeparatorChar + "info.xml"); local.CurrentVersion = inf.ResultsInVersion; DeSerializer.Serialize(local, basepath + Path.DirectorySeparatorChar + "info.xml"); #endregion #region Delete filelist if (File.Exists(filelist)) { File.Delete(filelist); } #endregion #region Start software updater Process proc = new Process(); if (gui == "/nogui") { Process.Start( new StringBuilder().Append(basepath).Append(Path.DirectorySeparatorChar).Append("SoftwareUpdater.exe").ToString(), "/nogui"); } else { Process.Start( new StringBuilder().Append(basepath).Append(Path.DirectorySeparatorChar).Append("SoftwareUpdater.exe").ToString()); } #endregion // exit with 0 when succesfully finished Exit(0); }