mirror of
https://mirror.ghproxy.com/https://github.com/dexyfex/CodeWalker
synced 2024-11-26 08:52:52 +08:00
Changed to more reusable methods
This commit is contained in:
parent
644733a8d0
commit
07a724ee0f
@ -54,8 +54,8 @@ namespace CodeWalker
|
|||||||
string folder = CurrentGTAFolder;
|
string folder = CurrentGTAFolder;
|
||||||
SelectFolderForm f = new SelectFolderForm();
|
SelectFolderForm f = new SelectFolderForm();
|
||||||
|
|
||||||
string autoFolder = AutoDetectFolder();
|
string autoFolder = AutoDetectFolder(out string source);
|
||||||
if (autoFolder != null)
|
if (autoFolder != null && MessageBox.Show($"Auto-detected game folder \"{autoFolder}\" from {source}.\n\nContinue with auto-detected folder?", "Auto-detected game folder", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
|
||||||
{
|
{
|
||||||
f.SelectedFolder = autoFolder;
|
f.SelectedFolder = autoFolder;
|
||||||
}
|
}
|
||||||
@ -103,11 +103,14 @@ namespace CodeWalker
|
|||||||
|
|
||||||
public static string GetCurrentGTAFolderWithTrailingSlash() =>CurrentGTAFolder.EndsWith(@"\") ? CurrentGTAFolder : CurrentGTAFolder + @"\";
|
public static string GetCurrentGTAFolderWithTrailingSlash() =>CurrentGTAFolder.EndsWith(@"\") ? CurrentGTAFolder : CurrentGTAFolder + @"\";
|
||||||
|
|
||||||
public static bool AutoDetectFolder(out string steamPath, out string retailPath, out string oivPath)
|
public static bool AutoDetectFolder(out Dictionary<string, string> matches)
|
||||||
{
|
{
|
||||||
retailPath = null;
|
matches = new Dictionary<string, string>();
|
||||||
steamPath = null;
|
|
||||||
oivPath = null;
|
if(ValidateGTAFolder(CurrentGTAFolder))
|
||||||
|
{
|
||||||
|
matches.Add("Current CodeWalker Folder", CurrentGTAFolder);
|
||||||
|
}
|
||||||
|
|
||||||
RegistryKey baseKey32 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
|
RegistryKey baseKey32 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
|
||||||
string steamPathValue = baseKey32.OpenSubKey(@"Software\Rockstar Games\GTAV")?.GetValue("InstallFolderSteam") as string;
|
string steamPathValue = baseKey32.OpenSubKey(@"Software\Rockstar Games\GTAV")?.GetValue("InstallFolderSteam") as string;
|
||||||
@ -121,40 +124,36 @@ namespace CodeWalker
|
|||||||
|
|
||||||
if(ValidateGTAFolder(steamPathValue))
|
if(ValidateGTAFolder(steamPathValue))
|
||||||
{
|
{
|
||||||
steamPath = steamPathValue;
|
matches.Add("Steam", steamPathValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ValidateGTAFolder(retailPathValue))
|
if(ValidateGTAFolder(retailPathValue))
|
||||||
{
|
{
|
||||||
retailPath = retailPathValue;
|
matches.Add("Retail", retailPathValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ValidateGTAFolder(oivPathValue))
|
if(ValidateGTAFolder(oivPathValue))
|
||||||
{
|
{
|
||||||
oivPath = oivPathValue;
|
matches.Add("OpenIV", oivPathValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
return steamPath != null || retailPath != null || oivPath != null;
|
return matches.Count > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string AutoDetectFolder()
|
public static string AutoDetectFolder(out string source)
|
||||||
{
|
{
|
||||||
if(AutoDetectFolder(out string steam, out string retail, out string oiv))
|
source = null;
|
||||||
|
|
||||||
|
if(AutoDetectFolder(out Dictionary<string, string> matches))
|
||||||
{
|
{
|
||||||
if(oiv != null)
|
var match = matches.First();
|
||||||
{
|
source = match.Key;
|
||||||
return oiv;
|
return match.Value;
|
||||||
}
|
|
||||||
if(steam != null)
|
|
||||||
{
|
|
||||||
return steam;
|
|
||||||
} else if(retail != null)
|
|
||||||
{
|
|
||||||
return retail;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string AutoDetectFolder() => AutoDetectFolder(out string _);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user