Skip to content

Commit 7e954f1

Browse files
committed
Tweak Target Validation
2 parents db095cf + 7eef25f commit 7e954f1

File tree

3 files changed

+117
-123
lines changed

3 files changed

+117
-123
lines changed

hxe/kernel/src/HXE.csproj

+2-4
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,23 @@
2828
<BootstrapperEnabled>true</BootstrapperEnabled>
2929
</PropertyGroup>
3030
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
31-
<PlatformTarget>x64</PlatformTarget>
31+
<PlatformTarget>AnyCPU</PlatformTarget>
3232
<DebugSymbols>true</DebugSymbols>
3333
<DebugType>full</DebugType>
3434
<Optimize>false</Optimize>
3535
<OutputPath>..\bin\Debug\</OutputPath>
3636
<DefineConstants>DEBUG;TRACE</DefineConstants>
3737
<ErrorReport>prompt</ErrorReport>
3838
<WarningLevel>4</WarningLevel>
39-
<Prefer32bit>false</Prefer32bit>
4039
</PropertyGroup>
4140
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
42-
<PlatformTarget>x64</PlatformTarget>
41+
<PlatformTarget>AnyCPU</PlatformTarget>
4342
<DebugType>pdbonly</DebugType>
4443
<Optimize>true</Optimize>
4544
<OutputPath>..\bin\Release\</OutputPath>
4645
<DefineConstants>TRACE</DefineConstants>
4746
<ErrorReport>prompt</ErrorReport>
4847
<WarningLevel>4</WarningLevel>
49-
<Prefer32bit>false</Prefer32bit>
5048
</PropertyGroup>
5149
<PropertyGroup>
5250
<ApplicationIcon>Assets\icon.ico</ApplicationIcon>

spv3/loader/src/Install.cs

