Skip to content

Commit

Permalink
updated to v2.9.13 (DiskUtils added)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael811125 committed Feb 1, 2024
1 parent e7435f3 commit 15c89d5
Show file tree
Hide file tree
Showing 174 changed files with 5,788 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public class CryptogramType
/// </summary>
public static bool skipMainDownload = false;

/// <summary>
/// 是否檢查磁碟空間
/// </summary>
public static bool checkDiskSpace = true;

/// <summary>
/// App Preset Package 清單
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ namespace OxGFrame.AssetLoader.Bundle
{
public class PackageOperation
{
public delegate void OnPatchRepairFailed();
public delegate void OnPatchInitPatchModeFailed();
public delegate void OnPatchVersionUpdateFailed();
public delegate void OnPatchManifestUpdateFailed();
public delegate void OnPatchCheckDiskNotEnoughSpace(int availableMegabytes, ulong patchTotalBytes);
public delegate void OnPatchDownloadFailed(string fileName, string error);

/// <summary>
/// Instance id
/// </summary>
Expand All @@ -28,7 +35,7 @@ public int hashId
public GroupInfo groupInfo { get; protected set; }

/// <summary>
/// Package operaion event group
/// Package operation event group
/// </summary>
public EventGroup eventGroup { get; protected set; }

Expand All @@ -37,6 +44,18 @@ public int hashId
/// </summary>
public bool skipDownload { get; protected set; }

/// <summary>
/// Enable or disable disk space check procedure (default is true)
/// </summary>
public bool checkDiskSpace = true;

public OnPatchRepairFailed onPatchRepairFailed;
public OnPatchInitPatchModeFailed onPatchInitPatchModeFailed;
public OnPatchVersionUpdateFailed onPatchVersionUpdateFailed;
public OnPatchManifestUpdateFailed onPatchManifestUpdateFailed;
public OnPatchCheckDiskNotEnoughSpace onPatchCheckDiskNotEnoughSpace;
public OnPatchDownloadFailed onPatchDownloadFailed;

private ResourceDownloaderOperation[] _downloaders;
private PackageInfoWithBuild[] _packageInfos;

Expand All @@ -58,14 +77,15 @@ protected PackageOperation()
this.eventGroup.AddListener<PackageEvents.PatchInitPatchModeFailed>(this._OnHandleEventMessage);
this.eventGroup.AddListener<PackageEvents.PatchVersionUpdateFailed>(this._OnHandleEventMessage);
this.eventGroup.AddListener<PackageEvents.PatchManifestUpdateFailed>(this._OnHandleEventMessage);
this.eventGroup.AddListener<PackageEvents.PatchCheckDiskNotEnoughSpace>(this._OnHandleEventMessage);
this.eventGroup.AddListener<PackageEvents.PatchDownloadFailed>(this._OnHandleEventMessage);
// User event receivers
this.eventGroup.AddListener<PackageUserEvents.UserTryPatchRepair>(this._OnHandleEventMessage);
this.eventGroup.AddListener<PackageUserEvents.UserTryInitPatchMode>(this._OnHandleEventMessage);
this.eventGroup.AddListener<PackageUserEvents.UserBeginDownload>(this._OnHandleEventMessage);
this.eventGroup.AddListener<PackageUserEvents.UserTryPatchVersionUpdate>(this._OnHandleEventMessage);
this.eventGroup.AddListener<PackageUserEvents.UserTryPatchManifestUpdate>(this._OnHandleEventMessage);
this.eventGroup.AddListener<PackageUserEvents.UserTryCreateDownloader>(this._OnHandleEventMessage);
this.eventGroup.AddListener<PackageUserEvents.UserBeginDownload>(this._OnHandleEventMessage);

// Register PatchFsm
this._patchFsm = new StateMachine(this);
Expand Down Expand Up @@ -351,6 +371,33 @@ public bool IsRepair()
}
#endregion

#region Retry Events
public void UserTryPatchRepair()
{
PackageUserEvents.UserTryPatchRepair.SendEventMessage(this.hashId);
}

public void UserTryInitPatchMode()
{
PackageUserEvents.UserTryInitPatchMode.SendEventMessage(this.hashId);
}

public void UserTryPatchVersionUpdate()
{
PackageUserEvents.UserTryPatchVersionUpdate.SendEventMessage(this.hashId);
}

public void UserTryPatchManifestUpdate()
{
PackageUserEvents.UserTryPatchManifestUpdate.SendEventMessage(this.hashId);
}

public void UserTryCreateDownloader()
{
PackageUserEvents.UserTryCreateDownloader.SendEventMessage(this.hashId);
}
#endregion

#region Event Handle
private void _OnHandleEventMessage(IEventMessage message)
{
Expand Down Expand Up @@ -397,23 +444,51 @@ private void _OnHandleEventMessage(IEventMessage message)
}
else if (message is PackageEvents.PatchRepairFailed)
{
PackageUserEvents.UserTryPatchRepair.SendEventMessage(this.hashId);
if (this.onPatchRepairFailed != null)
this.onPatchRepairFailed.Invoke();
else
PackageUserEvents.UserTryPatchRepair.SendEventMessage(this.hashId);
}
else if (message is PackageEvents.PatchInitPatchModeFailed)
{
PackageUserEvents.UserTryInitPatchMode.SendEventMessage(this.hashId);
if (this.onPatchInitPatchModeFailed != null)
this.onPatchInitPatchModeFailed.Invoke();
else
PackageUserEvents.UserTryInitPatchMode.SendEventMessage(this.hashId);
}
else if (message is PackageEvents.PatchVersionUpdateFailed)
{
PackageUserEvents.UserTryPatchVersionUpdate.SendEventMessage(this.hashId);
if (this.onPatchVersionUpdateFailed != null)
this.onPatchVersionUpdateFailed.Invoke();
else
PackageUserEvents.UserTryPatchVersionUpdate.SendEventMessage(this.hashId);
}
else if (message is PackageEvents.PatchManifestUpdateFailed)
{
PackageUserEvents.UserTryPatchManifestUpdate.SendEventMessage(this.hashId);
if (this.onPatchManifestUpdateFailed != null)
this.onPatchManifestUpdateFailed.Invoke();
else
PackageUserEvents.UserTryPatchManifestUpdate.SendEventMessage(this.hashId);
}
else if (message is PackageEvents.PatchCheckDiskNotEnoughSpace)
{
if (this.onPatchCheckDiskNotEnoughSpace != null)
{
var msgData = message as PackageEvents.PatchCheckDiskNotEnoughSpace;
this.onPatchCheckDiskNotEnoughSpace.Invoke(msgData.availableMegabytes, msgData.patchTotalBytes);
}
else
PackageUserEvents.UserTryCreateDownloader.SendEventMessage(this.hashId);
}
else if (message is PackageEvents.PatchDownloadFailed)
{
PackageUserEvents.UserTryCreateDownloader.SendEventMessage(this.hashId);
if (this.onPatchDownloadFailed != null)
{
var msgData = message as PackageEvents.PatchDownloadFailed;
this.onPatchDownloadFailed.Invoke(msgData.fileName, msgData.error);
}
else
PackageUserEvents.UserTryCreateDownloader.SendEventMessage(this.hashId);
}
// Package user events
else if (message is PackageUserEvents.UserTryPatchRepair)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ namespace OxGFrame.AssetLoader.PatchEvent
// 2. PatchInitPatchModeFailed
// 3. PatchVersionUpdateFailed
// 4. PatchManifestUpdateFailed
// 5. PatchDownloadProgression
// 6. PatchDownloadFailed
// 7. PatchDownloadCanceled
// 5. PatchCheckDiskNotEnoughSpace
// 6. PatchDownloadProgression
// 7. PatchDownloadFailed
// 8. PatchDownloadCanceled

public static class PackageEvents
{
Expand Down Expand Up @@ -77,6 +78,23 @@ public static void SendEventMessage(int groupId)
}
}

