/// <summary>Iterates through all the user profiles in the cache.</summary> public static IEnumerable <UserProfile> IterateAllUserProfiles() { string profileDirectory = IOUtilities.CombinePath(CacheClient.cacheDirectory, "users"); if (Directory.Exists(profileDirectory)) { string[] userFiles; try { userFiles = Directory.GetFiles(profileDirectory); } 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) { var profile = IOUtilities.ReadJsonObjectFile <UserProfile>(profileFilePath); if (profile != null) { yield return(profile); } } } }
/// <summary>Retrieves a mod's profile from the cache.</summary> public static ModProfile LoadModProfile(int modId) { string profileFilePath = GenerateModProfileFilePath(modId); ModProfile profile = IOUtilities.ReadJsonObjectFile <ModProfile>(profileFilePath); return(profile); }
/// <summary>Retrieves a mod team's data from the cache.</summary> public static List <ModTeamMember> LoadModTeam(int modId) { string filePath = CacheClient.GenerateModTeamFilePath(modId); var modTeam = IOUtilities.ReadJsonObjectFile <List <ModTeamMember> >(filePath); return(modTeam); }
/// <summary>Retrieves a user's profile from the cache.</summary> public static UserProfile LoadUserProfile(int userId) { string filePath = CacheClient.GenerateUserProfileFilePath(userId); var userProfile = IOUtilities.ReadJsonObjectFile <UserProfile>(filePath); return(userProfile); }
/// <summary>Retrieves a modfile from the cache.</summary> public static Modfile LoadModfile(int modId, int modfileId) { string modfileFilePath = GenerateModfileFilePath(modId, modfileId); var modfile = IOUtilities.ReadJsonObjectFile <Modfile>(modfileFilePath); return(modfile); }
/// <summary>Retrieves a mod's statistics from the cache.</summary> public static ModStatistics LoadModStatistics(int modId) { string statsFilePath = GenerateModStatisticsFilePath(modId); ModStatistics stats = IOUtilities.ReadJsonObjectFile <ModStatistics>(statsFilePath); return(stats); }
/// <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); } } } } }
/// <summary>Iterates through all of the mod profiles from the given offset.</summary> public static IEnumerable <ModProfile> IterateAllModProfilesFromOffset(int offset) { 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); } } } } }
/// <summary>Retrieves the game's profile from the cache.</summary> public static GameProfile LoadGameProfile() { return(IOUtilities.ReadJsonObjectFile <GameProfile>(gameProfileFilePath)); }
/// <summary>Retrieves the file paths for the mod logos in the cache.</summary> public static Dictionary <LogoSize, string> GetModLogoVersionFileNames(int modId) { return(IOUtilities.ReadJsonObjectFile <Dictionary <LogoSize, string> >(CacheClient.GenerateModLogoVersionInfoFilePath(modId))); }
/// <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); } } } } }