forked from OpenRA/OpenRA
/
MainForm.cs
82 lines (70 loc) · 2.28 KB
/
MainForm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#region Copyright & License Information
/*
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see LICENSE.
*/
#endregion
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows.Forms;
namespace OpenRA.Launcher
{
public partial class MainForm : Form
{
string configPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + Path.DirectorySeparatorChar + "OpenRA";
string[] currentMods;
public MainForm()
{
InitializeComponent();
quitButton.Click += (o, e) => { Application.Exit(); };
using (var s = UtilityProgram.Call("--settings-value", configPath, "Game.Mods"))
{
var response = s.ReadToEnd();
if (Util.IsError(ref response))
currentMods = new string[] { "ra" };
else
currentMods = response.Split(',');
}
UpdateModLabel();
}
void UpdateModLabel()
{
label1.Text = string.Format("Current Mods: {0}", currentMods.Length > 0 ? string.Join(",", currentMods) : "ra");
}
void ConfigureMods(object sender, EventArgs e)
{
var d = new ConfigureModsDialog(currentMods);
if (d.ShowDialog() != DialogResult.OK)
return;
currentMods = d.ActiveMods.ToArray();
UpdateModLabel();
}
void LaunchGame(object sender, EventArgs e)
{
string[] officialMods = { "ra", "cnc" };
bool allOk = true;
foreach(string s in officialMods)
if (currentMods.Contains(s))
allOk = CheckAndInstallPackages(s);
if (!allOk) return;
Process p = new Process();
p.StartInfo.FileName = "OpenRA.Game.exe";
p.StartInfo.Arguments = "Game.Mods=" + string.Join(",", currentMods);
p.Start();
}
bool CheckAndInstallPackages(string mod)
{
string packageDir = "mods" + Path.DirectorySeparatorChar + mod + Path.DirectorySeparatorChar + "packages";
if (Directory.Exists(packageDir) &&
Directory.GetFiles(packageDir, "*.mix").Length > 0) return true;
var dialog = new InstallPackagesDialog(mod);
if (dialog.ShowDialog() != DialogResult.OK) return false;
return true;
}
}
}