@@ -26,11 +26,10 @@ namespace Translator;
26
26
27
27
public partial class TranslatorWindow : Window
28
28
{
29
- private static string TempPath => Path . Combine ( "." , "ScreenToGif" , "Resources" ) ;
30
-
31
29
private readonly List < ResourceDictionary > _resourceList = new ( ) ;
32
30
private IEnumerable < string > _cultures ;
33
31
private ObservableCollection < Translation > _translationList = new ( ) ;
32
+ private string _tempPath ;
34
33
private string _resourceTemplate ;
35
34
36
35
public TranslatorWindow ( )
@@ -42,8 +41,7 @@ public TranslatorWindow()
42
41
43
42
private async void Window_Loaded ( object sender , RoutedEventArgs e )
44
43
{
45
- if ( ! Directory . Exists ( TempPath ) )
46
- Directory . CreateDirectory ( TempPath ) ;
44
+ PrepareTempPath ( ) ;
47
45
48
46
OpenButton . IsEnabled = false ;
49
47
RefreshButton . IsEnabled = false ;
@@ -220,17 +218,18 @@ private async void Load_Executed(object sender, ExecutedRoutedEventArgs e)
220
218
CheckFileExists = true ,
221
219
Title = "Open a Resource Dictionary" ,
222
220
Filter = "Resource Dictionay (*.xaml)|*.xaml;" ,
223
- InitialDirectory = Path . GetFullPath ( TempPath )
221
+ InitialDirectory = Path . GetFullPath ( _tempPath )
224
222
} ;
225
223
226
224
var result = ofd . ShowDialog ( ) ;
227
225
228
- if ( ! result . HasValue || ! result . Value ) return ;
226
+ if ( ! result . HasValue || ! result . Value )
227
+ return ;
229
228
230
229
//Will save the file to other folder.
231
- var tempFile = Path . Combine ( TempPath , "Temp" , Path . GetFileName ( ofd . FileName ) ) ;
230
+ var tempFile = Path . Combine ( _tempPath , "Temp" , Path . GetFileName ( ofd . FileName ) ) ;
232
231
233
- Directory . CreateDirectory ( Path . Combine ( TempPath , "Temp" ) ) ;
232
+ Directory . CreateDirectory ( Path . Combine ( _tempPath , "Temp" ) ) ;
234
233
235
234
//Replaces the special chars.
236
235
var text = await Task . Factory . StartNew ( ( ) => File . ReadAllText ( ofd . FileName , Encoding . UTF8 ) . Replace ( "&#" , "&#" ) . Replace ( "<!--<!--" , "<!--" ) . Replace ( "-->-->" , "-->" ) ) ;
@@ -290,7 +289,8 @@ private async void Export_Executed(object sender, ExecutedRoutedEventArgs e)
290
289
291
290
var result = sfd . ShowDialog ( ) ;
292
291
293
- if ( ! result . HasValue || ! result . Value ) return ;
292
+ if ( ! result . HasValue || ! result . Value )
293
+ return ;
294
294
295
295
BaseDataGrid . IsEnabled = false ;
296
296
StatusBand . Info ( "Exporting translation..." ) ;
@@ -321,6 +321,14 @@ private void Window_Closing(object sender, CancelEventArgs e)
321
321
322
322
#region Methods
323
323
324
+ private void PrepareTempPath ( )
325
+ {
326
+ _tempPath = Path . Combine ( AppDomain . CurrentDomain . BaseDirectory , "ScreenToGif" , "Resources" ) ;
327
+
328
+ if ( ! Directory . Exists ( _tempPath ) )
329
+ Directory . CreateDirectory ( _tempPath ) ;
330
+ }
331
+
324
332
private async Task DownloadSingleResourceAsync ( string culture )
325
333
{
326
334
try
@@ -425,7 +433,7 @@ private async Task DownloadFileAsync2(Uri uri, string name)
425
433
{
426
434
try
427
435
{
428
- var file = Path . Combine ( Dispatcher . Invoke < string > ( ( ) => TempPath ) , name ) ;
436
+ var file = Path . Combine ( Dispatcher . Invoke < string > ( ( ) => _tempPath ) , name ) ;
429
437
430
438
if ( File . Exists ( file ) )
431
439
File . Delete ( file ) ;
@@ -464,7 +472,7 @@ private async Task DownloadFileAsync(Uri uri, string name)
464
472
{
465
473
try
466
474
{
467
- var file = Path . Combine ( Dispatcher . Invoke < string > ( ( ) => TempPath ) , name ) ;
475
+ var file = Path . Combine ( Dispatcher . Invoke < string > ( ( ) => _tempPath ) , name ) ;
468
476
469
477
if ( File . Exists ( file ) )
470
478
File . Delete ( file ) ;
@@ -503,7 +511,7 @@ private async Task LoadFilesAsync()
503
511
{
504
512
try
505
513
{
506
- var files = await Task . Factory . StartNew ( ( ) => Directory . EnumerateFiles ( TempPath , "*.xaml" ) ) ;
514
+ var files = await Task . Factory . StartNew ( ( ) => Directory . EnumerateFiles ( _tempPath , "*.xaml" ) ) ;
507
515
508
516
foreach ( var file in files )
509
517
{
0 commit comments