From 504601fd44617c7f37667ae6de2d0ad9c01cc003 Mon Sep 17 00:00:00 2001 From: Emilian Roman Date: Sun, 18 Nov 2018 07:54:19 +0800 Subject: [PATCH] Implement installation of the OpenSauce IDE to the HCE directory --- AmaiSosu/AmaiSosu.csproj | 1 + AmaiSosu/Backup.cs | 3 ++- AmaiSosu/Copy.cs | 34 ++++++++++++++++++++++++++++++++++ AmaiSosu/Main.cs | 19 +++++++++++++++++++ README.md | 1 + 5 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 AmaiSosu/Copy.cs diff --git a/AmaiSosu/AmaiSosu.csproj b/AmaiSosu/AmaiSosu.csproj index 0f167bb..ca95eae 100644 --- a/AmaiSosu/AmaiSosu.csproj +++ b/AmaiSosu/AmaiSosu.csproj @@ -60,6 +60,7 @@ + MainWindow.xaml diff --git a/AmaiSosu/Backup.cs b/AmaiSosu/Backup.cs index 40c1338..310e5a6 100644 --- a/AmaiSosu/Backup.cs +++ b/AmaiSosu/Backup.cs @@ -21,7 +21,8 @@ public class Backup "data", "MaxScripts", "shaders", - "tags" + "tags", + "OpenSauceIDE" }; /// diff --git a/AmaiSosu/Copy.cs b/AmaiSosu/Copy.cs new file mode 100644 index 0000000..1ad8ddd --- /dev/null +++ b/AmaiSosu/Copy.cs @@ -0,0 +1,34 @@ +using System; +using System.IO; + +namespace AmaiSosu +{ + /// + /// Copy a directory and its contents. Adapted from the MSDN CopyAll method. + /// + /// + public static class Copy + { + public static void All(DirectoryInfo source, DirectoryInfo target) + { + if (string.Equals(source.FullName, target.FullName, StringComparison.CurrentCultureIgnoreCase)) return; + + // Check if the target directory exists, if not, create it. + if (Directory.Exists(target.FullName) == false) Directory.CreateDirectory(target.FullName); + + // Copy each file into it's new directory. + foreach (var fi in source.GetFiles()) + { + Console.WriteLine(@"Copying {0}\{1}", target.FullName, fi.Name); + fi.CopyTo(Path.Combine(target.ToString(), fi.Name), true); + } + + // Copy each subdirectory using recursion. + foreach (var diSourceSubDir in source.GetDirectories()) + { + var nextTargetSubDir = target.CreateSubdirectory(diSourceSubDir.Name); + All(diSourceSubDir, nextTargetSubDir); + } + } + } +} \ No newline at end of file diff --git a/AmaiSosu/Main.cs b/AmaiSosu/Main.cs index cdbde6f..087eb7c 100644 --- a/AmaiSosu/Main.cs +++ b/AmaiSosu/Main.cs @@ -98,6 +98,7 @@ public void Install() { new Backup(Path).Commit(); OpenSauce.Install(Path); + MoveOpenSauceIde(); InstallText = "Installation has been successful!"; } catch (Exception e) @@ -106,6 +107,24 @@ public void Install() } } + /// + /// Moves the OpenSauce IDE directory to the HCE directory for convenience. + /// This method calls the static Copy.All(DirectoryInfo source, DirectoryInfo target) method. + /// + private void MoveOpenSauceIde() + { + const string dirName = "OpenSauceIDE"; + + var source = + System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), + "Kornner Studios", "OpenSauce", dirName); + + var target = System.IO.Path.Combine(Path, dirName); + + Copy.All(new DirectoryInfo(source), new DirectoryInfo(target)); + Directory.Delete(source, true); + } + /// /// Updates the install text upon successful path provision. /// diff --git a/README.md b/README.md index 190196e..133894e 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ there is no collision. - installation of the OpenSauce libraries, in-game UI and user configurations; - installation of OpenSauce development tools (`OS_Guerilla`, `OS_Sapien`, `OS_Tool`, etc.); +- installation of the OpenSauce IDE to the HCE directory, for self-containerisation & convenience; - automatic back-up of existing OpenSauce data in the HCE directory (both files and folders); - automatic back-up & deactivation of HAC2 if it exists, due to its incompatibility with OpenSauce; - automatic detection attempt of a legally installed HCE directory for an even easier installation;