Exemple #1
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);
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>Generates a PluginSettings.Data instance with runtime defaults.</summary>
        public static PluginSettings.Data GenerateDefaultData()
        {
            PluginSettings.Data data = new PluginSettings.Data()
            {
                apiURL         = APIClient.API_URL_PRODUCTIONSERVER + APIClient.API_VERSION,
                gameId         = GameProfile.NULL_ID,
                gameAPIKey     = string.Empty,
                requestLogging = new RequestLoggingOptions()
                {
                    errorsAsWarnings = true,
                    logAllResponses  = false,
                    logOnSend        = false,
                },

                installationDirectory = IOUtilities.CombinePath("$DATA_PATH$", "mod.io", "mods"),
                cacheDirectory        = IOUtilities.CombinePath("$DATA_PATH$", "mod.io", "cache"),
                userDirectory         = IOUtilities.CombinePath("$PERSISTENT_DATA_PATH$", "mod.io-$GAME_ID$"),

                installationDirectoryEditor = IOUtilities.CombinePath("$CURRENT_DIRECTORY$", "mod.io", "editor", "$GAME_ID$", "mods"),
                cacheDirectoryEditor        = IOUtilities.CombinePath("$CURRENT_DIRECTORY$", "mod.io", "editor", "$GAME_ID$", "cache"),
                userDirectoryEditor         = IOUtilities.CombinePath("$CURRENT_DIRECTORY$", "mod.io", "editor", "$GAME_ID$", "user"),
            };

            return(data);
        }
Exemple #3
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);
        }
Exemple #4
0
 // ---------[ USERS ]---------
 /// <summary>Generates the file path for a user's profile.</summary>
 public static string GenerateUserProfileFilePath(int userId)
 {
     return(IOUtilities.CombinePath(CacheClient.cacheDirectory,
                                    "users",
                                    userId.ToString(),
                                    "profile.data"));
 }
Exemple #5
0
 public static string GenerateUserProfileFilePath(int userId)
 {
     return(IOUtilities.CombinePath(PluginSettings.CACHE_DIRECTORY,
                                    "users",
                                    userId.ToString(),
                                    "profile.data"));
 }
Exemple #6
0
        /// <summary>Iterates through all the user profiles in the cache.</summary>
        public static IEnumerable <UserProfile> IterateAllUserProfiles()
        {
            string profileDirectory = IOUtilities.CombinePath(CacheClient.cacheDirectory,
                                                              "users");

            if (Directory.Exists(profileDirectory))
            {
                string[] userFiles;
                try
                {
                    userFiles = Directory.GetFiles(profileDirectory);
                }
                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)
                {
                    var profile = IOUtilities.ReadJsonObjectFile <UserProfile>(profileFilePath);
                    if (profile != null)
                    {
                        yield return(profile);
                    }
                }
            }
        }
Exemple #7
0
        /// <summary>Determines how many ModProfiles are currently stored in the cache.</summary>
        public static int CountModProfiles()
        {
            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];
                }

                return(modDirectories.Length);
            }

            return(0);
        }
Exemple #8
0
 /// <summary>Generates the file path for a YouTube thumbnail.</summary>
 public static string GenerateModYouTubeThumbnailFilePath(int modId,
                                                          string youTubeId)
 {
     return(IOUtilities.CombinePath(GenerateModMediaDirectoryPath(modId),
                                    "youTube",
                                    youTubeId + ".png"));
 }
Exemple #9
0
        /// <summary>Gets the size and md5 hash of a file.</summary>
        public void GetFileSizeAndHash(string relativePath, GetFileSizeAndHashCallback callback)
        {
            Debug.Assert(!string.IsNullOrEmpty(relativePath));
            Debug.Assert(callback != null);

            string path = IOUtilities.CombinePath(this.userDir, relativePath);

            byte[] data      = null;
            Int64  byteCount = -1;
            string md5Hash   = null;

            if (Steamworks.SteamRemoteStorage.FileExists(path))
            {
                data = Steamworks.SteamRemoteStorage.FileRead(path);

                if (data != null)
                {
                    byteCount = data.Length;

                    using (var md5 = System.Security.Cryptography.MD5.Create())
                    {
                        var hash = md5.ComputeHash(data);
                        md5Hash = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
                    }
                }
            }

            callback.Invoke(relativePath, (data != null), byteCount, md5Hash);
        }
