2020-06-16 17:22:29 +00:00
|
|
|
|
using GCMM.Properties;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace GCMM
|
|
|
|
|
{
|
|
|
|
|
partial class MainForm
|
|
|
|
|
{
|
|
|
|
|
public void UpdateButton(Button button, bool enabled)
|
|
|
|
|
{
|
|
|
|
|
if (enabled)
|
|
|
|
|
{
|
|
|
|
|
button.ForeColor = Color.Lime;
|
|
|
|
|
button.FlatAppearance.MouseOverBackColor = Color.FromArgb(0, 40, 0);
|
|
|
|
|
button.FlatAppearance.MouseDownBackColor = Color.Green;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
button.ForeColor = Color.Green;
|
|
|
|
|
button.FlatAppearance.MouseOverBackColor = Color.Black;
|
|
|
|
|
button.FlatAppearance.MouseDownBackColor = Color.Black;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetGameFolder()
|
2020-07-03 00:00:08 +00:00
|
|
|
|
{ //TODO
|
2020-06-16 17:22:29 +00:00
|
|
|
|
string libs;
|
|
|
|
|
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
|
|
|
|
|
libs = @"C:\Program Files (x86)\Steam\steamapps\libraryfolders.vdf";
|
|
|
|
|
else
|
|
|
|
|
return null;
|
2020-07-17 18:57:46 +00:00
|
|
|
|
foreach (var line in File.ReadAllLines(libs).Concat(new[] {@"C:\Program Files (x86)\Steam\"}))
|
2020-06-16 17:22:29 +00:00
|
|
|
|
{
|
|
|
|
|
var regex = new Regex("\\t\"\\d+\"\\t\\t\"(.+)\"");
|
|
|
|
|
var match = regex.Match(line);
|
|
|
|
|
if (!match.Success)
|
|
|
|
|
continue;
|
|
|
|
|
string library = match.Groups[1].Value.Replace("\\\\", "\\");
|
|
|
|
|
library += @"\steamapps\common\";
|
2020-07-17 18:57:46 +00:00
|
|
|
|
if (GetExe(library + "Gamecraft") != null)
|
2020-06-16 17:22:29 +00:00
|
|
|
|
return library + "Gamecraft";
|
2020-07-17 18:57:46 +00:00
|
|
|
|
if (GetExe(library + "RobocraftX") != null)
|
2020-06-16 17:22:29 +00:00
|
|
|
|
return library + "RobocraftX";
|
|
|
|
|
}
|
2020-07-17 18:57:46 +00:00
|
|
|
|
return null;
|
2020-06-16 17:22:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string SelectGameFolder()
|
|
|
|
|
{
|
|
|
|
|
var ofd = new OpenFileDialog();
|
2020-07-17 18:57:46 +00:00
|
|
|
|
ofd.Filter = "Gamecraft executable|Gamecraft.exe|Gamecraft Preview executable|GamecraftPreview.exe";
|
2020-06-16 17:22:29 +00:00
|
|
|
|
ofd.Title = "Game location";
|
2020-07-03 00:00:08 +00:00
|
|
|
|
ofd.InitialDirectory = @"C:\Program Files (x86)\Steam\steamapps\common\"; //TODO
|
2020-06-16 17:22:29 +00:00
|
|
|
|
ofd.CheckFileExists = true;
|
|
|
|
|
ofd.ShowDialog();
|
|
|
|
|
if (string.IsNullOrWhiteSpace(ofd.FileName))
|
|
|
|
|
return null;
|
|
|
|
|
return Directory.GetParent(ofd.FileName).FullName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CheckStartGame(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Action act = () =>
|
|
|
|
|
{
|
2020-06-17 21:56:18 +00:00
|
|
|
|
if (((sender as Process)?.ExitCode ?? 0) != 0)
|
2020-06-16 17:22:29 +00:00
|
|
|
|
{
|
|
|
|
|
status.Text = "Status: Patching failed";
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-08-18 18:56:19 +00:00
|
|
|
|
if (CheckIfPatched() == GameState.Patched || unpatched.Checked)
|
2020-07-03 00:00:08 +00:00
|
|
|
|
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
|
|
|
|
|
Process.Start("steam://run/1078000/");
|
|
|
|
|
else
|
|
|
|
|
Process.Start("xdg-open", "steam://run/1078000/");
|
2020-06-16 17:22:29 +00:00
|
|
|
|
};
|
|
|
|
|
if (InvokeRequired)
|
|
|
|
|
Invoke(act);
|
2020-06-17 21:56:18 +00:00
|
|
|
|
else
|
|
|
|
|
act();
|
2020-06-18 16:28:07 +00:00
|
|
|
|
EndWork(false);
|
2020-06-16 17:22:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public WebClient GetClient()
|
|
|
|
|
{
|
|
|
|
|
var client = new WebClient();
|
|
|
|
|
if (!Settings.Default.UseProxy)
|
|
|
|
|
client.Proxy = null;
|
|
|
|
|
client.Headers.Clear();
|
|
|
|
|
client.Headers[HttpRequestHeader.Accept] = "application/json";
|
|
|
|
|
client.BaseAddress = "https://git.exmods.org";
|
|
|
|
|
return client;
|
|
|
|
|
}
|
2020-06-17 13:08:22 +00:00
|
|
|
|
|
|
|
|
|
private bool working = false;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Some simple "locking", only allow one operation at a time
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>Whether the work can begin</returns>
|
|
|
|
|
public bool BeginWork()
|
|
|
|
|
{
|
|
|
|
|
if (working) return false;
|
|
|
|
|
working = true;
|
|
|
|
|
UpdateButton(playbtn, false);
|
|
|
|
|
UpdateButton(installbtn, false);
|
|
|
|
|
UpdateButton(uninstallbtn, false);
|
|
|
|
|
UpdateButton(settingsbtn, false);
|
2021-01-19 23:49:11 +00:00
|
|
|
|
unpatched.Enabled = false;
|
2020-06-17 13:08:22 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-18 16:28:07 +00:00
|
|
|
|
public void EndWork(bool desc = true)
|
2020-06-17 13:08:22 +00:00
|
|
|
|
{
|
|
|
|
|
working = false;
|
|
|
|
|
UpdateButton(playbtn, true);
|
|
|
|
|
UpdateButton(settingsbtn, true);
|
2020-06-18 16:28:07 +00:00
|
|
|
|
if (desc)
|
|
|
|
|
modlist_SelectedIndexChanged(modlist, null);
|
2021-01-19 23:49:11 +00:00
|
|
|
|
unpatched.Enabled = true;
|
2020-06-17 13:08:22 +00:00
|
|
|
|
}
|
2020-07-03 00:00:08 +00:00
|
|
|
|
|
2020-07-17 18:57:46 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Path must start with \
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="path"></param>
|
|
|
|
|
/// <param name="gamepath"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public string GamePath(string path, string gamepath = null)
|
|
|
|
|
{
|
|
|
|
|
return ((gamepath ?? Settings.Default.GamePath) + path).Replace('\\', Path.DirectorySeparatorChar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetExe(string path = null)
|
2020-07-03 00:00:08 +00:00
|
|
|
|
{
|
2020-07-17 18:57:46 +00:00
|
|
|
|
if (File.Exists(GamePath("\\Gamecraft.exe", path)))
|
|
|
|
|
return "Gamecraft.exe";
|
|
|
|
|
if (File.Exists(GamePath("\\GamecraftPreview.exe", path)))
|
|
|
|
|
return "GamecraftPreview.exe";
|
|
|
|
|
return null;
|
2020-07-03 00:00:08 +00:00
|
|
|
|
}
|
2020-08-18 18:56:19 +00:00
|
|
|
|
|
|
|
|
|
private bool CheckNoExe()
|
|
|
|
|
{
|
|
|
|
|
return CheckNoExe(out _);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool CheckNoExe(out string path)
|
|
|
|
|
{
|
|
|
|
|
path = GetExe();
|
|
|
|
|
if (path == null)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Gamecraft not found! Set the correct path in Settings.");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2020-12-31 17:05:38 +00:00
|
|
|
|
|
2021-01-01 03:45:51 +00:00
|
|
|
|
public async Task<DateTime> GetLastGameUpdateTime()
|
2020-12-31 17:05:38 +00:00
|
|
|
|
{
|
2021-01-01 23:12:52 +00:00
|
|
|
|
/*using (var client = GetClient())
|
2020-12-31 17:05:38 +00:00
|
|
|
|
{
|
2021-01-01 23:12:52 +00:00
|
|
|
|
string html = await client.DownloadStringTaskAsync("https://api.steamcmd.net/v1/info/1078000");
|
2021-01-01 03:45:51 +00:00
|
|
|
|
var regex = new Regex("<i>timeupdated:</i>[^<]*<b>([^<]*)</b>");
|
|
|
|
|
var match = regex.Match(html);
|
2020-12-31 17:05:38 +00:00
|
|
|
|
if (!match.Success)
|
|
|
|
|
return default;
|
2021-01-01 03:45:51 +00:00
|
|
|
|
return new DateTime(1970, 1, 1).AddSeconds(long.Parse(match.Groups[1].Value));
|
2021-01-01 23:12:52 +00:00
|
|
|
|
}*/
|
2021-01-19 23:49:11 +00:00
|
|
|
|
//return new DateTime(2020, 12, 28);
|
|
|
|
|
return default;
|
2020-12-31 17:05:38 +00:00
|
|
|
|
}
|
2020-06-16 17:22:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|