forked from lafpeace/LeagueSharpLoader
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.xaml.cs
163 lines (146 loc) · 6.2 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
#region LICENSE
// Copyright 2014 LeagueSharp.Loader
// App.xaml.cs is part of LeagueSharp.Loader.
//
// LeagueSharp.Loader is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// LeagueSharp.Loader is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with LeagueSharp.Loader. If not, see <http://www.gnu.org/licenses/>.
#endregion
namespace LeagueSharp.Loader
{
#region
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows;
using LeagueSharp.Loader.Class;
using LeagueSharp.Loader.Data;
#endregion
public partial class App
{
private Mutex _mutex;
[DllImport("user32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")]
private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
protected override void OnStartup(StartupEventArgs e)
{
if (File.Exists(Updater.SetupFile))
{
Thread.Sleep(1000);
}
bool createdNew;
_mutex = new Mutex(true, @"LeagueSharp.Loader.Mutex", out createdNew);
if (!createdNew)
{
if (e.Args.Length > 0)
{
var wnd = Injection.FindWindow(IntPtr.Zero, "LeagueSharp");
if (wnd != IntPtr.Zero)
{
Clipboard.SetText(e.Args[0]);
ShowWindow(wnd, 5);
SetForegroundWindow(wnd);
}
}
_mutex = null;
Environment.Exit(0);
}
Utility.CreateFileFromResource(Directories.ConfigFilePath, "LeagueSharp.Loader.Resources.config.xml");
try
{
Config.Instance = ((Config) Utility.MapXmlFileToClass(typeof(Config), Directories.ConfigFilePath));
}
catch (Exception)
{
MessageBox.Show("Couldn't load config.xml.");
File.Delete(Directories.ConfigFilePath);
Environment.Exit(0);
}
//Load the language resources.
var dict = new ResourceDictionary();
if (Config.Instance.SelectedLanguage != null)
{
dict.Source = new Uri(
"..\\Resources\\Language\\" + Config.Instance.SelectedLanguage + ".xaml", UriKind.Relative);
}
else
{
var lid = Thread.CurrentThread.CurrentCulture.ToString().Contains("-")
? Thread.CurrentThread.CurrentCulture.ToString().Split('-')[0].ToUpperInvariant()
: Thread.CurrentThread.CurrentCulture.ToString().ToUpperInvariant();
switch (lid)
{
case "DE":
dict.Source = new Uri("..\\Resources\\Language\\German.xaml", UriKind.Relative);
break;
case "AR":
dict.Source = new Uri("..\\Resources\\Language\\Arabic.xaml", UriKind.Relative);
break;
case "ES":
dict.Source = new Uri("..\\Resources\\Language\\Spanish.xaml", UriKind.Relative);
break;
case "FR":
dict.Source = new Uri("..\\Resources\\Language\\French.xaml", UriKind.Relative);
break;
case "IT":
dict.Source = new Uri("..\\Resources\\Language\\Italian.xaml", UriKind.Relative);
break;
case "KO":
dict.Source = new Uri("..\\Resources\\Language\\Korean.xaml", UriKind.Relative);
break;
case "NL":
dict.Source = new Uri("..\\Resources\\Language\\Dutch.xaml", UriKind.Relative);
break;
case "PL":
dict.Source = new Uri("..\\Resources\\Language\\Polish.xaml", UriKind.Relative);
break;
case "PT":
dict.Source = new Uri("..\\Resources\\Language\\Portuguese.xaml", UriKind.Relative);
break;
case "RO":
dict.Source = new Uri("..\\Resources\\Language\\Romanian.xaml", UriKind.Relative);
break;
case "RU":
dict.Source = new Uri("..\\Resources\\Language\\Russian.xaml", UriKind.Relative);
break;
case "SE":
dict.Source = new Uri("..\\Resources\\Language\\Swedish.xaml", UriKind.Relative);
break;
case "TR":
dict.Source = new Uri("..\\Resources\\Language\\Turkish.xaml", UriKind.Relative);
break;
case "VI":
dict.Source = new Uri("..\\Resources\\Language\\Vietnamese.xaml", UriKind.Relative);
break;
case "ZH":
dict.Source = new Uri("..\\Resources\\Language\\Chinese.xaml", UriKind.Relative);
break;
default:
dict.Source = new Uri("..\\Resources\\Language\\English.xaml", UriKind.Relative);
break;
}
}
Resources.MergedDictionaries.Add(dict);
base.OnStartup(e);
}
protected override void OnExit(ExitEventArgs e)
{
if (_mutex != null)
{
_mutex.ReleaseMutex();
}
base.OnExit(e);
}
}
}