private void GetNewVersionNumber(GeneralData generalData, ref int updatedMajorVersionNumber, ref int updatedMinorVersionNumber, ref string updatedVersionNumber) { updatedMajorVersionNumber = generalData.SoftwareMajorVersionNumber; updatedMinorVersionNumber = generalData.SoftwareMinorVersionNumber; updatedVersionNumber = String.Format("{0}.{1}", generalData.SoftwareMajorVersionNumber, generalData.SoftwareMinorVersionNumber); }
private bool GetSettingsFiles(ref GeneralData generalData, ref User user) { for (int i = 0; i < 10; i++) { try { generalData = (GeneralData)Serializer.DeserializeNoLock(typeof(GeneralData), _appDataPath + "\\SettingsData\\ss_general_data.dat", "password"); } catch (IOException) { Thread.Sleep(100); } catch { _log.WriteEntry("Cannot retrieve general settings.", EventLogEntryType.Error); return(false); } } if (generalData == null) { _log.WriteEntry("Cannot retrieve general settings. File was possibly locked", EventLogEntryType.Error); return(false); } for (int i = 0; i < 10; i++) { try { user = (User)Serializer.DeserializeNoLock(typeof(User), _appDataPath + "\\SettingsData\\UserSettings.dat", "password"); } catch (IOException) { Thread.Sleep(100); } catch { _log.WriteEntry("Cannot retrieve user settings.", EventLogEntryType.Error); return(false); } } if (user == null) { _log.WriteEntry("Cannot retrieve user settings. File was possibly locked", EventLogEntryType.Error); return(false); } return(true); }
private static GeneralData GetGeneralData() { GeneralData generalData = null; try { generalData = (GeneralData)Serializer.DeserializeNoLock(typeof(GeneralData), System.Configuration.ConfigurationSettings.AppSettings["AppDataPath"] + "SettingsData\\ss_general_data.dat", "password"); } catch { // can't display interface, so ignore. } return(generalData); }
private bool GetValuesFromGeneralData(GeneralData generalData, ref int maxNoServersDownload, ref int maxNoServersRelay, ref int timeout, ref string primaryDomainName, ref string secondaryDomainName) { if (!int.TryParse(generalData.NoServers["download"], out maxNoServersDownload)) { _log.WriteEntry("Cannot get maximum number of component list download servers.", EventLogEntryType.Error); return(false); } if (!int.TryParse(generalData.NoServers["relayLog"], out maxNoServersRelay)) { _log.WriteEntry("Cannot get maximum number of component list relay servers.", EventLogEntryType.Error); return(false); } if (!int.TryParse(generalData.Properties["serverTimeout"], out timeout)) { _log.WriteEntry("Cannot get timeout download servers.", EventLogEntryType.Error); return(false); } if (!generalData.Properties.ContainsKey("primaryDomainName")) { _log.WriteEntry("Primary domain name not found.", EventLogEntryType.Error); return(false); } else { primaryDomainName = generalData.Properties["primaryDomainName"]; } if (!generalData.Properties.ContainsKey("secondaryDomainName")) { _log.WriteEntry("Secondary domain name not found.", EventLogEntryType.Error); return(false); } else { secondaryDomainName = generalData.Properties["secondaryDomainName"]; } return(true); }
private bool GetSettingsFiles(ref GeneralData generalData, ref User user) { try { generalData = (GeneralData)Serializer.DeserializeNoLock(typeof(GeneralData), _appDataPath + "\\SettingsData\\ss_general_data.dat", "password"); } catch { _log.WriteEntry("Cannot retrieve general settings. Updating will be postponed.", EventLogEntryType.Error); return(false); } try { user = (User)Serializer.DeserializeNoLock(typeof(User), _appDataPath + "\\SettingsData\\UserSettings.dat", "password"); } catch { _log.WriteEntry("Cannot retrieve user settings. Updating will be postponed.", EventLogEntryType.Error); return(false); } return(true); }
private void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("en-GB"); System.Threading.Thread.CurrentThread.CurrentCulture = ci; System.Threading.Thread.CurrentThread.CurrentUICulture = ci; string tempDir = _binariesPath + "Temp\\"; string binTempDir = _binariesPath + "Temp\\Bin\\"; string systemTempDir = _binariesPath + "Temp\\System\\"; // Check if admin has access rights in the binary folder. System folder will always fail as // method checks all fiels and some files are inaccessible. // We only need enough privileges to overwrite the Oxigen files. if (!FileDirectoryRightsChecker.CanCreateDeleteDirectories(_binariesPath) || !FileDirectoryRightsChecker.AreFilesReadableWritable(_binariesPath)) { _log.WriteEntry("Cannot update Oxigen. File and directory access rights are insufficient.", EventLogEntryType.Error); _bError = true; _bCanClose = true; return; } if (!Directory.Exists(binTempDir)) { Directory.CreateDirectory(binTempDir); } else { DeleteAllFiles(binTempDir); } if (!Directory.Exists(systemTempDir)) { Directory.CreateDirectory(systemTempDir); } else { DeleteAllFiles(systemTempDir); } GeneralData generalData = null; User user = null; if (!GetSettingsFiles(ref generalData, ref user)) { MessageBox.Show("Cannot retrieve new version info. Updating will be postponed.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); _bError = true; _bCanClose = true; return; } int maxNoServersDownload = -1; int maxNoServersDelay = -1; int timeout = -1; string primaryDomainName = null; string secondaryDomainName = null; int updatedMajorVersionNumber = -1; int updatedMinorVersionNumber = -1; string updatedVersionNumber = null; if (!GetValuesFromGeneralData(generalData, ref maxNoServersDownload, ref maxNoServersDelay, ref timeout, ref primaryDomainName, ref secondaryDomainName)) { MessageBox.Show("There was an error reading the global Oxigen settings.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); _bError = true; _bCanClose = true; return; } GetNewVersionNumber(generalData, ref updatedMajorVersionNumber, ref updatedMinorVersionNumber, ref updatedVersionNumber); string machineGUIDSuffix = user.GetMachineGUIDSuffix(); HashSet <InterCommunicationStructures.ComponentInfo> changedComponents; try { changedComponents = (HashSet <InterCommunicationStructures.ComponentInfo>)Serializer.DeserializeClearText(typeof(HashSet <InterCommunicationStructures.ComponentInfo>), _appDataPath + "\\SettingsData\\components.dat"); } catch { _log.WriteEntry("Error retrieving the Oxigen Updated Component List.", EventLogEntryType.Error); MessageBox.Show("There was an error retrieving the Oxigen Updated Components List.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); _bError = true; _bCanClose = true; return; } _step = 100 / (changedComponents.Count + 1); // Download components UserFileMarshallerSUClient client = null; StreamErrorWrapper wrapper = null; string uri = ResponsiveServerDeterminator.GetResponsiveURI(ServerType.DownloadGetFile, maxNoServersDownload, timeout, machineGUIDSuffix, primaryDomainName, secondaryDomainName, "UserFileMarshaller.svc"); if (uri == "") { backgroundWorker.ReportProgress(100); _bCanClose = true; Application.Exit(); return; } uri += "/file"; try { client = new UserFileMarshallerSUClient(); client.Endpoint.Address = new System.ServiceModel.EndpointAddress(uri); foreach (ComponentInfo component in changedComponents) { ComponentParameterMessage message = new ComponentParameterMessage() { ComponentFileName = component.File, VersionNumber = updatedVersionNumber, SystemPassPhrase = "password" }; wrapper = client.GetComponent(message); if (wrapper.ErrorStatus == ErrorStatus.Success) { string path = null; if (component.Location == ComponentLocation.BinaryFolder) { path = binTempDir + component.File; } else { path = systemTempDir + component.File; } SaveStreamAndDispose(wrapper.ReturnStream, path); ReportProgress(); } else { wrapper.ReturnStream.Dispose(); _log.WriteEntry("Attempting to download file: " + component.File + " returned this error: " + wrapper.ErrorCode + " " + wrapper.Message, EventLogEntryType.Error); MessageBox.Show("There was an error getting the update from the server. A new update will be attempted later."); if (Directory.Exists(tempDir)) { Directory.Delete(tempDir, true); } if (File.Exists(_appDataPath + "SettingsData\\components.dat")) { File.Delete(_appDataPath + "SettingsData\\components.dat"); } // it's an all-or-nothing update so if one file fails, abort _bError = true; _bCanClose = true; return; } } } catch (Exception ex1) { if (Directory.Exists(tempDir)) { try { Directory.Delete(tempDir, true); } catch (Exception ex2) { _log.WriteEntry(ex2.ToString(), EventLogEntryType.Error); } } _log.WriteEntry(ex1.ToString(), EventLogEntryType.Error); MessageBox.Show("Oxigen could not complete the software update. A new update will be attempted later."); _bError = true; _bCanClose = true; return; } finally { if (wrapper != null) { wrapper.ReturnStream.Dispose(); } client.Dispose(); } // stop the SSG KillProcess("OxigenService"); // kill the Tray that monitors the SSG KillProcess("OxigenTray"); // if CE and LE are running, wait until they're finished while (IsProcessRunning("OxigenLE") || IsProcessRunning("OxigenCE")) { ; } // TODO: stop the screensaver from starting MoveFiles(binTempDir, systemTempDir); System.Diagnostics.Process.Start(_binariesPath + "OxigenService.exe"); if (File.Exists(_appDataPath + "SettingsData\\components.dat")) { File.Delete(_appDataPath + "SettingsData\\components.dat"); } if (Directory.Exists(_binariesPath + "Temp\\")) { Directory.Delete(_binariesPath + "Temp\\", true); } // upload user info to server and update local UserSettings information with the latest version of Screensaver UploadUpdateCurrentVersionInfo(updatedMajorVersionNumber, updatedMinorVersionNumber, updatedVersionNumber, maxNoServersDelay, timeout, machineGUIDSuffix, primaryDomainName, secondaryDomainName); backgroundWorker.ReportProgress(100); Thread.Sleep(1000); }
static void Main(string[] args) { // Put main thread on hold for a second. This is for when the application restarts itself with elevated privileges // to perform the software update. // immediately after this line there is a check to see if there is a software updater already running and exit if // there is. As the software updater starts a new instance of itself if elevated privileges are needed and THEN // the first instance exits, it is possible that the second instance will start the check before the first instance // exits and that will exit too. // Sleeping the thread for 1 sec doesn't guarantee that the first instance won't exit in time but // the chances of both instances exiting are minuscule as the first instance starts the second just right before // it exits. System.Threading.Thread.Sleep(1000); // make sure no other software updater is running Process process = Process.GetCurrentProcess(); string processName = process.ProcessName; Process[] processes = Process.GetProcessesByName(processName); if (processes.Length > 1) { return; } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); SSLValidator.OverrideValidation(); System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("en-GB"); System.Threading.Thread.CurrentThread.CurrentCulture = ci; System.Threading.Thread.CurrentThread.CurrentUICulture = ci; string appDataPath = System.Configuration.ConfigurationSettings.AppSettings["AppDataPath"]; if (args.Length > 0) { // network access mode to provoke the client's firewall if (args[0] == "/n") { GeneralData generalData = GetGeneralData(); User user = GetUser(); if (generalData != null && user != null) { ResponsiveServerDeterminator.GetResponsiveURI (ServerType.RelayLogs, int.Parse(generalData.NoServers["relayChannelAssets"]), int.Parse(generalData.Properties["serverTimeout"]), user.GetMachineGUIDSuffix(), generalData.Properties["primaryDomainName"], generalData.Properties["secondaryDomainName"], "UserDataMarshaller.svc"); } Application.Exit(); return; } // verbose mode: pop up form. if (args[0] == "/v") { AppDataSingleton.Instance.IsVerboseMode = true; VerboseModeForm form = new VerboseModeForm(appDataPath); Application.Run(form); } } // This if will be true if user has restarted the application to gain Admin privileges. // Application does not need Admin privileges if it's only checking for new updates but only // if it has determined that they exist and needs to download them. if (HasAdminRights() && System.IO.Directory.Exists(appDataPath) && System.IO.File.Exists(appDataPath + "\\SettingsData\\components.dat")) { // update app.config with any new parameters UpdateConfig(); if (CanDeserialize(appDataPath + "\\SettingsData\\components.dat")) { Application.Run(new ProgressForm()); return; } else { File.Delete(appDataPath + "\\SettingsData\\components.dat"); } } if (args.Length == 0) { // Code that will execute if user run app as non-admin. // it will check for updates and ask for elevated privileges. ComponentListRetriever clr = new ComponentListRetriever(); clr.Retrieve(); UpdatePrompter prompter = new UpdatePrompter(clr, appDataPath); prompter.PromptForUpdateIfExists(); } }