This repository has been archived by the owner on May 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathApp.xaml.cs
189 lines (157 loc) · 5.65 KB
/
App.xaml.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
using SteamFriendsPatcher.Forms;
using SteamFriendsPatcher.Properties;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
using System.Windows;
using Timer = System.Timers.Timer;
namespace SteamFriendsPatcher
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App
{
private static readonly Mutex SingleInstance = new Mutex(true, Assembly.GetExecutingAssembly().GetName().Name);
public static MainWindow MainWindowRef { get; private set; }
// ReSharper disable once RedundantNameQualifier
public static Timer UpdateTimer { get; private set; }
public static bool UpdateTimerActive { get; private set; }
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
if (SingleInstance.WaitOne(TimeSpan.Zero, true))
{
MainWindowRef = new MainWindow();
PerformUpgrade();
const string ver = ThisAssembly.AssemblyInformationalVersion;
MainWindowRef.Title += $"v{ver.Substring(0, ver.IndexOf('+') > -1 ? ver.IndexOf('+') : ver.Length)}";
Task.Run(Setup);
if (Settings.Default.saveLastWindowSize)
{
MainWindowRef.Width = Settings.Default.windowWidth;
MainWindowRef.Height = Settings.Default.windowHeight;
}
MainWindowRef.WindowState = WindowState.Minimized;
Rect workingArea = SystemParameters.WorkArea;
MainWindowRef.Left = (workingArea.Width - Settings.Default.windowWidth) / 2 + workingArea.Left;
MainWindowRef.Top = (workingArea.Height - Settings.Default.windowHeight) / 2 + workingArea.Top;
MainWindowRef.Show();
if (Settings.Default.minimizeToTray && Settings.Default.startMinimized)
{
MainWindowRef.NotifyIcon.Visible = Settings.Default.showTrayIconHidden;
MainWindowRef.Hide();
}
else
{
MainWindowRef.NotifyIcon.Visible = Settings.Default.showTrayIconWindow;
}
if (!Settings.Default.startMinimized)
{
MainWindowRef.WindowState = WindowState.Normal;
}
SingleInstance.ReleaseMutex();
}
else
{
NativeMethods.PostMessage(
(IntPtr)NativeMethods.HwndBroadcast,
NativeMethods.WmShowme,
IntPtr.Zero,
IntPtr.Zero);
Current.Shutdown(1);
}
}
private void OnExit(object sender, ExitEventArgs e)
{
MainWindowRef.OnExit();
}
private static void Setup()
{
if (Settings.Default.checkForUpdates)
{
Task.Run(Program.UpdateChecker);
ToggleUpdateTimer();
}
/*if (Settings.Default.steamBeta)
{
FileWatcher.libraryRootCss = "5.css";
}*/
if (Settings.Default.libraryRootCss.Length >= 5)
{
FileWatcher.libraryRootCss = Settings.Default.libraryRootCss;
}
if (Settings.Default.autoScanOnStartup)
{
FileWatcher.ToggleCacheScanner(true);
}
if (Settings.Default.runSteamOnStartup && Process.GetProcessesByName("Steam").FirstOrDefault() == null)
{
Process.Start(Program.steamDir + "\\Steam.exe", Settings.Default.steamLaunchArgs);
}
if (Settings.Default.forceScanOnStartup)
{
Program.FindCacheFile();
}
}
public static void ShowMain()
{
if (!MainWindowRef.IsVisible)
{
MainWindowRef.Show();
}
MainWindowRef.NotifyIcon.Visible = Settings.Default.showTrayIconWindow;
if (MainWindowRef.WindowState == WindowState.Minimized)
{
MainWindowRef.WindowState = WindowState.Normal;
}
MainWindowRef.Activate();
}
public static void ToggleUpdateTimer(bool status = true)
{
if (!UpdateTimerActive && !status)
{
return;
}
if (!status)
{
UpdateTimer.Enabled = false;
return;
}
UpdateTimer = new Timer
{
Interval = TimeSpan.FromDays(1).TotalMilliseconds
};
UpdateTimer.Elapsed += UpdateTimer_Elapsed;
UpdateTimer.Enabled = true;
UpdateTimerActive = true;
}
private static void UpdateTimer_Elapsed(object sender, ElapsedEventArgs e)
{
Program.UpdateChecker();
}
private static void PerformUpgrade()
{
if (Settings.Default.upgradeVer == 2)
{
return;
}
Settings.Default.Upgrade();
if (Settings.Default.upgradeVer == 0)
{
if (File.Exists(Utilities.StartupLinkOld))
{
File.Delete(Utilities.StartupLinkOld);
Utilities.CreateStartUpShortcut();
}
}
Settings.Default.upgradeVer = 2;
Settings.Default.Save();
}
}
}