Use detected Steam locations, update launch options
This commit is contained in:
parent
5aa0f788c3
commit
b2d9b1073f
4 changed files with 102 additions and 51 deletions
|
@ -26,6 +26,7 @@ namespace GCMM
|
||||||
private readonly ModInfo gcipa = new ModInfo { Author = "modtainers", Name = "GCIPA" };
|
private readonly ModInfo gcipa = new ModInfo { Author = "modtainers", Name = "GCIPA" };
|
||||||
private readonly ModInfo gcmm = new ModInfo { Author = "NorbiPeti", Name = "GCMM" };
|
private readonly ModInfo gcmm = new ModInfo { Author = "NorbiPeti", Name = "GCMM" };
|
||||||
private DateTime lastGameUpdateTime;
|
private DateTime lastGameUpdateTime;
|
||||||
|
private string steamPath;
|
||||||
private const string defaultInfo = @"
|
private const string defaultInfo = @"
|
||||||
Gamecraft Mod Manager
|
Gamecraft Mod Manager
|
||||||
|
|
||||||
|
@ -64,7 +65,27 @@ You may also want to verify the game's files by right clicking the game in Steam
|
||||||
mods.Clear(); //This method may get called twice when ran from the command line
|
mods.Clear(); //This method may get called twice when ran from the command line
|
||||||
UpdateButton(installbtn, false);
|
UpdateButton(installbtn, false);
|
||||||
modinfobox.Text = defaultInfo;
|
modinfobox.Text = defaultInfo;
|
||||||
GetSteamLocationAndUser(); //TODO: If user is null then start Steam
|
var (steamPath, user) = GetSteamLocationAndUser(); //TODO: If user is 0 then start Steam
|
||||||
|
if (steamPath != null)
|
||||||
|
this.steamPath = steamPath;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Steam not found! If you have Steam installed, please report this to ExMods.\n\nThe Steam install is checked to autodetect where the game is installed and to optionally configure auto-patching.", "Steam not found");
|
||||||
|
status.Text = "Status: Steam not found";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (Settings.Default.SteamUserID == 0 && Settings.Default.AutoLaunch)
|
||||||
|
{
|
||||||
|
if (MessageBox.Show("Do you want GCMM to change the game's launch settings so it can ensure the game is patched?\n\n" +
|
||||||
|
"If you say yes, GCMM will do a quick check before the game is launched and patches if necessary. " +
|
||||||
|
"This way you (hopefully) won't see crashes after a Gamecraft update.\n\n" +
|
||||||
|
"Note that this also means that if you (re)move GCMM without disabling this in the settings then you won't be able to launch Gamecraft.",
|
||||||
|
"GCMM auto-patching", MessageBoxButtons.YesNo) == DialogResult.Yes)
|
||||||
|
DetectConfigLocationAndAutoStart(steamPath, ref user);
|
||||||
|
else
|
||||||
|
Settings.Default.AutoLaunch = false;
|
||||||
|
Settings.Default.Save();
|
||||||
|
}
|
||||||
if (string.IsNullOrWhiteSpace(Settings.Default.GamePath) || GetExe() == null)
|
if (string.IsNullOrWhiteSpace(Settings.Default.GamePath) || GetExe() == null)
|
||||||
{
|
{
|
||||||
Settings.Default.GamePath = GetGameFolder();
|
Settings.Default.GamePath = GetGameFolder();
|
||||||
|
@ -82,34 +103,6 @@ You may also want to verify the game's files by right clicking the game in Steam
|
||||||
DeleteEmptyPluginsDir(out bool pexists, out bool dexists);
|
DeleteEmptyPluginsDir(out bool pexists, out bool dexists);
|
||||||
if (!pexists && dexists)
|
if (!pexists && dexists)
|
||||||
unpatched.Checked = true; //It will call the event but that won't do anything
|
unpatched.Checked = true; //It will call the event but that won't do anything
|
||||||
if(Settings.Default.AutoLaunch && string.IsNullOrWhiteSpace(Settings.Default.SteamConfigFileForAutoLaunch))
|
|
||||||
{
|
|
||||||
string path = @"C:\Program Files (x86)\Steam\userdata";
|
|
||||||
if(MessageBox.Show("Do you want GCMM to change the game's launch settings so it can ensure the game is patched?\n\n" +
|
|
||||||
"If you say yes, GCMM will do a quick check before the game is launched and updates if necessary. " +
|
|
||||||
"This way you (hopefully) won't see crashes after a Gamecraft update.\n\n" +
|
|
||||||
"Note that this also means that if you (re)move GCMM without disabling this then you won't be able to launch Gamecraft.",
|
|
||||||
"GCMM auto-patching", MessageBoxButtons.YesNo)==DialogResult.Yes)
|
|
||||||
{
|
|
||||||
var dirs = Directory.GetDirectories(path);
|
|
||||||
var goodPaths = (from dir in dirs
|
|
||||||
where File.Exists(dir + @"\config\localconfig.vdf")
|
|
||||||
select dir + @"\config\localconfig.vdf").ToArray();
|
|
||||||
if (goodPaths.Length != 1)
|
|
||||||
path = SelectSteamConfigFile();
|
|
||||||
else
|
|
||||||
path = goodPaths[0];
|
|
||||||
//if (path is not null)
|
|
||||||
if (path != null)
|
|
||||||
{
|
|
||||||
Settings.Default.SteamConfigFileForAutoLaunch = path;
|
|
||||||
UpdateSteamConfigToAutoStart(true);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
Settings.Default.AutoLaunch = false;
|
|
||||||
Settings.Default.Save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await RefreshEverything();
|
await RefreshEverything();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ namespace GCMM
|
||||||
{ //TODO
|
{ //TODO
|
||||||
string libs;
|
string libs;
|
||||||
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
|
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
|
||||||
libs = Settings.Default.SteamConfigFileForAutoLaunch + @"\steamapps\libraryfolders.vdf"; //TODO: Not the Steam folder anymore!
|
libs = Settings.Default.SteamUserID + @"\steamapps\libraryfolders.vdf"; //TODO: Not the Steam folder anymore!
|
||||||
else
|
else
|
||||||
return null;
|
return null;
|
||||||
foreach (var line in File.ReadAllLines(libs).Concat(new[] {@"C:\Program Files (x86)\Steam\"}))
|
foreach (var line in File.ReadAllLines(libs).Concat(new[] {@"C:\Program Files (x86)\Steam\"}))
|
||||||
|
@ -68,23 +68,48 @@ namespace GCMM
|
||||||
return Directory.GetParent(ofd.FileName).FullName;
|
return Directory.GetParent(ofd.FileName).FullName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string SelectSteamConfigFile()
|
public (string, int) AskForSteamLogin()
|
||||||
{
|
{
|
||||||
MessageBox.Show("Please select your Steam config location in the next dialog. It's at Steam\\userdata\\<YourID>\\config\\localconfig.vdf");
|
while (MessageBox.Show("Couid not find your Steam configuration to set launch options.\n\n" +
|
||||||
var ofd = new OpenFileDialog();
|
"Please make sure you are logged into Steam and click Retry or click Cancel to skip setting this up.",
|
||||||
ofd.Filter = "Steam config|localconfig.vdf";
|
"Steam config not found", MessageBoxButtons.RetryCancel) != DialogResult.Cancel)
|
||||||
ofd.Title = "Steam config location (Steam\\userdata\\<YourID>\\config\\localconfig.vdf)";
|
{
|
||||||
ofd.InitialDirectory = @"C:\Program Files (x86)\Steam\\userdata\"; //TODO
|
var ret = GetSteamLocationAndUser();
|
||||||
ofd.CheckFileExists = true;
|
if (ret != (null, 0))
|
||||||
ofd.ShowDialog();
|
return ret;
|
||||||
if (string.IsNullOrWhiteSpace(ofd.FileName))
|
}
|
||||||
return null;
|
return (null, 0);
|
||||||
return ofd.FileName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateSteamConfigToAutoStart(bool autoLaunch)
|
private bool UpdateOrGetSteamConfigToAutoStart(bool? autoLaunch)
|
||||||
{
|
{
|
||||||
//TODO
|
var regex = new Regex(@"(\t{6}""LaunchOptions""\t+"")(.*)("")");
|
||||||
|
string path = steamPath + @"\userdata\" + Settings.Default.SteamUserID + @"\config\localconfig.vdf";
|
||||||
|
var lines = File.ReadAllLines(path);
|
||||||
|
bool shouldMatch = false;
|
||||||
|
bool ret = false;
|
||||||
|
for (int i = 0; i < lines.Length; i++)
|
||||||
|
{
|
||||||
|
if (lines[i] == "\t\t\t\t\t\"1078000\"")
|
||||||
|
shouldMatch = true; //Found the game
|
||||||
|
else if(shouldMatch)
|
||||||
|
{
|
||||||
|
var match = regex.Match(lines[i]);
|
||||||
|
if (!match.Success)
|
||||||
|
continue;
|
||||||
|
if (autoLaunch.HasValue)
|
||||||
|
{
|
||||||
|
if (autoLaunch.Value)
|
||||||
|
lines[i] = match.Groups[1].Value + Application.ExecutablePath + " -start %command%" + match.Groups[3].Value;
|
||||||
|
else
|
||||||
|
lines[i] = match.Groups[1].Value + match.Groups[2].Value;
|
||||||
|
File.WriteAllLines(path, lines);
|
||||||
|
}
|
||||||
|
ret = match.Groups[2].Value.Contains("GCMM.exe");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
private (string, int) GetSteamLocationAndUser()
|
private (string, int) GetSteamLocationAndUser()
|
||||||
|
@ -92,11 +117,44 @@ namespace GCMM
|
||||||
if (Environment.OSVersion.Platform != PlatformID.Win32NT) return (null, 0);
|
if (Environment.OSVersion.Platform != PlatformID.Win32NT) return (null, 0);
|
||||||
using (var key = Registry.CurrentUser.OpenSubKey(@"Software\Valve\Steam\ActiveProcess"))
|
using (var key = Registry.CurrentUser.OpenSubKey(@"Software\Valve\Steam\ActiveProcess"))
|
||||||
{
|
{
|
||||||
string path = Directory.GetParent((string)key.GetValue("SteamClientDll")).FullName;
|
string path = (string)key?.GetValue("SteamClientDll");
|
||||||
return (path, (int)key.GetValue("ActiveUser"));
|
path = path != null ? Directory.GetParent(path).FullName : null;
|
||||||
|
return (path, (int)(key.GetValue("ActiveUser") ?? 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void DetectConfigLocationAndAutoStart(string steamPath, ref int user)
|
||||||
|
{
|
||||||
|
string path = steamPath + @"\userdata";
|
||||||
|
if (user == 0)
|
||||||
|
{
|
||||||
|
var dirs = Directory.GetDirectories(path);
|
||||||
|
var goodPaths = (from dir in dirs
|
||||||
|
where File.Exists(dir + @"\config\localconfig.vdf")
|
||||||
|
select dir).ToArray();
|
||||||
|
if (goodPaths.Length != 1)
|
||||||
|
{
|
||||||
|
(_, user) = AskForSteamLogin();
|
||||||
|
path += user;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
path = goodPaths[0];
|
||||||
|
user = int.Parse(Path.GetFileName(path));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
path += user;
|
||||||
|
path += @"\config\localconfig.vdf";
|
||||||
|
if (path != null && user != 0 && File.Exists(path))
|
||||||
|
{
|
||||||
|
Settings.Default.SteamUserID = user;
|
||||||
|
UpdateOrGetSteamConfigToAutoStart(true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Settings.Default.AutoLaunch = false;
|
||||||
|
}
|
||||||
|
|
||||||
private void CheckStartGame(object sender, EventArgs e)
|
private void CheckStartGame(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Action act = () =>
|
Action act = () =>
|
||||||
|
|
8
GCMM/Properties/Settings.Designer.cs
generated
8
GCMM/Properties/Settings.Designer.cs
generated
|
@ -73,13 +73,13 @@ namespace GCMM.Properties {
|
||||||
|
|
||||||
[global::System.Configuration.UserScopedSettingAttribute()]
|
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||||
[global::System.Configuration.DefaultSettingValueAttribute("")]
|
[global::System.Configuration.DefaultSettingValueAttribute("0")]
|
||||||
public string SteamConfigFileForAutoLaunch {
|
public int SteamUserID {
|
||||||
get {
|
get {
|
||||||
return ((string)(this["SteamConfigFileForAutoLaunch"]));
|
return ((int)(this["SteamUserID"]));
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
this["SteamConfigFileForAutoLaunch"] = value;
|
this["SteamUserID"] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,8 +14,8 @@
|
||||||
<Setting Name="NeedsUpdate" Type="System.Boolean" Scope="User">
|
<Setting Name="NeedsUpdate" Type="System.Boolean" Scope="User">
|
||||||
<Value Profile="(Default)">True</Value>
|
<Value Profile="(Default)">True</Value>
|
||||||
</Setting>
|
</Setting>
|
||||||
<Setting Name="SteamConfigFileForAutoLaunch" Type="System.String" Scope="User">
|
<Setting Name="SteamUserID" Type="System.Int32" Scope="User">
|
||||||
<Value Profile="(Default)" />
|
<Value Profile="(Default)">0</Value>
|
||||||
</Setting>
|
</Setting>
|
||||||
<Setting Name="AutoLaunch" Type="System.Boolean" Scope="User">
|
<Setting Name="AutoLaunch" Type="System.Boolean" Scope="User">
|
||||||
<Value Profile="(Default)">True</Value>
|
<Value Profile="(Default)">True</Value>
|
||||||
|
|
Loading…
Reference in a new issue