fix repo update

This commit is contained in:
辉鸭蛋 2024-11-09 17:37:46 +08:00
parent fe1d67bf16
commit 19c7b10b01
2 changed files with 52 additions and 4 deletions

View File

@ -215,10 +215,18 @@ public class ScriptRepoUpdater : Singleton<ScriptRepoUpdater>
public async Task ImportScriptFromClipboard()
{
// 获取剪切板内容
if (Clipboard.ContainsText())
try
{
string clipboardText = Clipboard.GetText();
await ImportScriptFromUri(clipboardText, true);
if (Clipboard.ContainsText())
{
string clipboardText = Clipboard.GetText();
await ImportScriptFromUri(clipboardText, true);
}
}
catch (Exception e)
{
// 剪切板内容可能获取会失败
Console.WriteLine(e);
}
}
@ -373,7 +381,7 @@ public class ScriptRepoUpdater : Singleton<ScriptRepoUpdater>
{
if (Directory.Exists(destPath))
{
Directory.Delete(destPath, true);
DirectoryHelper.DeleteDirectoryWithReadOnlyCheck(destPath);
}
CopyDirectory(scriptPath, destPath);
@ -417,6 +425,8 @@ public class ScriptRepoUpdater : Singleton<ScriptRepoUpdater>
{
var destSubDir = Path.Combine(destDir, Path.GetFileName(dir));
CopyDirectory(dir, destSubDir);
// 图标处理
DealWithIconFolder(destSubDir);
}
}

View File

@ -19,6 +19,44 @@ public class DirectoryHelper
}
}
public static void DeleteDirectoryWithReadOnlyCheck(string directoryPath)
{
if (Directory.Exists(directoryPath))
{
// 获取目录信息
var directoryInfo = new DirectoryInfo(directoryPath);
// 递归删除目录及其内容
DeleteDirectory(directoryInfo);
}
}
private static void DeleteDirectory(DirectoryInfo directoryInfo)
{
// 递归处理子目录
foreach (var subDirectory in directoryInfo.GetDirectories())
{
DeleteDirectory(subDirectory);
}
// 移除文件的只读属性并删除文件
foreach (var file in directoryInfo.GetFiles())
{
if (file.Attributes.HasFlag(FileAttributes.ReadOnly))
{
file.Attributes &= ~FileAttributes.ReadOnly;
}
file.Delete();
}
// 移除目录的只读属性并删除目录
if (directoryInfo.Attributes.HasFlag(FileAttributes.ReadOnly))
{
directoryInfo.Attributes &= ~FileAttributes.ReadOnly;
}
directoryInfo.Delete();
}
private static void RemoveReadOnlyAttribute(DirectoryInfo directoryInfo)
{
// 移除目录的只读属性