This repository has been archived by the owner on Apr 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 773
/
App.xaml.cs
91 lines (82 loc) · 3.96 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
using System;
using System.IO;
using System.Windows;
using LECommonLibrary;
namespace LEGUI
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
internal static string StandaloneFilePath = string.Empty;
private void App_OnStartup(object sender, StartupEventArgs e)
{
if (e.Args.Length != 0)
{
StandaloneFilePath = e.Args[0];
// This happens when user is trying to drop a exe onto LEGUI.
if (!StandaloneFilePath.EndsWith(".le.config", true, null))
StandaloneFilePath += ".le.config";
}
bool isGlobalProfile = String.IsNullOrEmpty(StandaloneFilePath);
LEConfig.CheckGlobalConfigFile(true);
// We check StandaloneFilePath before loading UI, because this wil be faster.
if (
!SystemHelper.CheckPermission(isGlobalProfile
? Path.GetDirectoryName(LEConfig.GlobalConfigPath)
: Path.GetDirectoryName(StandaloneFilePath)))
{
if (SystemHelper.IsAdministrator())
{
// We can do nothing now.
if (isGlobalProfile)
MessageBox.Show(
string.Format("Home directory is not writable. \r\n" +
"Please move LE to another location and try again.\r\n" +
"Home directory: {0}",
Path.GetDirectoryName(LEConfig.GlobalConfigPath)),
"Locale Emulator",
MessageBoxButton.OK,
MessageBoxImage.Error);
else
MessageBox.Show(string.Format("The directory is not writable.\r\n" +
"Please use global profile instead.\r\n" +
"Current Directory: {0}",
Path.GetDirectoryName(StandaloneFilePath)),
"Locale Emulator",
MessageBoxButton.OK,
MessageBoxImage.Error);
Current.Shutdown();
}
else
{
// If we are not administrator, we can ask for administrator permission.
try
{
SystemHelper.RunWithElevatedProcess(
Path.Combine(
Path.GetDirectoryName(LEConfig.GlobalConfigPath),
"LEGUI.exe"),
e.Args);
}
catch (Exception ex)
{
MessageBox.Show("LEGUI requires administrator privilege to write to the current directory.",
"Locale Emulator",
MessageBoxButton.OK,
MessageBoxImage.Error);
}
finally
{
Current.Shutdown();
}
}
}
I18n.LoadLanguage();
Current.StartupUri = isGlobalProfile
? new Uri("GlobalConfig.xaml", UriKind.RelativeOrAbsolute)
: new Uri("AppConfig.xaml", UriKind.RelativeOrAbsolute);
}
}
}