@@ -588,13 +588,14 @@ void XgSelectDict(HWND hwnd, size_t iDict)
588
588
// カギを使って辞書を更新する。
589
589
BOOL XgUpdateDictionaryUsingClues (HWND hwnd, const XGStringW& dict_name)
590
590
{
591
- // カギがなければ失敗。
592
- if (!xg_bSolved || xg_vecHorzHints.empty () || xg_vecVertHints.empty ())
593
- return FALSE ;
591
+ WCHAR szText[MAX_PATH];
594
592
595
- // 辞書名がなければ失敗。
596
- if (dict_name.empty ())
593
+ // カギがなければ失敗。
594
+ if (!xg_bSolved || xg_vecHorzHints.empty () || xg_vecVertHints.empty ()) {
595
+ XgCenterMessageBoxW (hwnd, XgLoadStringDx1 (IDS_NOCHANGE),
596
+ XgLoadStringDx2 (IDS_APPNAME), MB_ICONINFORMATION);
597
597
return FALSE ;
598
+ }
598
599
599
600
// 単語からヒントへの写像を作成する。
600
601
std::map<XGStringW, XGStringW> word_to_hint_map;
@@ -607,8 +608,10 @@ BOOL XgUpdateDictionaryUsingClues(HWND hwnd, const XGStringW& dict_name)
607
608
608
609
// 辞書ファイルをすべて読み込む。
609
610
XGStringW str;
610
- if (!XgReadTextFileAll (dict_name.c_str (), str))
611
+ if (dict_name.empty () || !XgReadTextFileAll (dict_name.c_str (), str)) {
612
+ XgCenterMessageBoxW (hwnd, XgLoadStringDx1 (IDS_NODICTSELECTED), NULL , MB_ICONERROR);
611
613
return FALSE ;
614
+ }
612
615
613
616
// 改行コードを正規化。
614
617
xg_str_replace_all (str, L" \r\n " , L" \n " );
@@ -618,6 +621,7 @@ BOOL XgUpdateDictionaryUsingClues(HWND hwnd, const XGStringW& dict_name)
618
621
mstr_split (lines, str, L" \n " );
619
622
620
623
// 一行ずつ処理する。
624
+ BOOL bNoChange = TRUE ;
621
625
for (auto & line : lines) {
622
626
if (line[0 ] == L' #' )
623
627
continue ;
@@ -636,7 +640,11 @@ BOOL XgUpdateDictionaryUsingClues(HWND hwnd, const XGStringW& dict_name)
636
640
if (it != word_to_hint_map.end ()) {
637
641
fields[1 ] = it->second ;
638
642
word_to_hint_map.erase (it);
639
- line = mstr_join (fields, L" \t " );
643
+ auto strNew = mstr_join (fields, L" \t " );
644
+ if (line != strNew) {
645
+ line = strNew;
646
+ bNoChange = FALSE ;
647
+ }
640
648
}
641
649
}
642
650
@@ -646,12 +654,24 @@ BOOL XgUpdateDictionaryUsingClues(HWND hwnd, const XGStringW& dict_name)
646
654
line += pair.second ;
647
655
line += L' \n ' ;
648
656
lines.push_back (line);
657
+ bNoChange = FALSE ;
658
+ }
659
+
660
+ if (bNoChange) {
661
+ XgCenterMessageBoxW (hwnd, XgLoadStringDx1 (IDS_NOCHANGE),
662
+ XgLoadStringDx2 (IDS_APPNAME), MB_ICONINFORMATION);
663
+ return FALSE ;
649
664
}
650
665
651
666
// 辞書ファイルに書き込む。
652
667
FILE *fp = _wfopen (dict_name.c_str (), L" w" );
653
- if (!fp)
668
+ if (!fp) {
669
+ // 失敗メッセージ。
670
+ StringCchPrintfW (szText, _countof (szText), XgLoadStringDx1 (IDS_UPDATEDICTFAIL),
671
+ PathFindFileNameW (xg_dict_name.c_str ()));
672
+ XgCenterMessageBoxW (hwnd, szText, nullptr , MB_ICONERROR);
654
673
return FALSE ;
674
+ }
655
675
656
676
fprintf (fp, " \xEF\xBB\xBF " ); // UTF-8 BOM
657
677
@@ -664,5 +684,10 @@ BOOL XgUpdateDictionaryUsingClues(HWND hwnd, const XGStringW& dict_name)
664
684
665
685
fclose (fp);
666
686
687
+ // 成功メッセージ。
688
+ StringCchPrintfW (szText, _countof (szText), XgLoadStringDx1 (IDS_UPDATEDICTOK),
689
+ PathFindFileNameW (xg_dict_name.c_str ()));
690
+ XgCenterMessageBoxW (hwnd, szText, XgLoadStringDx2 (IDS_APPNAME), MB_ICONINFORMATION);
691
+
667
692
return TRUE ;
668
693
}
0 commit comments