/// <summary>Stores a mod's statistics in the cache.</summary> public static bool SaveModStatistics(ModStatistics stats) { Debug.Assert(stats != null); string statsFilePath = GenerateModStatisticsFilePath(stats.modId); return(LocalDataStorage.WriteJSONFile(statsFilePath, stats)); }
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); } } } }
/// <summary>Stores a mod logo in the cache with the given fileName.</summary> public static bool SaveModLogo(int modId, string fileName, LogoSize size, Texture2D logoTexture) { Debug.Assert(!String.IsNullOrEmpty(fileName)); Debug.Assert(logoTexture != null); bool success = false; string logoFilePath = CacheClient.GenerateModLogoFilePath(modId, size); byte[] imageData = logoTexture.EncodeToPNG(); // write file if (LocalDataStorage.WriteFile(logoFilePath, imageData)) { success = true; // - Update the versioning info - var versionInfo = CacheClient.GetModLogoVersionFileNames(modId); if (versionInfo == null) { versionInfo = new Dictionary <LogoSize, string>(); } versionInfo[size] = fileName; LocalDataStorage.WriteJSONFile(GenerateModLogoVersionInfoFilePath(modId), versionInfo); } return(success); }
/// <summary>Determines how many ModProfiles are currently stored in the cache.</summary> public static int CountModProfiles() { 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]; } return(modDirectories.Count); } return(0); }
/// <summary>Stores a mod's profile in the cache.</summary> public static bool SaveModProfile(ModProfile profile) { Debug.Assert(profile != null); string path = GenerateModProfileFilePath(profile.id); return(LocalDataStorage.WriteJSONFile(path, profile)); }
public static bool SaveUserProfile(UserProfile userProfile) { Debug.Assert(userProfile != null); string filePath = CacheClient.GenerateUserProfileFilePath(userProfile.id); return(LocalDataStorage.WriteJSONFile(filePath, userProfile)); }
public static byte[] LoadBinaryFile(string filePath) { byte[] data = null; LocalDataStorage.ReadFile(filePath, out data); return(data); }
public static T ReadJsonObjectFile <T>(string filePath) { T parsed; LocalDataStorage.ReadJSONFile <T>(filePath, out parsed); return(parsed); }
/// <summary>Retrieves the game's profile from the cache.</summary> public static GameProfile LoadGameProfile() { GameProfile profile; LocalDataStorage.ReadJSONFile(gameProfileFilePath, out profile); 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); List <ModTeamMember> modTeam; LocalDataStorage.ReadJSONFile(filePath, out modTeam); return(modTeam); }
/// <summary>Stores a mod team's data in the cache.</summary> public static bool SaveModTeam(int modId, List <ModTeamMember> modTeam) { Debug.Assert(modTeam != null); string filePath = CacheClient.GenerateModTeamFilePath(modId); return(LocalDataStorage.WriteJSONFile(filePath, modTeam)); }
/// <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); }
/// <summary>Retrieves a mod binary's ZipFile data from the cache.</summary> public static byte[] LoadModBinaryZip(int modId, int modfileId) { string filePath = GenerateModBinaryZipFilePath(modId, modfileId); byte[] zipData; LocalDataStorage.ReadFile(filePath, out zipData); return(zipData); }
/// <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); }
/// <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); }
public static string CalculateFileMD5Hash(string filePath) { Int64 byteCount; string hash; LocalDataStorage.GetFileSizeAndHash(filePath, out byteCount, out hash); return(hash); }
public static UserProfile LoadUserProfile(int userId) { string filePath = CacheClient.GenerateUserProfileFilePath(userId); UserProfile userProfile; LocalDataStorage.ReadJSONFile(filePath, out userProfile); return(userProfile); }
/// <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); }
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); }
/// <summary>Stores a mod binary's ZipFile data in the cache.</summary> public static bool SaveModBinaryZip(int modId, int modfileId, byte[] modBinary) { Debug.Assert(modBinary != null); Debug.Assert(modBinary.Length > 0); string filePath = GenerateModBinaryZipFilePath(modId, modfileId); return(LocalDataStorage.WriteFile(filePath, modBinary)); }
/// <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>Stores a user's avatar in the cache.</summary> public static bool SaveUserAvatar(int userId, UserAvatarSize size, Texture2D avatarTexture) { Debug.Assert(avatarTexture != null); string avatarFilePath = CacheClient.GenerateUserAvatarFilePath(userId, size); byte[] imageData = avatarTexture.EncodeToPNG(); return(LocalDataStorage.WriteFile(avatarFilePath, imageData)); }
public static bool TryLoadBinaryFile(string filePath, out byte[] output) { bool success = false; byte[] data = null; success = LocalDataStorage.ReadFile(filePath, out data); output = data; return(success); }
/// <summary>Stores a YouTube thumbnail in the cache.</summary> public static bool SaveModYouTubeThumbnail(int modId, string youTubeId, Texture2D thumbnail) { Debug.Assert(!String.IsNullOrEmpty(youTubeId)); Debug.Assert(thumbnail != null); string thumbnailFilePath = CacheClient.GenerateModYouTubeThumbnailFilePath(modId, youTubeId); byte[] imageData = thumbnail.EncodeToPNG(); return(LocalDataStorage.WriteFile(thumbnailFilePath, imageData)); }
public static bool WritePNGFile(string filePath, Texture2D texture) { byte[] data = null; if (texture != null) { data = texture.EncodeToPNG(); if (data != null) { return(LocalDataStorage.WriteFile(filePath, data)); } } return(false); }
public static Texture2D ReadImageFile(string filePath) { Texture2D parsed = null; bool success = false; byte[] data = null; success = LocalDataStorage.ReadFile(filePath, out data); if (success) { parsed = IOUtilities.ParseImageData(data); } return(parsed); }
/// <summary>Retrieves a mod logo from the cache.</summary> public static Texture2D LoadModLogo(int modId, LogoSize size) { string logoFilePath = CacheClient.GenerateModLogoFilePath(modId, size); byte[] imageData; if (LocalDataStorage.ReadFile(logoFilePath, out imageData) && imageData != null) { return(IOUtilities.ParseImageData(imageData)); } else { return(null); } }
/// <summary>Stores a mod gallery image in the cache.</summary> public static bool SaveModGalleryImage(int modId, string imageFileName, ModGalleryImageSize size, Texture2D imageTexture) { Debug.Assert(!String.IsNullOrEmpty(imageFileName)); Debug.Assert(imageTexture != null); string imageFilePath = CacheClient.GenerateModGalleryImageFilePath(modId, imageFileName, size); byte[] imageData = imageTexture.EncodeToPNG(); return(LocalDataStorage.WriteFile(imageFilePath, imageData)); }
/// <summary>Retrieves a user's avatar from the cache.</summary> public static Texture2D LoadUserAvatar(int userId, UserAvatarSize size) { string avatarFilePath = CacheClient.GenerateUserAvatarFilePath(userId, size); byte[] imageData; if (LocalDataStorage.ReadFile(avatarFilePath, out imageData) && imageData != null) { return(IOUtilities.ParseImageData(imageData)); } else { return(null); } }
private static void DownloadModBinary_Internal(ModfileIdPair idPair, string downloadURL) { FileDownloadInfo downloadInfo = modfileDownloadMap[idPair]; downloadInfo.request = UnityWebRequest.Get(downloadURL); string tempFilePath = downloadInfo.target + ".download"; bool success = false; success = LocalDataStorage.WriteFile(tempFilePath, new byte[0]); if (success) { downloadInfo.request.downloadHandler = new DownloadHandlerFile(tempFilePath); #if PLATFORM_PS4 // NOTE(@jackson): This workaround addresses an issue in UnityWebRequests on the // PS4 whereby redirects fail in specific cases. Special thanks to @Eamon of // Spiderling Studios (http://spiderlinggames.co.uk/) downloadInfo.request.redirectLimit = 0; #endif var operation = downloadInfo.request.SendWebRequest(); #if DEBUG DebugUtilities.DebugDownload(operation, LocalUser.instance, tempFilePath); #endif operation.completed += (o) => DownloadClient.OnModBinaryRequestCompleted(idPair); DownloadClient.StartMonitoringSpeed(); // notify download started if (DownloadClient.modfileDownloadStarted != null) { DownloadClient.modfileDownloadStarted(idPair, downloadInfo); } } else if (DownloadClient.modfileDownloadFailed != null) { string warningInfo = ("Failed to create download file on disk." + "\nSource: " + downloadURL + "\nDestination: " + tempFilePath + "\n\n"); modfileDownloadFailed(idPair, WebRequestError.GenerateLocal(warningInfo)); } }