2023-08-22 19:08:45 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
2024-04-18 16:41:33 +08:00
|
|
|
|
using NUnit.Framework;
|
2023-08-22 19:08:45 +08:00
|
|
|
|
|
|
|
|
|
|
namespace AutoConfig
|
|
|
|
|
|
{
|
|
|
|
|
|
using Cysharp.Threading.Tasks;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Net;
|
|
|
|
|
|
using UnityEditor;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using UnityEngine.Networking;
|
|
|
|
|
|
|
|
|
|
|
|
public class DownloadConfig
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
public static string SAVE_PATH = "";
|
|
|
|
|
|
|
|
|
|
|
|
private static int _DownloadCount;
|
2024-04-18 16:41:33 +08:00
|
|
|
|
|
|
|
|
|
|
public static List<DownloadConfigData> downloadConfigs = new List<DownloadConfigData>();
|
2023-10-24 12:15:31 +08:00
|
|
|
|
|
|
|
|
|
|
public static async UniTask AutoProcessConfig(List<ConfigInfo> m_Configs, string cookie)
|
2023-08-22 19:08:45 +08:00
|
|
|
|
{
|
|
|
|
|
|
var dir = new DirectoryInfo(ConfigTools.CONFIG_DIR);
|
|
|
|
|
|
SAVE_PATH = dir.FullName + "Datas/";
|
2024-04-18 16:41:33 +08:00
|
|
|
|
downloadConfigs.Clear();
|
2023-08-22 19:08:45 +08:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
_DownloadCount = 0;
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < m_Configs.Count; i++)
|
|
|
|
|
|
{
|
2024-04-18 16:41:33 +08:00
|
|
|
|
var config = m_Configs[i];
|
|
|
|
|
|
if (config.Check)
|
2023-08-22 19:08:45 +08:00
|
|
|
|
{
|
2024-04-18 16:41:33 +08:00
|
|
|
|
var downloader = StartDownload(config, cookie);
|
|
|
|
|
|
var downloadConfig = new DownloadConfigData();
|
|
|
|
|
|
downloadConfig.excelName = config.Name;
|
|
|
|
|
|
downloadConfig.downloader = downloader;
|
|
|
|
|
|
downloadConfigs.Add(downloadConfig);
|
2023-08-22 19:08:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-18 16:41:33 +08:00
|
|
|
|
var isFinished = false;
|
|
|
|
|
|
while (!isFinished)
|
2023-08-22 19:08:45 +08:00
|
|
|
|
{
|
2024-04-18 16:41:33 +08:00
|
|
|
|
isFinished = true;
|
|
|
|
|
|
for (int i = 0; i < downloadConfigs.Count; i++)
|
2023-08-22 19:08:45 +08:00
|
|
|
|
{
|
2024-04-18 16:41:33 +08:00
|
|
|
|
var config = downloadConfigs[i];
|
|
|
|
|
|
if (config.isDone)
|
2023-08-22 19:08:45 +08:00
|
|
|
|
{
|
2024-04-18 16:41:33 +08:00
|
|
|
|
continue;
|
2023-08-22 19:08:45 +08:00
|
|
|
|
}
|
2024-04-18 16:41:33 +08:00
|
|
|
|
isFinished = false;
|
2023-08-22 19:08:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
await UniTask.Delay(100);
|
2024-04-18 16:41:33 +08:00
|
|
|
|
|
|
|
|
|
|
// 排序,未完成的排在前面
|
|
|
|
|
|
downloadConfigs = downloadConfigs.OrderBy(x => x.isDone).ToList();
|
2023-08-22 19:08:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EditorUtility.ClearProgressBar();
|
|
|
|
|
|
|
|
|
|
|
|
bool hasError = false;
|
2024-04-18 16:41:33 +08:00
|
|
|
|
for (int i = 0; i < downloadConfigs.Count; i++)
|
2023-08-22 19:08:45 +08:00
|
|
|
|
{
|
2024-04-18 16:41:33 +08:00
|
|
|
|
var config = downloadConfigs[i];
|
|
|
|
|
|
if (!config.downloader.isDownloaded)
|
2023-08-22 19:08:45 +08:00
|
|
|
|
{
|
2024-04-18 16:41:33 +08:00
|
|
|
|
if (config.downloader.isCanceled)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogError("文件下载被取消,name=" + config.excelName);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogError("文件下载失败,name=" + config.excelName);
|
|
|
|
|
|
}
|
2023-08-22 19:08:45 +08:00
|
|
|
|
hasError = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!hasError)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.Log("所有文件下载成功");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogError("出现异常,message=" + e.Message + "\n,trace=" + e.StackTrace);
|
|
|
|
|
|
EditorUtility.ClearProgressBar();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-18 16:41:33 +08:00
|
|
|
|
public static WPExcelDownloader StartDownload(ConfigInfo ci, string cookie)
|
2023-08-22 19:08:45 +08:00
|
|
|
|
{
|
2023-10-24 12:15:31 +08:00
|
|
|
|
var downloader = new WPExcelDownloader(ci.Name, ci.DocID, cookie);
|
2024-04-18 16:41:33 +08:00
|
|
|
|
downloader.StartDownload().Forget();
|
|
|
|
|
|
return downloader;
|
2023-08-22 19:08:45 +08:00
|
|
|
|
}
|
2024-04-18 16:41:33 +08:00
|
|
|
|
|
2023-08-22 19:08:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|