예제 #1
0
        /// <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));
        }
예제 #2
0
        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);
                    }
                }
            }
        }
예제 #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);
        }
예제 #4
0
        /// <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);
        }
예제 #5
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));
        }
예제 #6
0
        public static bool SaveUserProfile(UserProfile userProfile)
        {
            Debug.Assert(userProfile != null);

            string filePath = CacheClient.GenerateUserProfileFilePath(userProfile.id);

            return(LocalDataStorage.WriteJSONFile(filePath, userProfile));
        }
예제 #7
0
        public static byte[] LoadBinaryFile(string filePath)
        {
            byte[] data = null;

            LocalDataStorage.ReadFile(filePath, out data);

            return(data);
        }
예제 #8
0
        public static T ReadJsonObjectFile <T>(string filePath)
        {
            T parsed;

            LocalDataStorage.ReadJSONFile <T>(filePath, out parsed);

            return(parsed);
        }
예제 #9
0
        /// <summary>Retrieves the game's profile from the cache.</summary>
        public static GameProfile LoadGameProfile()
        {
            GameProfile profile;

            LocalDataStorage.ReadJSONFile(gameProfileFilePath, out profile);

            return(profile);
        }
예제 #10
0
        /// <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);
        }
예제 #11
0
        /// <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));
        }
예제 #12
0
        /// <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);
        }
예제 #13
0
        /// <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);
        }
예제 #14
0
        /// <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);
        }
예제 #15
0
        /// <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);
        }
예제 #16
0
        public static string CalculateFileMD5Hash(string filePath)
        {
            Int64  byteCount;
            string hash;

            LocalDataStorage.GetFileSizeAndHash(filePath, out byteCount, out hash);

            return(hash);
        }
예제 #17
0
        public static UserProfile LoadUserProfile(int userId)
        {
            string      filePath = CacheClient.GenerateUserProfileFilePath(userId);
            UserProfile userProfile;

            LocalDataStorage.ReadJSONFile(filePath, out userProfile);

            return(userProfile);
        }
예제 #18
0
        /// <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);
        }
예제 #19
0
        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);
        }
예제 #20
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));
        }
예제 #21
0
        /// <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);
                        }
                    }
                }
            }
        }
예제 #22
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));
        }
예제 #23
0
        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);
        }
예제 #24
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));
        }
예제 #25
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);
        }
예제 #26
0
        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);
        }
예제 #27
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);
            }
        }
예제 #28
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));
        }
예제 #29
0
        /// <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);
            }
        }
예제 #30
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));
            }
        }