110 lines
3.5 KiB
C#
110 lines
3.5 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using NUnit.Framework;
|
||
|
||
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;
|
||
|
||
public static List<DownloadConfigData> downloadConfigs = new List<DownloadConfigData>();
|
||
|
||
public static async UniTask AutoProcessConfig(List<ConfigInfo> m_Configs, string cookie)
|
||
{
|
||
var dir = new DirectoryInfo(ConfigTools.CONFIG_DIR);
|
||
SAVE_PATH = dir.FullName + "Datas/";
|
||
downloadConfigs.Clear();
|
||
try
|
||
{
|
||
_DownloadCount = 0;
|
||
|
||
for (int i = 0; i < m_Configs.Count; i++)
|
||
{
|
||
var config = m_Configs[i];
|
||
if (config.Check)
|
||
{
|
||
var downloader = StartDownload(config, cookie);
|
||
var downloadConfig = new DownloadConfigData();
|
||
downloadConfig.excelName = config.Name;
|
||
downloadConfig.downloader = downloader;
|
||
downloadConfigs.Add(downloadConfig);
|
||
}
|
||
|
||
}
|
||
|
||
var isFinished = false;
|
||
while (!isFinished)
|
||
{
|
||
isFinished = true;
|
||
for (int i = 0; i < downloadConfigs.Count; i++)
|
||
{
|
||
var config = downloadConfigs[i];
|
||
if (config.isDone)
|
||
{
|
||
continue;
|
||
}
|
||
isFinished = false;
|
||
}
|
||
await UniTask.Delay(100);
|
||
|
||
// 排序,未完成的排在前面
|
||
downloadConfigs = downloadConfigs.OrderBy(x => x.isDone).ToList();
|
||
}
|
||
|
||
EditorUtility.ClearProgressBar();
|
||
|
||
bool hasError = false;
|
||
for (int i = 0; i < downloadConfigs.Count; i++)
|
||
{
|
||
var config = downloadConfigs[i];
|
||
if (!config.downloader.isDownloaded)
|
||
{
|
||
if (config.downloader.isCanceled)
|
||
{
|
||
Debug.LogError("文件下载被取消,name=" + config.excelName);
|
||
}
|
||
else
|
||
{
|
||
Debug.LogError("文件下载失败,name=" + config.excelName);
|
||
}
|
||
hasError = true;
|
||
}
|
||
}
|
||
|
||
if (!hasError)
|
||
{
|
||
Debug.Log("所有文件下载成功");
|
||
}
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
Debug.LogError("出现异常,message=" + e.Message + "\n,trace=" + e.StackTrace);
|
||
EditorUtility.ClearProgressBar();
|
||
}
|
||
|
||
}
|
||
|
||
public static WPExcelDownloader StartDownload(ConfigInfo ci, string cookie)
|
||
{
|
||
var downloader = new WPExcelDownloader(ci.Name, ci.DocID, cookie);
|
||
downloader.StartDownload().Forget();
|
||
return downloader;
|
||
}
|
||
|
||
}
|
||
}
|