TBMM/GCMM/MainForm.cs

103 lines
3.3 KiB
C#
Raw Normal View History

2020-06-15 19:11:05 +00:00
using GCMM.Properties;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace GCMM
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
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();
}
}
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()
{
string libs;
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
libs = @"C:\Program Files (x86)\Steam\steamapps\libraryfolders.vdf";
else
return null;
foreach (var line in File.ReadAllLines(libs).Concat(new[] { @"C:\Program Files (x86)\Steam\" }))
{
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\";
if (File.Exists(library + @"Gamecraft\Gamecraft.exe"))
return library + "Gamecraft";
if (File.Exists(library + @"RobocraftX\Gamecraft.exe"))
return library + "RobocraftX";
}
return libs;
}
public string SelectGameFolder()
{
var ofd = new OpenFileDialog();
ofd.Filter = "Gamecraft executable|Gamecraft.exe";
ofd.Title = "Game location";
ofd.InitialDirectory = @"C:\Program Files (x86)\Steam\steamapps\common\";
ofd.CheckFileExists = true;
ofd.ShowDialog();
if (string.IsNullOrWhiteSpace(ofd.FileName))
return null;
return Directory.GetParent(ofd.FileName).FullName;
}
private void playbtn_Click(object sender, EventArgs e)
{
}
private void settingsbtn_Click(object sender, EventArgs e)
{
var sf = new SettingsForm();
sf.ShowDialog(this);
}
}
}