Exemple #1
0
        public void Save(List <Gump> gumps = null)
        {
            if (string.IsNullOrEmpty(ServerName))
            {
                throw new InvalidDataException();
            }

            if (string.IsNullOrEmpty(Username))
            {
                throw new InvalidDataException();
            }

            if (string.IsNullOrEmpty(CharacterName))
            {
                throw new InvalidDataException();
            }

            string path = FileSystemHelper.CreateFolderIfNotExists(ProfilePath, Username.Trim(), ServerName.Trim(), CharacterName.Trim());

            Log.Trace($"Saving path:\t\t{path}");

            // Save profile settings
            ConfigurationResolver.Save(this, Path.Combine(path, "profile.json"), new JsonSerializerSettings
            {
                TypeNameHandling         = TypeNameHandling.All,
                MetadataPropertyHandling = MetadataPropertyHandling.ReadAhead
            });

            // Save opened gumps
            SaveGumps(path, gumps);

            Log.Trace("Saving done!");
        }
Exemple #2
0
        public void Save(List <Gump> gumps = null)
        {
            if (string.IsNullOrEmpty(ServerName))
            {
                throw new InvalidDataException();
            }
            if (string.IsNullOrEmpty(Username))
            {
                throw new InvalidDataException();
            }
            if (string.IsNullOrEmpty(CharacterName))
            {
                throw new InvalidDataException();
            }

            string path = FileSystemHelper.CreateFolderIfNotExists(ProfilePath, Username, ServerName, CharacterName);

            Log.Message(LogTypes.Trace, $"Saving path:\t\t{path}");

            // save settings.json
            ConfigurationResolver.Save(this, Path.Combine(path, Engine.SettingsFile), new JsonSerializerSettings()
            {
                TypeNameHandling         = TypeNameHandling.All,
                MetadataPropertyHandling = MetadataPropertyHandling.ReadAhead
            });

            // save gumps.bin
            SaveGumps(path, gumps);

            Log.Message(LogTypes.Trace, "Saving done!");
        }
Exemple #3
0
        public static void Load(string servername, string username, string charactername)
        {
            string path = FileSystemHelper.CreateFolderIfNotExists(CUOEnviroment.ExecutablePath, "Data", "Profiles", username, servername, charactername);



            string fileToLoad = Path.Combine(path, "profile.json");

            if (!File.Exists(fileToLoad))
            {
                Current = new Profile(username, servername, charactername);
            }
            else
            {
                Current = ConfigurationResolver.Load <Profile>(fileToLoad,
                                                               new JsonSerializerSettings
                {
                    TypeNameHandling         = TypeNameHandling.All,
                    MetadataPropertyHandling = MetadataPropertyHandling.ReadAhead
                });
                if (Current == null)
                {
                    Current = new Profile(username, servername, charactername);
                }
                else
                {
                    Current.Username      = username;
                    Current.ServerName    = servername;
                    Current.CharacterName = charactername;
                }
            }

            ProfileLoaded?.Invoke();
        }
Exemple #4
0
        public static void Load(string servername, string username, string charactername)
        {
            string rootpath;

            if (string.IsNullOrWhiteSpace(Settings.GlobalSettings.ProfilesPath))
            {
                rootpath = Path.Combine(CUOEnviroment.ExecutablePath, "Data", "Profiles");
            }
            else
            {
                rootpath = Settings.GlobalSettings.ProfilesPath;
            }

            string path       = FileSystemHelper.CreateFolderIfNotExists(rootpath, username, servername, charactername);
            string fileToLoad = Path.Combine(path, "profile.json");

            ProfilePath    = path;
            CurrentProfile = ConfigurationResolver.Load <Profile>(fileToLoad) ?? new Profile();

            CurrentProfile.Username      = username;
            CurrentProfile.ServerName    = servername;
            CurrentProfile.CharacterName = charactername;

            ValidateFields(CurrentProfile);
        }
Exemple #5
0
        public static void Load(string servername, string username, string charactername)
        {
            string path = FileSystemHelper.CreateFolderIfNotExists(CUOEnviroment.ExecutablePath, "Data", "Profiles", username, servername, charactername);



            string fileToLoad = Path.Combine(path, "profile.json");

            if (!File.Exists(fileToLoad))
            {
                Current = new Profile(username, servername, charactername);
            }
            else
            {
                Current = ConfigurationResolver.Load <Profile>(fileToLoad);
                if (Current == null)
                {
                    Current = new Profile(username, servername, charactername);
                }
                else
                {
                    Current.Username      = username;
                    Current.ServerName    = servername;
                    Current.CharacterName = charactername;
                }
            }

            ValidateFields(Current);

            ProfileLoaded?.Invoke();
        }
Exemple #6
0
        public void Save(List <Gump> gumps = null)
        {
            if (string.IsNullOrEmpty(ServerName))
            {
                throw new InvalidDataException();
            }
            if (string.IsNullOrEmpty(Username))
            {
                throw new InvalidDataException();
            }
            if (string.IsNullOrEmpty(CharacterName))
            {
                throw new InvalidDataException();
            }

            string path = FileSystemHelper.CreateFolderIfNotExists(Engine.ExePath, "Data", "Profiles", Username, ServerName, CharacterName);

            Log.Message(LogTypes.Trace, $"Saving path:\t\t{path}");

            // save settings.json
            ConfigurationResolver.Save(this, Path.Combine(path, "settings.json"));

            // save gumps.bin
            SaveGumps(path, gumps);

            Log.Message(LogTypes.Trace, "Saving done!");
        }
