public static void SaveModLogo(int modId, string fileName, LogoSize size, Texture2D logoTexture) { Debug.Assert(modId > 0, "[mod.io] Cannot cache a mod logo without a mod id"); Debug.Assert(!String.IsNullOrEmpty(fileName), "[mod.io] Cannot cache a mod logo without file name as it" + " is used for versioning purposes"); string logoFilePath = CacheClient.GenerateModLogoFilePath(modId, size); CacheClient.WritePNGFile(logoFilePath, logoTexture); // - Version Info - var versionInfo = CacheClient.LoadModLogoVersionInfo(modId); if (versionInfo == null) { versionInfo = new Dictionary <LogoSize, string>(); } versionInfo[size] = fileName; CacheClient.WriteJsonObjectFile(GenerateModLogoVersionInfoFilePath(modId), versionInfo); }
public static Texture2D LoadModLogo(int modId, LogoSize size) { string logoFilePath = CacheClient.GenerateModLogoFilePath(modId, size); Texture2D logoTexture = CacheClient.ReadImageFile(logoFilePath); return(logoTexture); }
/// <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>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 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); string logoFilePath = CacheClient.GenerateModLogoFilePath(modId, size); bool isSuccessful = IOUtilities.WritePNGFile(logoFilePath, logoTexture); // - Update the versioning info - var versionInfo = CacheClient.GetModLogoVersionFileNames(modId); if (versionInfo == null) { versionInfo = new Dictionary <LogoSize, string>(); } versionInfo[size] = fileName; isSuccessful = (IOUtilities.WriteJsonObjectFile(GenerateModLogoVersionInfoFilePath(modId), versionInfo) && isSuccessful); return(isSuccessful); }