Exemplo n.º 1
0
        public void Write()
        {
            Logger.LogDebug("SettingsService", "Writing settings to disk");

            var profiles   = UserProfiles.ToDictionary(profile => profile.Id, profile => profile.Name);
            var configFile = new ConfigFile
            {
                ApplicationSettings = ApplicationSettings,
                DefaultProfileId    = DefaultProfileId,
                Profiles            = profiles,
                Servers             = Servers
            };

            try
            {
                //If no config directory exists, create it
                if (!_fileAccessor.DirectoryExists(ApplicationConfig.ConfigPath))
                {
                    _fileAccessor.CreateDirectory(ApplicationConfig.ConfigPath);
                }

                _fileAccessor.WriteAllText(Path.Combine(ApplicationConfig.ConfigPath, ApplicationConfig.ConfigFileName), JsonConvert.SerializeObject(configFile, ApplicationConfig.JsonFormatting));
            }
            catch (Exception e)
            {
                Logger.LogException("SettingsService", "Error writing settings", e);
            }
        }
Exemplo n.º 2
0
        public void Write(UserProfile profile, BindableCollection <Addon> addons, BindableCollection <LaunchParameter> parameters, LaunchSettings launchSettings)
        {
            Logger.LogDebug("ProfileService", "Writing profile to disk");

            try
            {
                ProfileFile profileFile = new ProfileFile
                {
                    Profile        = profile,
                    Addons         = addons ?? new BindableCollection <Addon>(),
                    Parameters     = parameters ?? new BindableCollection <LaunchParameter>(),
                    LaunchSettings = launchSettings ?? new LaunchSettings()
                };

                if (!_fileAccessor.DirectoryExists(Path.Combine(ApplicationConfig.ConfigPath, ApplicationConfig.ProfilesFolder)))
                {
                    _fileAccessor.CreateDirectory(Path.Combine(ApplicationConfig.ConfigPath, ApplicationConfig.ProfilesFolder));
                }

                _fileAccessor.WriteAllText(Path.Combine(ApplicationConfig.ConfigPath, ApplicationConfig.ProfilesFolder, string.Format(ApplicationConfig.ProfileNameFormat, profile.Id)),
                                           JsonConvert.SerializeObject(profileFile, ApplicationConfig.JsonFormatting));
            }
            catch (Exception e)
            {
                Logger.LogException("ProfileService", "Error writing profile", e);
            }
        }