/// <summary>
/// Patch check disk if not enough space
/// </summary>
public class PatchCheckDiskNotEnoughSpace : IEventMessage
{
public int availableMegabytes;
public ulong patchTotalBytes;

public static void SendEventMessage(int availableMegabytes, ulong patchTotalBytes)
{
var msg = new PatchCheckDiskNotEnoughSpace();
msg.availableMegabytes = availableMegabytes;
msg.patchTotalBytes = patchTotalBytes;
UniEvent.SendMessage(msg);
}
}

/// <summary>
/// Patch download progression
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ namespace OxGFrame.AssetLoader.PatchEvent
// 5. PatchVersionUpdateFailed
// 6. PatchManifestUpdateFailed
// 7. PatchCreateDownloader
// 8. PatchDownloadProgression
// 9. PatchDownloadFailed
// 10. PatchDownloadCanceled
// 8. PatchCheckDiskNotEnoughSpace
// 9. PatchDownloadProgression
// 10. PatchDownloadFailed
// 11. PatchDownloadCanceled

public static class PatchEvents
{
Expand Down Expand Up @@ -120,6 +121,23 @@ public static void SendEventMessage(GroupInfo[] groupInfos)
}
}

/// <summary>
/// Patch check disk if not enough space
/// </summary>
public class PatchCheckDiskNotEnoughSpace : IEventMessage
{
public int availableMegabytes;
public ulong patchTotalBytes;

public static void SendEventMessage(int availableMegabytes, ulong patchTotalBytes)
{
var msg = new PatchCheckDiskNotEnoughSpace();
msg.availableMegabytes = availableMegabytes;
msg.patchTotalBytes = patchTotalBytes;
UniEvent.SendMessage(msg);
}
}

