From 8d35722da1d081a476c1119c062e697306ddfc10 Mon Sep 17 00:00:00 2001 From: Kiper <27647817+Kipero@users.noreply.github.com> Date: Mon, 14 Jun 2021 19:46:16 +0200 Subject: [PATCH] Improve git code cloning Remove directory while trying to clone code * Before removing we need to set files attributes to normal as git files refuse to be deleted --- .../leagueSandboxAutoSetupForm.cs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/League Sandbox Auto Setup/leagueSandboxAutoSetupForm.cs b/League Sandbox Auto Setup/leagueSandboxAutoSetupForm.cs index 7a3fde3..f458809 100644 --- a/League Sandbox Auto Setup/leagueSandboxAutoSetupForm.cs +++ b/League Sandbox Auto Setup/leagueSandboxAutoSetupForm.cs @@ -75,6 +75,19 @@ private void startButton_Click(object sender, EventArgs e) } } + private void setAttributesNormal(DirectoryInfo dir) + { + foreach (var subDir in dir.GetDirectories()) + { + setAttributesNormal(subDir); + subDir.Attributes = FileAttributes.Normal; + } + foreach (var file in dir.GetFiles()) + { + file.Attributes = FileAttributes.Normal; + } + } + private void startCloningRepositories() { cloningProgressLabel.Text = "--"; @@ -143,6 +156,15 @@ private void startCloningRepositories() if (!Directory.Exists(cloningPath)) { Directory.CreateDirectory(cloningPath); + } + if (Directory.Exists(cloningPath)) + { + System.IO.DirectoryInfo cloningDir = new System.IO.DirectoryInfo(cloningPath); + // Set attributes in cloningDir to normal, as git files refuse to be deleted + setAttributesNormal(cloningDir); + cloningDir.Delete(true); + Directory.CreateDirectory(cloningPath); + } Repository.Clone("https://github.com/LeagueSandbox/GameServer", cloningPath, options); options.BranchName = "master"; Repository.Clone("https://github.com/LeagueSandbox/LeaguePackets", Path.Combine(cloningPath, "LeaguePackets"), options);