126 lines
4.3 KiB
C#
126 lines
4.3 KiB
C#
using GCMM.Properties;
|
|
using Newtonsoft.Json.Linq;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.IO.Compression;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Reflection;
|
|
using System.Text.RegularExpressions;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace GCMM
|
|
{
|
|
public partial class MainForm : Form
|
|
{
|
|
public MainForm()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private Dictionary<string, ModInfo> mods = new Dictionary<string, ModInfo>();
|
|
|
|
private void Form1_Load(object sender, EventArgs e)
|
|
{
|
|
modlist.Items.Clear();
|
|
UpdateButton(installbtn, false);
|
|
modinfobox.Text = "";
|
|
if (string.IsNullOrWhiteSpace(Settings.Default.GamePath))
|
|
{
|
|
Settings.Default.GamePath = GetGameFolder();
|
|
if (string.IsNullOrWhiteSpace(Settings.Default.GamePath))
|
|
Settings.Default.GamePath = SelectGameFolder();
|
|
else
|
|
MessageBox.Show("Found game at " + Settings.Default.GamePath);
|
|
Settings.Default.Save();
|
|
}
|
|
if(string.IsNullOrWhiteSpace(Settings.Default.GamePath))
|
|
{
|
|
status.Text = "Status: Game not found";
|
|
return;
|
|
}
|
|
CheckIfPatched();
|
|
GetInstalledMods();
|
|
GetAvailableMods();
|
|
}
|
|
|
|
private void playbtn_Click(object sender, EventArgs e)
|
|
{
|
|
if (playbtn.ForeColor == Color.Green) return; //Disabled
|
|
if (!BeginWork()) return;
|
|
PatchGame();
|
|
EndWork();
|
|
}
|
|
|
|
private void settingsbtn_Click(object sender, EventArgs e)
|
|
{
|
|
if (settingsbtn.ForeColor == Color.Green) return; //Disabled
|
|
var sf = new SettingsForm();
|
|
sf.ShowDialog(this);
|
|
}
|
|
|
|
private void modlist_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
if (working) return;
|
|
switch (modlist.SelectedItems.Count)
|
|
{
|
|
case 0:
|
|
modinfobox.Text = "";
|
|
UpdateButton(installbtn, false);
|
|
UpdateButton(uninstallbtn, false);
|
|
break;
|
|
case 1:
|
|
default:
|
|
installbtn.Text = "Install mod";
|
|
UpdateButton(installbtn, false);
|
|
UpdateButton(uninstallbtn, false);
|
|
foreach (ListViewItem item in modlist.SelectedItems)
|
|
{
|
|
var mod = mods[item.Name];
|
|
if (modlist.SelectedItems.Count == 1)
|
|
modinfobox.Text = mod.Description?.Replace("\n", Environment.NewLine);
|
|
else
|
|
modinfobox.Text = modlist.SelectedItems.Count + " mods selected";
|
|
if (mod.DownloadURL != null && !(mod.LatestVersion <= mod.Version))
|
|
{
|
|
UpdateButton(installbtn, true);
|
|
if (mod.Version != null)
|
|
installbtn.Text = "Update mod";
|
|
else
|
|
installbtn.Text = "Install mod";
|
|
}
|
|
if (mod.Version != null)
|
|
UpdateButton(uninstallbtn, true);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
private async void installbtn_Click(object sender, EventArgs e)
|
|
{
|
|
if (installbtn.ForeColor == Color.Green) return; //Disabled
|
|
if (!BeginWork()) return;
|
|
foreach (ListViewItem item in modlist.SelectedItems)
|
|
{
|
|
if (item.Group.Name == "installed") continue;
|
|
await InstallMod(mods[item.Name]);
|
|
}
|
|
EndWork();
|
|
}
|
|
|
|
private void uninstallbtn_Click(object sender, EventArgs e)
|
|
{
|
|
if (uninstallbtn.ForeColor == Color.Green) return; //Disabled
|
|
foreach (ListViewItem item in modlist.SelectedItems)
|
|
{
|
|
if (item.Group.Name != "installed") continue;
|
|
UninstallMod(mods[item.Name]);
|
|
}
|
|
EndWork(); //Update button states
|
|
}
|
|
}
|
|
}
|