update runtime code
重构了PersistentTools类
This commit is contained in:
@@ -45,7 +45,7 @@ namespace YooAsset
|
||||
{
|
||||
// BundleFiles
|
||||
{
|
||||
string rootPath = PersistentTools.GetCachedBundleFileFolderPath(_packageName);
|
||||
string rootPath = PersistentTools.GetPersistent(_packageName).SandboxCacheBundleFilesRoot;
|
||||
DirectoryInfo rootDirectory = new DirectoryInfo(rootPath);
|
||||
if (rootDirectory.Exists)
|
||||
{
|
||||
@@ -56,7 +56,7 @@ namespace YooAsset
|
||||
|
||||
// RawFiles
|
||||
{
|
||||
string rootPath = PersistentTools.GetCachedRawFileFolderPath(_packageName);
|
||||
string rootPath = PersistentTools.GetPersistent(_packageName).SandboxCacheRawFilesRoot;
|
||||
DirectoryInfo rootDirectory = new DirectoryInfo(rootPath);
|
||||
if (rootDirectory.Exists)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,163 @@
|
||||
using System.IO;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class Persistent
|
||||
{
|
||||
private readonly string _packageName;
|
||||
|
||||
public string BuildinRoot { private set; get; }
|
||||
public string BuildinPackageRoot { private set; get; }
|
||||
|
||||
public string SandboxRoot { private set; get; }
|
||||
public string SandboxPackageRoot { private set; get; }
|
||||
public string SandboxCacheBundleFilesRoot { private set; get; }
|
||||
public string SandboxCacheRawFilesRoot { private set; get; }
|
||||
public string SandboxManifestFilesRoot { private set; get; }
|
||||
public string SandboxAppFootPrintFilePath { private set; get; }
|
||||
|
||||
|
||||
public Persistent(string packageName)
|
||||
{
|
||||
_packageName = packageName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重写根路径
|
||||
/// </summary>
|
||||
public void OverwriteRootDirectory(string buildinRoot, string sandboxRoot)
|
||||
{
|
||||
if (string.IsNullOrEmpty(buildinRoot))
|
||||
BuildinRoot = CreateDefaultBuildinRoot();
|
||||
else
|
||||
BuildinRoot = buildinRoot;
|
||||
|
||||
if (string.IsNullOrEmpty(sandboxRoot))
|
||||
SandboxRoot = CreateDefaultSandboxRoot();
|
||||
else
|
||||
SandboxRoot = sandboxRoot;
|
||||
|
||||
BuildinPackageRoot = PathUtility.Combine(BuildinRoot, _packageName);
|
||||
SandboxPackageRoot = PathUtility.Combine(SandboxRoot, _packageName);
|
||||
SandboxCacheBundleFilesRoot = PathUtility.Combine(SandboxPackageRoot, YooAssetSettings.CachedBundleFileFolder);
|
||||
SandboxCacheRawFilesRoot = PathUtility.Combine(SandboxPackageRoot, YooAssetSettings.CachedRawFileFolder);
|
||||
SandboxManifestFilesRoot = PathUtility.Combine(SandboxPackageRoot, YooAssetSettings.ManifestFolderName);
|
||||
SandboxAppFootPrintFilePath = PathUtility.Combine(SandboxPackageRoot, YooAssetSettings.AppFootPrintFileName);
|
||||
}
|
||||
private static string CreateDefaultBuildinRoot()
|
||||
{
|
||||
return PathUtility.Combine(UnityEngine.Application.streamingAssetsPath, YooAssetSettings.DefaultYooFolderName);
|
||||
}
|
||||
private static string CreateDefaultSandboxRoot()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
// 注意:为了方便调试查看,编辑器下把存储目录放到项目里。
|
||||
string projectPath = Path.GetDirectoryName(UnityEngine.Application.dataPath);
|
||||
projectPath = PathUtility.RegularPath(projectPath);
|
||||
return PathUtility.Combine(projectPath, YooAssetSettings.DefaultYooFolderName);
|
||||
#elif UNITY_STANDALONE
|
||||
return PathUtility.Combine(UnityEngine.Application.dataPath, YooAssetSettings.DefaultYooFolderName);
|
||||
#else
|
||||
return PathUtility.Combine(UnityEngine.Application.persistentDataPath, YooAssetSettings.DefaultYooFolderName);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 删除沙盒里的包裹目录
|
||||
/// </summary>
|
||||
public void DeleteSandboxPackageFolder()
|
||||
{
|
||||
if (Directory.Exists(SandboxPackageRoot))
|
||||
Directory.Delete(SandboxPackageRoot, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除沙盒内的缓存文件夹
|
||||
/// </summary>
|
||||
public void DeleteSandboxCacheFilesFolder()
|
||||
{
|
||||
// CacheBundleFiles
|
||||
if (Directory.Exists(SandboxCacheBundleFilesRoot))
|
||||
Directory.Delete(SandboxCacheBundleFilesRoot, true);
|
||||
|
||||
// CacheRawFiles
|
||||
if (Directory.Exists(SandboxCacheRawFilesRoot))
|
||||
Directory.Delete(SandboxCacheRawFilesRoot, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除沙盒内的清单文件夹
|
||||
/// </summary>
|
||||
public void DeleteSandboxManifestFilesFolder()
|
||||
{
|
||||
if (Directory.Exists(SandboxManifestFilesRoot))
|
||||
Directory.Delete(SandboxManifestFilesRoot, true);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取沙盒内包裹的清单文件的路径
|
||||
/// </summary>
|
||||
public string GetSandboxPackageManifestFilePath(string packageVersion)
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_packageName, packageVersion);
|
||||
return PathUtility.Combine(SandboxManifestFilesRoot, fileName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取沙盒内包裹的哈希文件的路径
|
||||
/// </summary>
|
||||
public string GetSandboxPackageHashFilePath(string packageVersion)
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetPackageHashFileName(_packageName, packageVersion);
|
||||
return PathUtility.Combine(SandboxManifestFilesRoot, fileName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取沙盒内包裹的版本文件的路径
|
||||
/// </summary>
|
||||
public string GetSandboxPackageVersionFilePath()
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetPackageVersionFileName(_packageName);
|
||||
return PathUtility.Combine(SandboxManifestFilesRoot, fileName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存沙盒内默认的包裹版本
|
||||
/// </summary>
|
||||
public void SaveSandboxPackageVersionFile(string version)
|
||||
{
|
||||
string filePath = GetSandboxPackageVersionFilePath();
|
||||
FileUtility.WriteAllText(filePath, version);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取APP内包裹的清单文件的路径
|
||||
/// </summary>
|
||||
public string GetBuildinPackageManifestFilePath(string packageVersion)
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_packageName, packageVersion);
|
||||
return PathUtility.Combine(BuildinPackageRoot, fileName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取APP内包裹的哈希文件的路径
|
||||
/// </summary>
|
||||
public string GetBuildinPackageHashFilePath(string packageVersion)
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetPackageHashFileName(_packageName, packageVersion);
|
||||
return PathUtility.Combine(BuildinPackageRoot, fileName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取APP内包裹的版本文件的路径
|
||||
/// </summary>
|
||||
public string GetBuildinPackageVersionFilePath()
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetPackageVersionFileName(_packageName);
|
||||
return PathUtility.Combine(BuildinPackageRoot, fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 62ee5fd2821fe85488efff3f8242b703
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -3,92 +3,31 @@ using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal static class PersistentTools
|
||||
internal class PersistentTools
|
||||
{
|
||||
private const string SandboxFolderName = "Sandbox";
|
||||
private const string CacheFolderName = "CacheFiles";
|
||||
private const string CachedBundleFileFolder = "BundleFiles";
|
||||
private const string CachedRawFileFolder = "RawFiles";
|
||||
private const string ManifestFolderName = "ManifestFiles";
|
||||
private const string AppFootPrintFileName = "ApplicationFootPrint.bytes";
|
||||
|
||||
private static string _buildinPath;
|
||||
private static string _sandboxPath;
|
||||
|
||||
private static readonly Dictionary<string, Persistent> _persitentDic = new Dictionary<string, Persistent>(100);
|
||||
|
||||
/// <summary>
|
||||
/// 重写内置跟路径
|
||||
/// 获取包裹的持久化类
|
||||
/// </summary>
|
||||
public static void OverwriteBuildinPath(string path)
|
||||
public static Persistent GetPersistent(string packageName)
|
||||
{
|
||||
_buildinPath = path;
|
||||
if (_persitentDic.ContainsKey(packageName) == false)
|
||||
throw new System.Exception("Should never get here !");
|
||||
return _persitentDic[packageName];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重写沙盒跟路径
|
||||
/// 获取或创建包裹的持久化类
|
||||
/// </summary>
|
||||
public static void OverwriteSandboxPath(string path)
|
||||
public static Persistent GetOrCreatePersistent(string packageName)
|
||||
{
|
||||
_sandboxPath = path;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取沙盒文件夹路径
|
||||
/// </summary>
|
||||
public static string GetPersistentRootPath()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
// 注意:为了方便调试查看,编辑器下把存储目录放到项目里
|
||||
if (string.IsNullOrEmpty(_sandboxPath))
|
||||
if (_persitentDic.ContainsKey(packageName) == false)
|
||||
{
|
||||
string projectPath = Path.GetDirectoryName(UnityEngine.Application.dataPath);
|
||||
projectPath = PathUtility.RegularPath(projectPath);
|
||||
_sandboxPath = PathUtility.Combine(projectPath, SandboxFolderName);
|
||||
Persistent persistent = new Persistent(packageName);
|
||||
_persitentDic.Add(packageName, persistent);
|
||||
}
|
||||
#elif UNITY_STANDALONE
|
||||
if (string.IsNullOrEmpty(_sandboxPath))
|
||||
{
|
||||
_sandboxPath = PathUtility.Combine(UnityEngine.Application.dataPath, SandboxFolderName);
|
||||
}
|
||||
#else
|
||||
if (string.IsNullOrEmpty(_sandboxPath))
|
||||
{
|
||||
_sandboxPath = PathUtility.Combine(UnityEngine.Application.persistentDataPath, SandboxFolderName);
|
||||
}
|
||||
#endif
|
||||
|
||||
return _sandboxPath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取基于流文件夹的加载路径
|
||||
/// </summary>
|
||||
public static string MakeStreamingLoadPath(string path)
|
||||
{
|
||||
if (string.IsNullOrEmpty(_buildinPath))
|
||||
{
|
||||
_buildinPath = PathUtility.Combine(UnityEngine.Application.streamingAssetsPath, YooAssetSettings.StreamingAssetsBuildinFolder);
|
||||
}
|
||||
return PathUtility.Combine(_buildinPath, path);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取基于沙盒文件夹的加载路径
|
||||
/// </summary>
|
||||
public static string MakePersistentLoadPath(string path)
|
||||
{
|
||||
string root = GetPersistentRootPath();
|
||||
return PathUtility.Combine(root, path);
|
||||
}
|
||||
public static string MakePersistentLoadPath(string path1, string path2)
|
||||
{
|
||||
string root = GetPersistentRootPath();
|
||||
return PathUtility.Combine(root, path1, path2);
|
||||
}
|
||||
public static string MakePersistentLoadPath(string path1, string path2, string path3)
|
||||
{
|
||||
string root = GetPersistentRootPath();
|
||||
return PathUtility.Combine(root, path1, path2, path3);
|
||||
return _persitentDic[packageName];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -108,109 +47,5 @@ namespace YooAsset
|
||||
return path;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 删除沙盒总目录
|
||||
/// </summary>
|
||||
public static void DeleteSandbox()
|
||||
{
|
||||
string directoryPath = GetPersistentRootPath();
|
||||
if (Directory.Exists(directoryPath))
|
||||
Directory.Delete(directoryPath, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除沙盒内的缓存文件夹
|
||||
/// </summary>
|
||||
public static void DeleteCacheFolder()
|
||||
{
|
||||
string root = MakePersistentLoadPath(CacheFolderName);
|
||||
if (Directory.Exists(root))
|
||||
Directory.Delete(root, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除沙盒内的清单文件夹
|
||||
/// </summary>
|
||||
public static void DeleteManifestFolder()
|
||||
{
|
||||
string root = MakePersistentLoadPath(ManifestFolderName);
|
||||
if (Directory.Exists(root))
|
||||
Directory.Delete(root, true);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取缓存的BundleFile文件夹路径
|
||||
/// </summary>
|
||||
private readonly static Dictionary<string, string> _cachedBundleFileFolder = new Dictionary<string, string>(100);
|
||||
public static string GetCachedBundleFileFolderPath(string packageName)
|
||||
{
|
||||
if (_cachedBundleFileFolder.TryGetValue(packageName, out string value) == false)
|
||||
{
|
||||
value = MakePersistentLoadPath(CacheFolderName, packageName, CachedBundleFileFolder);
|
||||
_cachedBundleFileFolder.Add(packageName, value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取缓存的RawFile文件夹路径
|
||||
/// </summary>
|
||||
private readonly static Dictionary<string, string> _cachedRawFileFolder = new Dictionary<string, string>(100);
|
||||
public static string GetCachedRawFileFolderPath(string packageName)
|
||||
{
|
||||
if (_cachedRawFileFolder.TryGetValue(packageName, out string value) == false)
|
||||
{
|
||||
value = MakePersistentLoadPath(CacheFolderName, packageName, CachedRawFileFolder);
|
||||
_cachedRawFileFolder.Add(packageName, value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取应用程序的水印文件路径
|
||||
/// </summary>
|
||||
public static string GetAppFootPrintFilePath()
|
||||
{
|
||||
return MakePersistentLoadPath(AppFootPrintFileName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取沙盒内清单文件的路径
|
||||
/// </summary>
|
||||
public static string GetCacheManifestFilePath(string packageName, string packageVersion)
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(packageName, packageVersion);
|
||||
return MakePersistentLoadPath(ManifestFolderName, fileName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取沙盒内包裹的哈希文件的路径
|
||||
/// </summary>
|
||||
public static string GetCachePackageHashFilePath(string packageName, string packageVersion)
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetPackageHashFileName(packageName, packageVersion);
|
||||
return MakePersistentLoadPath(ManifestFolderName, fileName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取沙盒内包裹的版本文件的路径
|
||||
/// </summary>
|
||||
public static string GetCachePackageVersionFilePath(string packageName)
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetPackageVersionFileName(packageName);
|
||||
return MakePersistentLoadPath(ManifestFolderName, fileName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存默认的包裹版本
|
||||
/// </summary>
|
||||
public static void SaveCachePackageVersionFile(string packageName, string version)
|
||||
{
|
||||
string filePath = GetCachePackageVersionFilePath(packageName);
|
||||
FileUtility.WriteAllText(filePath, version);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user