Ejemplo n.º 1
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(CacheClient.cacheDirectory, "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(CacheClient.cacheDirectory, "mods");

            if (Directory.Exists(profileDirectory))
            {
                string[] modDirectories;
                try
                {
                    modDirectories = Directory.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];
                }

                int offsetDirCount = modDirectories.Length - offset;
                if (offsetDirCount > 0)
                {
                    string[] offsetModDirectories = new string[offsetDirCount];
                    Array.Copy(modDirectories, offset,
                               offsetModDirectories, 0,
                               offsetDirCount);

                    foreach (string modDirectory in offsetModDirectories)
                    {
                        string     profilePath = IOUtilities.CombinePath(modDirectory, "profile.data");
                        ModProfile profile     = IOUtilities.ReadJsonObjectFile <ModProfile>(profilePath);

                        if (profile != null)
                        {
                            yield return(profile);
                        }
                        else
                        {
                            IOUtilities.DeleteFile(profilePath);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
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);
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
 public static string GenerateModBuildsDirectoryPath(int modId)
 {
     return(CacheClient.GenerateModDirectoryPath(modId)
            + "builds/");
 }
Ejemplo n.º 4
0
 // ---------[ MOD TEAM ]---------
 public static string GenerateModTeamFilePath(int modId)
 {
     return(CacheClient.GenerateModDirectoryPath(modId)
            + "team.data");
 }
Ejemplo n.º 5
0
 // ---------[ MOD MEDIA ]---------
 public static string GenerateModLogoDirectoryPath(int modId)
 {
     return(CacheClient.GenerateModDirectoryPath(modId)
            + "logo/");
 }
Ejemplo n.º 6
0
        public static void DeleteMod(int modId)
        {
            string modDir = CacheClient.GenerateModDirectoryPath(modId);

            CacheClient.DeleteDirectory(modDir);
        }
Ejemplo n.º 7
0
 // ---------[ MOD PROFILES ]---------
 public static string GenerateModProfileFilePath(int modId)
 {
     return(CacheClient.GenerateModDirectoryPath(modId)
            + "profile.data");
 }
Ejemplo n.º 8
0
 // ------[ PROFILES ]------
 /// <summary>Generates the file path for a mod's profile data.</summary>
 public static string GenerateModProfileFilePath(int modId)
 {
     return(IOUtilities.CombinePath(CacheClient.GenerateModDirectoryPath(modId),
                                    "profile.data"));
 }
Ejemplo n.º 9
0
 // ------[ MEDIA ]------
 /// <summary>Generates the directory path for a mod logo collection.</summary>
 public static string GenerateModLogoCollectionDirectoryPath(int modId)
 {
     return(IOUtilities.CombinePath(CacheClient.GenerateModDirectoryPath(modId),
                                    "logo"));
 }
Ejemplo n.º 10
0
 // ------[ MODFILES ]------
 /// <summary>Generates the path for a cached mod build directory.</summary>
 public static string GenerateModBinariesDirectoryPath(int modId)
 {
     return(IOUtilities.CombinePath(CacheClient.GenerateModDirectoryPath(modId), "binaries"));
 }
Ejemplo n.º 11
0
        /// <summary>Deletes all of a mod's data from the cache.</summary>
        public static bool DeleteMod(int modId)
        {
            string modDir = CacheClient.GenerateModDirectoryPath(modId);

            return(IOUtilities.DeleteDirectory(modDir));
        }
Ejemplo 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(CacheClient.cacheDirectory, "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(CacheClient.cacheDirectory, "mods");

            if (Directory.Exists(profileDirectory))
            {
                string[] modDirectories;
                try
                {
                    modDirectories = Directory.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     = IOUtilities.ReadJsonObjectFile <ModProfile>(profilePath);

                        if (profile != null)
                        {
                            yield return(profile);
                        }
                        else
                        {
                            IOUtilities.DeleteFile(profilePath);
                        }
                    }
                }
            }
        }
Ejemplo n.º 13
0
        /// <summary>Deletes all of a mod's data from the cache.</summary>
        public static bool DeleteMod(int modId)
        {
            string modDir = CacheClient.GenerateModDirectoryPath(modId);

            return(LocalDataStorage.DeleteDirectory(modDir));
        }