热更流程完成
This commit is contained in:
@@ -28,8 +28,8 @@ public class PatchOperation
|
||||
this.data = data;
|
||||
PkgVersionKey = $"{Application.productName}_{data.packageName}";
|
||||
}
|
||||
#region <EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
public async UniTask<InitializationOperation> InitializePackage()
|
||||
#region 初始化相关
|
||||
public async UniTask<bool> InitializePackage()
|
||||
{
|
||||
package = YooAssets.TryGetPackage(data.packageName);
|
||||
if (package == null)
|
||||
@@ -56,7 +56,19 @@ public class PatchOperation
|
||||
break;
|
||||
}
|
||||
await initializationOperation.ToUniTask();
|
||||
return initializationOperation;
|
||||
if (initializationOperation.Status != EOperationStatus.Succeed)
|
||||
{
|
||||
MessageBox.Show()
|
||||
.SetTitle($"{data.packageName}初始化")
|
||||
.SetContent($"{initializationOperation.Error}")
|
||||
.AddButton("退出", (box) => { Application.Quit(); });
|
||||
}
|
||||
else
|
||||
{
|
||||
PatchEvent.UpdateStatus($"初始化成功{data.packageName}");
|
||||
Debug.Log($"初始化成功{data.packageName}");
|
||||
}
|
||||
return initializationOperation.Status == EOperationStatus.Succeed;
|
||||
}
|
||||
private InitializationOperation InitializeEditorMode(ResourcePackage package)
|
||||
{
|
||||
@@ -79,14 +91,14 @@ public class PatchOperation
|
||||
FileSystemParameters buildinFileSystemParams = null;
|
||||
if (data.useBuildinFileSystem)
|
||||
{
|
||||
// ע<EFBFBD>⣺<EFBFBD><EFBFBD><EFBFBD>ò<EFBFBD><EFBFBD><EFBFBD>COPY_BUILDIN_PACKAGE_MANIFEST<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Գ<EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>嵥<EFBFBD><EFBFBD>ɳ<EFBFBD><EFBFBD>Ŀ¼
|
||||
// 注意:设置参数COPY_BUILDIN_PACKAGE_MANIFEST,可以初始化的时候拷贝内置清单到沙盒目录
|
||||
buildinFileSystemParams = FileSystemParameters.CreateDefaultBuildinFileSystemParameters();
|
||||
buildinFileSystemParams.AddParameter(FileSystemParametersDefine.COPY_BUILDIN_PACKAGE_MANIFEST, true);
|
||||
}
|
||||
string defaultHostServer = GetHostServerURL();
|
||||
string fallbackHostServer = GetHostServerURL();
|
||||
IRemoteServices remoteServices = new RemoteServices(defaultHostServer, fallbackHostServer);
|
||||
// ע<EFBFBD>⣺<EFBFBD><EFBFBD><EFBFBD>ò<EFBFBD><EFBFBD><EFBFBD>INSTALL_CLEAR_MODE<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Խ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD>װ<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>嵥<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>⡣
|
||||
// 注意:设置参数INSTALL_CLEAR_MODE,可以解决覆盖安装的时候将拷贝的内置清单文件清理的问题。
|
||||
var cacheFileSystemParams = FileSystemParameters.CreateDefaultCacheFileSystemParameters(remoteServices);
|
||||
cacheFileSystemParams.AddParameter(FileSystemParametersDefine.INSTALL_CLEAR_MODE, EOverwriteInstallClearMode.ClearAllManifestFiles);
|
||||
|
||||
@@ -102,7 +114,7 @@ public class PatchOperation
|
||||
var createParameters = new WebPlayModeParameters();
|
||||
string defaultHostServer = GetHostServerURL();
|
||||
string fallbackHostServer = GetHostServerURL();
|
||||
string packageRoot = $"{WeChatWASM.WX.env.USER_DATA_PATH}/__GAME_FILE_CACHE"; //ע<EFBFBD>⣺<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ˴<EFBFBD><EFBFBD><EFBFBD>
|
||||
string packageRoot = $"{WeChatWASM.WX.env.USER_DATA_PATH}/__GAME_FILE_CACHE"; //注意:如果有子目录,请修改此处!
|
||||
IRemoteServices remoteServices = new RemoteServices(defaultHostServer, fallbackHostServer);
|
||||
createParameters.WebServerFileSystemParameters = WechatFileSystemCreater.CreateFileSystemParameters(packageRoot, remoteServices);
|
||||
return package.InitializeAsync(createParameters);
|
||||
@@ -157,13 +169,29 @@ public class PatchOperation
|
||||
return $"{_fallbackHostServer}/{fileName}";
|
||||
}
|
||||
}
|
||||
#endregion <EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#region <EFBFBD>汾<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD>嵥<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
public async UniTask<RequestPackageVersionOperation> RequestPackageVersion()
|
||||
#endregion 初始化相关
|
||||
#region 版本和资源清单相关
|
||||
public async UniTask<bool> RequestPackageVersion(bool showBox = true)
|
||||
{
|
||||
var operation = package.RequestPackageVersionAsync(true, 1);
|
||||
var operation = package.RequestPackageVersionAsync(true, 5);
|
||||
await operation.ToUniTask();
|
||||
return operation;
|
||||
if (operation.Status != EOperationStatus.Succeed)
|
||||
{
|
||||
if (showBox)
|
||||
{
|
||||
MessageBox.Show()
|
||||
.SetTitle($"{data.packageName}请求版本")
|
||||
.SetContent($"{operation.Error}")
|
||||
.AddButton("退出", (box) => { Application.Quit(); });
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
packageVersion = operation.PackageVersion;
|
||||
PatchEvent.UpdateStatus($"获取版本成功{data.packageName}");
|
||||
Debug.Log($"获取版本成功{data.packageName}:{packageVersion}");
|
||||
}
|
||||
return operation.Status == EOperationStatus.Succeed;
|
||||
}
|
||||
public async Task<string> GetBuildinPackageVersion()
|
||||
{
|
||||
@@ -194,37 +222,101 @@ public class PatchOperation
|
||||
PlayerPrefs.SetString(PkgVersionKey, packageVersion);
|
||||
PlayerPrefs.Save();
|
||||
#endif
|
||||
PatchEvent.UpdateStatus($"更新完成{data.packageName}");
|
||||
Debug.Log($"更新{data.packageName}完成,版本号{packageVersion}");
|
||||
|
||||
}
|
||||
public async UniTask<UpdatePackageManifestOperation> UpdatePackageManifest()
|
||||
public async UniTask<bool> UpdatePackageManifest(bool showBox = true)
|
||||
{
|
||||
var operation = package.UpdatePackageManifestAsync(packageVersion,5);
|
||||
var operation = package.UpdatePackageManifestAsync(packageVersion,10);
|
||||
await operation.ToUniTask();
|
||||
return operation;
|
||||
if (operation.Status != EOperationStatus.Succeed)
|
||||
{
|
||||
if (showBox)
|
||||
{
|
||||
MessageBox.Show()
|
||||
.SetTitle($"{data.packageName}更新清单")
|
||||
.SetContent($"{operation.Error}")
|
||||
.AddButton("退出", (box) => { Application.Quit(); });
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PatchEvent.UpdateStatus($"获取资源清单成功{data.packageName}");
|
||||
Debug.Log($"获取资源清单成功{data.packageName}");
|
||||
}
|
||||
return operation.Status == EOperationStatus.Succeed;
|
||||
}
|
||||
#endregion <EFBFBD>汾<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD>嵥<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
public ResourceDownloaderOperation CreateDownloader()
|
||||
#endregion 版本和资源清单相关
|
||||
#region 下载相关
|
||||
public bool CreateDownloader()
|
||||
{
|
||||
downloader = package.CreateResourceDownloader(data.downloadingMaxNum, data.failedTryAgain);
|
||||
downloader.DownloadErrorCallback = data.downloadError;
|
||||
downloader.DownloadFinishCallback = data.downloadFinish;
|
||||
downloader.DownloadUpdateCallback = data.downloadUpdate;
|
||||
return downloader;
|
||||
if (downloader.TotalDownloadCount == 0) return false;
|
||||
return true;
|
||||
}
|
||||
public async UniTask<bool> DownloadPackageFiles()
|
||||
public async UniTask<bool> CheckDownloadOrSkip()
|
||||
{
|
||||
var completionSource = new UniTaskCompletionSource<bool>();
|
||||
MessageBox.Show()
|
||||
.SetTitle($"{data.packageName}发现更新")
|
||||
.SetContent($"发现资源更新\n{GetCachedPackageVersion()}=>{packageVersion}: {downloader.TotalDownloadBytes / 1024f / 1024f:F1}MB")
|
||||
.AddButton("下载", async (box) =>
|
||||
{
|
||||
bool success = await DownloadPackageFiles();
|
||||
completionSource.TrySetResult(success);
|
||||
})
|
||||
.AddButton("跳过", (box) =>
|
||||
{
|
||||
downloader.CancelDownload();
|
||||
completionSource.TrySetResult(true);
|
||||
})
|
||||
.AddButton("退出", (box) =>
|
||||
{
|
||||
completionSource.TrySetResult(false);
|
||||
Application.Quit();
|
||||
});
|
||||
bool shouldContinue = await completionSource.Task;
|
||||
return shouldContinue;
|
||||
}
|
||||
public async UniTask<bool> DownloadPackageFiles(bool showBox = true)
|
||||
{
|
||||
if (downloader.TotalDownloadCount == 0)
|
||||
return true;
|
||||
Debug.Log($"{data.packageName} DownloadPackageFiles {downloader.TotalDownloadCount}");
|
||||
downloader.BeginDownload();
|
||||
await downloader.ToUniTask();
|
||||
if (downloader.Status != EOperationStatus.Succeed)
|
||||
{
|
||||
if (showBox)
|
||||
{
|
||||
MessageBox.Show()
|
||||
.SetTitle($"{data.packageName}下载文件")
|
||||
.SetContent($"{downloader.Error}")
|
||||
.AddButton("退出", (box) => { Application.Quit(); });
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return downloader.Status == EOperationStatus.Succeed;
|
||||
}
|
||||
public async UniTask<ClearCacheFilesOperation> ClearCacheBundle()
|
||||
public async UniTask<bool> ClearCacheBundle(bool showBox = true)
|
||||
{
|
||||
var operation = package.ClearCacheFilesAsync(EFileClearMode.ClearUnusedBundleFiles);
|
||||
await operation.ToUniTask();
|
||||
return operation;
|
||||
if (operation.Status != EOperationStatus.Succeed)
|
||||
{
|
||||
if (showBox)
|
||||
{
|
||||
MessageBox.Show()
|
||||
.SetTitle($"{data.packageName}清除缓存")
|
||||
.SetContent($"{operation.Error}")
|
||||
.AddButton("退出", (box) => { Application.Quit(); });
|
||||
}
|
||||
}
|
||||
return operation.Status == EOperationStatus.Succeed;
|
||||
}
|
||||
#endregion <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#endregion 下载相关
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user