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 pathInstallerWindow.xaml.cs
More file actions
181 lines (149 loc) · 6.59 KB
/
Copy pathInstallerWindow.xaml.cs
File metadata and controls
181 lines (149 loc) · 6.59 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
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.Shapes;
using Microsoft.Win32;
using System.Reflection;
using System.IO;
using System.Diagnostics;
namespace ClientInstaller
{
/// <summary>
/// Interaction logic for InstallerWindow.xaml
/// </summary>
///
public partial class InstallerWindow : Window
{
private static void ExtractEmbeddedResource(string outputDir, string resourceLocation, List<string> files)
{
foreach (string file in files)
{
using (System.IO.Stream stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceLocation + @"." + file))
{
using (System.IO.FileStream fileStream = new System.IO.FileStream(System.IO.Path.Combine(outputDir, file), System.IO.FileMode.Create))
{
for (int i = 0; i < stream.Length; i++)
{
fileStream.WriteByte((byte)stream.ReadByte());
}
fileStream.Close();
}
}
}
}
public InstallerWindow()
{
InitializeComponent();
}
private void InstallClientStartMenu(string GameDir)
{
string ClientPath = GameDir + "\\nvmp_launcher.exe";
string CommonStartMenuPath = Environment.GetFolderPath( Environment.SpecialFolder.CommonStartMenu );
string ApplicationStartMenuPath = System.IO.Path.Combine( CommonStartMenuPath, "Programs", "NVMP" );
if (!Directory.Exists( ApplicationStartMenuPath ))
Directory.CreateDirectory( ApplicationStartMenuPath );
string ShortcutLocation = System.IO.Path.Combine( ApplicationStartMenuPath, "New Vegas Multiplayer.lnk" );
IWshRuntimeLibrary.WshShell Shell = new IWshRuntimeLibrary.WshShell();
IWshRuntimeLibrary.IWshShortcut Shortcut = (IWshRuntimeLibrary.IWshShortcut) Shell.CreateShortcut( ShortcutLocation );
Shortcut.Description = "NV:MP Game Client";
Shortcut.TargetPath = ClientPath;
Shortcut.Save();
}
private string InstallClientFiles(string GameDir)
{
ExtractEmbeddedResource(GameDir, "ClientInstaller.Res", new List<string> { "nvmp_launcher.exe" });
try
{
File.Copy(Assembly.GetEntryAssembly().Location, GameDir + "\\nvmp_installer.exe", true);
} catch (Exception)
{
return null;
}
return GameDir + "\\nvmp_installer.exe";
}
private void InstallClientRegistry(string UninstallerLocation)
{
using (RegistryKey parent = Registry.LocalMachine.OpenSubKey(
SharedUtil.RegKeyPath, true))
{
if (parent == null)
{
throw new Exception("Windows registry key not found.");
}
try
{
RegistryKey key = null;
try
{
string guidText = SharedUtil.ProgramGUID;
key = parent.OpenSubKey(guidText, true) ??
parent.CreateSubKey(guidText);
if (key == null)
{
throw new Exception(String.Format("Unable to create uninstaller '{0}\\{1}'", SharedUtil.RegKeyPath, guidText));
}
Assembly asm = GetType().Assembly;
Version v = asm.GetName().Version;
string exe = "\"" + UninstallerLocation + "\"";
key.SetValue("DisplayName", ProgramDetails.DisplayName);
key.SetValue("URLInfoAbout", ProgramDetails.URLInfoAbout);
key.SetValue("Contact", ProgramDetails.Contact);
key.SetValue("Publisher", ProgramDetails.Publisher);
key.SetValue("ApplicationVersion", v.ToString());
key.SetValue("DisplayIcon", exe);
key.SetValue("DisplayVersion", v.ToString(2));
key.SetValue("InstallDate", DateTime.Now.ToString("yyyyMMdd"));
key.SetValue("UninstallString", exe + " /uninstall");
}
finally
{
if (key != null)
{
key.Close();
}
}
}
catch (Exception ex)
{
throw new Exception(
"An error occurred writing uninstall information to the registry. NV:MP is installed, but can only be uninstalled manually through the command line.",
ex);
}
}
}
public void Install(Window caller, string GameDir)
{
if (GameDir == null)
throw new Exception("Fallout directory not found, installation quitting.");
StatusLabel.Content = "Installing client files...";
string UninstallFile = InstallClientFiles( GameDir );
if (UninstallFile == null)
throw new Exception("Could not copy over the uninstallation program.");
System.Threading.Thread.Sleep( 500 );
StatusLabel.Content = "Adding program to registry...";
InstallClientRegistry( UninstallFile );
StatusLabel.Content = "Adding program to start menu...";
InstallClientStartMenu( GameDir );
System.Threading.Thread.Sleep(500);
StatusLabel.Content = "Complete.";
System.Threading.Thread.Sleep(1000);
// Shut down the WPF interface.
caller.Close();
Close();
// Start up the client to start the patching process.
Process client = new Process();
client.StartInfo.FileName = GameDir + "\\nvmp_launcher.exe";
if (!client.Start())
throw new Exception( "Failed starting client, installation may be corrupted." );
}
}
}