2023-08-22 19:08:45 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
|
|
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 _totalDownloadCount;
|
|
|
|
|
|
private static int _DownloadCount;
|
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/";
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
_totalDownloadCount = 0;
|
|
|
|
|
|
_DownloadCount = 0;
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < m_Configs.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_Configs[i].Check)
|
|
|
|
|
|
{
|
2023-10-24 12:15:31 +08:00
|
|
|
|
StartDownload(m_Configs[i], cookie);
|
2023-08-22 19:08:45 +08:00
|
|
|
|
_totalDownloadCount++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EditorUtility.DisplayProgressBar("配置工具", $"正在下载 0/{_totalDownloadCount}", 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (_DownloadCount < _totalDownloadCount)
|
|
|
|
|
|
{
|
|
|
|
|
|
_DownloadCount = 0;
|
|
|
|
|
|
for (int i = 0; i < m_Configs.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_Configs[i].Check)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_Configs[i].IsError || m_Configs[i].IsDownloadOK)
|
|
|
|
|
|
{
|
|
|
|
|
|
_DownloadCount++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
await UniTask.Delay(100);
|
|
|
|
|
|
var remainCount = _totalDownloadCount - _DownloadCount;
|
|
|
|
|
|
EditorUtility.DisplayCancelableProgressBar("配置工具", $"正在下载 {remainCount}/{_totalDownloadCount}",
|
|
|
|
|
|
_DownloadCount / (float)_totalDownloadCount);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EditorUtility.ClearProgressBar();
|
|
|
|
|
|
|
|
|
|
|
|
bool hasError = false;
|
|
|
|
|
|
for (int i = 0; i < m_Configs.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_Configs[i].Check && m_Configs[i].IsError)
|
|
|
|
|
|
{
|
|
|
|
|
|
hasError = true;
|
|
|
|
|
|
Debug.LogError("文件下载失败,name=" + m_Configs[i].Name);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!hasError)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.Log("所有文件下载成功");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogError("出现异常,message=" + e.Message + "\n,trace=" + e.StackTrace);
|
|
|
|
|
|
EditorUtility.ClearProgressBar();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-10-24 12:15:31 +08:00
|
|
|
|
public static async void 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);
|
2023-08-22 19:08:45 +08:00
|
|
|
|
var result = await downloader.StartDownload();
|
|
|
|
|
|
|
|
|
|
|
|
if (result)
|
|
|
|
|
|
{
|
|
|
|
|
|
ci.IsDownloadOK = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
ci.IsError = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|