aphla 测试 1
Some checks failed
Plugin Library CI / publish (00.BuildOriginality) (push) Successful in 4s
Plugin Library CI / publish (00.StaryEvo) (push) Successful in 4s
Plugin Library CI / publish (00.StaryEvoTools) (push) Failing after 10s
Plugin Library CI / publish (01.HybridCLR) (push) Successful in 4s
Plugin Library CI / publish (02.InformationSave) (push) Successful in 3s
Plugin Library CI / publish (03.YooAsset) (push) Successful in 32s
Plugin Library CI / publish (04.AudioCore) (push) Successful in 2s
Plugin Library CI / publish (05.TableTextConversion) (push) Successful in 3s
Plugin Library CI / publish (06.UIFarme) (push) Successful in 16s
Plugin Library CI / publish (07.RKTools) (push) Successful in 3s
Plugin Library CI / publish (08.UniTask) (push) Successful in 3s
Plugin Library CI / publish (09.CodeChecker) (push) Successful in 16s
Plugin Library CI / publish (11.PointCloudTools) (push) Successful in 2s
Plugin Library CI / publish (10.StoryEditor) (push) Successful in 3s
Plugin Library CI / publish (10.XNode) (push) Successful in 3s
Some checks failed
Plugin Library CI / publish (00.BuildOriginality) (push) Successful in 4s
Plugin Library CI / publish (00.StaryEvo) (push) Successful in 4s
Plugin Library CI / publish (00.StaryEvoTools) (push) Failing after 10s
Plugin Library CI / publish (01.HybridCLR) (push) Successful in 4s
Plugin Library CI / publish (02.InformationSave) (push) Successful in 3s
Plugin Library CI / publish (03.YooAsset) (push) Successful in 32s
Plugin Library CI / publish (04.AudioCore) (push) Successful in 2s
Plugin Library CI / publish (05.TableTextConversion) (push) Successful in 3s
Plugin Library CI / publish (06.UIFarme) (push) Successful in 16s
Plugin Library CI / publish (07.RKTools) (push) Successful in 3s
Plugin Library CI / publish (08.UniTask) (push) Successful in 3s
Plugin Library CI / publish (09.CodeChecker) (push) Successful in 16s
Plugin Library CI / publish (11.PointCloudTools) (push) Successful in 2s
Plugin Library CI / publish (10.StoryEditor) (push) Successful in 3s
Plugin Library CI / publish (10.XNode) (push) Successful in 3s
This commit is contained in:
@@ -4,36 +4,86 @@ using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Threading;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Stary.Evo.Unzip;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
using WeChatWASM;
|
||||
|
||||
namespace Stary.Evo
|
||||
{
|
||||
public class ZipTool
|
||||
{
|
||||
private static SemaphoreSlim unzipLock = new(1, 1);
|
||||
|
||||
// 新增:带进度回调的下载解压方法
|
||||
public static async UniTask DownloadAndUnzipAsync(string fildId, string extractPath,
|
||||
Action<float> downloadProgress = null, Action<float> unzipProgress = null)
|
||||
{
|
||||
string tempPath = Path.Combine(Application.persistentDataPath, "temp.zip");
|
||||
|
||||
try
|
||||
{
|
||||
string url = $"{AppConfig.IpConfig}/FileLoad/Download/{fildId}";
|
||||
await WebRequestSystem.GetFile(url, tempPath,downloadProgress);
|
||||
|
||||
|
||||
#if !WEIXINMINIGAME
|
||||
string tempPath = Path.Combine(Application.persistentDataPath, "temp.zip");
|
||||
await WebRequestSystem.GetFile(url, tempPath, downloadProgress);
|
||||
#else
|
||||
bool isCompleted = false;
|
||||
string tempPath = WX.env.USER_DATA_PATH + "/temp.zip"; // 指定保存路径
|
||||
var downloadTask = WX.DownloadFile(new DownloadFileOption()
|
||||
{
|
||||
url = url,
|
||||
filePath = WX.env.USER_DATA_PATH + "/temp.zip", // 指定保存路径
|
||||
success = (res) => {
|
||||
isCompleted = true;
|
||||
},
|
||||
fail = (err) => {
|
||||
Debug.LogError("下载失败:" + err.errMsg);
|
||||
isCompleted = true;
|
||||
}
|
||||
});
|
||||
// 注册进度回调(关键代码)
|
||||
downloadTask.OnProgressUpdate((res) =>
|
||||
{
|
||||
// res.progress: 下载进度 0-100
|
||||
// res.totalBytesExpectedToWrite: 预期总字节数
|
||||
// res.totalBytesWritten: 已下载字节数
|
||||
downloadProgress?.Invoke((float) res.progress);
|
||||
Debug.Log($"下载进度:{res.progress:F1}% | " +
|
||||
$"已下载:{res.totalBytesWritten / 1024}KB / " +
|
||||
$"总计:{res.totalBytesExpectedToWrite / 1024}KB");
|
||||
});
|
||||
// 等待完成或被取消
|
||||
await new WaitUntil(() => isCompleted);
|
||||
// 等待下载完成,同时可以更新 UI
|
||||
// while (!isCompleted)
|
||||
// {
|
||||
// // 在这里更新 Unity UI 进度条
|
||||
// UpdateProgressUI(currentProgress);
|
||||
// yield return null;
|
||||
// }
|
||||
// WX.GetFileSystemManager().Unzip(new UnzipOption()
|
||||
// {
|
||||
// zipFilePath = tempPath,
|
||||
// targetPath = extractPath,
|
||||
// success = (suc) =>
|
||||
// {
|
||||
// Debug.Log("解压成功");
|
||||
// File.Delete(tempPath);
|
||||
// },
|
||||
// fail = (err) =>
|
||||
// {
|
||||
// Debug.LogError($"解压失败:{err.errMsg}");
|
||||
// }
|
||||
// });
|
||||
#endif
|
||||
|
||||
// 解压下载的文件
|
||||
await UnzipAsync(tempPath, extractPath, unzipProgress);
|
||||
File.Delete(tempPath);
|
||||
await CrossPlatformUnzip.UnzipAsync(tempPath, extractPath, unzipProgress);
|
||||
}
|
||||
finally
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 清理临时文件
|
||||
if (File.Exists(tempPath))
|
||||
{
|
||||
File.Delete(tempPath);
|
||||
}
|
||||
Debug.LogError($"解压失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +110,7 @@ namespace Stary.Evo
|
||||
Debug.LogWarning($"跳过不安全的文件路径: {entry.FullName}");
|
||||
continue;
|
||||
}
|
||||
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(filePath));
|
||||
|
||||
if (!string.IsNullOrEmpty(entry.Name))
|
||||
@@ -67,7 +118,7 @@ namespace Stary.Evo
|
||||
using (Stream inputStream = entry.Open())
|
||||
using (FileStream outputStream = File.Create(filePath))
|
||||
{
|
||||
await inputStream.CopyToAsync(outputStream,81920);
|
||||
await inputStream.CopyToAsync(outputStream, 81920);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,6 +127,7 @@ namespace Stary.Evo
|
||||
progressCallback?.Invoke(progress);
|
||||
}
|
||||
}
|
||||
|
||||
Debug.Log($"解压完成: {extractPath}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -85,6 +137,7 @@ namespace Stary.Evo
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 自定义网络请求器需要登录
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user