-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathApp.xaml.cs
129 lines (98 loc) · 4.75 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
/*
* Copyright 2009-2011 Francesco Tonucci
*
* This file is part of PDFRider.
*
* PDFRider 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 2 of the License, or
* (at your option) any later version.
*
* PDFRider 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 PDFRider; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*
* Project page: http://pdfrider.codeplex.com
*/
using System;
using System.Windows;
using System.IO;
namespace PDFRider
{
public partial class App : Application
{
#region Command Line Options
// Tells that the document may has been changed
public const string CLO_DOCUMENT_CHANGED = "/C";
#endregion
public const string PROCESS_NAME = "PDFRider";
const string LOC_DIR_NAME = "Locales";
const string LOC_FILE_NAME = "LocTable-{0}.xaml";
public static string NAME = App.ResourceAssembly.GetName().Name;
public static string TITLE = "PDF Rider";
public static string VERSION = String.Format("{0}.{1}.{2}",
App.ResourceAssembly.GetName().Version.Major.ToString(),
App.ResourceAssembly.GetName().Version.Minor.ToString(),
App.ResourceAssembly.GetName().Version.Build.ToString());
public static string FULL_VERSION = App.ResourceAssembly.GetName().Version.ToString();
public static string WEBSITE = "http://pdfrider.codeplex.com";
//Locale directory (e.g. {app}\Languages\en-US\ )
//The locale specific part is added in the constructor, after the localization test part.
public static string LOC_DIR = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, App.LOC_DIR_NAME);
//Temporary directory ( %TEMP% )
public static string TEMP_DIR = Environment.GetEnvironmentVariable("TEMP");
public static string HOME_URI = "";
private ApplicationController _applicationController;
public App()
{
#region Test localization
// -- Remove or comment this block in the final version --
//System.Globalization.CultureInfo enCulture = new System.Globalization.CultureInfo("ja-JP");
////enCulture = new System.Globalization.CultureInfo("fr-FR");
//System.Threading.Thread.CurrentThread.CurrentCulture = enCulture;
//System.Threading.Thread.CurrentThread.CurrentUICulture = enCulture;
#endregion
App.LOC_DIR = Path.Combine(App.LOC_DIR, System.Threading.Thread.CurrentThread.CurrentCulture.ToString());
// Verifies the directory structure
if (!Directory.Exists(App.LOC_DIR))
Directory.CreateDirectory(App.LOC_DIR);
if (!Directory.Exists(App.TEMP_DIR))
Directory.CreateDirectory(App.TEMP_DIR);
}
// Shows the main window.
// Command line arguments are handled via Environment.GetCommandLineArgs() in MainWindowViewModel
protected override void OnStartup(StartupEventArgs e)
{
// This must be called after the initialization
SetLocalizedStrings();
// Start the application GUI
this._applicationController = new ApplicationController();
this._applicationController.OpenMainWindow();
}
//Gets the localized strings file and adds it to the the application resources
private void SetLocalizedStrings()
{
ResourceDictionary dictionary = new ResourceDictionary();
string cultureName = System.Threading.Thread.CurrentThread.CurrentCulture.Name;
Uri languageUri = new Uri(
Path.Combine(App.LOC_DIR, String.Format(App.LOC_FILE_NAME, cultureName)));
//If the localized StringTable doesn't exist, the default (compiled)
//LocTable will be used.
if (File.Exists(languageUri.LocalPath))
{
try
{
dictionary.Source = languageUri;
this.Resources.MergedDictionaries.Add(dictionary);
}
catch { } //No action, the default LocTable.xaml is used
}
}
}
}