Exemplo n.º 1
0
        public static IEnumerable <UserProfile> IterateAllUserProfiles()
        {
            string profileDirectory = IOUtilities.CombinePath(PluginSettings.CACHE_DIRECTORY,
                                                              "users");

            if (LocalDataStorage.GetDirectoryExists(profileDirectory))
            {
                IList <string> userFiles;
                try
                {
                    userFiles = LocalDataStorage.GetFiles(profileDirectory, null, false);
                }
                catch (Exception e)
                {
                    string warningInfo = ("[mod.io] Failed to read user profile directory."
                                          + "\nDirectory: " + profileDirectory + "\n\n");

                    Debug.LogWarning(warningInfo
                                     + Utility.GenerateExceptionDebugString(e));

                    userFiles = new string[0];
                }

                foreach (string profileFilePath in userFiles)
                {
                    UserProfile profile;
                    LocalDataStorage.ReadJSONFile(profileFilePath, out profile);

                    if (profile != null)
                    {
                        yield return(profile);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public static T ReadJsonObjectFile <T>(string filePath)
        {
            T parsed;

            LocalDataStorage.ReadJSONFile <T>(filePath, out parsed);

            return(parsed);
        }
Exemplo n.º 3
0
        /// <summary>Retrieves the game's profile from the cache.</summary>
        public static GameProfile LoadGameProfile()
        {
            GameProfile profile;

            LocalDataStorage.ReadJSONFile(gameProfileFilePath, out profile);

            return(profile);
        }
Exemplo n.º 4
0
        public static UserProfile LoadUserProfile(int userId)
        {
            string      filePath = CacheClient.GenerateUserProfileFilePath(userId);
            UserProfile userProfile;

            LocalDataStorage.ReadJSONFile(filePath, out userProfile);

            return(userProfile);
        }
Exemplo n.º 5
0
        /// <summary>Retrieves a mod's profile from the cache.</summary>
        public static ModProfile LoadModProfile(int modId)
        {
            string     path = GenerateModProfileFilePath(modId);
            ModProfile profile;

            LocalDataStorage.ReadJSONFile(path, out profile);

            return(profile);
        }
Exemplo n.º 6
0
        /// <summary>Retrieves a mod team's data from the cache.</summary>
        public static List <ModTeamMember> LoadModTeam(int modId)
        {
            string filePath = CacheClient.GenerateModTeamFilePath(modId);
            List <ModTeamMember> modTeam;

            LocalDataStorage.ReadJSONFile(filePath, out modTeam);

            return(modTeam);
        }
Exemplo n.º 7
0
        /// <summary>Retrieves the file paths for the mod logos in the cache.</summary>
        public static Dictionary <LogoSize, string> GetModLogoVersionFileNames(int modId)
        {
            string path = CacheClient.GenerateModLogoVersionInfoFilePath(modId);
            Dictionary <LogoSize, string> retVal;

            LocalDataStorage.ReadJSONFile(path, out retVal);

            return(retVal);
        }
Exemplo n.º 8
0
        /// <summary>Retrieves a modfile from the cache.</summary>
        public static Modfile LoadModfile(int modId, int modfileId)
        {
            string  modfileFilePath = GenerateModfileFilePath(modId, modfileId);
            Modfile modfile;

            LocalDataStorage.ReadJSONFile(modfileFilePath, out modfile);

            return(modfile);
        }
Exemplo n.º 9
0
        /// <summary>Retrieves a mod's statistics from the cache.</summary>
        public static ModStatistics LoadModStatistics(int modId)
        {
            string        statsFilePath = GenerateModStatisticsFilePath(modId);
            ModStatistics stats;

            LocalDataStorage.ReadJSONFile(statsFilePath, out stats);

            return(stats);
        }
Exemplo n.º 10
0
        public static bool TryReadJsonObjectFile <T>(string filePath, out T jsonObject)
        {
            T    parsed;
            bool success = false;

            success    = LocalDataStorage.ReadJSONFile <T>(filePath, out parsed);
            jsonObject = parsed;

            return(success);
        }
Exemplo n.º 11
0
        /// <summary>Iterates through all of the mod profiles from the given offset.</summary>
        public static IEnumerable <ModProfile> IterateAllModProfilesFromOffset(int offset)
        {
            Debug.Assert(IOUtilities.CombinePath(PluginSettings.CACHE_DIRECTORY, "mods", "0")
                         == CacheClient.GenerateModDirectoryPath(0),
                         "[mod.io] This function relies on mod directory path being a generated in"
                         + " a specific way. Changing CacheClient.GenerateModDirectoryPath()"
                         + " necessitates changes in this function.");

            Debug.Assert(IOUtilities.CombinePath(CacheClient.GenerateModDirectoryPath(0), "profile.data")
                         == CacheClient.GenerateModProfileFilePath(0),
                         "[mod.io] This function relies on mod directory profile file path being a generated in"
                         + " a specific way. Changing CacheClient.GenerateModProfileFilePath()"
                         + " necessitates changes in this function.");

            string profileDirectory = IOUtilities.CombinePath(PluginSettings.CACHE_DIRECTORY, "mods");

            if (LocalDataStorage.GetDirectoryExists(profileDirectory))
            {
                IList <string> modDirectories;
                try
                {
                    modDirectories = LocalDataStorage.GetDirectories(profileDirectory);
                }
                catch (Exception e)
                {
                    string warningInfo = ("[mod.io] Failed to read mod profile directory."
                                          + "\nDirectory: " + profileDirectory + "\n\n");

                    Debug.LogWarning(warningInfo
                                     + Utility.GenerateExceptionDebugString(e));

                    modDirectories = new string[0];
                }

                if (modDirectories.Count - offset > 0)
                {
                    for (int i = offset; i < modDirectories.Count; ++i)
                    {
                        string     profilePath = IOUtilities.CombinePath(modDirectories[i], "profile.data");
                        ModProfile profile;

                        LocalDataStorage.ReadJSONFile(profilePath, out profile);

                        if (profile != null)
                        {
                            yield return(profile);
                        }
                        else
                        {
                            LocalDataStorage.DeleteFile(profilePath);
                        }
                    }
                }
            }
        }
Exemplo n.º 12
0
        /// <summary>Iterates through all of the mod profiles returning only those matching the id filter.</summary>
        public static IEnumerable <ModProfile> IterateFilteredModProfiles(IList <int> idFilter)
        {
            if (idFilter == null || idFilter.Count == 0)
            {
                yield break;
            }

            Debug.Assert(IOUtilities.CombinePath(PluginSettings.CACHE_DIRECTORY, "mods", "0")
                         == CacheClient.GenerateModDirectoryPath(0),
                         "[mod.io] This function relies on mod directory path being a generated in"
                         + " a specific way. Changing CacheClient.GenerateModDirectoryPath()"
                         + " necessitates changes in this function.");

            Debug.Assert(IOUtilities.CombinePath(CacheClient.GenerateModDirectoryPath(0), "profile.data")
                         == CacheClient.GenerateModProfileFilePath(0),
                         "[mod.io] This function relies on mod directory profile file path being a generated in"
                         + " a specific way. Changing CacheClient.GenerateModProfileFilePath()"
                         + " necessitates changes in this function.");

            string profileDirectory = IOUtilities.CombinePath(PluginSettings.CACHE_DIRECTORY, "mods");

            if (LocalDataStorage.GetDirectoryExists(profileDirectory))
            {
                IList <string> modDirectories;
                try
                {
                    modDirectories = LocalDataStorage.GetDirectories(profileDirectory);
                }
                catch (Exception e)
                {
                    string warningInfo = ("[mod.io] Failed to read mod profile directory."
                                          + "\nDirectory: " + profileDirectory + "\n\n");

                    Debug.LogWarning(warningInfo
                                     + Utility.GenerateExceptionDebugString(e));

                    modDirectories = new string[0];
                }

                foreach (string modDirectory in modDirectories)
                {
                    string idPart = modDirectory.Substring(profileDirectory.Length + 1);
                    int    modId  = ModProfile.NULL_ID;
                    if (!int.TryParse(idPart, out modId))
                    {
                        modId = ModProfile.NULL_ID;
                    }

                    if (idFilter.Contains(modId))
                    {
                        string     profilePath = IOUtilities.CombinePath(modDirectory, "profile.data");
                        ModProfile profile;

                        LocalDataStorage.ReadJSONFile(profilePath, out profile);

                        if (profile != null)
                        {
                            yield return(profile);
                        }
                        else
                        {
                            LocalDataStorage.DeleteFile(profilePath);
                        }
                    }
                }
            }
        }