NorbiPeti
e69b357da1
Handling "install and update" button label Fixed mod updating New version detection fixed, highlighting and showing a message in the info section Showing release information for mods that have a new version available Added information about mod requirements Added a button to find the game log Added a checkbox to run the game unpatched Added information about using the program
96 lines
3.9 KiB
C#
96 lines
3.9 KiB
C#
using GCMM.Properties;
|
|
using Newtonsoft.Json.Linq;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.IO.Compression;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace GCMM
|
|
{
|
|
partial class MainForm
|
|
{
|
|
public bool? CheckIfPatched()
|
|
{
|
|
if (!File.Exists(Settings.Default.GamePath + @"\IPA.exe"))
|
|
{
|
|
status.Text = "Status: Patcher missing\nClicking Play will install it";
|
|
return null;
|
|
}
|
|
string nopatch = "Status: Unpatched" + (unpatched.Checked ? "" : "\nClicking Play patches it");
|
|
if (!Directory.Exists(Settings.Default.GamePath + @"\IPA\Backups\Gamecraft"))
|
|
{
|
|
status.Text = nopatch;
|
|
return false;
|
|
}
|
|
string backup = Directory.EnumerateDirectories(Settings.Default.GamePath + @"\IPA\Backups\Gamecraft").OrderByDescending(s => s).FirstOrDefault();
|
|
if (backup == null)
|
|
{
|
|
status.Text = nopatch;
|
|
return false;
|
|
}
|
|
if (File.GetLastWriteTime(Settings.Default.GamePath + @"\Gamecraft_Data\Managed\Assembly-CSharp.dll")
|
|
> //If the file was updated at least 2 minutes after patching
|
|
Directory.GetLastWriteTime(backup).AddMinutes(2))
|
|
{
|
|
status.Text = nopatch;
|
|
return false;
|
|
}
|
|
status.Text = "Status: Patched" + (unpatched.Checked ? "\nClicking Play unpatches it" : "");
|
|
return true;
|
|
}
|
|
|
|
public async void PatchStartGame()
|
|
{
|
|
if (!CheckIfPatched().HasValue)
|
|
{
|
|
if (MessageBox.Show("The patcher (GCIPA) is not found. It will be downloaded from https://git.exmods.org/modtainers/GCIPA/releases and ran to patch the game.", "Patcher download needed", MessageBoxButtons.OKCancel)
|
|
== DialogResult.Cancel)
|
|
return;
|
|
string releases = "/api/v1/repos/modtainers/GCIPA/releases";
|
|
string url;
|
|
this.status.Text = "Status: Patching...";
|
|
using (WebClient client = GetClient())
|
|
{
|
|
url = JArray.Parse(await client.DownloadStringTaskAsync(releases)).First["assets"].First["browser_download_url"].ToString();
|
|
await client.DownloadFileTaskAsync(url, "IPA.zip");
|
|
ZipFile.ExtractToDirectory("IPA.zip", Settings.Default.GamePath);
|
|
}
|
|
}
|
|
bool? status = CheckIfPatched();
|
|
if (!status.HasValue) //Make sure it actually worked
|
|
return;
|
|
if (!status.Value ^ unpatched.Checked)
|
|
{
|
|
var psi = new ProcessStartInfo(Settings.Default.GamePath + @"\IPA.exe", "Gamecraft.exe "
|
|
+ (unpatched.Checked ? "--revert " : "") + "--nowait")
|
|
{
|
|
UseShellExecute = false,
|
|
RedirectStandardError = true,
|
|
RedirectStandardOutput = true,
|
|
WorkingDirectory = Settings.Default.GamePath,
|
|
CreateNoWindow = true
|
|
};
|
|
var process = Process.Start(psi);
|
|
process.BeginErrorReadLine();
|
|
process.BeginOutputReadLine();
|
|
process.EnableRaisingEvents = true;
|
|
modinfobox.Text = "";
|
|
DataReceivedEventHandler onoutput = (sender, e) =>
|
|
{
|
|
Invoke((Action)(() => modinfobox.Text += e.Data + Environment.NewLine));
|
|
};
|
|
process.OutputDataReceived += onoutput;
|
|
process.ErrorDataReceived += onoutput;
|
|
process.Exited += CheckStartGame;
|
|
}
|
|
else
|
|
CheckStartGame(null, null);
|
|
}
|
|
}
|
|
}
|