This repository was archived by the owner on Aug 11, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
218 lines (183 loc) · 6.35 KB
/
Copy pathMainWindow.xaml.cs
File metadata and controls
218 lines (183 loc) · 6.35 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;
using System.Threading;
using Microsoft.Win32;
namespace ClientInstaller
{
public class InstallStatus
{
private string FalloutDirectoryOverride = null;
public string FalloutDirectory
{
get
{
if (FalloutDirectoryOverride != null)
return FalloutDirectoryOverride;
return FalloutFinder.GameDir();
}
set
{
FalloutDirectoryOverride = value;
}
}
public bool IsFalloutInstalled => Directory.Exists(FalloutDirectory);
public bool IsNVMPInstalled
{
get
{
try
{
using (RegistryKey parent = Registry.LocalMachine.OpenSubKey(
SharedUtil.RegKeyPath, true))
{
if (parent == null)
{
return false;
}
RegistryKey key = null;
try
{
string guidText = SharedUtil.ProgramGUID;
key = parent.OpenSubKey(guidText, false);
return key != null;
}
finally
{
if (key != null)
{
key.Close();
}
}
}
}
catch (Exception)
{
}
return false;
}
}
public string GetMessage()
{
if (!IsFalloutInstalled)
return "Fallout: New Vegas is not installed, or could not be found.";
if (IsNVMPInstalled)
return "NV:MP is already installed, please uninstall before attempting to reinstall.";
return null;
}
public bool CanInstall()
{
return (IsFalloutInstalled && (!IsNVMPInstalled));
}
}
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private InstallStatus Status;
private InstallerWindow InstallerWindowInstance = null;
private UninstallerWindow UninstallerWindowInstance = null;
public void OnInstallClick(object sender, RoutedEventArgs evt)
{
if (Status.FalloutDirectory == null)
{
MessageBox.Show("Could not start the installation as the Fallout directory seems to be invalid!");
return;
}
InstallerWindowInstance = new InstallerWindow();
InstallerWindowInstance.Show();
Hide();
try {
Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new ThreadStart( ()=>
InstallerWindowInstance.Install(this, Status.FalloutDirectory)));
}
catch (Exception e)
{
InstallerWindowInstance.Close();
MessageBox.Show("Installation Error: " + e.ToString());
Show();
}
}
public void DoUninstall()
{
UninstallerWindowInstance = new UninstallerWindow();
UninstallerWindowInstance.Show();
Close();
try {
UninstallerWindowInstance.Uninstall( Status.FalloutDirectory );
} catch (Exception e)
{
MessageBox.Show("Uninstallation Error: " + e.ToString());
}
UninstallerWindowInstance.Close();
}
public bool IsUninstallRequested()
{
string[] CmdArguments = Environment.GetCommandLineArgs();
if (CmdArguments.Length < 2)
return false;
if (CmdArguments[1] == "/uninstall")
return true;
return false;
}
public MainWindow()
{
InitializeComponent();
// Install the program.
Status = new InstallStatus();
// Uninstall the program.
if ( IsUninstallRequested() )
{
DoUninstall();
return;
}
if (!Status.CanInstall())
{
if (Status.IsNVMPInstalled)
{
var result = MessageBox.Show("ERROR: NV:MP is already installed, would you like to uninstall it?"
, "NV:MP Installer"
, MessageBoxButton.OKCancel);
if (result == MessageBoxResult.OK)
{
DoUninstall();
return;
}
}
if (!Status.IsFalloutInstalled)
{
var result = MessageBox.Show("ERROR: Could not find an installation of Fallout: New Vegas. Would you like to manually select a folder to use for installation?"
, "NV:MP Installer"
, MessageBoxButton.OKCancel);
if (result == MessageBoxResult.OK)
{
using (var dialog = new System.Windows.Forms.FolderBrowserDialog())
{
var dresult = dialog.ShowDialog();
if (dresult == System.Windows.Forms.DialogResult.OK && !string.IsNullOrWhiteSpace(dialog.SelectedPath))
{
Status.FalloutDirectory = dialog.SelectedPath;
return;
}
}
}
}
MessageBox.Show( Status.GetMessage(), "NV:MP Installer" );
Close();
}
}
}
}