Skip to content

Commit

Permalink
updated to v2.9.7
Browse files Browse the repository at this point in the history
  • Loading branch information
michael811125 committed Dec 7, 2023
1 parent ce3ca79 commit 86d2e17
Show file tree
Hide file tree
Showing 7 changed files with 1,670 additions and 191 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -306,23 +306,28 @@ public static ulong GetPackageSizeInLocal(string packageName)
public static async UniTask<bool> UnloadPackageAndClearCacheFiles(string packageName)
{
var package = GetPackage(packageName);
if (package == null) return false;
if (package == null)
{
Logging.PrintWarning<Logger>($"[Invalid unload] Package is null (return true). Package Name: {packageName}");
return true;
}

try
{
// delete local files first
package.ClearPackageSandbox();

await UniTask.Delay(TimeSpan.FromSeconds(1f));
await UniTask.NextFrame();

// after clear package cache files
var operation = package.ClearAllCacheFilesAsync();
await operation;

if (operation.Status == EOperationStatus.Succeed) return true;
}
catch
catch (Exception ex)
{
Logging.PrintWarning<Logger>(ex);
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public static class PatchFsmStates
public class FsmPatchRepair : IStateNode
{
private StateMachine _machine;
private int _retryCount = _RETRY_COUNT;

private const int _RETRY_COUNT = 1;

public FsmPatchRepair() { }

Expand All @@ -34,6 +37,7 @@ void IStateNode.OnEnter()
{
// 流程準備
PatchEvents.PatchFsmState.SendEventMessage(this);
PatchManager.GetInstance().MarkRepairState();
this._DeleteLocalSaveFiles().Forget();
}

Expand All @@ -47,26 +51,45 @@ void IStateNode.OnExit()

private async UniTask _DeleteLocalSaveFiles()
{
// EditorSimulateMode skip repair
if (BundleConfig.playMode == BundleConfig.PlayMode.EditorSimulateMode)
{
this._machine.ChangeState<FsmPatchPrepare>();
return;
}

// Cancel main download first
PatchManager.GetInstance().Cancel(false);

// Wait a frame
await UniTask.NextFrame();

// Delete Last Group Info record
PatchManager.DelLastGroupInfo();

// Get preset app package names
bool isCleared = false;

// Combine packages
// Get preset app package names and combine packages
var appPackageNames = PackageManager.GetPresetAppPackageNames();
var dlcPackageNames = PackageManager.GetPresetDlcPackageNames();
var packageNames = appPackageNames.Concat(dlcPackageNames).ToArray();

bool isCleared = false;
foreach (var packageName in packageNames)
{
// Clear cache and files of package
isCleared = await PackageManager.UnloadPackageAndClearCacheFiles(packageName);
if (!isCleared) isCleared = false;
if (!isCleared) break;
}

if (isCleared) this._machine.ChangeState<FsmPatchPrepare>();
else PatchEvents.PatchRepairFailed.SendEventMessage();
if (isCleared || this._retryCount <= 0)
{
this._retryCount = _RETRY_COUNT;
this._machine.ChangeState<FsmPatchPrepare>();
}
else
{
this._retryCount--;
PatchEvents.PatchRepairFailed.SendEventMessage();
}
}
}

Expand All @@ -88,6 +111,9 @@ void IStateNode.OnEnter()
{
// 流程準備
PatchEvents.PatchFsmState.SendEventMessage(this);
// 不管怎樣都進行修復完成的標記
PatchManager.GetInstance().MarkRepairAsDone();
PatchManager.GetInstance().MarkCheckState();
this._machine.ChangeState<FsmAppVersionUpdate>();
}

Expand Down Expand Up @@ -937,7 +963,7 @@ void IStateNode.OnEnter()
// 更新完畢
PatchEvents.PatchFsmState.SendEventMessage(this);
// Patch 標記完成
PatchManager.GetInstance().MarkAsDone();
PatchManager.GetInstance().MarkPatchAsDone();
}

void IStateNode.OnUpdate()
Expand Down
44 changes: 34 additions & 10 deletions Assets/OxGFrame/AssetLoader/Scripts/Runtime/Bundle/PatchManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,13 @@ public PatchManager()
/// </summary>
public void Check()
{
if (!this._isCheck)
if (!this._isCheck && !this._isRepair)
{
this._isCheck = true;
this._patchFsm.Run<PatchFsmStates.FsmPatchPrepare>();
}
else
{
Debug.LogWarning("Patch Checking...");
Logging.PrintWarning<Logger>("Patch Checking...");
}
}

Expand All @@ -150,12 +149,11 @@ public void Repair()
{
if (!this._isRepair)
{
this._isRepair = true;
this._patchFsm.Run<PatchFsmStates.FsmPatchRepair>();
}
else
{
Debug.LogWarning("Patch Repairing...");
Logging.PrintWarning<Logger>("Patch Repairing...");
}
}

Expand Down Expand Up @@ -186,30 +184,56 @@ public void Resume()
/// <summary>
/// 取消下載
/// </summary>
public void Cancel()
public void Cancel(bool sendEvent = true)
{
if (this.mainDownloaders == null) return;
foreach (var downloader in this.mainDownloaders)
{
downloader.CancelDownload();
}
PatchEvents.PatchDownloadCanceled.SendEventMessage();
if (sendEvent) PatchEvents.PatchDownloadCanceled.SendEventMessage();
}
#endregion

#region Patch Flag
/// <summary>
/// 標記更新結束
/// 標記 Check 狀態
/// </summary>
public void MarkAsDone()
public void MarkCheckState()
{
this._isDone = true;
this._isDone = false;
this._isCheck = true;
}

/// <summary>
/// 標記 Repair 狀態
/// </summary>
public void MarkRepairState()
{
this._isDone = false;
this._isRepair = true;
}

/// <summary>
/// 標記 Patch 結束
/// </summary>
public void MarkPatchAsDone()
{
this._isDone = true;
this._isCheck = false;
this._isRepair = false;
this.mainDownloaders = null;
}

/// <summary>
/// 標記 Repair 結束
/// </summary>
public void MarkRepairAsDone()
{
this._isRepair = false;
this.mainDownloaders = null;
}

/// <summary>
/// 是否更新結束
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions Assets/OxGFrame/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# CHANGELOG

## [2.9.7] - 2023-12-07
- Modified repair procedure (Supports patch repair during download).
- Modified BundleDemo in Samples.
- Fixed AssetPatcher flags bug issue (IsCheck(), IsRepair(), IsDone()).

## [2.9.6] - 2023-12-06
- Fixed a bug where the RawFileBuildPipeline download file was missing an extension.

Expand Down
Loading

0 comments on commit 86d2e17

Please sign in to comment.