示例#1
0
        private bool DownloadComponentList(int maxNoServers, int timeout, ref ComponentInfo[] componentList)
        {
            string uri = ResponsiveServerDeterminator.GetResponsiveURI(ServerType.RelayLogs, maxNoServers, timeout,
                                                                       _user.GetMachineGUIDSuffix(), _generalData.Properties["primaryDomainName"],
                                                                       _generalData.Properties["secondaryDomainName"], "UserDataMarshaller.svc");

            if (uri == "")
            {
                return(false);
            }

            uri += "/su";

            UserDataMarshallerSUStreamerClient client = null;
            StreamErrorWrapper      wrapper           = null;
            VersionParameterMessage message           = new VersionParameterMessage()
            {
                Version          = String.Format("{0}.{1}", _generalData.SoftwareMajorVersionNumber, _generalData.SoftwareMinorVersionNumber),
                SystemPassPhrase = "password"
            };

            try
            {
                client = new UserDataMarshallerSUStreamerClient();
                client.Endpoint.Address = new System.ServiceModel.EndpointAddress(uri);
                wrapper = client.GetComponentList(message);
            }
            catch (Exception ex)
            {
                client.Dispose();
                _log.WriteEntry("Could not get a list of updated components.", EventLogEntryType.Error);
                return(false);
            }

            if (wrapper.ErrorStatus == ErrorStatus.NoData)
            {
                _log.WriteEntry(wrapper.ErrorCode + " " + wrapper.Message, EventLogEntryType.Warning);
                return(false);
            }

            if (wrapper.ErrorStatus == ErrorStatus.Failure)
            {
                _log.WriteEntry(wrapper.ErrorCode + " " + wrapper.Message, EventLogEntryType.Error);
                return(false);
            }

            byte[] buffer = StreamToByteArray(wrapper.ReturnStream);

            if (wrapper.ReturnStream != null)
            {
                wrapper.ReturnStream.Dispose();
            }

            string stringXmlObj = ByteArrayToString(buffer);

            componentList = (ComponentInfo[])Serializer.DeserializeFromString(typeof(ComponentInfo[]), stringXmlObj);

            return(true);
        }
示例#2
0
        private void UploadUpdateCurrentVersionInfo(int updatedMajorVersionNumber,
                                                    int updatedMinorVersionNumber,
                                                    string updatedVersionNumber,
                                                    int maxNoServersRelay,
                                                    int timeout,
                                                    string machineGUIDSuffix,
                                                    string primaryDomainName,
                                                    string secondaryDomainName)
        {
            User user = null;

            // try to deserialize 10 times in case another application is accessing the file
            for (int i = 0; i < 10; i++)
            {
                try
                {
                    user = (User)Serializer.DeserializeNoLock(typeof(User), _userSettingsPath, "password");
                    break;
                }
                catch (IOException)
                {
                    System.Threading.Thread.Sleep(1000);
                    // ignore
                }

                if (user == null)
                {
                    return;
                }
            }

            UserDataMarshallerSUClient client = null;

            string uri = ResponsiveServerDeterminator.GetResponsiveURI(ServerType.RelayLogs, maxNoServersRelay,
                                                                       timeout, machineGUIDSuffix, primaryDomainName, secondaryDomainName, "UserDataMarshaller.svc");

            if (uri == "")
            {
                backgroundWorker.ReportProgress(100);
                _bCanClose = true;

                // if no responsive URI found, abort and re-update later.
                // we need to keep database up to date with end user's machine, so we need
                // to re-initiate update next time the SU runs.
                return;
            }

            uri += "/suno";

            try
            {
                client = new UserDataMarshallerSUClient();

                client.Endpoint.Address = new System.ServiceModel.EndpointAddress(uri);

                client.SetCurrentVersionInfo(user.UserGUID, user.MachineGUID, updatedVersionNumber, "password");
            }
            catch
            {
                // ignore
            }
            finally
            {
                client.Dispose();
            }

            user.SoftwareMajorVersionNumber = updatedMajorVersionNumber;
            user.SoftwareMinorVersionNumber = updatedMinorVersionNumber;

            // try to deserialize 10 times in order another application is accessing the file
            for (int i = 0; i < 10; i++)
            {
                try
                {
                    Serializer.Serialize(user, _userSettingsPath, "password");
                    break;
                }
                catch (IOException)
                {
                    System.Threading.Thread.Sleep(1000);
                    // ignore
                }
            }
        }
示例#3
0
        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);
        }
示例#4
0
        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();
            }
        }