/// <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); } } } } }
/// <summary>Deletes a modfile and binary from the cache.</summary> public static bool DeleteModfileAndBinaryZip(int modId, int modfileId) { string modfilePath = CacheClient.GenerateModfileFilePath(modId, modfileId); string zipPath = CacheClient.GenerateModBinaryZipFilePath(modId, modfileId); bool success = true; if (!LocalDataStorage.DeleteFile(modfilePath)) { success = false; } if (!LocalDataStorage.DeleteFile(zipPath)) { success = false; } return(success); }
public static bool DeleteFile(string filePath) { return(LocalDataStorage.DeleteFile(filePath)); }
public static bool DeleteUserProfile(int userId) { string path = CacheClient.GenerateUserProfileFilePath(userId); return(LocalDataStorage.DeleteFile(path)); }
/// <summary>Deletes a mod team's data from the cache.</summary> public static bool DeleteModTeam(int modId) { string path = CacheClient.GenerateModTeamFilePath(modId); return(LocalDataStorage.DeleteFile(path)); }
/// <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); } } } } }