+113-115
Original file line numberDiff line numberDiff line change
@@ -121,120 +121,7 @@ public string Target
121121
if (value == _target) return;
122122
_target = value;
123123
OnPropertyChanged();
124-
125-
/**
126-
* Check validity of the specified target value.
127-
*/
128-
if (string.IsNullOrEmpty(Target) || !Directory.Exists(Target))
129-
{
130-
Status = "Enter a valid path.";
131-
CanInstall = false;
132-
return;
133-
}
134-
135-
if (Target.Contains(GetFolderPath(ProgramFiles))
136-
|| !string.IsNullOrEmpty(GetFolderPath(ProgramFilesX86)) && Target.Contains(GetFolderPath(ProgramFilesX86)) )
137-
{
138-
Status = "The game does not function correctly when install to Program Files. Please choose a difference location.";
139-
CanInstall = false;
140-
return;
141-
}
142-
143-
144-
try
145-
{
146-
var exists = Directory.Exists(Target);
147-
var path = Target;
148-
var rootExists = Directory.Exists(Path.GetPathRoot(Target));
149-
150-
if (!exists && !rootExists)
151-
{
152-
throw new DirectoryNotFoundException(Target);
153-
}
154-
if (!exists && rootExists)
155-
{
156-
while (!Directory.Exists(path))
157-
{
158-
path = Directory.GetParent(path).Name;
159-
if (path == "Debug") return;
160-
}
161-
}
162-
163-
// if Target and Root exist...
164-
_target = Path.GetFullPath(_target);
165-
value = Path.GetFullPath(value);
166-
var test = Path.Combine(path, "io.bin");
167-
WriteAllBytes(test, new byte[8]);
168-
Delete(test);
169-
170-
Status = "Waiting for user to install SPV3.";
171-
CanInstall = true;
172-
}
173-
catch (Exception e)
174-
{
175-
var msg = "Installation not possible at selected path: " + Target + "\n Error: " + e.ToString() + "\n";
176-
var log = (HXE.File)Paths.Exception;
177-
log.AppendAllText(msg);
178-
Status = msg;
179-
CanInstall = false;
180-
return;
181-
}
182-
183-
/**
184-
* Check available disk space. This will NOT work on UNC paths!
185-
*/
186-
try
187-
{
188-
189-
/** First, check the C:\ drive to ensure there's enough free space
190-
* for temporary extraction to %temp% */
191-
if (Directory.Exists(@"C:\"))
192-
{
193-
var systemDrive = new DriveInfo(@"C:\");
194-
if (systemDrive.TotalFreeSpace < 10737418240)
195-
{
196-
Status = @"Not enough disk space (10GB required) on the C:\ drive. " +
197-
"Clear junk files using Disk Cleanup or allocate more space to the volume";
198-
CanInstall = false;
199-
return;
200-
}
201-
}
202-
203-
/**
204-
* Check if the target drive has at least 16GB of free space
205-
*/
206-
var targetDrive = new DriveInfo(Path.GetPathRoot(Target));
207-
208-
if (targetDrive.IsReady && targetDrive.TotalFreeSpace > 17179869184)
209-
{
210-
CanInstall = true;
211-
}
212-
else
213-
{
214-
Status = "Not enough disk space (16GB required) at selected path: " + Target;
215-
CanInstall = false;
216-
return;
217-
}
218-
}
219-
catch (Exception e)
220-
{
221-
var msg = "Failed to get drive space.\n Error: " + e.ToString() + "\n";
222-
var log = (HXE.File)Paths.Exception;
223-
log.AppendAllText(msg);
224-
Status = msg;
225-
CanInstall = false;
226-
}
227-
228-
/**
229-
* Prohibit installations to known problematic folders.
230-
*/
231-
if (Exists(Path.Combine(Target, HXE.Paths.HCE.Executable))
232-
|| Exists(Path.Combine(Target, HXE.Paths.Executable))
233-
|| Exists(Path.Combine(Target, Paths.Executable)))
234-
{
235-
Status = "Selected folder contains existing HCE or SPV3 data. Please choose a different location.";
236-
CanInstall = false;
237-
}
124+
ValidateTarget(value);
238125
}
239126
}
240127

@@ -278,10 +165,11 @@ public void Initialise()
278165
Main = Visible;
279166
Activation = Collapsed;
280167

168+
ValidateTarget(Target);
169+
281170
/**
282171
* Determine if the current environment fulfills the installation requirements.
283172
*/
284-
285173
if (Registry.GameExists("Custom")
286174
|| Registry.GameExists("Retail")
287175
|| ( Kernel.hxe.Tweaks.Patches & Patcher.EXEP.DISABLE_DRM_AND_KEY_CHECKS) == 1)
@@ -455,6 +343,116 @@ public void CheckSteamPath(string exe)
455343
Update_SteamStatus();
456344
}
457345

