Example #1
0
        public Profile Load(string name)
        {
            return Lock.Read(() => {
                var filePath = Path.Combine(PathForProfiles(), name, Config_File_Name);

                if(!_fileSystem.Exists(filePath))
                    return new Profile { Name = name };

                var text = _fileSystem.ReadAllText(filePath);

                var accountMatch = Regex.Match(text, "Account: (?<account>\\S*)", RegexOptions.IgnoreCase);
                var gameMatch = Regex.Match(text, "Game: (?<game>\\S*)", RegexOptions.IgnoreCase);
                var characterMatch = Regex.Match(text, "Character: (?<character>\\S*)", RegexOptions.IgnoreCase);

                var profile = new Profile
                {
                    Name = new DirectoryInfo(name).Name,
                    Account = accountMatch.Success ? accountMatch.Groups["account"].Value.Trim() : string.Empty,
                    Game = gameMatch.Success ? gameMatch.Groups["game"].Value.Trim() : string.Empty,
                    Character = characterMatch.Success ? characterMatch.Groups["character"].Value.Trim() : string.Empty
                };

                return profile;
            });
        }
Example #2
0
        public void Save(Profile profile)
        {
            Lock.Write(() => {
                var filePath = Path.Combine(PathForProfiles(), profile.Name, Config_File_Name);

                _appDirBuilder.BuildProfile(profile.Name);

                var builder = new StringBuilder();
                builder.AppendFormat("Account: {0}\n", profile.Account);
                builder.AppendFormat("Game: {0}\n", profile.Game);
                builder.AppendFormat("Character: {0}", profile.Character);

                _fileSystem.Save(builder.ToString(), filePath);
            });
        }
 public static ProfileInfo For(Profile profile)
 {
     return For(profile.Name, profile.Game, profile.Account, profile.Character);
 }