Fixed the prevent-crash-on-missing-dir patch

This commit is contained in:
EvilFactory
2024-03-28 16:54:25 -03:00
parent 19af26ddbe
commit 8b4f5d1d04

View File

@@ -1,32 +1,8 @@
diff --git a/Deploy/DeployAll/Util.cs b/Deploy/DeployAll/Util.cs diff --git a/Deploy/DeployAll/Util.cs b/Deploy/DeployAll/Util.cs
index 6962ac512..d700c7f8e 100644 index 0a4fc80911..bcec72a168 100644
--- a/Deploy/DeployAll/Util.cs --- a/Deploy/DeployAll/Util.cs
+++ b/Deploy/DeployAll/Util.cs +++ b/Deploy/DeployAll/Util.cs
@@ -10,97 +10,106 @@ namespace DeployAll; @@ -36,7 +36,16 @@ public static class Util
public static class Util
{
public static void DeleteFiles(string path, params string[] patterns)
{
foreach (var file in patterns.SelectMany(p => Directory.GetFiles(path, p, SearchOption.AllDirectories)))
{
File.Delete(file);
string dir = file;
do
{
dir = Path.GetDirectoryName(dir) ?? "";
if (Directory.GetFiles(dir, "*", SearchOption.AllDirectories).Length == 0)
{
Directory.Delete(dir, recursive: false);
}
else
{
break;
}
} while (dir.LastIndexOf('/') > 0);
}
}
public static void CopyDirectory(string sourceDir, string destinationDir)
{ {
var dir = new DirectoryInfo(sourceDir); var dir = new DirectoryInfo(sourceDir);
@@ -44,70 +20,10 @@ index 6962ac512..d700c7f8e 100644
Directory.CreateDirectory(destinationDir); Directory.CreateDirectory(destinationDir);
foreach (FileInfo file in dir.GetFiles()) @@ -152,4 +161,4 @@ public static class Util
{
string targetFilePath = Path.Combine(destinationDir, file.Name);
file.CopyTo(targetFilePath);
}
foreach (DirectoryInfo subDir in dirs)
{
string newDestinationDir = Path.Combine(destinationDir, subDir.Name);
CopyDirectory(subDir.FullName, newDestinationDir);
}
}
public static void DeleteDirectory(string path)
{
if (Directory.Exists(path))
{
Directory.Delete(path, recursive: true);
}
}
public static void RecreateDirectory(string path)
{
DeleteDirectory(path);
Directory.CreateDirectory(path);
}
public static IReadOnlyList<byte> DownloadFile(string url)
{
var httpClient = new HttpClient();
var response = httpClient.Send(new HttpRequestMessage(
HttpMethod.Get,
new Uri(url)));
using var stream = response.Content.ReadAsStream();
using var reader = new BinaryReader(stream);
var contents = new List<byte>();
while (true)
{
byte[] bytesRead = reader.ReadBytes(1024);
if (bytesRead.Length == 0) { break; }
contents.AddRange(bytesRead);
}
return contents;
}
public static string AskQuestion(string question)
{
Console.WriteLine(question);
Console.Write("> ");
string answer = Console.ReadLine() ?? "";
Console.WriteLine("");
return answer;
}
public static bool AnsweredYes(this string answer)
=> answer.Equals("y", StringComparison.InvariantCulture);
public static bool AnsweredNo(this string answer)
=> !answer.AnsweredYes();
public static Process StartProcess(ProcessStartInfo info) public static Process StartProcess(ProcessStartInfo info)
=> Process.Start(info) => Process.Start(info)
?? throw new Exception($"Failed to start process \"{info.FileName}\""); ?? throw new Exception($"Failed to start process \"{info.FileName}\"");
} -}
\ No newline at end of file \ No newline at end of file
+}