/// <summary>
/// Patch download progression
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ namespace OxGFrame.AssetLoader.PatchEvent
// 0. UserTryPatchRepair
// 1. UserTryAppVersionUpdate
// 2. UserTryInitPatchMode
// 3. UserBeginDownload
// 4. UserTryPatchVersionUpdate
// 5. UserTryPatchManifestUpdate
// 6. UserTryCreateDownloader
// 3. UserTryPatchVersionUpdate
// 4. UserTryPatchManifestUpdate
// 5. UserTryCreateDownloader
// 6. UserBeginDownload

public class PatchUserEvents
{
Expand All @@ -26,7 +26,7 @@ public static void SendEventMessage()
}

/// <summary>
/// User retry update app verison again
/// User retry update app version again
/// </summary>
public class UserTryAppVersionUpdate : IEventMessage
{
Expand All @@ -49,19 +49,6 @@ public static void SendEventMessage()
}
}

/// <summary>
/// User begin download
/// </summary>
public class UserBeginDownload : IEventMessage
{
public static void SendEventMessage(GroupInfo groupInfo)
{
var msg = new UserBeginDownload();
PatchManager.SetLastGroupInfo(groupInfo);
UniEvent.SendMessage(msg);
}
}

/// <summary>
/// User retry update patch version again
/// </summary>
Expand Down Expand Up @@ -97,5 +84,18 @@ public static void SendEventMessage()
UniEvent.SendMessage(msg);
}
}

