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

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

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

            LocalDataStorage.ReadFile(filePath, out data);

            return(data);
        }
Esempio n. 8
0
        public static T ReadJsonObjectFile <T>(string filePath)
        {
            T parsed;

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

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

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

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

            LocalDataStorage.ReadJSONFile(filePath, out userProfile);

            return(userProfile);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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));
        }
Esempio n. 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);
                        }
                    }
                }
            }
        }
Esempio n. 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));
        }
Esempio n. 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);
        }
Esempio n. 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));
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
            }
        }
Esempio n. 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));
        }
Esempio n. 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);
            }
        }
Esempio n. 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));
            }
        }