public void Dispose()
        {
            // SAVE
            string registryFilePath = Registry.GetUserRegistryFilePath();

            try
            {
                XmlHelpers.SaveToFile("Registry", registryFilePath, this);
            }
            catch (Exception exception)
            {
                Diagnostics.Debug.LogError("Fail to save registry. {0}", exception.Message);
            }
        }
Exemple #2
0
        public void Save()
        {
            this.Clean();

            // Save the settings in a temporary files (we'll write the settings file when we'll succeed to write the registry keys).
            string temporaryFilePath = Settings.GetUserSettingsTemporaryFilePath();

            XmlHelpers.SaveToFile("Settings", temporaryFilePath, this);

            // Compute the registry entries data from settings.
            Dictionary <string, List <string> > registryEntries = Settings.ComputeRegistryEntriesFromConvertionPresets(this.ConversionPresets);

            // Detect if existing registry configuration need to be modified.
            bool registryNeedModifications = Settings.IsRegistryNeedModifications(registryEntries);

            if (registryNeedModifications)
            {
                // Write the settings in registry.
                if (Settings.IsInAdmininstratorPrivileges)
                {
                    // We are in admin mode, write registry ...
                    bool succeed = Settings.ApplyRegistryModifications(registryEntries);
                    if (succeed)
                    {
                        // ... and copy temporary settings file to the real settings file.
                        string userFilePath = Settings.GetUserSettingsFilePath();
                        File.Copy(temporaryFilePath, userFilePath, true);
                        File.Delete(temporaryFilePath);
                    }
                }
                else
                {
                    // Run the application in admin mode in order to perform modifications.
                    Settings.RunSaveInAdminMode();
                }
            }
            else
            {
                // Copy temporary settings file to the real settings file.
                string userFilePath = Settings.GetUserSettingsFilePath();
                File.Copy(temporaryFilePath, userFilePath, true);
                File.Delete(temporaryFilePath);
            }
        }