Exemple #7
0
        public static void Load(string language)
        {
            string path = FileSystemHelper.CreateFolderIfNotExists(CUOEnviroment.ExecutablePath, "Language");


            string fileToLoad = Path.Combine(path, language);

            if (!File.Exists(fileToLoad))
            {
                Current = new Language();
            }
            else
            {
                Current = ConfigurationResolver.Load <Language>(fileToLoad,
                                                                new JsonSerializerSettings
                {
                    TypeNameHandling         = TypeNameHandling.All,
                    MetadataPropertyHandling = MetadataPropertyHandling.ReadAhead
                });
                if (Current == null)
                {
                    Current = new Language();
                }
            }
        }
        public static void Save()
        {
            if (!Directory.Exists(_path))
            {
                Directory.CreateDirectory(_path);
            }

            ConfigurationResolver.Save(Current, Current.Path);
        }
Exemple #9
0
        public void Load(string servername, string username, string charactername)
        {
            string path = FileSystemHelper.CreateFolderIfNotExists(Engine.ExePath, "Data", "Profiles", username, servername, charactername);



            // FIXME: this is a temporary patch to change the profile settings name safety
            string fileToLoad = Path.Combine(path, "settings.json");
            string newPath    = Path.Combine(path, "profile.json");

            if (File.Exists(newPath))
            {
                if (File.Exists(fileToLoad))
                {
                    try
                    {
                        File.Delete(fileToLoad);
                    }
                    catch (Exception)
                    {
                        Log.Message(LogTypes.Warning, $"Failed to delete file: '{fileToLoad}'");
                    }
                }

                fileToLoad = newPath;
            }
            //



            if (!File.Exists(fileToLoad))
            {
                Current = new Profile(username, servername, charactername);
            }
            else
            {
                Current = ConfigurationResolver.Load <Profile>(fileToLoad,
                                                               new JsonSerializerSettings
                {
                    TypeNameHandling         = TypeNameHandling.All,
                    MetadataPropertyHandling = MetadataPropertyHandling.ReadAhead
                });
                if (Current == null)
                {
                    Current = new Profile(username, servername, charactername);
                }
                else
                {
                    Current.Username      = username;
                    Current.ServerName    = servername;
                    Current.CharacterName = charactername;
                }
            }
        }
Exemple #10
0
        public void Save(string path)
        {
            Log.Trace($"Saving path:\t\t{path}");

            // Save profile settings
            ConfigurationResolver.Save(this, Path.Combine(path, "profile.json"));

            // Save opened gumps
            SaveGumps(path);

            Log.Trace("Saving done!");
        }
Exemple #11
0
        public void Load(string servername, string username, string charactername)
        {
            string path = FileSystemHelper.CreateFolderIfNotExists(Engine.ExePath, "Data", "Profiles", username, servername, charactername);

            if (!File.Exists(Path.Combine(path, "settings.json")))
            {
                Current = new Profile(username, servername, charactername);
            }
            else
            {
                Current = ConfigurationResolver.Load <Profile>(Path.Combine(path, "settings.json")) ?? new Profile(username, servername, charactername);
            }
        }
        public static void Load(string name)
        {
            string ext = Path.GetExtension(name);

            if (string.IsNullOrEmpty(ext))
            {
                name = name + ".json";
            }

            if (File.Exists(name))
            {
                Current = ConfigurationResolver.Load <Profile>(name);
            }
        }
Exemple #13
0
        public void Save()
        {
            // Make a copy of the settings object that we will use in the saving process
            Settings settingsToSave = JsonConvert.DeserializeObject <Settings>(JsonConvert.SerializeObject(this));

            // Make sure we don't save username and password if `saveaccount` flag is not set
            // NOTE: Even if we pass username and password via command-line arguments they won't be saved
            if (!settingsToSave.SaveAccount)
            {
                settingsToSave.Username = string.Empty;
                settingsToSave.Password = string.Empty;
            }

            // NOTE: We can do any other settings clean-ups here before we save them

            ConfigurationResolver.Save(settingsToSave, GetSettingsFilepath());
        }
Exemple #14
0
        public void Load(string servername, string username, string charactername)
        {
            string path = FileSystemHelper.CreateFolderIfNotExists(Engine.ExePath, "Data", "Profiles", username, servername, charactername);

            if (!File.Exists(Path.Combine(path, Engine.SettingsFile)))
            {
                Current = new Profile(username, servername, charactername);
            }
            else
            {
                Current = ConfigurationResolver.Load <Profile>(Path.Combine(path, Engine.SettingsFile),
                                                               new JsonSerializerSettings()
                {
                    TypeNameHandling         = TypeNameHandling.All,
                    MetadataPropertyHandling = MetadataPropertyHandling.ReadAhead
                }) ?? new Profile(username, servername, charactername);
            }
        }
Exemple #15
0
 public void Save()
 {
     ConfigurationResolver.Save(this, Path.Combine(Engine.ExePath, "settings.json"));
 }