CI / Go Backend (push) Canceled after 0s
初始化 monorepo: Go后端(7微服务) + Unity客户端(9模块) + 启动器 HTML5原型: Three.js 3D体素世界, Perlin噪声地形, 原版材质, 22种方块 Minecraft创造模式背包: 双栏布局, 拖拽移动物品, 方向性元件引脚 AI助搭策划文档 + 客户端/服务端骨架 + Docker Compose + CI
66 lines
1.7 KiB
C#
66 lines
1.7 KiB
C#
using System.IO;
|
|
using System.Threading;
|
|
|
|
namespace PCL.Network.Loaders;
|
|
|
|
public class LoaderDownloadUnc : ModLoader.LoaderBase
|
|
{
|
|
public string unc;
|
|
public string savePath;
|
|
private CancellationTokenSource? _cancellationTokenSource;
|
|
|
|
public LoaderDownloadUnc(string name, Tuple<string, string> file)
|
|
{
|
|
base.name = name;
|
|
unc = file.Item1;
|
|
savePath = file.Item2;
|
|
}
|
|
|
|
public override void Start(object input = null, bool isForceRestart = false)
|
|
{
|
|
if (input is Tuple<string, string> tuple)
|
|
{
|
|
unc = tuple.Item1;
|
|
savePath = tuple.Item2;
|
|
}
|
|
|
|
lock (lockState)
|
|
{
|
|
if (State == ModBase.LoadState.Loading)
|
|
return;
|
|
State = ModBase.LoadState.Loading;
|
|
}
|
|
|
|
_cancellationTokenSource = new CancellationTokenSource();
|
|
ModBase.RunInNewThread(() => Run(_cancellationTokenSource.Token), $"UNC/{Uuid}");
|
|
}
|
|
|
|
private void Run(CancellationToken cancellationToken)
|
|
{
|
|
try
|
|
{
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
Directory.CreateDirectory(Path.GetDirectoryName(savePath) ?? throw new IOException("下载路径无效"));
|
|
ModBase.CopyFile(unc, savePath);
|
|
State = ModBase.LoadState.Finished;
|
|
}
|
|
catch (OperationCanceledException)
|
|
{
|
|
Abort();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Error = ex;
|
|
State = ModBase.LoadState.Failed;
|
|
}
|
|
}
|
|
|
|
public override void Abort()
|
|
{
|
|
if (State >= ModBase.LoadState.Finished)
|
|
return;
|
|
State = ModBase.LoadState.Aborted;
|
|
_cancellationTokenSource?.Cancel();
|
|
}
|
|
}
|