Example #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));
        }
Example #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);
                    }
                }
            }
        }
Example #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);
        }
Example #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);
        }
Example #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));
        }
Example #6
0
        public static bool SaveUserProfile(UserProfile userProfile)
        {
            Debug.Assert(userProfile != null);

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

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

            LocalDataStorage.ReadFile(filePath, out data);

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

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

            return(parsed);
        }
Example #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);
        }
Example #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);
        }
Example #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));
        }
Example #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);
        }
Example #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);
        }
Example #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);
        }
Example #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);
        }
Example #16
0
        public static string CalculateFileMD5Hash(string filePath)
        {
            Int64  byteCount;
            string hash;

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

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

            LocalDataStorage.ReadJSONFile(filePath, out userProfile);

            return(userProfile);
        }
Example #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);
        }
Example #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);
        }
Example #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));
        }
Example #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);
                        }
                    }
                }
            }
        }
Example #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));
        }
Example #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);
        }
Example #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));
        }
Example #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);
        }
Example #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);
        }
Example #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);
            }
        }
Example #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));
        }
Example #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);
            }
        }
Example #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));
            }
        }