@@ -21,8 +21,11 @@ public partial class App : Application
2121 public static bool CheckInstalledMods ;
2222 public static bool SelectInstalledMods ;
2323 public static bool ReinstallInstalledMods ;
24+ public static bool CloseWindowOnFinish ;
2425 public static string Version = Assembly . GetExecutingAssembly ( ) . GetName ( ) . Version . ToString ( ) ;
2526 public static List < string > SavedMods = ModAssistant . Properties . Settings . Default . SavedMods . Split ( ',' ) . ToList ( ) ;
27+ public static MainWindow window ;
28+ public static string Arguments ;
2629 public static bool Update = true ;
2730 public static bool GUI = true ;
2831
@@ -31,12 +34,7 @@ private async void Application_Startup(object sender, StartupEventArgs e)
3134 {
3235 // Set SecurityProtocol to prevent crash with TLS
3336 System . Net . ServicePointManager . SecurityProtocol |= SecurityProtocolType . Tls12 ;
34-
35- // Load localisation languages
36- LoadLanguage ( CultureInfo . CurrentCulture . Name ) ;
37-
38- // Uncomment the next line to debug localisation
39- // LoadLanguage("en-DEBUG");
37+ Languages . LoadLanguages ( ) ;
4038
4139 if ( ModAssistant . Properties . Settings . Default . UpgradeRequired )
4240 {
@@ -68,27 +66,40 @@ private async void Application_Startup(object sender, StartupEventArgs e)
6866 CheckInstalledMods = ModAssistant . Properties . Settings . Default . CheckInstalled ;
6967 SelectInstalledMods = ModAssistant . Properties . Settings . Default . SelectInstalled ;
7068 ReinstallInstalledMods = ModAssistant . Properties . Settings . Default . ReinstallInstalled ;
69+ CloseWindowOnFinish = ModAssistant . Properties . Settings . Default . CloseWindowOnFinish ;
7170
7271 await ArgumentHandler ( e . Args ) ;
73- await Init ( Update , GUI ) ;
72+ await Init ( ) ;
7473 }
7574
76- private async Task Init ( bool Update , bool GUI )
75+ private async Task Init ( )
7776 {
7877 if ( Update )
7978 {
80- await Task . Run ( async ( ) => await Updater . Run ( ) ) ;
79+ try
80+ {
81+ await Task . Run ( async ( ) => await Updater . Run ( ) ) ;
82+ }
83+ catch ( UnauthorizedAccessException )
84+ {
85+ Utils . StartAsAdmin ( Arguments , true ) ;
86+ }
8187 }
8288
8389 if ( GUI )
8490 {
85- MainWindow window = new MainWindow ( ) ;
91+ window = new MainWindow ( ) ;
8692 window . Show ( ) ;
8793 }
94+ else
95+ {
96+ //Application.Current.Shutdown();
97+ }
8898 }
8999
90100 private async Task ArgumentHandler ( string [ ] args )
91101 {
102+ Arguments = string . Join ( " " , args ) ;
92103 while ( args . Length > 0 )
93104 {
94105 switch ( args [ 0 ] )
@@ -103,6 +114,12 @@ private async Task ArgumentHandler(string[] args)
103114 await OneClickInstaller . InstallAsset ( args [ 1 ] ) ;
104115 }
105116
117+ if ( CloseWindowOnFinish )
118+ {
119+ await Task . Delay ( 5 * 1000 ) ;
120+ Current . Shutdown ( ) ;
121+ }
122+
106123 Update = false ;
107124 GUI = false ;
108125 args = Shift ( args , 2 ) ;
@@ -120,7 +137,12 @@ private async Task ArgumentHandler(string[] args)
120137 }
121138 else
122139 {
123- LoadLanguage ( args [ 1 ] ) ;
140+ if ( Languages . LoadLanguage ( args [ 1 ] ) )
141+ {
142+ ModAssistant . Properties . Settings . Default . LanguageCode = args [ 1 ] ;
143+ ModAssistant . Properties . Settings . Default . Save ( ) ;
144+ Languages . UpdateUI ( args [ 1 ] ) ;
145+ }
124146 }
125147
126148 args = Shift ( args , 2 ) ;
@@ -156,6 +178,12 @@ private async Task ArgumentHandler(string[] args)
156178 args = Shift ( args , 2 ) ;
157179 break ;
158180
181+ case "--runforever" :
182+ while ( true )
183+ {
184+
185+ }
186+
159187 default :
160188 Utils . SendNotify ( ( string ) Current . FindResource ( "App:UnrecognizedArgument" ) ) ;
161189 args = Shift ( args ) ;
@@ -185,29 +213,5 @@ private void Application_DispatcherUnhandledException(object sender, System.Wind
185213 e . Handled = true ;
186214 Application . Current . Shutdown ( ) ;
187215 }
188-
189- private ResourceDictionary LanguagesDict
190- {
191- get
192- {
193- return Resources . MergedDictionaries [ 1 ] ;
194- }
195- }
196-
197- private void LoadLanguage ( string culture )
198- {
199- try
200- {
201- LanguagesDict . Source = new Uri ( $ "Localisation/{ culture } .xaml", UriKind . Relative ) ;
202- }
203- catch ( IOException )
204- {
205- if ( culture . Contains ( "-" ) )
206- {
207- LoadLanguage ( culture . Split ( '-' ) . First ( ) ) ;
208- }
209- // Can't load language file
210- }
211- }
212216 }
213217}
0 commit comments