Ask to change Steam config & file selecting

This commit is contained in:
Norbi Peti 2021-01-20 02:21:22 +01:00
parent ac6d07df59
commit 3520015649
5 changed files with 84 additions and 14 deletions

View file

@ -81,6 +81,34 @@ 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();
} }

View file

@ -143,25 +143,16 @@ namespace GCMM
}; };
process.OutputDataReceived += onoutput; process.OutputDataReceived += onoutput;
process.ErrorDataReceived += onoutput; process.ErrorDataReceived += onoutput;
process.Exited += command != null ? (EventHandler) ((sender, e) => StartGameUsingCommand(command)) : CheckStartGame; //target-typed conditional expression - C# 9.0 process.Exited += CheckStartGame; //target-typed conditional expression - C# 9.0
} }
break; break;
case GameState.Patched: case GameState.Patched:
if (command != null) CheckStartGame(command, null); //Command may be null but that's okay
StartGameUsingCommand(command);
else
CheckStartGame(null, null);
break; break;
} }
return retOpenedWindowShouldStay; return retOpenedWindowShouldStay;
} }
private void StartGameUsingCommand(string command)
{
Process.Start(command);
EndWork(false);
}
public enum GameState public enum GameState
{ {
NotFound, NotFound,

View file

@ -35,7 +35,7 @@ namespace GCMM
{ //TODO { //TODO
string libs; string libs;
if (Environment.OSVersion.Platform == PlatformID.Win32NT) if (Environment.OSVersion.Platform == PlatformID.Win32NT)
libs = @"C:\Program Files (x86)\Steam\steamapps\libraryfolders.vdf"; libs = Settings.Default.SteamConfigFileForAutoLaunch + @"\steamapps\libraryfolders.vdf";
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\"}))
@ -67,6 +67,25 @@ namespace GCMM
return Directory.GetParent(ofd.FileName).FullName; return Directory.GetParent(ofd.FileName).FullName;
} }
public string SelectSteamConfigFile()
{
MessageBox.Show("Please select your Steam config location in the next dialog. It's at Steam\\userdata\\<YourID>\\config\\localconfig.vdf");
var ofd = new OpenFileDialog();
ofd.Filter = "Steam config|localconfig.vdf";
ofd.Title = "Steam config location (Steam\\userdata\\<YourID>\\config\\localconfig.vdf)";
ofd.InitialDirectory = @"C:\Program Files (x86)\Steam\\userdata\"; //TODO
ofd.CheckFileExists = true;
ofd.ShowDialog();
if (string.IsNullOrWhiteSpace(ofd.FileName))
return null;
return ofd.FileName;
}
private void UpdateSteamConfigToAutoStart(bool autoLaunch)
{
}
private void CheckStartGame(object sender, EventArgs e) private void CheckStartGame(object sender, EventArgs e)
{ {
Action act = () => Action act = () =>
@ -77,7 +96,9 @@ namespace GCMM
return; return;
} }
if (CheckIfPatched() == GameState.Patched || unpatched.Checked) if (CheckIfPatched() == GameState.Patched || unpatched.Checked)
if (Environment.OSVersion.Platform == PlatformID.Win32NT) if (sender is string command)
Process.Start(command);
else if (Environment.OSVersion.Platform == PlatformID.Win32NT)
Process.Start("steam://run/1078000/"); Process.Start("steam://run/1078000/");
else else
Process.Start("xdg-open", "steam://run/1078000/"); Process.Start("xdg-open", "steam://run/1078000/");

View file

@ -12,7 +12,7 @@ namespace GCMM.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.5.0.0")] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.8.1.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
@ -70,5 +70,29 @@ namespace GCMM.Properties {
this["NeedsUpdate"] = value; this["NeedsUpdate"] = value;
} }
} }
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string SteamConfigFileForAutoLaunch {
get {
return ((string)(this["SteamConfigFileForAutoLaunch"]));
}
set {
this["SteamConfigFileForAutoLaunch"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("True")]
public bool AutoLaunch {
get {
return ((bool)(this["AutoLaunch"]));
}
set {
this["AutoLaunch"] = value;
}
}
} }
} }

View file

@ -14,5 +14,11 @@
<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">
<Value Profile="(Default)" />
</Setting>
<Setting Name="AutoLaunch" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
</Settings> </Settings>
</SettingsFile> </SettingsFile>