Exemple #10
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);
                        }
                    }
                }
            }
        }
Exemple #11
0
 /// <summary>Generates the file path for a mod galley image.</summary>
 public static string GenerateModGalleryImageFilePath(int modId,
                                                      string imageFileName,
                                                      ModGalleryImageSize size)
 {
     return(IOUtilities.CombinePath(GenerateModMediaDirectoryPath(modId),
                                    "images_" + size.ToString(),
                                    Path.GetFileNameWithoutExtension(imageFileName) + ".png"));
 }
Exemple #12
0
        /// <summary>Function for deleting a user-specific file.</summary>
        public static void DeleteFile(string filePathRelative, WriteFileCallback callback)
        {
            Debug.Assert(UserDataStorage.isInitialized);
            Debug.Assert(!string.IsNullOrEmpty(filePathRelative));

            string filePath = IOUtilities.CombinePath(UserDataStorage.activeUserDirectory, filePathRelative);

            UserDataStorage.PLATFORM.DeleteFile(filePath, callback);
        }
Exemple #13
0
        /// <summary>Gets the size of a file.</summary>
        public void GetFileSize(string relativePath, GetFileSizeCallback callback)
        {
            Debug.Assert(!string.IsNullOrEmpty(relativePath));
            Debug.Assert(callback != null);

            string path      = IOUtilities.CombinePath(this.userDir, relativePath);
            Int64  byteCount = this.GetFileSize(path);

            callback.Invoke(relativePath, byteCount);
        }
Exemple #14
0
        /// <summary>Checks for the existence of a file.</summary>
        public void GetFileExists(string relativePath, GetFileExistsCallback callback)
        {
            Debug.Assert(!string.IsNullOrEmpty(relativePath));
            Debug.Assert(callback != null);

            string path       = IOUtilities.CombinePath(this.userDir, relativePath);
            bool   fileExists = Steamworks.SteamRemoteStorage.FileExists(path);

            callback.Invoke(relativePath, fileExists);
        }
Exemple #15
0
        /// <summary>Gets the size of a file.</summary>
        public void GetFileSize(string relativePath, GetFileSizeCallback callback)
        {
            Debug.Assert(!string.IsNullOrEmpty(relativePath));
            Debug.Assert(callback != null);

            string path     = IOUtilities.CombinePath(this.userDir, relativePath);
            int    fileSize = Steamworks.SteamRemoteStorage.FileSize(path);

            callback.Invoke(relativePath, (Int64)fileSize);
        }
Exemple #16
0
        /// <summary>Checks for the existence of a file.</summary>
        public void GetFileExists(string relativePath, GetFileExistsCallback callback)
        {
            Debug.Assert(!string.IsNullOrEmpty(relativePath));
            Debug.Assert(callback != null);

            string path      = IOUtilities.CombinePath(this.userDir, relativePath);
            bool   doesExist = this.GetFileExists(path);

            callback.Invoke(relativePath, doesExist);
        }
