update runtime code

优化了文件路径合并的逻辑。
pull/122/head
hevinci 2023-06-09 18:25:43 +08:00
parent 895dde1cc8
commit 651b65d148
2 changed files with 29 additions and 21 deletions

View File

@ -32,19 +32,18 @@ namespace YooAsset
// 注意:为了方便调试查看,编辑器下把存储目录放到项目里 // 注意:为了方便调试查看,编辑器下把存储目录放到项目里
if (string.IsNullOrEmpty(_sandboxPath)) if (string.IsNullOrEmpty(_sandboxPath))
{ {
string directory = Path.GetDirectoryName(UnityEngine.Application.dataPath); string projectPath = Path.GetDirectoryName(UnityEngine.Application.dataPath);
string projectPath = GetRegularPath(directory); _sandboxPath = Path.Combine(projectPath, "Sandbox");
_sandboxPath = StringUtility.Format("{0}/Sandbox", projectPath);
} }
#elif UNITY_STANDALONE #elif UNITY_STANDALONE
if (string.IsNullOrEmpty(_sandboxPath)) if (string.IsNullOrEmpty(_sandboxPath))
{ {
_sandboxPath = StringUtility.Format("{0}/Sandbox", UnityEngine.Application.dataPath); _sandboxPath = Path.Combine(UnityEngine.Application.dataPath, "Sandbox");
} }
#else #else
if (string.IsNullOrEmpty(_sandboxPath)) if (string.IsNullOrEmpty(_sandboxPath))
{ {
_sandboxPath = StringUtility.Format("{0}/Sandbox", UnityEngine.Application.persistentDataPath); _sandboxPath = Path.Combine(UnityEngine.Application.persistentDataPath, "Sandbox");
} }
#endif #endif
@ -63,9 +62,9 @@ namespace YooAsset
{ {
if (string.IsNullOrEmpty(_buildinPath)) 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);
} }
/// <summary> /// <summary>
@ -74,7 +73,17 @@ namespace YooAsset
public static string MakePersistentLoadPath(string path) public static string MakePersistentLoadPath(string path)
{ {
string root = GetPersistentRootPath(); 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);
} }
/// <summary> /// <summary>
@ -101,7 +110,7 @@ namespace YooAsset
/// </summary> /// </summary>
public static void DeleteSandbox() public static void DeleteSandbox()
{ {
string directoryPath = MakePersistentLoadPath(string.Empty); string directoryPath = GetPersistentRootPath();
if (Directory.Exists(directoryPath)) if (Directory.Exists(directoryPath))
Directory.Delete(directoryPath, true); Directory.Delete(directoryPath, true);
} }
@ -135,8 +144,7 @@ namespace YooAsset
{ {
if (_cachedBundleFileFolder.TryGetValue(packageName, out string value) == false) if (_cachedBundleFileFolder.TryGetValue(packageName, out string value) == false)
{ {
string root = MakePersistentLoadPath(CacheFolderName); value = MakePersistentLoadPath(CacheFolderName, packageName, CachedBundleFileFolder);
value = $"{root}/{packageName}/{CachedBundleFileFolder}";
_cachedBundleFileFolder.Add(packageName, value); _cachedBundleFileFolder.Add(packageName, value);
} }
return value; return value;
@ -150,8 +158,7 @@ namespace YooAsset
{ {
if (_cachedRawFileFolder.TryGetValue(packageName, out string value) == false) if (_cachedRawFileFolder.TryGetValue(packageName, out string value) == false)
{ {
string root = MakePersistentLoadPath(CacheFolderName); value = MakePersistentLoadPath(CacheFolderName, packageName, CachedRawFileFolder);
value = $"{root}/{packageName}/{CachedRawFileFolder}";
_cachedRawFileFolder.Add(packageName, value); _cachedRawFileFolder.Add(packageName, value);
} }
return value; return value;
@ -171,7 +178,7 @@ namespace YooAsset
public static string GetCacheManifestFilePath(string packageName, string packageVersion) public static string GetCacheManifestFilePath(string packageName, string packageVersion)
{ {
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(packageName, packageVersion); string fileName = YooAssetSettingsData.GetManifestBinaryFileName(packageName, packageVersion);
return MakePersistentLoadPath($"{ManifestFolderName}/{fileName}"); return MakePersistentLoadPath(ManifestFolderName, fileName);
} }
/// <summary> /// <summary>
@ -180,7 +187,7 @@ namespace YooAsset
public static string GetCachePackageHashFilePath(string packageName, string packageVersion) public static string GetCachePackageHashFilePath(string packageName, string packageVersion)
{ {
string fileName = YooAssetSettingsData.GetPackageHashFileName(packageName, packageVersion); string fileName = YooAssetSettingsData.GetPackageHashFileName(packageName, packageVersion);
return MakePersistentLoadPath($"{ManifestFolderName}/{fileName}"); return MakePersistentLoadPath(ManifestFolderName, fileName);
} }
/// <summary> /// <summary>
@ -189,7 +196,7 @@ namespace YooAsset
public static string GetCachePackageVersionFilePath(string packageName) public static string GetCachePackageVersionFilePath(string packageName)
{ {
string fileName = YooAssetSettingsData.GetPackageVersionFileName(packageName); string fileName = YooAssetSettingsData.GetPackageVersionFileName(packageName);
return MakePersistentLoadPath($"{ManifestFolderName}/{fileName}"); return MakePersistentLoadPath(ManifestFolderName, fileName);
} }
/// <summary> /// <summary>
@ -198,7 +205,7 @@ namespace YooAsset
public static void SaveCachePackageVersionFile(string packageName, string version) public static void SaveCachePackageVersionFile(string packageName, string version)
{ {
string filePath = GetCachePackageVersionFilePath(packageName); string filePath = GetCachePackageVersionFilePath(packageName);
FileUtility.CreateFile(filePath, version); FileUtility.WriteAllText(filePath, version);
} }
} }
} }

