From f90408ead129f7db4987d3ebd4556fb921593e08 Mon Sep 17 00:00:00 2001 From: Emilian Roman Date: Sun, 14 Feb 2021 21:19:38 +0800 Subject: [PATCH 01/10] Revert "Let HXE target x64 only" This reverts commit 11164076a1c4db6ee8547fd83ab1edad4c2ca3f5. --- hxe/kernel/src/HXE.csproj | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/hxe/kernel/src/HXE.csproj b/hxe/kernel/src/HXE.csproj index 43bb6abe4..c3fc42c0b 100644 --- a/hxe/kernel/src/HXE.csproj +++ b/hxe/kernel/src/HXE.csproj @@ -28,7 +28,7 @@ true - x64 + AnyCPU true full false @@ -36,17 +36,15 @@ DEBUG;TRACE prompt 4 - false - x64 + AnyCPU pdbonly true ..\bin\Release\ TRACE prompt 4 - false Assets\icon.ico From 468de7ce417bccf6fb1a603b8a207400dc507143 Mon Sep 17 00:00:00 2001 From: Emilian Roman Date: Sun, 14 Feb 2021 21:19:58 +0800 Subject: [PATCH 02/10] Revert "Let SPV3 target x64 only" This reverts commit 674832c18929ed3b278b8c4782d802036d99457c. --- spv3/loader/src/SPV3.csproj | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/spv3/loader/src/SPV3.csproj b/spv3/loader/src/SPV3.csproj index a7341218b..7ede782cd 100644 --- a/spv3/loader/src/SPV3.csproj +++ b/spv3/loader/src/SPV3.csproj @@ -33,7 +33,7 @@ true - x64 + AnyCPU true full false @@ -41,17 +41,15 @@ DEBUG;TRACE prompt 4 - false - x64 + AnyCPU pdbonly true ..\bin\Release\ TRACE prompt 4 - false Assets\icon.ico From f4e6bb1f1032c07b87adea3bf2868e74ce97ca25 Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sun, 14 Feb 2021 05:09:17 -0800 Subject: [PATCH 03/10] Check if the root of the Target folder doesn't exist Fix tired me's mistake I am also tired me --- spv3/loader/src/Install.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spv3/loader/src/Install.cs b/spv3/loader/src/Install.cs index 984ed049f..5729eaed9 100644 --- a/spv3/loader/src/Install.cs +++ b/spv3/loader/src/Install.cs @@ -125,7 +125,7 @@ public string Target /** * Check validity of the specified target value. */ - if (string.IsNullOrEmpty(Target) || !Directory.Exists(Target)) + if (string.IsNullOrEmpty(Target) || !Directory.Exists(Path.GetPathRoot(Target))) { Status = "Enter a valid path."; CanInstall = false; From 4ae409e0e1ad2c15cd9f263dc363011f7b9c3fa1 Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sun, 14 Feb 2021 05:16:53 -0800 Subject: [PATCH 04/10] Move Target.Set{} code block to its own function --- spv3/loader/src/Install.cs | 229 +++++++++++++++++++------------------ 1 file changed, 116 insertions(+), 113 deletions(-) diff --git a/spv3/loader/src/Install.cs b/spv3/loader/src/Install.cs index 5729eaed9..e6d88efbe 100644 --- a/spv3/loader/src/Install.cs +++ b/spv3/loader/src/Install.cs @@ -122,119 +122,6 @@ public string Target _target = value; OnPropertyChanged(); - /** - * Check validity of the specified target value. - */ - if (string.IsNullOrEmpty(Target) || !Directory.Exists(Path.GetPathRoot(Target))) - { - Status = "Enter a valid path."; - CanInstall = false; - return; - } - - if (Target.Contains(GetFolderPath(ProgramFiles)) - || !string.IsNullOrEmpty(GetFolderPath(ProgramFilesX86)) && Target.Contains(GetFolderPath(ProgramFilesX86)) ) - { - Status = "The game does not function correctly when install to Program Files. Please choose a difference location."; - CanInstall = false; - return; - } - - - try - { - var exists = Directory.Exists(Target); - var path = Target; - var rootExists = Directory.Exists(Path.GetPathRoot(Target)); - - if (!exists && !rootExists) - { - throw new DirectoryNotFoundException(Target); - } - if (!exists && rootExists) - { - while (!Directory.Exists(path)) - { - path = Directory.GetParent(path).Name; - if (path == "Debug") return; - } - } - - // if Target and Root exist... - _target = Path.GetFullPath(_target); - value = Path.GetFullPath(value); - var test = Path.Combine(path, "io.bin"); - WriteAllBytes(test, new byte[8]); - Delete(test); - - Status = "Waiting for user to install SPV3."; - CanInstall = true; - } - catch (Exception e) - { - var msg = "Installation not possible at selected path: " + Target + "\n Error: " + e.ToString() + "\n"; - var log = (HXE.File)Paths.Exception; - log.AppendAllText(msg); - Status = msg; - CanInstall = false; - return; - } - - /** - * Check available disk space. This will NOT work on UNC paths! - */ - try - { - - /** First, check the C:\ drive to ensure there's enough free space - * for temporary extraction to %temp% */ - if (Directory.Exists(@"C:\")) - { - var systemDrive = new DriveInfo(@"C:\"); - if (systemDrive.TotalFreeSpace < 10737418240) - { - Status = @"Not enough disk space (10GB required) on the C:\ drive. " + - "Clear junk files using Disk Cleanup or allocate more space to the volume"; - CanInstall = false; - return; - } - } - - /** - * Check if the target drive has at least 16GB of free space - */ - var targetDrive = new DriveInfo(Path.GetPathRoot(Target)); - - if (targetDrive.IsReady && targetDrive.TotalFreeSpace > 17179869184) - { - CanInstall = true; - } - else - { - Status = "Not enough disk space (16GB required) at selected path: " + Target; - CanInstall = false; - return; - } - } - catch (Exception e) - { - var msg = "Failed to get drive space.\n Error: " + e.ToString() + "\n"; - var log = (HXE.File)Paths.Exception; - log.AppendAllText(msg); - Status = msg; - CanInstall = false; - } - - /** - * Prohibit installations to known problematic folders. - */ - if (Exists(Path.Combine(Target, HXE.Paths.HCE.Executable)) - || Exists(Path.Combine(Target, HXE.Paths.Executable)) - || Exists(Path.Combine(Target, Paths.Executable))) - { - Status = "Selected folder contains existing HCE or SPV3 data. Please choose a different location."; - CanInstall = false; - } } } @@ -455,6 +342,122 @@ public void CheckSteamPath(string exe) Update_SteamStatus(); } + public void ValidateTarget(string path) + { + /** + * Check validity of the specified target value. + */ + if (string.IsNullOrEmpty(path) || !Directory.Exists(Path.GetPathRoot(path))) + { + Status = "Enter a valid path."; + CanInstall = false; + return; + } + + if (path.Contains(GetFolderPath(ProgramFiles)) + || !string.IsNullOrEmpty(GetFolderPath(ProgramFilesX86)) && Target.Contains(GetFolderPath(ProgramFilesX86))) + { + Status = "The game does not function correctly when install to Program Files. Please choose a difference location."; + CanInstall = false; + return; + } + + try + { + var exists = Directory.Exists(Target); + var rootExists = Directory.Exists(Path.GetPathRoot(Target)); + + if (!exists && !rootExists) + { + throw new DirectoryNotFoundException(Target); + } + if (!exists && rootExists) + { + while (!Directory.Exists(path)) + { + path = Directory.GetParent(path).Name; + if (path == "Debug") return; + } + } + + // if Target and Root exist... + _target = Path.GetFullPath(_target); + value = Path.GetFullPath(value); + var test = Path.Combine(path, "io.bin"); + WriteAllBytes(test, new byte[8]); + Delete(test); + + Status = "Waiting for user to install SPV3."; + CanInstall = true; + } + catch (Exception e) + { + var msg = "Installation not possible at selected path: " + Target + "\n Error: " + e.ToString() + "\n"; + var log = (HXE.File)Paths.Exception; + log.AppendAllText(msg); + Status = msg; + CanInstall = false; + return; + } + + /** + * Check available disk space. This will NOT work on UNC paths! + */ + try + { + + /** First, check the C:\ drive to ensure there's enough free space + * for temporary extraction to %temp% */ + if (Directory.Exists(@"C:\")) + { + var systemDrive = new DriveInfo(@"C:\"); + if (systemDrive.TotalFreeSpace < 10737418240) + { + Status = @"Not enough disk space (10GB required) on the C:\ drive. " + + "Clear junk files using Disk Cleanup or allocate more space to the volume"; + CanInstall = false; + return; + } + } + + /** + * Check if the target drive has at least 16GB of free space + */ + var targetDrive = new DriveInfo(Path.GetPathRoot(Target)); + + if (targetDrive.IsReady && targetDrive.TotalFreeSpace > 17179869184) + { + CanInstall = true; + } + else + { + Status = "Not enough disk space (16GB required) at selected path: " + Target; + CanInstall = false; + return; + } + } + catch (Exception e) + { + var msg = "Failed to get drive space.\n Error: " + e.ToString() + "\n"; + var log = (HXE.File)Paths.Exception; + log.AppendAllText(msg); + Status = msg; + CanInstall = false; + } + + /** + * Prohibit installations to known problematic folders. + */ + if (Exists(Path.Combine(Target, HXE.Paths.HCE.Executable)) + || Exists(Path.Combine(Target, HXE.Paths.Executable)) + || Exists(Path.Combine(Target, Paths.Executable))) + { + Status = "Selected folder contains existing HCE or SPV3 data. Please choose a different location."; + CanInstall = false; + } + + } + public void ViewActivation() // Debug widget { Main = Collapsed; From aafb8bcdda953e60f8ef80ade44b133fd3dbf0fe Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sun, 14 Feb 2021 05:25:06 -0800 Subject: [PATCH 05/10] Finish refactoring Target references to "path" --- spv3/loader/src/Install.cs | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/spv3/loader/src/Install.cs b/spv3/loader/src/Install.cs index e6d88efbe..0db36fe59 100644 --- a/spv3/loader/src/Install.cs +++ b/spv3/loader/src/Install.cs @@ -354,8 +354,12 @@ public void ValidateTarget(string path) return; } + /** + * Check if path contains Program Files or Program Files (x86) + */ if (path.Contains(GetFolderPath(ProgramFiles)) - || !string.IsNullOrEmpty(GetFolderPath(ProgramFilesX86)) && Target.Contains(GetFolderPath(ProgramFilesX86))) + || !string.IsNullOrEmpty(GetFolderPath(ProgramFilesX86)) + && path.Contains(GetFolderPath(ProgramFilesX86))) { Status = "The game does not function correctly when install to Program Files. Please choose a difference location."; CanInstall = false; @@ -364,12 +368,12 @@ public void ValidateTarget(string path) try { - var exists = Directory.Exists(Target); - var rootExists = Directory.Exists(Path.GetPathRoot(Target)); + var exists = Directory.Exists(path); + var rootExists = Directory.Exists(Path.GetPathRoot(path)); if (!exists && !rootExists) { - throw new DirectoryNotFoundException(Target); + throw new DirectoryNotFoundException(path); } if (!exists && rootExists) { @@ -381,8 +385,7 @@ public void ValidateTarget(string path) } // if Target and Root exist... - _target = Path.GetFullPath(_target); - value = Path.GetFullPath(value); + path = Path.GetFullPath(path); var test = Path.Combine(path, "io.bin"); WriteAllBytes(test, new byte[8]); Delete(test); @@ -392,8 +395,8 @@ public void ValidateTarget(string path) } catch (Exception e) { - var msg = "Installation not possible at selected path: " + Target + "\n Error: " + e.ToString() + "\n"; - var log = (HXE.File)Paths.Exception; + var msg = "Installation not possible at selected path: " + path + "\n Error: " + e.ToString() + "\n"; + var log = (HXE.File) Paths.Exception; log.AppendAllText(msg); Status = msg; CanInstall = false; @@ -423,7 +426,7 @@ public void ValidateTarget(string path) /** * Check if the target drive has at least 16GB of free space */ - var targetDrive = new DriveInfo(Path.GetPathRoot(Target)); + var targetDrive = new DriveInfo(Path.GetPathRoot(path)); if (targetDrive.IsReady && targetDrive.TotalFreeSpace > 17179869184) { @@ -431,7 +434,7 @@ public void ValidateTarget(string path) } else { - Status = "Not enough disk space (16GB required) at selected path: " + Target; + Status = "Not enough disk space (16GB required) at selected path: " + path; CanInstall = false; return; } @@ -448,9 +451,9 @@ public void ValidateTarget(string path) /** * Prohibit installations to known problematic folders. */ - if (Exists(Path.Combine(Target, HXE.Paths.HCE.Executable)) - || Exists(Path.Combine(Target, HXE.Paths.Executable)) - || Exists(Path.Combine(Target, Paths.Executable))) + if (Exists(Path.Combine(path, HXE.Paths.HCE.Executable)) + || Exists(Path.Combine(path, HXE.Paths.Executable)) + || Exists(Path.Combine(path, Paths.Executable))) { Status = "Selected folder contains existing HCE or SPV3 data. Please choose a different location."; CanInstall = false; From 5b7e4ce6a2020bb7b6d21647d0fba540b5a59c1c Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sun, 14 Feb 2021 05:26:03 -0800 Subject: [PATCH 06/10] Update required Temp data to 11GiB --- spv3/loader/src/Install.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spv3/loader/src/Install.cs b/spv3/loader/src/Install.cs index 0db36fe59..dc3fbf447 100644 --- a/spv3/loader/src/Install.cs +++ b/spv3/loader/src/Install.cs @@ -414,9 +414,9 @@ public void ValidateTarget(string path) if (Directory.Exists(@"C:\")) { var systemDrive = new DriveInfo(@"C:\"); - if (systemDrive.TotalFreeSpace < 10737418240) + if (systemDrive.TotalFreeSpace < 11811160064) { - Status = @"Not enough disk space (10GB required) on the C:\ drive. " + + Status = @"Not enough disk space (11GB required) on the C:\ drive. " + "Clear junk files using Disk Cleanup or allocate more space to the volume"; CanInstall = false; return; From a17e39c899168fae29c9ed7c7248bb819f596048 Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sun, 14 Feb 2021 05:35:26 -0800 Subject: [PATCH 07/10] Infer Temp and its drive from user's %temp% variable --- spv3/loader/src/Install.cs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/spv3/loader/src/Install.cs b/spv3/loader/src/Install.cs index dc3fbf447..9f2dd0b2d 100644 --- a/spv3/loader/src/Install.cs +++ b/spv3/loader/src/Install.cs @@ -121,7 +121,7 @@ public string Target if (value == _target) return; _target = value; OnPropertyChanged(); - + ValidateTarget(value); } } @@ -380,7 +380,7 @@ public void ValidateTarget(string path) while (!Directory.Exists(path)) { path = Directory.GetParent(path).Name; - if (path == "Debug") return; + if (path == CurrentDirectory) return; } } @@ -408,12 +408,11 @@ public void ValidateTarget(string path) */ try { - - /** First, check the C:\ drive to ensure there's enough free space + /** First, check the user's temp folder's drive to ensure there's enough free space * for temporary extraction to %temp% */ - if (Directory.Exists(@"C:\")) { - var systemDrive = new DriveInfo(@"C:\"); + var tmpath = Path.GetPathRoot(Path.GetTempPath()); + var systemDrive = new DriveInfo(tmpath); if (systemDrive.TotalFreeSpace < 11811160064) { Status = @"Not enough disk space (11GB required) on the C:\ drive. " + From 875040f617330704d9145ab2b20f1801ac8bb83b Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sun, 14 Feb 2021 05:44:29 -0800 Subject: [PATCH 08/10] Conditionally output %temp%'s drive letter to Status --- spv3/loader/src/Install.cs | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/spv3/loader/src/Install.cs b/spv3/loader/src/Install.cs index 9f2dd0b2d..61e7392e0 100644 --- a/spv3/loader/src/Install.cs +++ b/spv3/loader/src/Install.cs @@ -347,7 +347,8 @@ public void ValidateTarget(string path) /** * Check validity of the specified target value. */ - if (string.IsNullOrEmpty(path) || !Directory.Exists(Path.GetPathRoot(path))) + if (string.IsNullOrEmpty(path) + || !Directory.Exists(Path.GetPathRoot(path))) { Status = "Enter a valid path."; CanInstall = false; @@ -371,10 +372,6 @@ public void ValidateTarget(string path) var exists = Directory.Exists(path); var rootExists = Directory.Exists(Path.GetPathRoot(path)); - if (!exists && !rootExists) - { - throw new DirectoryNotFoundException(path); - } if (!exists && rootExists) { while (!Directory.Exists(path)) @@ -409,14 +406,15 @@ public void ValidateTarget(string path) try { /** First, check the user's temp folder's drive to ensure there's enough free space - * for temporary extraction to %temp% */ + * for temporary extraction to %temp% + */ { var tmpath = Path.GetPathRoot(Path.GetTempPath()); var systemDrive = new DriveInfo(tmpath); if (systemDrive.TotalFreeSpace < 11811160064) { - Status = @"Not enough disk space (11GB required) on the C:\ drive. " + - "Clear junk files using Disk Cleanup or allocate more space to the volume"; + Status = $"Not enough disk space (11GB required) on the {tmpath} drive. " + + "Clear junk files using Disk Cleanup or allocate more space to the volume"; CanInstall = false; return; } @@ -446,18 +444,6 @@ public void ValidateTarget(string path) Status = msg; CanInstall = false; } - - /** - * Prohibit installations to known problematic folders. - */ - if (Exists(Path.Combine(path, HXE.Paths.HCE.Executable)) - || Exists(Path.Combine(path, HXE.Paths.Executable)) - || Exists(Path.Combine(path, Paths.Executable))) - { - Status = "Selected folder contains existing HCE or SPV3 data. Please choose a different location."; - CanInstall = false; - } - } public void ViewActivation() // Debug widget From f9e4a5673480ba220ccc9b647a270a4518152a41 Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sun, 14 Feb 2021 06:11:09 -0800 Subject: [PATCH 09/10] Fix infinite While loop --- spv3/loader/src/Install.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/spv3/loader/src/Install.cs b/spv3/loader/src/Install.cs index 61e7392e0..8fdffb5c6 100644 --- a/spv3/loader/src/Install.cs +++ b/spv3/loader/src/Install.cs @@ -370,14 +370,20 @@ public void ValidateTarget(string path) try { var exists = Directory.Exists(path); - var rootExists = Directory.Exists(Path.GetPathRoot(path)); + var root = Path.GetPathRoot(path); + var rootExists = Directory.Exists(root); if (!exists && rootExists) { while (!Directory.Exists(path)) { - path = Directory.GetParent(path).Name; - if (path == CurrentDirectory) return; + path = Directory.GetParent(path).FullName; + if (path == CurrentDirectory) + { + Status = "Enter a valid path."; + CanInstall = false; + return; + } } } From 7eef25fb02f703b4bd90cec462a044ac81fa9f33 Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sun, 14 Feb 2021 06:13:01 -0800 Subject: [PATCH 10/10] Add ValidateTarget() to Initialize() --- spv3/loader/src/Install.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spv3/loader/src/Install.cs b/spv3/loader/src/Install.cs index 8fdffb5c6..90273dd6d 100644 --- a/spv3/loader/src/Install.cs +++ b/spv3/loader/src/Install.cs @@ -165,10 +165,11 @@ public void Initialise() Main = Visible; Activation = Collapsed; + ValidateTarget(Target); + /** * Determine if the current environment fulfills the installation requirements. */ - if (Registry.GameExists("Custom") || Registry.GameExists("Retail") || ( Kernel.hxe.Tweaks.Patches & Patcher.EXEP.DISABLE_DRM_AND_KEY_CHECKS) == 1)