Fixes, Patch & Play, automatically install API

This commit is contained in:
Norbi Peti 2020-07-18 22:25:52 +02:00
parent b4d64c50d0
commit 9e088c02f0
5 changed files with 29 additions and 6 deletions

View file

@ -76,6 +76,7 @@ If you encounter an issue while the game is patched, report it to us. If you thi
private async void playbtn_Click(object sender, EventArgs e) private async void playbtn_Click(object sender, EventArgs e)
{ {
if (playbtn.ForeColor == Color.Green) return; //Disabled if (playbtn.ForeColor == Color.Green) return; //Disabled
await UpdateAPI();
await PatchStartGame(); //It will call EndWork(); await PatchStartGame(); //It will call EndWork();
} }
@ -108,15 +109,15 @@ If you encounter an issue while the game is patched, report it to us. If you thi
var mod = mods[item.Name]; var mod = mods[item.Name];
if (modlist.SelectedItems.Count == 1) if (modlist.SelectedItems.Count == 1)
{ {
bool up = mod.Version != null && mod.Version < mod.LatestVersion; bool up = mod.Updatable;
modinfobox.Text = ((up ? "New version available! " + mod.UpdateDetails + "\n\n" modinfobox.Text = ((up ? "New version available! " + mod.UpdateDetails + "\n\n"
: "") + mod.Description).Replace("\n", Environment.NewLine); : "") + mod.Description).Replace("\n", Environment.NewLine);
if(up) if(up)
{ {
modinfobox.Select(0, "New version available!".Length); modinfobox.Select(0, "New version available!".Length);
//modinfobox.SelectionColor = Color.Aqua; modinfobox.SelectionColor = Color.Aqua;
//modinfobox.DeselectAll(); modinfobox.DeselectAll();
//modinfobox.SelectionColor = modinfobox.ForeColor; modinfobox.SelectionColor = modinfobox.ForeColor;
} }
} }
else else

View file

@ -21,6 +21,8 @@ namespace GCMM
MessageBox.Show("Gamecraft not found. Set the correct path in Settings."); MessageBox.Show("Gamecraft not found. Set the correct path in Settings.");
return; return;
} }
if (mod.Name != "GamecraftModdingAPI")
await UpdateAPI();
var tmp = Directory.CreateDirectory("temp"); var tmp = Directory.CreateDirectory("temp");
var plugins = Directory.CreateDirectory(GamePath(@"\Plugins")); var plugins = Directory.CreateDirectory(GamePath(@"\Plugins"));
string tmppath = tmp.FullName + Path.DirectorySeparatorChar + mod.Name; string tmppath = tmp.FullName + Path.DirectorySeparatorChar + mod.Name;
@ -135,5 +137,16 @@ namespace GCMM
mod.Version = null; //Not installed mod.Version = null; //Not installed
AddUpdateModInList(mod); //Update list AddUpdateModInList(mod); //Update list
} }
public async Task UpdateAPI()
{
var gcmapi = mods["GamecraftModdingAPI"];
if (!gcmapi.Installed || gcmapi.Updatable)
{
if (MessageBox.Show($"GamecraftModdingAPI will be {(gcmapi.Installed ? "updated" : "installed")} as most mods need it to work. You can uninstall it if you're sure you don't need it.", "API needed", MessageBoxButtons.OKCancel)
== DialogResult.OK)
await InstallMod(gcmapi);
}
}
} }
} }

View file

@ -17,32 +17,39 @@ namespace GCMM
{ {
public bool? CheckIfPatched() public bool? CheckIfPatched()
{ {
string pnp = unpatched.Checked ? "Play" : "Patch && Play";
if (!File.Exists(GamePath(@"\IPA.exe"))) if (!File.Exists(GamePath(@"\IPA.exe")))
{ {
status.Text = "Status: Patcher missing\nClicking Play will install it"; status.Text = "Status: Patcher missing\nClicking Play will install it";
playbtn.Text = pnp;
return null; return null;
} }
string nopatch = "Status: Unpatched" + (unpatched.Checked ? "" : "\nClicking Play patches it"); string nopatch = "Status: Unpatched" + (unpatched.Checked ? "" : "\nClicking Play patches it");
string backups = GamePath(@"\IPA\Backups\Gamecraft"); string gc = GetExe().Replace(".exe", "");
string backups = GamePath(@"\IPA\Backups\" + gc);
if (!Directory.Exists(backups)) if (!Directory.Exists(backups))
{ {
status.Text = nopatch; status.Text = nopatch;
playbtn.Text = pnp;
return false; return false;
} }
string backup = Directory.EnumerateDirectories(backups).OrderByDescending(s => s).FirstOrDefault(); string backup = Directory.EnumerateDirectories(backups).OrderByDescending(s => s).FirstOrDefault();
if (backup == null) if (backup == null)
{ {
status.Text = nopatch; status.Text = nopatch;
playbtn.Text = pnp;
return false; return false;
} }
if (File.GetLastWriteTime(GamePath(@"\Gamecraft_Data\Managed\Assembly-CSharp.dll")) if (File.GetLastWriteTime(GamePath($@"\{gc}_Data\Managed\Assembly-CSharp.dll"))
> //If the file was updated at least 2 minutes after patching > //If the file was updated at least 2 minutes after patching
Directory.GetLastWriteTime(backup).AddMinutes(2)) Directory.GetLastWriteTime(backup).AddMinutes(2))
{ {
status.Text = nopatch; status.Text = nopatch;
playbtn.Text = pnp;
return false; return false;
} }
status.Text = "Status: Patched" + (unpatched.Checked ? "\nClicking Play unpatches it" : ""); status.Text = "Status: Patched" + (unpatched.Checked ? "\nClicking Play unpatches it" : "");
playbtn.Text = unpatched.Checked ? "Unpatch && Play" : "Play";
return true; return true;
} }

View file

@ -27,5 +27,6 @@ namespace GCMM
public string DownloadURL { get; set; } public string DownloadURL { get; set; }
public HashSet<string> ModFiles { get; set; } public HashSet<string> ModFiles { get; set; }
public string UpdateDetails { get; set; } public string UpdateDetails { get; set; }
public bool Updatable => Version != null && LatestVersion != null && Version < LatestVersion;
} }
} }

View file

@ -7,6 +7,7 @@ A manager that handles everything needed to use mods for Gamecraft.
* Download and run GCIPA if needed * Download and run GCIPA if needed
* List, install and uninstall mods * List, install and uninstall mods
* Keep track of files added by mods and remove them when the mod is uninstalled * Keep track of files added by mods and remove them when the mod is uninstalled
* Preview support for the game and mods for it
## Mod requirements ## Mod requirements
* For a mod to be listed, it needs to have a regular release (so not a prerelease) with exactly 1 recognised attached asset. * For a mod to be listed, it needs to have a regular release (so not a prerelease) with exactly 1 recognised attached asset.