/// <summary>
/// User begin download
/// </summary>
public class UserBeginDownload : IEventMessage
{
public static void SendEventMessage(GroupInfo groupInfo)
{
var msg = new UserBeginDownload();
PatchManager.SetLastGroupInfo(groupInfo);
UniEvent.SendMessage(msg);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,23 @@ private async UniTask _StartDownload()
totalBytes += downloader.TotalDownloadBytes;
}

#if !UNITY_WEBGL
// Check flag if enabled
if ((this._machine.Owner as PackageOperation).checkDiskSpace)
{
// Check disk space
int availableDiskSpaceMegabytes = BundleUtility.CheckAvailableDiskSpaceMegabytes();
int patchTotalMegabytes = (int)(totalBytes / (1 << 20));
Logging.Print<Logger>($"<color=#2cff96>[Disk Space Check] Available Disk Space Size: {BundleUtility.GetMegabytesToString(availableDiskSpaceMegabytes)}</color>, <color=#2cbbff>Total Patch Size: {BundleUtility.GetBytesToString((ulong)totalBytes)}</color>");
if (patchTotalMegabytes > availableDiskSpaceMegabytes)
{
PackageEvents.PatchCheckDiskNotEnoughSpace.SendEventMessage(availableDiskSpaceMegabytes, (ulong)totalBytes);
Logging.Print<Logger>($"<color=#ff2c48>Disk Not Enough Space!!! Available Disk Space Size: {BundleUtility.GetMegabytesToString(availableDiskSpaceMegabytes)}</color>, <color=#2cbbff>Total Patch Size: {BundleUtility.GetBytesToString((ulong)totalBytes)}</color>");
return;
}
}
#endif

// Begin Download
int currentCount = 0;
long currentBytes = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Linq;
using UniFramework.Machine;
using YooAsset;
using static UnityEngine.Mesh;

namespace OxGFrame.AssetLoader.PatchFsm
{
Expand Down Expand Up @@ -812,6 +813,23 @@ private async UniTask _StartDownload()
totalBytes += downloader.TotalDownloadBytes;
}

#if !UNITY_WEBGL
// Check flag if enabled
if (BundleConfig.checkDiskSpace)
{
// Check disk space
int availableDiskSpaceMegabytes = BundleUtility.CheckAvailableDiskSpaceMegabytes();
int patchTotalMegabytes = (int)(totalBytes / (1 << 20));
Logging.Print<Logger>($"<color=#2cff96>[Disk Space Check] Available Disk Space Size: {BundleUtility.GetMegabytesToString(availableDiskSpaceMegabytes)}</color>, <color=#2cbbff>Total Patch Size: {BundleUtility.GetBytesToString((ulong)totalBytes)}</color>");
if (patchTotalMegabytes > availableDiskSpaceMegabytes)
{
PatchEvents.PatchCheckDiskNotEnoughSpace.SendEventMessage(availableDiskSpaceMegabytes, (ulong)totalBytes);
Logging.Print<Logger>($"<color=#ff2c48>Disk Not Enough Space!!! Available Disk Space Size: {BundleUtility.GetMegabytesToString(availableDiskSpaceMegabytes)}</color>, <color=#2cbbff>Total Patch Size: {BundleUtility.GetBytesToString((ulong)totalBytes)}</color>");
return;
}
}
#endif

// Begin Download
int currentCount = 0;
long currentBytes = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ internal class PatchLauncher : MonoBehaviour
public BundleConfig.SemanticRule semanticRule = new BundleConfig.SemanticRule();
[Tooltip("If checked, will skip preset app packages download step of the patch (force download while playing)."), ConditionalField(nameof(playMode), false, BundleConfig.PlayMode.HostMode)]
public bool skipMainDownload = false;
[Tooltip("If checked, will check disk space is it enough while patch checking."), ConditionalField(new string[] { nameof(playMode), nameof(skipMainDownload) }, new bool[] { false, true }, BundleConfig.PlayMode.HostMode)]
public bool checkDiskSpace = true;

[Separator("Preset App Packages")]
[Tooltip("The first element will be default app package.\n\nNote: The presets will combine in main download of the patch.")]
Expand Down Expand Up @@ -62,6 +64,7 @@ private async void Awake()
{
BundleConfig.semanticRule = this.semanticRule;
BundleConfig.skipMainDownload = this.skipMainDownload;
BundleConfig.checkDiskSpace = this.checkDiskSpace;
}
// For WebGL Mode
else if (this.playMode == BundleConfig.PlayMode.WebGLMode)
Expand Down
Loading

0 comments on commit 15c89d5

Please sign in to comment.