-
Notifications
You must be signed in to change notification settings - Fork 369
Expand file tree
/
Copy pathControl_Witcher3.xaml.cs
More file actions
209 lines (178 loc) · 7.69 KB
/
Control_Witcher3.xaml.cs
File metadata and controls
209 lines (178 loc) · 7.69 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
using Aurora.Controls;
using Aurora.Utils;
using System;
using System.IO;
using Ionic.Zip;
using System.Timers;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Navigation;
using Aurora.Devices;
using Aurora.Settings;
using Xceed.Wpf.Toolkit;
using Aurora.Profiles.Witcher3.GSI;
using MessageBox = System.Windows.MessageBox;
namespace Aurora.Profiles.Witcher3
{
/// <summary>
/// Interaction logic for Control_Witcher3.xaml
/// </summary>
public partial class Control_Witcher3 : UserControl
{
private Application profile_manager;
public Control_Witcher3(Application profile)
{
InitializeComponent();
profile_manager = profile;
SetSettings();
if (!(profile_manager.Settings as FirstTimeApplicationSettings).IsFirstTimeInstalled)
{
(profile_manager.Settings as FirstTimeApplicationSettings).IsFirstTimeInstalled = true;
}
profile_manager.ProfileChanged += Control_Witcher3_ProfileChanged;
}
private void Control_Witcher3_ProfileChanged(object sender, EventArgs e)
{
SetSettings();
}
private void SetSettings()
{
this.game_enabled.IsChecked = profile_manager.Settings.IsEnabled;
}
//Overview
private void install_mod_button_Click(object sender, RoutedEventArgs e)
{
string Steaminstallpath = SteamUtils.GetGamePath(292030);
string Epicinstallpath = EpicUtils.GetGameManifestByExe("Witcher3.exe")?.InstallLocation;
string GOGinstallpath = GOGUtils.GetGamePath(1207664643); //Normal version
string GOGGotyinstallpath = GOGUtils.GetGamePath(1495134320); //GOTY version
if (!String.IsNullOrWhiteSpace(Steaminstallpath) || !String.IsNullOrWhiteSpace(Epicinstallpath) || !String.IsNullOrWhiteSpace(GOGinstallpath) || !String.IsNullOrWhiteSpace(GOGGotyinstallpath))
{
if (!String.IsNullOrWhiteSpace(Steaminstallpath))
InstallMod(Steaminstallpath);
if (!String.IsNullOrWhiteSpace(Epicinstallpath))
InstallMod(Epicinstallpath);
if (!String.IsNullOrWhiteSpace(GOGinstallpath))
InstallMod(GOGinstallpath);
if (!String.IsNullOrWhiteSpace(GOGGotyinstallpath))
InstallMod(GOGGotyinstallpath);
}
else//user could have the Origin version of the game
{
System.Windows.MessageBox.Show("Witcher 3 was not installed through Steam, Epic Games or GOG, please pick the path manually");
var dialog = new System.Windows.Forms.FolderBrowserDialog();
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
InstallMod(dialog.SelectedPath);
}
}
}
private void uninstall_mod_button_Click(object sender, RoutedEventArgs e)
{
string Steaminstallpath = SteamUtils.GetGamePath(292030);
string Epicinstallpath = EpicUtils.GetGameManifestByExe("Witcher3.exe")?.InstallLocation;
string GOGinstallpath = GOGUtils.GetGamePath(1207664643); //Normal version
string GOGGotyinstallpath = GOGUtils.GetGamePath(1495134320); //GOTY version
if (!String.IsNullOrWhiteSpace(Steaminstallpath) || !String.IsNullOrWhiteSpace(Epicinstallpath) || !String.IsNullOrWhiteSpace(GOGinstallpath) || !String.IsNullOrWhiteSpace(GOGGotyinstallpath))
{
if (!String.IsNullOrWhiteSpace(Steaminstallpath))
UninstallMod(Steaminstallpath);
if (!String.IsNullOrWhiteSpace(Epicinstallpath))
UninstallMod(Epicinstallpath);
if (!String.IsNullOrWhiteSpace(GOGinstallpath))
UninstallMod(GOGinstallpath);
if (!String.IsNullOrWhiteSpace(GOGGotyinstallpath))
UninstallMod(GOGGotyinstallpath);
}
else
{
MessageBox.Show("Witcher 3 was not installed through Steam, Epic Games or GOG, please pick the path manually");
var dialog = new System.Windows.Forms.FolderBrowserDialog();
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
UninstallMod(dialog.SelectedPath);
}
}
}
private void game_enabled_Checked(object sender, RoutedEventArgs e)
{
if (IsLoaded)
{
profile_manager.Settings.IsEnabled = (this.game_enabled.IsChecked.HasValue) ? this.game_enabled.IsChecked.Value : false;
profile_manager.SaveProfiles();
}
}
private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
{
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(e.Uri.AbsoluteUri));
e.Handled = true;
}
private void InstallMod(string root)
{
if (!Directory.Exists(root))
{
MessageBox.Show("Witcher 3 directory not found");
return;
}
try
{
using (MemoryStream w3_mod = new MemoryStream(Properties.Resources.witcher3_mod))
{
using (ZipFile zip = ZipFile.Read(w3_mod))
{
foreach (ZipEntry entry in zip)
{
entry.Extract(root, ExtractExistingFileAction.OverwriteSilently);//the zip's directory structure assumes
//it is extracted to the root folder of the game
}
MessageBox.Show("Witcher 3 mod installed.");
return;
}
}
}
catch (Exception e)
{
Global.logger.Error("Error installing the Witcher 3 mod: " + e.Message);
MessageBox.Show("Witcher 3 directory is not found.\r\nCould not install the mod.");
return;
}
}
private void UninstallMod(string root)
{
if (!Directory.Exists(root))
{
MessageBox.Show("Witcher 3 directory not found");
return;
}
var modfolder = Path.Combine(root, "mods", "modArtemis");
var cfgfile = Path.Combine(root, "bin", "config", "r4game", "user_config_matrix", "pc", "artemis.xml");
try
{
var previouslyInstalled = false;
if (Directory.Exists(modfolder))
{
previouslyInstalled = true;
Directory.Delete(modfolder, true);
}
if (File.Exists(cfgfile))
{
previouslyInstalled = true;
File.Delete(cfgfile);
}
if(previouslyInstalled)
MessageBox.Show("Witcher 3 mod uninstalled successfully!");
else
MessageBox.Show("Witcher 3 mod already uninstalled!");
return;
}
catch (Exception e)
{
Global.logger.Error("Error uninstalling witcher 3 mod: " + e.Message);
MessageBox.Show("Witcher 3 mod uninstall failed!");
return;
}
}
}
}