Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        public static Texture2D LoadModLogo(int modId, LogoSize size)
        {
            string    logoFilePath = CacheClient.GenerateModLogoFilePath(modId, size);
            Texture2D logoTexture  = CacheClient.ReadImageFile(logoFilePath);

            return(logoTexture);
        }
Esempio n. 3
0
        /// <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);
        }
Esempio n. 4
0
        /// <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);
            }
        }
Esempio n. 5
0
        /// <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);
        }