1
1
using System ;
2
- using System . CodeDom ;
3
- using System . CodeDom . Compiler ;
4
2
using System . Collections ;
5
3
using System . Collections . Generic ;
6
4
using System . ComponentModel ;
7
5
using System . Diagnostics ;
8
6
using System . IO ;
9
7
using System . Linq ;
10
- using System . Net . Mime ;
11
8
using System . Text ;
12
9
using System . Windows ;
13
10
using System . Windows . Controls ;
14
11
using System . Windows . Input ;
15
12
using System . Windows . Media . Animation ;
16
13
using System . Text . RegularExpressions ;
17
- using System . Threading ;
18
14
using System . Threading . Tasks ;
19
- using System . Windows . Forms . VisualStyles ;
20
15
using System . Xml ;
21
16
using ICSharpCode . AvalonEdit . Highlighting ;
22
17
using ICSharpCode . AvalonEdit . Highlighting . Xshd ;
25
20
using ICSharpCode . AvalonEdit . CodeCompletion ;
26
21
using System . Windows . Media ;
27
22
using ICSharpCode . AvalonEdit ;
28
- using MahApps . Metro ;
29
- using MahApps . Metro . Controls ;
30
23
using MahApps . Metro . IconPacks ;
24
+ using Newtonsoft . Json ;
31
25
32
26
namespace Translator ;
33
27
/// <summary>
@@ -41,7 +35,7 @@ public partial class MainWindow
41
35
private string FileDir = "" ;
42
36
private StringBuilder EnJsonText = new ( ) ;
43
37
private ScrollViewer ScrollViewer ;
44
- private Hashtable Dict = new ( ) ;
38
+ private Dictionary < string , List < string > > Dict = new ( ) ;
45
39
private DictObject dictObject = new ( ) ;
46
40
private bool baidu = false ;
47
41
@@ -257,38 +251,23 @@ private async void TransWordList_OnSelectionChanged(object sender, SelectionChan
257
251
await GetTransDict ( ) ;
258
252
}
259
253
260
- private int count = 0 ;
254
+ // private int count = 0;
261
255
262
256
private async Task GetTransDict ( )
263
257
{
264
258
dictObject . DictTrans . Clear ( ) ;
265
259
await Task . Delay ( new Random ( ) . Next ( 50 , 300 ) ) ;
266
260
TranslateSelector . ItemsSource = null ;
267
- if ( Dict . Contains ( AvalonText . Text ) )
268
- dictObject . DictTrans . Add ( new DictTransList ( ) { Trans = ( string ) Dict [ AvalonText . Text ] , MyIcon = PackIconUniconsKind . BookAlt } ) ;
269
- if ( TransCheckBox . IsOn )
270
- {
271
- count += 1 ;
272
- if ( count > 10 )
273
- {
274
- TransCheckBox . IsOn = false ;
275
- TransCloseTips ( ) ;
276
- }
277
- else
261
+ if ( Dict . ContainsKey ( AvalonText . Text ) )
262
+ foreach ( var value in Dict [ AvalonText . Text ] )
278
263
{
279
- var google = await TransApi . Google . Contect ( AvalonText . Text ) ;
280
- if ( google != "" ) dictObject . DictTrans . Add ( new DictTransList ( ) { Trans = google , MyIcon = PackIconUniconsKind . Google } ) ;
281
- try
282
- {
283
- var baidu = await TransApi . Baidu . Contect ( AvalonText . Text ) ;
284
- if ( baidu != "" ) dictObject . DictTrans . Add ( new DictTransList ( ) { Trans = baidu , MyIcon = PackIconUniconsKind . Bold } ) ;
285
- }
286
- catch ( Exception e )
287
- {
288
- // nothing :)
289
- }
264
+ dictObject . DictTrans . Add (
265
+ new DictTransList ( )
266
+ {
267
+ Trans = value ,
268
+ MyIcon = PackIconUniconsKind . BookAlt
269
+ } ) ;
290
270
}
291
- }
292
271
293
272
if ( dictObject . DictTrans . Count > 0 )
294
273
Dispatcher . Invoke ( ( ) =>
@@ -437,32 +416,28 @@ private void Grid_Loaded(object sender, RoutedEventArgs e)
437
416
438
417
ScrollViewer . ScrollToHorizontalOffset ( 0 ) ;
439
418
440
- if ( File . Exists ( "./dict.json" ) )
441
- Dict = SerialText ( File . ReadAllText ( "./dict.json" ) , out var deleted ) ;
442
-
443
- if ( File . Exists ( "./baidu.ini" ) )
419
+ if ( File . Exists ( "./Dict-Mini.json" ) )
420
+ Dict = JsonConvert . DeserializeObject < Dictionary < string , List < string > > > ( File . ReadAllText ( "./Dict-Mini.json" ) ) ;
421
+ // Dict = SerialText(File.ReadAllText("./Dict-Mini.json"), out var deleted);
422
+
423
+ var args = Environment . GetCommandLineArgs ( ) ;
424
+ if ( args . Length <= 1 ) return ;
425
+ FileDir = args [ 1 ] ;
426
+ var enDir = Path . Combine ( FileDir , "en_us.json" ) ;
427
+ var zhDir = Path . Combine ( FileDir , "zh_cn.json" ) ;
428
+ if ( File . Exists ( zhDir ) )
444
429
{
445
- string id = "" , key = "" ;
446
- // 读取百度翻译的配置文件,不用IniFile类
447
- var baiduIni = File . ReadAllText ( "./baidu.ini" ) ;
448
- var baiduIniLines = baiduIni . Split ( '\n ' ) ;
449
- foreach ( var line in baiduIniLines )
450
- {
451
- var lineSplit = line . Split ( '=' ) ;
452
- if ( lineSplit [ 0 ] == "id" )
453
- id = lineSplit [ 1 ] ;
454
- if ( lineSplit [ 0 ] == "key" )
455
- key = lineSplit [ 1 ] ;
456
- }
457
- // 判断id和key是否为空
458
- if ( id != "" && key != "" )
459
- {
460
- baidu = true ;
461
- TransApi . Baidu . SetTransAPI ( id , key ) ;
462
- // MessageBox.Show(id);
463
- // MessageBox.Show(key);
464
- }
430
+ var enAllText = File . ReadAllText ( enDir ) ;
431
+ var zhAllText = File . ReadAllText ( zhDir ) ;
432
+ SerialJson ( enAllText , zhAllText ) ;
465
433
}
434
+ else
435
+ {
436
+ var enAllText = File . ReadAllText ( enDir ) ;
437
+ SerialJson ( enAllText , "{}" ) ;
438
+ }
439
+ FirstPage . Visibility = Visibility . Hidden ;
440
+ SyncScrollPos ( ) ;
466
441
}
467
442
468
443
private List < string > formatList1 = new ( ) ;
@@ -544,8 +519,8 @@ private void MarkCheckBox_OnToggled(object sender, RoutedEventArgs e)
544
519
545
520
private async void TransCheckBox_OnToggled ( object sender , RoutedEventArgs e )
546
521
{
547
- count = 0 ;
548
- if ( TransCheckBox . IsOn ) TransTips . Visibility = Visibility . Hidden ;
522
+ // count = 0;
523
+ // if (TransCheckBox.IsOn) TransTips.Visibility = Visibility.Hidden;
549
524
await GetTransDict ( ) ;
550
525
}
551
526
@@ -577,7 +552,7 @@ private async void SearchWordList_OnSelectionChanged(object sender, SelectionCha
577
552
578
553
private void OpenGithubSite ( object sender , RoutedEventArgs e )
579
554
{
580
- Process . Start ( "https://github.com/Tryanks /Minecraft-Mods-Translator" ) ;
555
+ Process . Start ( "https://github.com/CFPATools /Minecraft-Mods-Translator" ) ;
581
556
}
582
557
}
583
558
0 commit comments