Skip to content

Commit 9ad574d

Browse files
committed
improve
1 parent 5c9f45d commit 9ad574d

File tree

5 files changed

+39
-17
lines changed

5 files changed

+39
-17
lines changed

Dictionary.cpp

+33-8
Original file line numberDiff line numberDiff line change
@@ -588,13 +588,14 @@ void XgSelectDict(HWND hwnd, size_t iDict)
588588
// カギを使って辞書を更新する。
589589
BOOL XgUpdateDictionaryUsingClues(HWND hwnd, const XGStringW& dict_name)
590590
{
591-
// カギがなければ失敗。
592-
if (!xg_bSolved || xg_vecHorzHints.empty() || xg_vecVertHints.empty())
593-
return FALSE;
591+
WCHAR szText[MAX_PATH];
594592

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);
597597
return FALSE;
598+
}
598599

599600
// 単語からヒントへの写像を作成する。
600601
std::map<XGStringW, XGStringW> word_to_hint_map;
@@ -607,8 +608,10 @@ BOOL XgUpdateDictionaryUsingClues(HWND hwnd, const XGStringW& dict_name)
607608

608609
// 辞書ファイルをすべて読み込む。
609610
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);
611613
return FALSE;
614+
}
612615

613616
// 改行コードを正規化。
614617
xg_str_replace_all(str, L"\r\n", L"\n");
@@ -618,6 +621,7 @@ BOOL XgUpdateDictionaryUsingClues(HWND hwnd, const XGStringW& dict_name)
618621
mstr_split(lines, str, L"\n");
619622

620623
// 一行ずつ処理する。
624+
BOOL bNoChange = TRUE;
621625
for (auto& line : lines) {
622626
if (line[0] == L'#')
623627
continue;
@@ -636,7 +640,11 @@ BOOL XgUpdateDictionaryUsingClues(HWND hwnd, const XGStringW& dict_name)
636640
if (it != word_to_hint_map.end()) {
637641
fields[1] = it->second;
638642
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+
}
640648
}
641649
}
642650

@@ -646,12 +654,24 @@ BOOL XgUpdateDictionaryUsingClues(HWND hwnd, const XGStringW& dict_name)
646654
line += pair.second;
647655
line += L'\n';
648656
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;
649664
}
650665

651666
// 辞書ファイルに書き込む。
652667
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);
654673
return FALSE;
674+
}
655675

656676
fprintf(fp, "\xEF\xBB\xBF"); // UTF-8 BOM
657677

@@ -664,5 +684,10 @@ BOOL XgUpdateDictionaryUsingClues(HWND hwnd, const XGStringW& dict_name)
664684

665685
fclose(fp);
666686

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+
667692
return TRUE;
668693
}

XG_HiddenDialog.cpp

-9
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,10 @@ class XG_HiddenDialog
5858
break;
5959
case psh4: // カギを使って辞書を更新する。
6060
if (codeNotify == BN_CLICKED) {
61-
WCHAR szText[MAX_PATH * 2];
6261
HCURSOR hOldCursor = ::SetCursor(::LoadCursor(NULL, IDC_WAIT));
6362
XG_HintsWnd::UpdateHintData(); // ヒントに変更があれば、更新する。
6463
if (XgUpdateDictionaryUsingClues(hwnd, xg_dict_name)) {
65-
// 成功メッセージ。
66-
StringCchPrintfW(szText, _countof(szText), XgLoadStringDx1(IDS_UPDATEDICTOK),
67-
PathFindFileNameW(xg_dict_name.c_str()));
68-
XgCenterMessageBoxW(hwnd, szText, XgLoadStringDx2(IDS_APPNAME), MB_ICONINFORMATION);
6964
} else {
70-
// 失敗メッセージ。
71-
StringCchPrintfW(szText, _countof(szText), XgLoadStringDx1(IDS_UPDATEDICTFAIL),
72-
PathFindFileNameW(xg_dict_name.c_str()));
73-
XgCenterMessageBoxW(hwnd, szText, nullptr, MB_ICONERROR);
7465
}
7566
::SetCursor(hOldCursor);
7667
}

lang/en_US.rc

+2
Original file line numberDiff line numberDiff line change
@@ -1831,6 +1831,8 @@ STRINGTABLE
18311831
IDS_UPDATEDTIME, "Updated Time"
18321832
IDS_UPDATEDICTOK, "Successfully wrote to dictionary file ""%s""."
18331833
IDS_UPDATEDICTFAIL, "Failed to write to dictionary file ""%s"". The folder may not be writable."
1834+
IDS_NOCHANGE, "There is no change."
1835+
IDS_NODICTSELECTED, "No dictionary selected, or unable to load the dictionary."
18341836
IDS_TT_NEW, "New crossword"
18351837
IDS_TT_GENERATE, "Generate crossword"
18361838
IDS_TT_OPEN, "Open crossword"

lang/ja_JP.rc

+2
Original file line numberDiff line numberDiff line change
@@ -1835,6 +1835,8 @@ STRINGTABLE
18351835
IDS_UPDATEDTIME, "更新日時"
18361836
IDS_UPDATEDICTOK, "辞書ファイル「%s」への書き込みに成功しました。"
18371837
IDS_UPDATEDICTFAIL, "辞書ファイル「%s」への書き込みに失敗しました。書き込めないフォルダの可能性があります。"
1838+
IDS_NOCHANGE, "変更点はありません。"
1839+
IDS_NODICTSELECTED, "辞書が選択されていないか、読み込めません。"
18381840
IDS_TT_NEW, "新規作成"
18391841
IDS_TT_GENERATE, "問題を自動生成する"
18401842
IDS_TT_OPEN, "問題を開く"

resource.h

+2
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@
257257
#define IDS_UPDATEDTIME 334
258258
#define IDS_UPDATEDICTOK 335
259259
#define IDS_UPDATEDICTFAIL 336
260+
#define IDS_NOCHANGE 337
261+
#define IDS_NODICTSELECTED 338
260262
#define IDS_TT_NEW 10100
261263
#define IDS_TT_GENERATE 10101
262264
#define IDS_TT_OPEN 10102

0 commit comments

Comments
 (0)