View File

@ -75,12 +75,13 @@ namespace YooAsset
if (IsRawFile) if (IsRawFile)
{ {
string cacheRoot = PersistentTools.GetCachedRawFileFolderPath(PackageName); 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 else
{ {
string cacheRoot = PersistentTools.GetCachedBundleFileFolderPath(PackageName); string cacheRoot = PersistentTools.GetCachedBundleFileFolderPath(PackageName);
_cachedDataFilePath = $"{cacheRoot}/{folderName}/{CacheGUID}/{YooAssetSettings.CacheBundleDataFileName}"; _cachedDataFilePath = System.IO.Path.Combine(cacheRoot, folderName, CacheGUID, YooAssetSettings.CacheBundleDataFileName);
} }
return _cachedDataFilePath; return _cachedDataFilePath;
} }
@ -101,12 +102,12 @@ namespace YooAsset
if (IsRawFile) if (IsRawFile)
{ {
string cacheRoot = PersistentTools.GetCachedRawFileFolderPath(PackageName); string cacheRoot = PersistentTools.GetCachedRawFileFolderPath(PackageName);
_cachedInfoFilePath = $"{cacheRoot}/{folderName}/{CacheGUID}/{YooAssetSettings.CacheBundleInfoFileName}"; _cachedInfoFilePath = System.IO.Path.Combine(cacheRoot, folderName, CacheGUID, YooAssetSettings.CacheBundleInfoFileName);
} }
else else
{ {
string cacheRoot = PersistentTools.GetCachedBundleFileFolderPath(PackageName); string cacheRoot = PersistentTools.GetCachedBundleFileFolderPath(PackageName);
_cachedInfoFilePath = $"{cacheRoot}/{folderName}/{CacheGUID}/{YooAssetSettings.CacheBundleInfoFileName}"; _cachedInfoFilePath = System.IO.Path.Combine(cacheRoot, folderName, CacheGUID, YooAssetSettings.CacheBundleInfoFileName);
} }
return _cachedInfoFilePath; return _cachedInfoFilePath;
} }