Exemple #17
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);
                        }
                    }
                }
            }
        }
        #pragma warning restore 0649

        /// <summary>Loads the Data from the asset instance.</summary>
        private static void LoadDataInstance()
        {
            PluginSettings wrapper = Resources.Load <PluginSettings>(PluginSettings.FILE_PATH);

            if (wrapper == null)
            {
                PluginSettings._dataInstance = new Data();
            }
            else
            {
                Data settings = wrapper.m_data;

                // - Path variable replacement -
                // cachedir
                if (settings.cacheDirectory != null)
                {
                    string[] cacheDirParts = settings.cacheDirectory.Split(System.IO.Path.AltDirectorySeparatorChar,
                                                                           System.IO.Path.DirectorySeparatorChar);
                    for (int i = 0; i < cacheDirParts.Length; ++i)
                    {
                        if (cacheDirParts[i].ToUpper().Equals("$PERSISTENT_DATA_PATH$"))
                        {
                            cacheDirParts[i] = Application.persistentDataPath;
                        }

                        cacheDirParts[i] = cacheDirParts[i].Replace("$GAME_ID$", settings.gameId.ToString());
                    }
                    settings.cacheDirectory = IOUtilities.CombinePath(cacheDirParts);
                }

                // installdir
                if (settings.installationDirectory != null)
                {
                    string[] installDirParts = settings.installationDirectory.Split(System.IO.Path.AltDirectorySeparatorChar,
                                                                                    System.IO.Path.DirectorySeparatorChar);
                    for (int i = 0; i < installDirParts.Length; ++i)
                    {
                        if (installDirParts[i].ToUpper().Equals("$PERSISTENT_DATA_PATH$"))
                        {
                            installDirParts[i] = Application.persistentDataPath;
                        }

                        installDirParts[i] = installDirParts[i].Replace("$GAME_ID$", settings.gameId.ToString());
                    }

                    settings.installationDirectory = IOUtilities.CombinePath(installDirParts);
                }

                // apply to data instance
                PluginSettings._dataInstance = settings;
            }

            PluginSettings._loaded = true;
        }
Exemple #19
0
        /// <summary>Determines the user directory for a given user id..</summary>
        protected virtual string GenerateActiveUserDirectory(string platformUserId)
        {
            string userDir = PluginSettings.USER_DIRECTORY;

            if (!string.IsNullOrEmpty(platformUserId))
            {
                string folderName = IOUtilities.MakeValidFileName(platformUserId);
                userDir = IOUtilities.CombinePath(PluginSettings.USER_DIRECTORY, folderName);
            }

            return(userDir);
        }
Exemple #20
0
        // --- File Management ---
        /// <summary>Deletes a file.</summary>
        void IUserDataIO.DeleteFile(string relativePath, UserDataIOCallbacks.DeleteFileCallback callback)
        {
            Debug.Assert(!string.IsNullOrEmpty(relativePath));

            string path    = IOUtilities.CombinePath(this.UserDirectory, relativePath);
            bool   success = this.DeleteFile(path);

            if (callback != null)
            {
                callback.Invoke(relativePath, success);
            }
        }
Exemple #21
0
        /// <summary>Determines the user directory for a given user id..</summary>
        protected virtual string GenerateActiveUserDirectory(string platformUserId)
        {
            string userDir = this.rootUserDir;

            if (!string.IsNullOrEmpty(platformUserId))
            {
                string folderName = IOUtilities.MakeValidFileName(platformUserId);
                userDir = IOUtilities.CombinePath(this.rootUserDir, folderName);
            }

            return(userDir);
        }
Exemple #22
0
        /// <summary>Gets the size and md5 hash of a file.</summary>
        public void GetFileSizeAndHash(string relativePath, GetFileSizeAndHashCallback callback)
        {
            Debug.Assert(!string.IsNullOrEmpty(relativePath));
            Debug.Assert(callback != null);

            string path = IOUtilities.CombinePath(this.userDir, relativePath);
            Int64  byteCount;
            string md5Hash;
            bool   success = this.GetFileSizeAndHash(path, out byteCount, out md5Hash);

            callback.Invoke(relativePath, success, byteCount, md5Hash);
        }
Exemple #23
0
        /// <summary>Determines the user directory for a given user id.</summary>
        protected string GenerateActiveUserDirectory(string platformUserId)
        {
            string userDir = SteamworksNETUserDataIO.USER_DIR_ROOT;

            if (!string.IsNullOrEmpty(platformUserId))
            {
                string folderName = IOUtilities.MakeValidFileName(platformUserId);
                userDir = IOUtilities.CombinePath(SteamworksNETUserDataIO.USER_DIR_ROOT, folderName);
            }

            return(userDir);
        }
