Example #1
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(CacheClient.cacheDirectory, "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(CacheClient.cacheDirectory, "mods");

            if (Directory.Exists(profileDirectory))
            {
                string[] modDirectories;
                try
                {
                    modDirectories = Directory.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];
                }

                int offsetDirCount = modDirectories.Length - offset;
                if (offsetDirCount > 0)
                {
                    string[] offsetModDirectories = new string[offsetDirCount];
                    Array.Copy(modDirectories, offset,
                               offsetModDirectories, 0,
                               offsetDirCount);

                    foreach (string modDirectory in offsetModDirectories)
                    {
                        string     profilePath = IOUtilities.CombinePath(modDirectory, "profile.data");
                        ModProfile profile     = IOUtilities.ReadJsonObjectFile <ModProfile>(profilePath);

                        if (profile != null)
                        {
                            yield return(profile);
                        }
                        else
                        {
                            IOUtilities.DeleteFile(profilePath);
                        }
                    }
                }
            }
        }
Example #2
0
        /// <summary>Deletes a modfile and binary from the cache.</summary>
        public static bool DeleteModfileAndBinaryZip(int modId, int modfileId)
        {
            bool isSuccessful = IOUtilities.DeleteFile(CacheClient.GenerateModfileFilePath(modId, modfileId));

            isSuccessful = (IOUtilities.DeleteFile(CacheClient.GenerateModBinaryZipFilePath(modId, modfileId)) &&
                            isSuccessful);
            return(isSuccessful);
        }
Example #3
0
        /// <summary>Deletes a user data file. (Standalone Application)</summary>
        public static void DeleteFile_Standalone(string filePath, WriteFileCallback callback)
        {
            Debug.Assert(!string.IsNullOrEmpty(filePath));

            bool success = false;

            success = IOUtilities.DeleteFile(filePath);

            if (callback != null)
            {
                callback.Invoke(success);
            }
        }
Example #4
0
        /// <summary>Delete a user file. (Unity Editor)</summary>
        public static void DeleteFile_Editor(string filePath, WriteFileCallback callback)
        {
            Debug.Assert(!string.IsNullOrEmpty(filePath));

            bool fileExisted = System.IO.File.Exists(filePath);
            bool success     = true;

            if (fileExisted)
            {
                success = IOUtilities.DeleteFile(filePath);

                if (success)
                {
                    UnityEditor.AssetDatabase.Refresh();
                }
            }

            if (callback != null)
            {
                callback.Invoke(success);
            }
        }
 /// <summary>Clears the instance and deletes the data on disk.</summary>
 public static void Clear()
 {
     UserAuthenticationData.m_instance = UserAuthenticationData.NONE;
     IOUtilities.DeleteFile(UserAuthenticationData.FILE_LOCATION);
 }
