From a01931b5f805ea7d3cea33e63a6cf44888280686 Mon Sep 17 00:00:00 2001 From: JoshuaMKW <60854312+JoshuaMKW@users.noreply.github.com> Date: Wed, 26 Aug 2020 17:58:41 -0500 Subject: [PATCH] Final tweaks --- installer.cs | 50 +++++++++++++++++++++++++++----------------------- setup.py | 3 ++- 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/installer.cs b/installer.cs index 0842274..1e5c4fa 100644 --- a/installer.cs +++ b/installer.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Xml.Serialization; @@ -25,27 +26,22 @@ public class Installer overwrite = true; } - void CopyAll (DirectoryInfo source, DirectoryInfo destination, string wildcard, string[] exclude, int maxdepth = 16) + void CopyAll (DirectoryInfo source, DirectoryInfo destination, string wildcard, string[] exclude, int maxdepth = 4) { + Console.WriteLine("{0}, {1}", source.FullName, destination.FullName); if (maxdepth <= 0) return; DirectoryInfo[] subdirs = source.GetDirectories(); foreach (DirectoryInfo dirPath in source.EnumerateDirectories()) + { Directory.CreateDirectory(dirPath.FullName.Replace(source.FullName, destination.FullName)); + } + foreach (FileInfo filePath in source.EnumerateFiles(wildcard)) { - bool include = true; - foreach (string exc in exclude) - { - if (exc.ToLower().Contains(filePath.Name.ToLower())) - { - include = false; - break; - } - } - if (include) File.Copy(filePath.FullName, filePath.FullName.Replace(source.FullName, destination.FullName), true); + File.Copy(filePath.FullName, filePath.FullName.Replace(source.FullName, destination.FullName), true); } foreach (DirectoryInfo dir in subdirs) @@ -90,31 +86,38 @@ public class Installer private void SetProgramFolder(string folderName) { - this.programfolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "GeckoLoader", "data"); + this.programfolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "GeckoLoader"); } - private void SetProgramFolderToPath() + private void SetFolderToPath(string dir, string subdir) { var scope = EnvironmentVariableTarget.User; var curPATH = Environment.GetEnvironmentVariable("PATH", scope); - if (!curPATH.Contains(this.programfolder)) + if (!curPATH.Contains(Path.Combine(dir, subdir))) { - var newValue = curPATH + ";" + this.programfolder; - Environment.SetEnvironmentVariable("PATH", newValue, scope); + var newValue = curPATH + ";" + Path.Combine(dir, subdir); + Environment.SetEnvironmentVariable("PATH", newValue.Replace(";;", ";"), scope); } } - private void RemoveProgramFolderFromPath() + private void RemoveFolderGroupFromPath(string dir) { var scope = EnvironmentVariableTarget.User; var curPATH = Environment.GetEnvironmentVariable("PATH", scope); - if (curPATH.Contains(this.programfolder)) + string[] oldPATHList = curPATH.Split(';'); + List newPATHList = new List(); + + foreach(string path in oldPATHList) { - var newValue = curPATH.Replace(";" + this.programfolder, ""); - Environment.SetEnvironmentVariable("PATH", newValue, scope); + if (!path.ToLower().Contains(dir.ToLower())) + { + newPATHList.Add(path); + } } + Environment.SetEnvironmentVariable("PATH", String.Join(";", newPATHList.ToArray()), scope); + } private bool MoveFilesToprogramfolder(string wildcard, bool copy = true, bool overwrite = false) @@ -172,10 +175,11 @@ public class Installer status = HandleConsoleQuestion("What do you want to do?", actionoptions); if (status.ToLower() == (string)actionoptions.GetValue(0)) { - this.SetProgramFolderToPath(); + this.RemoveFolderGroupFromPath(this.programfolder); + this.SetFolderToPath(this.programfolder, ""); if (this.MoveFilesToprogramfolder("*", this.copyfiles, this.overwrite) == false) { - Console.WriteLine("Failed to install :( Is Geckoloader and its dependancies in the same directory?"); + Console.WriteLine("Failed to install :("); } else { @@ -184,7 +188,7 @@ public class Installer } else { - this.RemoveProgramFolderFromPath(); + this.RemoveFolderGroupFromPath(this.programfolder); this.DeleteProgramFolder(); Console.WriteLine("Uninstalled successfully!"); } diff --git a/setup.py b/setup.py index e600532..7b74f4d 100644 --- a/setup.py +++ b/setup.py @@ -3,6 +3,7 @@ from cx_Freeze import setup, Executable options = { 'build_exe': { + 'optimize': 2, 'excludes': ['tkinter'] } } @@ -12,7 +13,7 @@ executables = [ ] setup(name='GeckoLoader', - version='v6.0.0', + version='v6.0.1', description='DOL Patcher for extending the codespace of Wii/GC games', executables=executables, options=options