346+
public void ValidateTarget(string path)
347+
{
348+
/**
349+
* Check validity of the specified target value.
350+
*/
351+
if (string.IsNullOrEmpty(path)
352+
|| !Directory.Exists(Path.GetPathRoot(path)))
353+
{
354+
Status = "Enter a valid path.";
355+
CanInstall = false;
356+
return;
357+
}
358+
359+
/**
360+
* Check if path contains Program Files or Program Files (x86)
361+
*/
362+
if (path.Contains(GetFolderPath(ProgramFiles))
363+
|| !string.IsNullOrEmpty(GetFolderPath(ProgramFilesX86))
364+
&& path.Contains(GetFolderPath(ProgramFilesX86)))
365+
{
366+
Status = "The game does not function correctly when install to Program Files. Please choose a difference location.";
367+
CanInstall = false;
368+
return;
369+
}
370+
371+
try
372+
{
373+
var exists = Directory.Exists(path);
374+
var root = Path.GetPathRoot(path);
375+
var rootExists = Directory.Exists(root);
376+
377+
if (!exists && rootExists)
378+
{
379+
while (!Directory.Exists(path))
380+
{
381+
path = Directory.GetParent(path).FullName;
382+
if (path == CurrentDirectory)
383+
{
384+
Status = "Enter a valid path.";
385+
CanInstall = false;
386+
return;
387+
}
388+
}
389+
}
390+
391+
// if Target and Root exist...
392+
path = Path.GetFullPath(path);
393+
var test = Path.Combine(path, "io.bin");
394+
WriteAllBytes(test, new byte[8]);
395+
Delete(test);
396+
397+
Status = "Waiting for user to install SPV3.";
398+
CanInstall = true;
399+
}
400+
catch (Exception e)
401+
{
402+
var msg = "Installation not possible at selected path: " + path + "\n Error: " + e.ToString() + "\n";
403+
var log = (HXE.File) Paths.Exception;
404+
log.AppendAllText(msg);
405+
Status = msg;
406+
CanInstall = false;
407+
return;
408+
}
409+
410+
/**
411+
* Check available disk space. This will NOT work on UNC paths!
412+
*/
413+
try
414+
{
415+
/** First, check the user's temp folder's drive to ensure there's enough free space
416+
* for temporary extraction to %temp%
417+
*/
418+
{
419+
var tmpath = Path.GetPathRoot(Path.GetTempPath());
420+
var systemDrive = new DriveInfo(tmpath);
421+
if (systemDrive.TotalFreeSpace < 11811160064)
422+
{
423+
Status = $"Not enough disk space (11GB required) on the {tmpath} drive. " +
424+
"Clear junk files using Disk Cleanup or allocate more space to the volume";
425+
CanInstall = false;
426+
return;
427+
}
428+
}
429+
430+
/**
431+
* Check if the target drive has at least 16GB of free space
432+
*/
433+
var targetDrive = new DriveInfo(Path.GetPathRoot(path));
434+
435+
if (targetDrive.IsReady && targetDrive.TotalFreeSpace > 17179869184)
436+
{
437+
CanInstall = true;
438+
}
439+
else
440+
{
441+
Status = "Not enough disk space (16GB required) at selected path: " + path;
442+
CanInstall = false;
443+
return;
444+
}
445+
}
446+
catch (Exception e)
447+
{
448+
var msg = "Failed to get drive space.\n Error: " + e.ToString() + "\n";
449+
var log = (HXE.File)Paths.Exception;
450+
log.AppendAllText(msg);
451+
Status = msg;
452+
CanInstall = false;
453+
}
454+
}
455+
458456
public void ViewActivation() // Debug widget
459457
{
460458
Main = Collapsed;

spv3/loader/src/SPV3.csproj

+2-4
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,23 @@
3333
<BootstrapperEnabled>true</BootstrapperEnabled>
3434
</PropertyGroup>
3535
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
36-
<PlatformTarget>x64</PlatformTarget>
36+
<PlatformTarget>AnyCPU</PlatformTarget>
3737
<DebugSymbols>true</DebugSymbols>
3838
<DebugType>full</DebugType>
3939
<Optimize>false</Optimize>
4040
<OutputPath>..\bin\Debug\</OutputPath>
4141
<DefineConstants>DEBUG;TRACE</DefineConstants>
4242
<ErrorReport>prompt</ErrorReport>
4343
<WarningLevel>4</WarningLevel>
44-
<Prefer32bit>false</Prefer32bit>
4544
</PropertyGroup>
4645
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
47-
<PlatformTarget>x64</PlatformTarget>
46+
<PlatformTarget>AnyCPU</PlatformTarget>
4847
<DebugType>pdbonly</DebugType>
4948
<Optimize>true</Optimize>
5049
<OutputPath>..\bin\Release\</OutputPath>
5150
<DefineConstants>TRACE</DefineConstants>
5251
<ErrorReport>prompt</ErrorReport>
5352
<WarningLevel>4</WarningLevel>
54-
<Prefer32bit>false</Prefer32bit>
5553
</PropertyGroup>
5654
<PropertyGroup>
5755
<ApplicationIcon>Assets\icon.ico</ApplicationIcon>

0 commit comments

Comments
 (0)