Пример #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);
        }
Пример #2
0
        // ---------[ MOD IMAGES ]---------
        // TODO(@jackson): Look at reconfiguring params
        public static void GetModLogo(ModProfile profile, LogoSize size,
                                      Action <Texture2D> onSuccess,
                                      Action <WebRequestError> onError)
        {
            Debug.Assert(onSuccess != null);

            var logoTexture = CacheClient.LoadModLogo(profile.id, size);

            if (logoTexture != null)
            {
                onSuccess(logoTexture);
            }

            var versionInfo = CacheClient.LoadModLogoVersionInfo(profile.id);

            if (logoTexture == null ||
                versionInfo[size] != profile.logoLocator.GetFileName())
            {
                var textureDownload = DownloadClient.DownloadModLogo(profile, size);

                textureDownload.succeeded += (d) =>
                {
                    CacheClient.SaveModLogo(profile.id, profile.logoLocator.GetFileName(),
                                            size, d.imageTexture);
                };

                textureDownload.succeeded += (d) => onSuccess(d.imageTexture);
                textureDownload.failed    += (d) => onError(d.error);
            }
        }