Ejemplo n.º 1
0
        private static void Load()
        {
            string registryFilePath = Registry.GetUserRegistryFilePath();

            if (!File.Exists(registryFilePath))
            {
                Registry.instance = new Registry();
                return;
            }

            try
            {
                Registry.instance = null;
                XmlHelpers.LoadFromFile <Registry>("Registry", registryFilePath, out Registry.instance);
            }
            catch (Exception exception)
            {
                Registry.instance = new Registry();
                Diagnostics.Debug.LogError("Fail to load registry. {0}", exception.Message);
                while (exception.InnerException != null)
                {
                    exception = exception.InnerException;
                    Diagnostics.Debug.LogError("Inner exception: {0}", exception.Message);
                }
            }
        }
Ejemplo n.º 2
0
        public static void ApplyTemporarySettings()
        {
            // Load temporary settings.
            string temporaryFilePath = Settings.GetUserSettingsTemporaryFilePath();

            if (!File.Exists(temporaryFilePath))
            {
                return;
            }

            Settings settings = null;

            XmlHelpers.LoadFromFile("Settings", temporaryFilePath, out settings);

            RegistryKey registryKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\FileConverter");

            if (registryKey == null)
            {
                Diagnostics.Debug.LogError("Can't apply settings in registry. (code 0x03)");
                return;
            }

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

            bool succeed = Settings.ApplyRegistryModifications(registryEntries);

            if (succeed)
            {
                // Copy temporary settings file to the real settings file.
                string userFilePath = Settings.GetUserSettingsFilePath();
                File.Copy(temporaryFilePath, userFilePath, true);
                File.Delete(temporaryFilePath);
            }
        }
Ejemplo n.º 3
0
        public static void PostInstallationInitialization()
        {
            Settings defaultSettings = null;

            // Load the default settings.
            string defaultFilePath = Settings.GetDefaultSettingsFilePath();

            if (File.Exists(defaultFilePath))
            {
                try
                {
                    XmlHelpers.LoadFromFile <Settings>("Settings", defaultFilePath, out defaultSettings);
                }
                catch (Exception exception)
                {
                    Diagnostics.Debug.LogError("Fail to load file converter default settings. {0}", exception.Message);
                }
            }
            else
            {
                Diagnostics.Debug.LogError("Default settings not found at path {0}. You should try to reinstall the application.", defaultFilePath);
            }

            // Load user settings if exists.
            Settings userSettings = null;
            string   userFilePath = Settings.GetUserSettingsFilePath();

            if (File.Exists(userFilePath))
            {
                try
                {
                    XmlHelpers.LoadFromFile <Settings>("Settings", userFilePath, out userSettings);
                }
                catch (Exception)
                {
                    System.IO.File.Delete(userFilePath);
                }

                if (userSettings != null)
                {
                    if (userSettings.SerializationVersion != Version)
                    {
                        Settings.MigrateSettingsToCurrentVersion(userSettings);

                        Diagnostics.Debug.Log("File converter settings has been imported from version {0} to version {1}.", userSettings.SerializationVersion, Version);
                        userSettings.SerializationVersion = Version;
                    }

                    // Remove default settings.
                    if (userSettings.ConversionPresets != null)
                    {
                        for (int index = userSettings.ConversionPresets.Count - 1; index >= 0; index--)
                        {
                            if (userSettings.ConversionPresets[index].IsDefaultSettings)
                            {
                                userSettings.ConversionPresets.RemoveAt(index);
                            }
                        }
                    }
                }
            }

            Settings settings = userSettings != null?userSettings.Merge(defaultSettings) : defaultSettings;

            settings.Save();
        }
Ejemplo n.º 4
0
        public static Settings Load()
        {
            Settings settings     = null;
            string   userFilePath = Settings.GetUserSettingsFilePath();

            if (File.Exists(userFilePath))
            {
                Settings userSettings = null;
                try
                {
                    XmlHelpers.LoadFromFile <Settings>("Settings", userFilePath, out userSettings);
                    settings = userSettings;
                }
                catch (Exception)
                {
                    MessageBoxResult messageBoxResult =
                        MessageBox.Show(
                            "Can't load file converter user settings. Do you want to fall back to default settings ?",
                            "Error",
                            MessageBoxButton.YesNo,
                            MessageBoxImage.Exclamation);

                    if (messageBoxResult == MessageBoxResult.Yes)
                    {
                        System.IO.File.Delete(userFilePath);
                        return(Settings.Load());
                    }
                    else if (messageBoxResult == MessageBoxResult.No)
                    {
                        return(null);
                    }
                }

                if (userSettings != null && userSettings.SerializationVersion != Version)
                {
                    Settings.MigrateSettingsToCurrentVersion(userSettings);

                    Diagnostics.Debug.Log("File converter settings has been imported from version {0} to version {1}.", userSettings.SerializationVersion, Version);
                    userSettings.SerializationVersion = Version;
                    userSettings.Save();
                }
            }
            else
            {
                // Load the default settings.
                string defaultFilePath = Settings.GetDefaultSettingsFilePath();
                if (File.Exists(defaultFilePath))
                {
                    Settings defaultSettings = null;
                    try
                    {
                        XmlHelpers.LoadFromFile <Settings>("Settings", defaultFilePath, out defaultSettings);
                        settings = defaultSettings;
                    }
                    catch (Exception exception)
                    {
                        Diagnostics.Debug.LogError("Fail to load file converter default settings. {0}", exception.Message);
                    }
                }
                else
                {
                    Diagnostics.Debug.LogError("Default settings not found at path {0}. You should try to reinstall the application.", defaultFilePath);
                }
            }

            return(settings);
        }