diff --git a/Assets/YooAsset/Runtime/CacheSystem/PersistentTools.cs b/Assets/YooAsset/Runtime/CacheSystem/PersistentTools.cs index ceb7eed..407da3f 100644 --- a/Assets/YooAsset/Runtime/CacheSystem/PersistentTools.cs +++ b/Assets/YooAsset/Runtime/CacheSystem/PersistentTools.cs @@ -32,19 +32,18 @@ namespace YooAsset // 注意:为了方便调试查看,编辑器下把存储目录放到项目里 if (string.IsNullOrEmpty(_sandboxPath)) { - string directory = Path.GetDirectoryName(UnityEngine.Application.dataPath); - string projectPath = GetRegularPath(directory); - _sandboxPath = StringUtility.Format("{0}/Sandbox", projectPath); + string projectPath = Path.GetDirectoryName(UnityEngine.Application.dataPath); + _sandboxPath = Path.Combine(projectPath, "Sandbox"); } #elif UNITY_STANDALONE if (string.IsNullOrEmpty(_sandboxPath)) { - _sandboxPath = StringUtility.Format("{0}/Sandbox", UnityEngine.Application.dataPath); + _sandboxPath = Path.Combine(UnityEngine.Application.dataPath, "Sandbox"); } #else if (string.IsNullOrEmpty(_sandboxPath)) { - _sandboxPath = StringUtility.Format("{0}/Sandbox", UnityEngine.Application.persistentDataPath); + _sandboxPath = Path.Combine(UnityEngine.Application.persistentDataPath, "Sandbox"); } #endif @@ -63,9 +62,9 @@ namespace YooAsset { if (string.IsNullOrEmpty(_buildinPath)) { - _buildinPath = StringUtility.Format("{0}/{1}", UnityEngine.Application.streamingAssetsPath, YooAssetSettings.StreamingAssetsBuildinFolder); + _buildinPath = Path.Combine(UnityEngine.Application.streamingAssetsPath, YooAssetSettings.StreamingAssetsBuildinFolder); } - return StringUtility.Format("{0}/{1}", _buildinPath, path); + return Path.Combine(_buildinPath, path); } /// @@ -74,7 +73,17 @@ namespace YooAsset public static string MakePersistentLoadPath(string path) { string root = GetPersistentRootPath(); - return StringUtility.Format("{0}/{1}", root, path); + return Path.Combine(root, path); + } + public static string MakePersistentLoadPath(string path1, string path2) + { + string root = GetPersistentRootPath(); + return Path.Combine(root, path1, path2); + } + public static string MakePersistentLoadPath(string path1, string path2, string path3) + { + string root = GetPersistentRootPath(); + return Path.Combine(root, path1, path2, path3); } /// @@ -101,7 +110,7 @@ namespace YooAsset /// public static void DeleteSandbox() { - string directoryPath = MakePersistentLoadPath(string.Empty); + string directoryPath = GetPersistentRootPath(); if (Directory.Exists(directoryPath)) Directory.Delete(directoryPath, true); } @@ -135,8 +144,7 @@ namespace YooAsset { if (_cachedBundleFileFolder.TryGetValue(packageName, out string value) == false) { - string root = MakePersistentLoadPath(CacheFolderName); - value = $"{root}/{packageName}/{CachedBundleFileFolder}"; + value = MakePersistentLoadPath(CacheFolderName, packageName, CachedBundleFileFolder); _cachedBundleFileFolder.Add(packageName, value); } return value; @@ -150,8 +158,7 @@ namespace YooAsset { if (_cachedRawFileFolder.TryGetValue(packageName, out string value) == false) { - string root = MakePersistentLoadPath(CacheFolderName); - value = $"{root}/{packageName}/{CachedRawFileFolder}"; + value = MakePersistentLoadPath(CacheFolderName, packageName, CachedRawFileFolder); _cachedRawFileFolder.Add(packageName, value); } return value; @@ -171,7 +178,7 @@ namespace YooAsset public static string GetCacheManifestFilePath(string packageName, string packageVersion) { string fileName = YooAssetSettingsData.GetManifestBinaryFileName(packageName, packageVersion); - return MakePersistentLoadPath($"{ManifestFolderName}/{fileName}"); + return MakePersistentLoadPath(ManifestFolderName, fileName); } /// @@ -180,7 +187,7 @@ namespace YooAsset public static string GetCachePackageHashFilePath(string packageName, string packageVersion) { string fileName = YooAssetSettingsData.GetPackageHashFileName(packageName, packageVersion); - return MakePersistentLoadPath($"{ManifestFolderName}/{fileName}"); + return MakePersistentLoadPath(ManifestFolderName, fileName); } /// @@ -189,7 +196,7 @@ namespace YooAsset public static string GetCachePackageVersionFilePath(string packageName) { string fileName = YooAssetSettingsData.GetPackageVersionFileName(packageName); - return MakePersistentLoadPath($"{ManifestFolderName}/{fileName}"); + return MakePersistentLoadPath(ManifestFolderName, fileName); } /// @@ -198,7 +205,7 @@ namespace YooAsset public static void SaveCachePackageVersionFile(string packageName, string version) { string filePath = GetCachePackageVersionFilePath(packageName); - FileUtility.CreateFile(filePath, version); + FileUtility.WriteAllText(filePath, version); } } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/PackageSystem/PackageBundle.cs b/Assets/YooAsset/Runtime/PackageSystem/PackageBundle.cs index 4045a13..2dac595 100644 --- a/Assets/YooAsset/Runtime/PackageSystem/PackageBundle.cs +++ b/Assets/YooAsset/Runtime/PackageSystem/PackageBundle.cs @@ -75,12 +75,13 @@ namespace YooAsset if (IsRawFile) { string cacheRoot = PersistentTools.GetCachedRawFileFolderPath(PackageName); - _cachedDataFilePath = $"{cacheRoot}/{folderName}/{CacheGUID}/{YooAssetSettings.CacheBundleDataFileName}{_fileExtension}"; + _cachedDataFilePath = System.IO.Path.Combine(cacheRoot, folderName, CacheGUID, YooAssetSettings.CacheBundleDataFileName); + _cachedDataFilePath += _fileExtension; } else { string cacheRoot = PersistentTools.GetCachedBundleFileFolderPath(PackageName); - _cachedDataFilePath = $"{cacheRoot}/{folderName}/{CacheGUID}/{YooAssetSettings.CacheBundleDataFileName}"; + _cachedDataFilePath = System.IO.Path.Combine(cacheRoot, folderName, CacheGUID, YooAssetSettings.CacheBundleDataFileName); } return _cachedDataFilePath; } @@ -101,12 +102,12 @@ namespace YooAsset if (IsRawFile) { string cacheRoot = PersistentTools.GetCachedRawFileFolderPath(PackageName); - _cachedInfoFilePath = $"{cacheRoot}/{folderName}/{CacheGUID}/{YooAssetSettings.CacheBundleInfoFileName}"; + _cachedInfoFilePath = System.IO.Path.Combine(cacheRoot, folderName, CacheGUID, YooAssetSettings.CacheBundleInfoFileName); } else { string cacheRoot = PersistentTools.GetCachedBundleFileFolderPath(PackageName); - _cachedInfoFilePath = $"{cacheRoot}/{folderName}/{CacheGUID}/{YooAssetSettings.CacheBundleInfoFileName}"; + _cachedInfoFilePath = System.IO.Path.Combine(cacheRoot, folderName, CacheGUID, YooAssetSettings.CacheBundleInfoFileName); } return _cachedInfoFilePath; }