-
-
Notifications
You must be signed in to change notification settings - Fork 45
/
AppViewModel.cs
427 lines (388 loc) · 13.2 KB
/
AppViewModel.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
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
// FFXIVAPP.Client
// AppViewModel.cs
//
// Copyright © 2007 - 2015 Ryan Wilson - All Rights Reserved
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of SyndicatedLife nor the names of its contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.ComponentModel.Composition;
using System.Drawing;
using System.IO;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;
using System.Windows.Threading;
using FFXIVAPP.Client.Memory;
using FFXIVAPP.Client.Properties;
using FFXIVAPP.Common.Core.Memory;
using FFXIVAPP.Common.Helpers;
using ContextMenu = System.Windows.Forms.ContextMenu;
namespace FFXIVAPP.Client
{
[Export(typeof (AppViewModel))]
internal sealed class AppViewModel : INotifyPropertyChanged
{
#region Property Bindings
private static AppViewModel _instance;
private static bool _hasPlugins;
private string _appTitle;
private List<ChatLogEntry> _chatHistory;
private string _configurationsPath;
private string _currentVersion;
private string _downloadUri;
private bool _hasNewPluginUpdate;
private bool _hasNewVersion;
private string _latestVersion;
private Dictionary<string, string> _locale;
private string _logsPath;
private NotifyIcon _notifyIcon;
private ObservableCollection<TabItem> _pluginTabItems;
private string _pluginsSettingsPath;
private List<string> _savedLogsDirectoryList;
private string _screenShotsPath;
private string _selected;
private string _settingsPath;
private List<Signature> _signatures;
private string _soundsPath;
private Style _tabControlCollapsedHeader;
private List<string> _updateNotes;
public static AppViewModel Instance
{
get { return _instance ?? (_instance = new AppViewModel()); }
}
public Dictionary<string, string> Locale
{
get { return _locale ?? (_locale = new Dictionary<string, string>()); }
set
{
_locale = value;
RaisePropertyChanged();
}
}
public NotifyIcon NotifyIcon
{
get
{
if (_notifyIcon == null)
{
using (var iconStream = ResourceHelper.StreamResource(Common.Constants.AppPack + "Resources/Media/Icons/FFXIVAPP.ico")
.Stream)
{
_notifyIcon = new NotifyIcon
{
Icon = new Icon(iconStream),
Visible = true
};
iconStream.Dispose();
_notifyIcon.Text = "FFXIVAPP";
var contextMenu = new ContextMenu();
contextMenu.MenuItems.Add("&Restore Application")
.Enabled = false;
contextMenu.MenuItems.Add("&Exit");
contextMenu.MenuItems[0].Click += NotifyIconOnRestoreClick;
contextMenu.MenuItems[1].Click += NotifyIconOnExitClick;
_notifyIcon.ContextMenu = contextMenu;
_notifyIcon.MouseDoubleClick += NotifyIconOnMouseDoubleClick;
}
}
return _notifyIcon;
}
}
public string AppTitle
{
get { return _appTitle; }
set
{
var tempvalue = Constants.IsOpen ? value : String.Format("{0} : OFFLINE", value);
_appTitle = String.IsNullOrWhiteSpace(tempvalue) ? "FFXIVAPP" : String.Format("FFXIVAPP ~ {0}", tempvalue);
RaisePropertyChanged();
}
}
public ObservableCollection<TabItem> PluginTabItems
{
get { return _pluginTabItems ?? (_pluginTabItems = new ObservableCollection<TabItem>()); }
set
{
_pluginTabItems = value;
RaisePropertyChanged();
}
}
public bool HasPlugins
{
get { return _hasPlugins; }
set
{
_hasPlugins = value;
RaisePropertyChanged();
}
}
public string Selected
{
get { return _selected; }
set
{
_selected = value;
RaisePropertyChanged();
}
}
public Style TabControlCollapsedHeader
{
get
{
if (_tabControlCollapsedHeader == null)
{
var s = new Style();
s.Setters.Add(new Setter(UIElement.VisibilityProperty, Visibility.Collapsed));
_tabControlCollapsedHeader = s;
}
return _tabControlCollapsedHeader;
}
set
{
_tabControlCollapsedHeader = value;
RaisePropertyChanged();
}
}
public string ConfigurationsPath
{
get { return _configurationsPath; }
set
{
_configurationsPath = value;
if (!Directory.Exists(_configurationsPath))
{
Directory.CreateDirectory(_configurationsPath);
}
RaisePropertyChanged();
}
}
public string LogsPath
{
get { return _logsPath; }
set
{
_logsPath = value;
if (!Directory.Exists(_logsPath))
{
Directory.CreateDirectory(_logsPath);
}
RaisePropertyChanged();
}
}
public List<string> SavedLogsDirectoryList
{
get { return _savedLogsDirectoryList ?? (_savedLogsDirectoryList = new List<string>()); }
set
{
foreach (var directoryPath in value)
{
var path = Path.Combine(LogsPath, directoryPath);
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
}
_savedLogsDirectoryList = value;
RaisePropertyChanged();
}
}
public string ScreenShotsPath
{
get { return _screenShotsPath; }
set
{
_screenShotsPath = value;
if (!Directory.Exists(_screenShotsPath))
{
Directory.CreateDirectory(_screenShotsPath);
}
RaisePropertyChanged();
}
}
public string SoundsPath
{
get { return _soundsPath; }
set
{
_soundsPath = value;
if (!Directory.Exists(_soundsPath))
{
Directory.CreateDirectory(_soundsPath);
}
RaisePropertyChanged();
}
}
public string SettingsPath
{
get { return _settingsPath; }
set
{
_settingsPath = value;
if (!Directory.Exists(_settingsPath))
{
Directory.CreateDirectory(_settingsPath);
}
RaisePropertyChanged();
}
}
public string PluginsSettingsPath
{
get { return _pluginsSettingsPath; }
set
{
_pluginsSettingsPath = value;
if (!Directory.Exists(_pluginsSettingsPath))
{
Directory.CreateDirectory(_pluginsSettingsPath);
}
RaisePropertyChanged();
}
}
public List<ChatLogEntry> ChatHistory
{
get { return _chatHistory ?? (_chatHistory = new List<ChatLogEntry>()); }
set
{
_chatHistory = value;
RaisePropertyChanged();
}
}
public bool HasNewVersion
{
get { return _hasNewVersion; }
set
{
_hasNewVersion = value;
RaisePropertyChanged();
}
}
public bool HasNewPluginUpdate
{
get { return _hasNewPluginUpdate; }
set
{
_hasNewPluginUpdate = value;
RaisePropertyChanged();
}
}
public string DownloadUri
{
get { return _downloadUri; }
set
{
_downloadUri = value;
RaisePropertyChanged();
}
}
public string LatestVersion
{
get { return _latestVersion; }
set
{
_latestVersion = value;
RaisePropertyChanged();
}
}
public List<string> UpdateNotes
{
get { return _updateNotes ?? (_updateNotes = new List<string>()); }
set
{
if (_updateNotes == null)
{
_updateNotes = new List<string>();
}
_updateNotes = value;
RaisePropertyChanged();
}
}
public string CurrentVersion
{
get { return _currentVersion; }
set
{
_currentVersion = value;
RaisePropertyChanged();
}
}
public string Copyright
{
get { return AssemblyHelper.Copyright; }
}
public List<Signature> Signatures
{
get { return _signatures ?? (_signatures = new List<Signature>()); }
set
{
_signatures = value;
RaisePropertyChanged();
}
}
#endregion
#region Loading Functions
#endregion
#region Private Functions
/// <summary>
/// </summary>
/// <param name="sender"></param>
/// <param name="eventArgs"></param>
private static void NotifyIconOnRestoreClick(object sender, EventArgs eventArgs)
{
ShellView.View.WindowState = WindowState.Normal;
ShellView.View.Topmost = true;
ShellView.View.Topmost = Settings.Default.TopMost;
}
/// <summary>
/// </summary>
/// <param name="sender"></param>
/// <param name="eventArgs"></param>
private static void NotifyIconOnExitClick(object sender, EventArgs eventArgs)
{
DispatcherHelper.Invoke(() => ShellView.CloseApplication(), DispatcherPriority.Send);
}
/// <summary>
/// </summary>
/// <param name="sender"></param>
/// <param name="mouseEventArgs"></param>
private static void NotifyIconOnMouseDoubleClick(object sender, MouseEventArgs mouseEventArgs)
{
ShellView.View.WindowState = WindowState.Normal;
ShellView.View.Topmost = true;
ShellView.View.Topmost = Settings.Default.TopMost;
}
#endregion
#region Implementation of INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged = delegate { };
private void RaisePropertyChanged([CallerMemberName] string caller = "")
{
PropertyChanged(this, new PropertyChangedEventArgs(caller));
}
#endregion
}
}