Add support for running from the command line
To be used from Steam
This commit is contained in:
parent
890a650093
commit
ac6d07df59
7 changed files with 88 additions and 12 deletions
1
GCMM/MainForm.Designer.cs
generated
1
GCMM/MainForm.Designer.cs
generated
|
@ -273,6 +273,7 @@
|
||||||
this.Name = "MainForm";
|
this.Name = "MainForm";
|
||||||
this.Text = "Gamecraft Mod Manager";
|
this.Text = "Gamecraft Mod Manager";
|
||||||
this.Load += new System.EventHandler(this.Form1_Load);
|
this.Load += new System.EventHandler(this.Form1_Load);
|
||||||
|
this.Shown += new System.EventHandler(this.MainForm_Shown);
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
this.PerformLayout();
|
this.PerformLayout();
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,12 @@ If you encounter an issue while any mods are installed, report it to us. If you
|
||||||
You may also want to verify the game's files by right clicking the game in Steam and choosing Properties, going to Local files and clicking Verify integrity of game files.
|
You may also want to verify the game's files by right clicking the game in Steam and choosing Properties, going to Local files and clicking Verify integrity of game files.
|
||||||
";
|
";
|
||||||
|
|
||||||
private void Form1_Load(object sender, EventArgs e)
|
private async void Form1_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
await LoadEverything();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task LoadEverything()
|
||||||
{
|
{
|
||||||
if (Settings.Default.NeedsUpdate)
|
if (Settings.Default.NeedsUpdate)
|
||||||
{
|
{
|
||||||
|
@ -56,6 +61,7 @@ You may also want to verify the game's files by right clicking the game in Steam
|
||||||
Settings.Default.Save();
|
Settings.Default.Save();
|
||||||
}
|
}
|
||||||
modlist.Items.Clear();
|
modlist.Items.Clear();
|
||||||
|
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;
|
||||||
if (string.IsNullOrWhiteSpace(Settings.Default.GamePath) || GetExe() == null)
|
if (string.IsNullOrWhiteSpace(Settings.Default.GamePath) || GetExe() == null)
|
||||||
|
@ -75,7 +81,7 @@ 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
|
||||||
refreshbtn_Click(refreshbtn, null);
|
await RefreshEverything();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void playbtn_Click(object sender, EventArgs e)
|
private async void playbtn_Click(object sender, EventArgs e)
|
||||||
|
@ -243,6 +249,11 @@ You may also want to verify the game's files by right clicking the game in Steam
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void refreshbtn_Click(object sender, EventArgs e)
|
private async void refreshbtn_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
await RefreshEverything();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task RefreshEverything()
|
||||||
{
|
{
|
||||||
CheckIfPatched(); //Set from placeholder
|
CheckIfPatched(); //Set from placeholder
|
||||||
lastGameUpdateTime = await GetLastGameUpdateTime();
|
lastGameUpdateTime = await GetLastGameUpdateTime();
|
||||||
|
@ -265,5 +276,10 @@ You may also want to verify the game's files by right clicking the game in Steam
|
||||||
else
|
else
|
||||||
Process.Start("xdg-open", "steam://validate/1078000/");
|
Process.Start("xdg-open", "steam://validate/1078000/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void MainForm_Shown(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Focus();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -190,7 +190,7 @@ namespace GCMM
|
||||||
}
|
}
|
||||||
if (mod.LatestVersion != null && mod.Version != null && mod.Version < mod.LatestVersion)
|
if (mod.LatestVersion != null && mod.Version != null && mod.Version < mod.LatestVersion)
|
||||||
item.ForeColor = Color.Blue;
|
item.ForeColor = Color.Blue;
|
||||||
else if (mod.LastUpdated < lastGameUpdateTime)
|
else if (mod.LastUpdated != default && mod.LastUpdated < lastGameUpdateTime)
|
||||||
item.ForeColor = Color.DarkOrange;
|
item.ForeColor = Color.DarkOrange;
|
||||||
else
|
else
|
||||||
item.ForeColor = modlist.ForeColor;
|
item.ForeColor = modlist.ForeColor;
|
||||||
|
|
|
@ -66,18 +66,27 @@ namespace GCMM
|
||||||
return GameState.Patched;
|
return GameState.Patched;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task PatchStartGame()
|
public async Task<bool?> PatchStartGame(string command = null)
|
||||||
{
|
{
|
||||||
if (!BeginWork()) return;
|
if (!BeginWork()) return false;
|
||||||
foreach (ListViewItem item in modlist.SelectedItems)
|
foreach (ListViewItem item in modlist.SelectedItems)
|
||||||
item.Selected = false;
|
item.Selected = false;
|
||||||
|
bool? retOpenedWindowShouldStay = null;
|
||||||
|
void EnsureShown(bool stay)
|
||||||
|
{
|
||||||
|
if (!Visible)
|
||||||
|
{
|
||||||
|
Show();
|
||||||
|
retOpenedWindowShouldStay = stay;
|
||||||
|
}
|
||||||
|
}
|
||||||
var status = CheckIfPatched();
|
var status = CheckIfPatched();
|
||||||
switch (status)
|
switch (status)
|
||||||
{
|
{
|
||||||
case GameState.NotFound:
|
case GameState.NotFound:
|
||||||
MessageBox.Show("Gamecraft not found! Set the correct path in Settings.");
|
MessageBox.Show("Gamecraft not found! Set the correct path in Settings.");
|
||||||
EndWork(false);
|
EndWork(false);
|
||||||
return;
|
return retOpenedWindowShouldStay;
|
||||||
case GameState.NoPatcher:
|
case GameState.NoPatcher:
|
||||||
case GameState.OldPatcher:
|
case GameState.OldPatcher:
|
||||||
{
|
{
|
||||||
|
@ -88,9 +97,10 @@ namespace GCMM
|
||||||
"Patcher download needed", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
|
"Patcher download needed", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
|
||||||
{
|
{
|
||||||
EndWork();
|
EndWork();
|
||||||
return;
|
return retOpenedWindowShouldStay;
|
||||||
}
|
}
|
||||||
this.status.Text = "Status: Patching...";
|
this.status.Text = "Status: Patching...";
|
||||||
|
EnsureShown(false);
|
||||||
using (WebClient client = GetClient())
|
using (WebClient client = GetClient())
|
||||||
{
|
{
|
||||||
string url = gcipa.DownloadURL;
|
string url = gcipa.DownloadURL;
|
||||||
|
@ -110,9 +120,10 @@ namespace GCMM
|
||||||
case GameState.NoPatcher: //Make sure it actually worked
|
case GameState.NoPatcher: //Make sure it actually worked
|
||||||
case GameState.OldPatcher:
|
case GameState.OldPatcher:
|
||||||
EndWork(false);
|
EndWork(false);
|
||||||
return;
|
return retOpenedWindowShouldStay;
|
||||||
case GameState.Unpatched:
|
case GameState.Unpatched:
|
||||||
{ //TODO: Wine
|
{ //TODO: Wine
|
||||||
|
EnsureShown(false);
|
||||||
var psi = new ProcessStartInfo(GamePath(@"\IPA.exe"), GetExe() + " --nowait")
|
var psi = new ProcessStartInfo(GamePath(@"\IPA.exe"), GetExe() + " --nowait")
|
||||||
{
|
{
|
||||||
UseShellExecute = false,
|
UseShellExecute = false,
|
||||||
|
@ -132,13 +143,23 @@ namespace GCMM
|
||||||
};
|
};
|
||||||
process.OutputDataReceived += onoutput;
|
process.OutputDataReceived += onoutput;
|
||||||
process.ErrorDataReceived += onoutput;
|
process.ErrorDataReceived += onoutput;
|
||||||
process.Exited += CheckStartGame;
|
process.Exited += command != null ? (EventHandler) ((sender, e) => StartGameUsingCommand(command)) : CheckStartGame; //target-typed conditional expression - C# 9.0
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case GameState.Patched:
|
case GameState.Patched:
|
||||||
|
if (command != null)
|
||||||
|
StartGameUsingCommand(command);
|
||||||
|
else
|
||||||
CheckStartGame(null, null);
|
CheckStartGame(null, null);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
return retOpenedWindowShouldStay;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void StartGameUsingCommand(string command)
|
||||||
|
{
|
||||||
|
Process.Start(command);
|
||||||
|
EndWork(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum GameState
|
public enum GameState
|
||||||
|
|
|
@ -113,6 +113,7 @@ namespace GCMM
|
||||||
UpdateButton(installbtn, false);
|
UpdateButton(installbtn, false);
|
||||||
UpdateButton(uninstallbtn, false);
|
UpdateButton(uninstallbtn, false);
|
||||||
UpdateButton(settingsbtn, false);
|
UpdateButton(settingsbtn, false);
|
||||||
|
unpatched.Enabled = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,6 +124,7 @@ namespace GCMM
|
||||||
UpdateButton(settingsbtn, true);
|
UpdateButton(settingsbtn, true);
|
||||||
if (desc)
|
if (desc)
|
||||||
modlist_SelectedIndexChanged(modlist, null);
|
modlist_SelectedIndexChanged(modlist, null);
|
||||||
|
unpatched.Enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -172,7 +174,8 @@ namespace GCMM
|
||||||
return default;
|
return default;
|
||||||
return new DateTime(1970, 1, 1).AddSeconds(long.Parse(match.Groups[1].Value));
|
return new DateTime(1970, 1, 1).AddSeconds(long.Parse(match.Groups[1].Value));
|
||||||
}*/
|
}*/
|
||||||
return new DateTime(2020, 12, 28);
|
//return new DateTime(2020, 12, 28);
|
||||||
|
return default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,12 +12,40 @@ namespace GCMM
|
||||||
/// The main entry point for the application.
|
/// The main entry point for the application.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[STAThread]
|
[STAThread]
|
||||||
static void Main()
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
//Application.SetHighDpiMode(HighDpiMode.SystemAware);
|
//Application.SetHighDpiMode(HighDpiMode.SystemAware);
|
||||||
Application.EnableVisualStyles();
|
Application.EnableVisualStyles();
|
||||||
Application.SetCompatibleTextRenderingDefault(false);
|
Application.SetCompatibleTextRenderingDefault(false);
|
||||||
|
if (args.Length > 0)
|
||||||
|
{
|
||||||
|
DealWithCommandLineAsync(args);
|
||||||
|
Application.Run();
|
||||||
|
return;
|
||||||
|
}
|
||||||
Application.Run(new MainForm());
|
Application.Run(new MainForm());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static async void DealWithCommandLineAsync(string[] args)
|
||||||
|
{
|
||||||
|
var form = new MainForm();
|
||||||
|
await form.LoadEverything();
|
||||||
|
bool? shouldStay = null;
|
||||||
|
if (args[0] == "-start" && args.Length > 1)
|
||||||
|
shouldStay = await form.PatchStartGame(args[1]);
|
||||||
|
else
|
||||||
|
MessageBox.Show("Supported options:\n-start <command> - Starts the game using the given command");
|
||||||
|
if (shouldStay.HasValue)
|
||||||
|
{
|
||||||
|
form.FormClosed += (sender, e) => Application.Exit();
|
||||||
|
if (!shouldStay.Value)
|
||||||
|
{
|
||||||
|
await Task.Delay(2000);
|
||||||
|
form.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Application.Exit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
7
GCMM/Properties/launchSettings.json
Normal file
7
GCMM/Properties/launchSettings.json
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"profiles": {
|
||||||
|
"GCMM": {
|
||||||
|
"commandName": "Project"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue