示例#1
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);
        }
示例#2
0
        /// <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));
        }
示例#3
0
        /// <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));
        }
示例#4
0
        /// <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));
        }
示例#5
0
        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);
        }
示例#6
0
        /// <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));
        }
示例#7
0
        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));
            }
        }
示例#8
0
        /// <summary>Writes a JSON file.</summary>
        public static bool WriteJSONFile <T>(string path, T jsonObject)
        {
            bool success = false;

            byte[] data = IOUtilities.GenerateUTF8JSONData <T>(jsonObject);

            if (data != null && data.Length > 0)
            {
                success = LocalDataStorage.WriteFile(path, data);
            }
            else
            {
                Debug.LogWarning("[mod.io] Failed create JSON representation of object before writing file."
                                 + "\nFile: " + path + "\n\n");
            }

            return(success);
        }
示例#9
0
 public static bool WriteBinaryFile(string filePath, byte[] data)
 {
     return(LocalDataStorage.WriteFile(filePath, data));
 }