Browse Source

Ask to change Steam config & file selecting

tags/v1.4.0
NorbiPeti 3 years ago
parent
commit
3520015649
5 changed files with 84 additions and 14 deletions
  1. +28
    -0
      GCMM/MainForm.cs
  2. +2
    -11
      GCMM/MainPatcher.cs
  3. +23
    -2
      GCMM/MainUtils.cs
  4. +25
    -1
      GCMM/Properties/Settings.Designer.cs
  5. +6
    -0
      GCMM/Properties/Settings.settings

+ 28
- 0
GCMM/MainForm.cs 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);
if (!pexists && dexists)
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();
}



+ 2
- 11
GCMM/MainPatcher.cs View File

@@ -143,25 +143,16 @@ namespace GCMM
};
process.OutputDataReceived += 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;
case GameState.Patched:
if (command != null)
StartGameUsingCommand(command);
else
CheckStartGame(null, null);
CheckStartGame(command, null); //Command may be null but that's okay
break;
}
return retOpenedWindowShouldStay;
}

private void StartGameUsingCommand(string command)
{
Process.Start(command);
EndWork(false);
}

public enum GameState
{
NotFound,


+ 23
- 2
GCMM/MainUtils.cs View File

@@ -35,7 +35,7 @@ namespace GCMM
{ //TODO
string libs;
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
libs = @"C:\Program Files (x86)\Steam\steamapps\libraryfolders.vdf";
libs = Settings.Default.SteamConfigFileForAutoLaunch + @"\steamapps\libraryfolders.vdf";
else
return null;
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;
}

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)
{
Action act = () =>
@@ -77,7 +96,9 @@ namespace GCMM
return;
}
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/");
else
Process.Start("xdg-open", "steam://run/1078000/");


+ 25
- 1
GCMM/Properties/Settings.Designer.cs View File

@@ -12,7 +12,7 @@ namespace GCMM.Properties {
[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 {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
@@ -70,5 +70,29 @@ namespace GCMM.Properties {
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;
}
}
}
}

+ 6
- 0
GCMM/Properties/Settings.settings View File

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

Loading…
Cancel
Save