Exemple #24
0
        /// <summary>Determines the user directory for a given user id.</summary>
        protected string GenerateActiveUserDirectory(string platformUserId)
        {
            string userDir = FacepunchUserDataIO.ROOT_DIR;

            if (!string.IsNullOrEmpty(platformUserId))
            {
                string folderName = IOUtilities.MakeValidFileName(platformUserId);
                userDir = IOUtilities.CombinePath(FacepunchUserDataIO.ROOT_DIR, folderName);
            }

            return(userDir);
        }
Exemple #25
0
        // --- File Management ---
        /// <summary>Deletes a file.</summary>
        public void DeleteFile(string relativePath, DeleteFileCallback callback)
        {
            Debug.Assert(!string.IsNullOrEmpty(relativePath));

            string path    = IOUtilities.CombinePath(this.userDir, relativePath);
            bool   success = this.DeleteFile(path);

            if (callback != null)
            {
                callback.Invoke(relativePath, success);
            }
        }
Exemple #26
0
        // --- File I/O ---
        /// <summary>Reads a file.</summary>
        public void ReadFile(string relativePath, ReadFileCallback callback)
        {
            Debug.Assert(!string.IsNullOrEmpty(relativePath));
            Debug.Assert(callback != null);

            string path = IOUtilities.CombinePath(this.userDir, relativePath);

            byte[] data;
            bool   success = this.ReadFile(path, out data);

            callback.Invoke(relativePath, success, data);
        }
Exemple #27
0
        /// <summary>Writes a file.</summary>
        public void WriteFile(string relativePath, byte[] data, WriteFileCallback callback)
        {
            Debug.Assert(!string.IsNullOrEmpty(relativePath));
            Debug.Assert(data != null);

            string path    = IOUtilities.CombinePath(this.userDir, relativePath);
            bool   success = Steamworks.SteamRemoteStorage.FileWrite(path, data, data.Length);

            if (callback != null)
            {
                callback.Invoke(relativePath, success);
            }
        }
Exemple #28
0
        // --- File I/O ---
        /// <summary>Reads a file.</summary>
        public void ReadFile(string relativePath, ReadFileCallback callback)
        {
            Debug.Assert(!string.IsNullOrEmpty(relativePath));
            Debug.Assert(callback != null);

            string path = IOUtilities.CombinePath(this.userDir, relativePath);

            byte[] data = null;
            if (Steamworks.SteamRemoteStorage.FileExists(path))
            {
                data = Steamworks.SteamRemoteStorage.FileRead(path);
            }

            callback.Invoke(relativePath, (data != null), data);
        }
Exemple #29
0
        /// <summary>Function for writing a user-specific file.</summary>
        public static void WriteFile(string filePathRelative, byte[] fileData, WriteFileCallback callback)
        {
            Debug.Assert(UserDataStorage.isInitialized);
            Debug.Assert(!string.IsNullOrEmpty(filePathRelative));
            Debug.Assert(fileData != null);

            #if DEBUG
            if (fileData.Length == 0)
            {
                Debug.LogWarning("[mod.io] Writing 0-byte user file to: " + filePathRelative);
            }
            #endif // DEBUG

            string filePath = IOUtilities.CombinePath(UserDataStorage.activeUserDirectory, filePathRelative);
            UserDataStorage.PLATFORM.WriteFile(filePath, fileData, callback);
        }
Exemple #30
0
        // --- File Management ---
        /// <summary>Deletes a file.</summary>
        public void DeleteFile(string relativePath, DeleteFileCallback callback)
        {
            Debug.Assert(!string.IsNullOrEmpty(relativePath));

            string path    = IOUtilities.CombinePath(this.userDir, relativePath);
            bool   success = true;

            if (Steamworks.SteamRemoteStorage.FileExists(path))
            {
                success = Steamworks.SteamRemoteStorage.FileDelete(path);
            }

            if (callback != null)
            {
                callback.Invoke(relativePath, success);
            }
        }