Example #6
0
        // ---------[ 2019 ]---------
        /// <summary>Moves the data from the UserAuthenticationData and ModManager caches to UserAccountManagement.</summary>
        private static void Update_2_0_to_2_1_UserData()
        {
            Debug.Log("[mod.io] Attempting 2.0->2.1 UserData update.");

            // check if the file already exists
            byte[] fileData = null;

            UserDataStorage.InitializeForUser(null, () => {});
            UserDataStorage.ReadFile(LocalUser.FILENAME, (success, data) => fileData = data);

            if (fileData != null && fileData.Length > 0)
            {
                Debug.Log("[mod.io] Aborting UserData update. FileExists: \'"
                          + LocalUser.FILENAME + "\' ["
                          + ValueFormatting.ByteCount(fileData.Length, null) + "]");
            }

            // update
            GenericJSONObject dataWrapper;
            LocalUser         userData = new LocalUser();
            string            filePath = null;

            // - copy enabled/subbed -
            filePath = ModManager.PERSISTENTDATA_FILEPATH;

            if (IOUtilities.TryReadJsonObjectFile(filePath, out dataWrapper))
            {
                int[] modIds = null;

                if (DataUpdater.TryGetArrayField(dataWrapper,
                                                 "subscribedModIds",
                                                 out modIds))
                {
                    userData.subscribedModIds = new List <int>(modIds);
                }

                if (DataUpdater.TryGetArrayField(dataWrapper,
                                                 "enabledModIds",
                                                 out modIds))
                {
                    userData.enabledModIds = new List <int>(modIds);
                }
            }

            // - copy queued subs/unsubs -
            filePath = IOUtilities.CombinePath(CacheClient.cacheDirectory,
                                               ModIO.UI.ModBrowser.MANIFEST_FILENAME);

            if (IOUtilities.TryReadJsonObjectFile(filePath, out dataWrapper))
            {
                List <int> modIds = null;

                if (DataUpdater.TryGetArrayField(dataWrapper,
                                                 "queuedSubscribes",
                                                 out modIds))
                {
                    userData.queuedSubscribes = new List <int>(modIds);
                }

                if (DataUpdater.TryGetArrayField(dataWrapper,
                                                 "queuedUnsubscribes",
                                                 out modIds))
                {
                    userData.queuedUnsubscribes = new List <int>(modIds);
                }
            }

            // - copy UAD -
            filePath = UserAuthenticationData.FILE_LOCATION;

            if (IOUtilities.TryReadJsonObjectFile(filePath, out dataWrapper))
            {
                // user profile
                int userId = UserProfile.NULL_ID;
                if (dataWrapper.data.ContainsKey("userId"))
                {
                    userId = (int)dataWrapper.data["userId"];
                }

                userData.profile = null;
                if (userId != UserProfile.NULL_ID)
                {
                    userData.profile = CacheClient.LoadUserProfile(userId);
                }

                // token data
                if (dataWrapper.data.ContainsKey("token"))
                {
                    userData.oAuthToken = (string)dataWrapper.data["token"];
                }
                if (dataWrapper.data.ContainsKey("wasTokenRejected"))
                {
                    userData.wasTokenRejected = (bool)dataWrapper.data["wasTokenRejected"];
                }

                // NOTE(@jackson): External Authentication is no longer saved to disk and is thus ignored.

                IOUtilities.DeleteFile(filePath);
            }

            // - set and save -
            LocalUser.instance = userData;
            LocalUser.isLoaded = true;
            LocalUser.Save();

            Debug.Log("[mod.io] UserData updated completed.");
        }
Example #7
0
 /// <summary>Deletes a user's profile from the cache.</summary>
 public static bool DeleteUserProfile(int userId)
 {
     return(IOUtilities.DeleteFile(CacheClient.GenerateUserProfileFilePath(userId)));
 }
Example #8
0
 /// <summary>Deletes a mod team's data from the cache.</summary>
 public static bool DeleteModTeam(int modId)
 {
     return(IOUtilities.DeleteFile(CacheClient.GenerateModTeamFilePath(modId)));
 }
Example #9
0
        /// <summary>Iterates through all of the mod profiles returning only those matching the id filter.</summary>
        public static IEnumerable <ModProfile> IterateFilteredModProfiles(IList <int> idFilter)
        {
            if (idFilter == null || idFilter.Count == 0)
            {
                yield break;
            }

            Debug.Assert(IOUtilities.CombinePath(CacheClient.cacheDirectory, "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(CacheClient.cacheDirectory, "mods");

            if (Directory.Exists(profileDirectory))
            {
                string[] modDirectories;
                try
                {
                    modDirectories = Directory.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];
                }

                foreach (string modDirectory in modDirectories)
                {
                    string idPart = modDirectory.Substring(profileDirectory.Length + 1);
                    int    modId  = ModProfile.NULL_ID;
                    if (!int.TryParse(idPart, out modId))
                    {
                        modId = ModProfile.NULL_ID;
                    }

                    if (idFilter.Contains(modId))
                    {
                        string     profilePath = IOUtilities.CombinePath(modDirectory, "profile.data");
                        ModProfile profile     = IOUtilities.ReadJsonObjectFile <ModProfile>(profilePath);

                        if (profile != null)
                        {
                            yield return(profile);
                        }
                        else
                        {
                            IOUtilities.DeleteFile(profilePath);
                        }
                    }
                }
            }
        }