From f8ca6568701ca5b1778277b2d395eb3793d139c2 Mon Sep 17 00:00:00 2001 From: stary <834207172@qq.COM> Date: Thu, 16 Apr 2026 22:26:36 +0800 Subject: [PATCH] =?UTF-8?q?1.4.5=E6=8A=A5=E9=94=99=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Runtime/Tools/CrossPlatformUnzip.cs | 57 +++++++++---------- .../00.StaryEvoTools/Runtime/Tools/ZipTool.cs | 2 + .../Runtime/com.staryevo.tools.runtime.asmdef | 1 - 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/Assets/00.StaryEvoTools/Runtime/Tools/CrossPlatformUnzip.cs b/Assets/00.StaryEvoTools/Runtime/Tools/CrossPlatformUnzip.cs index 1ebf009..3a0f87d 100644 --- a/Assets/00.StaryEvoTools/Runtime/Tools/CrossPlatformUnzip.cs +++ b/Assets/00.StaryEvoTools/Runtime/Tools/CrossPlatformUnzip.cs @@ -5,6 +5,7 @@ using Cysharp.Threading.Tasks; #if WECHAT_MINIGAME using WeChatWASM; + #else using System.IO; // 仅在非微信平台使用 using ICSharpCode.SharpZipLib.Zip; @@ -14,7 +15,7 @@ namespace Stary.Evo.Unzip { public static class CrossPlatformUnzip { - public static async UniTask UnzipAsync(string zipPath, string extractPath, + public static async UniTask UnzipAsync(string zipPath, string extractPath, Action progressCallback = null, bool deleteAfterExtract = true) { #if WECHAT_MINIGAME && UNITY_WEBGL @@ -32,7 +33,7 @@ namespace Stary.Evo.Unzip #region 1. 微信小程序实现(零 System.IO) #if WECHAT_MINIGAME - private static async UniTask UnzipWeChatNativeAsync(string zipPath, string extractPath, + private static async UniTask UnzipWeChatNativeAsync(string zipPath, string extractPath, Action progressCallback, bool deleteAfterExtract) { var tcs = new UniTaskCompletionSource(); @@ -40,24 +41,24 @@ namespace Stary.Evo.Unzip // 检查 ZIP 存在(使用微信 API) bool fileExists = false; - fs.Access(new AccessOption() + fs.Access(new AccessParam() { path = zipPath, success = (res) => fileExists = true, fail = (err) => { } }); - + await UniTask.Delay(50); // 等待异步结果 if (!fileExists) throw new Exception($"ZIP 不存在: {zipPath}"); // 清理目标目录(递归删除) - try - { - fs.RmdirSync(extractPath, true); + try + { + fs.RmdirSync(extractPath, true); } - catch - { + catch + { // 目录不存在或已删除 } @@ -69,7 +70,7 @@ namespace Stary.Evo.Unzip var progressTask = SimulateProgressAsync(progressCallback, () => reportedProgress >= 1f); // 微信原生解压(性能最佳,C++ 实现) - WX.Unzip(new UnzipOption() + WX.GetFileSystemManager().Unzip(new UnzipOption() { zipFilePath = zipPath, targetPath = extractPath, @@ -79,10 +80,7 @@ namespace Stary.Evo.Unzip progressCallback?.Invoke(1f); tcs.TrySetResult(); }, - fail = (err) => - { - tcs.TrySetException(new Exception($"微信解压失败: {err.errMsg}")); - } + fail = (err) => { tcs.TrySetException(new Exception($"微信解压失败: {err.errMsg}")); } }); await tcs.Task; @@ -98,7 +96,7 @@ namespace Stary.Evo.Unzip private static async UniTask SimulateProgressAsync(Action callback, Func isCompleted) { if (callback == null) return; - + float progress = 0f; while (!isCompleted()) { @@ -108,16 +106,16 @@ namespace Stary.Evo.Unzip } } - private static void DeleteWeChatFileSafe(FileSystemManager fs, string path) + private static void DeleteWeChatFileSafe(WXFileSystemManager fs, string path) { - try - { - fs.UnlinkSync(path); + try + { + fs.UnlinkSync(path); Debug.Log($"[微信] 已删除 ZIP"); } - catch (Exception ex) - { - Debug.LogWarning($"[微信] 删除失败: {ex.Message}"); + catch (Exception ex) + { + Debug.LogWarning($"[微信] 删除失败: {ex.Message}"); } } @@ -222,8 +220,8 @@ namespace Stary.Evo.Unzip #endregion #region 3. PC/移动端实现(标准 System.IO) - - private static async UniTask UnzipStandardAsync(string zipPath, string extractPath, +#if !UNITY_WEBGL && !WECHAT_MINIGAME + private static async UniTask UnzipStandardAsync(string zipPath, string extractPath, Action progressCallback, bool deleteAfterExtract) { await UniTask.SwitchToThreadPool(); @@ -234,7 +232,7 @@ namespace Stary.Evo.Unzip throw new FileNotFoundException($"ZIP 不存在: {zipPath}"); string fullExtractPath = Path.GetFullPath(extractPath); - + if (Directory.Exists(extractPath)) Directory.Delete(extractPath, true); Directory.CreateDirectory(extractPath); @@ -244,7 +242,8 @@ namespace Stary.Evo.Unzip { int total = 0; foreach (ZipEntry entry in zipFile) - if (entry.IsFile) total++; + if (entry.IsFile) + total++; int processed = 0; foreach (ZipEntry entry in zipFile) @@ -263,7 +262,7 @@ namespace Stary.Evo.Unzip } processed++; - + await UniTask.SwitchToMainThread(); progressCallback?.Invoke((float)processed / total); await UniTask.SwitchToThreadPool(); @@ -277,7 +276,7 @@ namespace Stary.Evo.Unzip File.Delete(zipPath); } } - +#endif #endregion #region 4. 公共工具(平台特定) @@ -301,7 +300,7 @@ namespace Stary.Evo.Unzip { #if WECHAT_MINIGAME bool exists = false; - WX.GetFileSystemManager().Access(new AccessOption() + WX.GetFileSystemManager().Access(new AccessParam() { path = path, success = (res) => exists = true, diff --git a/Assets/00.StaryEvoTools/Runtime/Tools/ZipTool.cs b/Assets/00.StaryEvoTools/Runtime/Tools/ZipTool.cs index 126df80..a7700f2 100644 --- a/Assets/00.StaryEvoTools/Runtime/Tools/ZipTool.cs +++ b/Assets/00.StaryEvoTools/Runtime/Tools/ZipTool.cs @@ -7,7 +7,9 @@ using Cysharp.Threading.Tasks; using Stary.Evo.Unzip; using UnityEngine; using UnityEngine.Networking; +#if WEIXINMINIGAME using WeChatWASM; +#endif namespace Stary.Evo { diff --git a/Assets/00.StaryEvoTools/Runtime/com.staryevo.tools.runtime.asmdef b/Assets/00.StaryEvoTools/Runtime/com.staryevo.tools.runtime.asmdef index b67c9f9..63c1d59 100644 --- a/Assets/00.StaryEvoTools/Runtime/com.staryevo.tools.runtime.asmdef +++ b/Assets/00.StaryEvoTools/Runtime/com.staryevo.tools.runtime.asmdef @@ -6,7 +6,6 @@ "com.audiocore.runtime", "com.stary.evo.runtime", "HybridCLR.Runtime", - "ImmersalSDK", "Informationsave.runtime", "DOTween.Modules", "com.stary.buildoriginality.runtime",