Ejemplo n.º 1
0
        /// <summary>Gets the name of the item (file/folder) at the given path.</summary>
        public static string GetPathItemName(string path)
        {
            Debug.Assert(!String.IsNullOrEmpty(path));

            // remove any separators
            while (IOUtilities.PathEndsWithDirectorySeparator(path))
            {
                path = path.Remove(path.Length - 1);
            }

            if (path.Length == 0)
            {
                return(string.Empty);
            }

            // get parent directory and remove
            string folderName      = path;
            string parentDirectory = Path.GetDirectoryName(path);

            if (!String.IsNullOrEmpty(parentDirectory))
            {
                folderName = path.Substring(parentDirectory.Length + 1);
            }

            return(folderName);
        }
Ejemplo n.º 2
0
        /// <summary>Replaces variables in the directory values.</summary>
        public static string ReplaceDirectoryVariables(string directory, int gameId)
        {
            // remove any trailing DSCs from Application paths
            string app_persistentDataPath = Application.persistentDataPath;

            if (IOUtilities.PathEndsWithDirectorySeparator(app_persistentDataPath))
            {
                app_persistentDataPath = app_persistentDataPath.Remove(app_persistentDataPath.Length - 1);
            }
            string app_dataPath = Application.dataPath;

            if (IOUtilities.PathEndsWithDirectorySeparator(app_dataPath))
            {
                app_dataPath = app_dataPath.Remove(app_dataPath.Length - 1);
            }
            string app_temporaryCachePath = Application.temporaryCachePath;

            if (IOUtilities.PathEndsWithDirectorySeparator(app_temporaryCachePath))
            {
                app_temporaryCachePath = app_temporaryCachePath.Remove(app_temporaryCachePath.Length - 1);
            }

            // straight replaces
            directory = (directory
                         .Replace("$PERSISTENT_DATA_PATH$", app_persistentDataPath)
                         .Replace("$DATA_PATH$", app_dataPath)
                         .Replace("$TEMPORARY_CACHE_PATH$", app_temporaryCachePath)
                         .Replace("$BUILD_GUID$", Application.buildGUID)
                         .Replace("$COMPANY_NAME$", Application.companyName)
                         .Replace("$PRODUCT_NAME$", Application.productName)
                         .Replace("$APPLICATION_IDENTIFIER", Application.identifier)
                         .Replace("$GAME_ID$", gameId.ToString())
                         .Replace("$CURRENT_DIRECTORY$", System.IO.Directory.GetCurrentDirectory())
                         );

            return(directory);
        }
Ejemplo n.º 3
0
        // ---------[ Initialization ]---------
        /// <summary>Loads the platform I/O behaviour.</summary>
        static DataStorage()
        {
            // Selects the platform appropriate functions
            #if UNITY_EDITOR
            DataStorage.PLATFORM_IO = new SystemIOWrapper_Editor();
            #else
            DataStorage.PLATFORM_IO = new SystemIOWrapper();
            #endif

            #if DEBUG
            // NOTE(@jackson): Due to hardcoded directory names the following configuration of
            // directories causes errors during the mod installation process.

            const string modCacheDir = "mods";

            string cacheDirNoSep = DataStorage.PLATFORM_IO.CacheDirectory;
            if (IOUtilities.PathEndsWithDirectorySeparator(cacheDirNoSep))
            {
                cacheDirNoSep = cacheDirNoSep.Substring(0, cacheDirNoSep.Length - 1);
            }

            string installDirNoSep = DataStorage.PLATFORM_IO.InstallationDirectory;
            if (IOUtilities.PathEndsWithDirectorySeparator(installDirNoSep))
            {
                installDirNoSep = installDirNoSep.Substring(0, installDirNoSep.Length - 1);
            }

            if (System.IO.Path.GetDirectoryName(installDirNoSep) == cacheDirNoSep &&
                installDirNoSep.Substring(cacheDirNoSep.Length + 1) == modCacheDir)
            {
                Debug.LogError("[mod.io] The installation directory cannot be a directory named"
                               + " 'mods' and a child of the cache directory as this will cause"
                               + " issues during the installation process."
                               + "\nPlease change the values in your PluginSettings.");
            }
            #endif
        }