Skip to content

Commit bd34d15

Browse files
committed
add setting of serial numbering filenames
1 parent 9f34582 commit bd34d15

File tree

8 files changed

+143
-8
lines changed

8 files changed

+143
-8
lines changed

GUI.cpp

Lines changed: 91 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,11 @@ enum {
287287
// 音声ファイル。
288288
WCHAR xg_aszSoundFiles[I_SOUND_MAX][MAX_PATH];
289289

290+
// 連番ファイル名1。
291+
WCHAR xg_szNumberingFileName1[MAX_PATH];
292+
// 連番ファイル名2。
293+
WCHAR xg_szNumberingFileName2[MAX_PATH];
294+
290295
//////////////////////////////////////////////////////////////////////////////
291296
// static variables
292297

@@ -955,6 +960,9 @@ void XgResetSettings(void)
955960
for (auto& item : xg_aszSoundFiles) {
956961
item[0] = 0;
957962
}
963+
964+
StringCchCopyW(xg_szNumberingFileName1, _countof(xg_szNumberingFileName1), L"Crossword-%Wx%H-%4N.xd");
965+
StringCchCopyW(xg_szNumberingFileName2, _countof(xg_szNumberingFileName2), L"Pat-%Wx%H-%4N.xd");
958966
}
959967

960968
// 設定を読み込む。
@@ -1243,6 +1251,12 @@ bool __fastcall XgLoadSettings(void)
12431251
StringCchCopy(xg_aszSoundFiles[2], _countof(xg_aszSoundFiles[2]), sz);
12441252
}
12451253
}
1254+
if (!app_key.QuerySz(L"NumberingFilename1", sz, _countof(sz))) {
1255+
StringCchCopy(xg_szNumberingFileName1, _countof(xg_szNumberingFileName1), sz);
1256+
}
1257+
if (!app_key.QuerySz(L"NumberingFilename2", sz, _countof(sz))) {
1258+
StringCchCopy(xg_szNumberingFileName2, _countof(xg_szNumberingFileName2), sz);
1259+
}
12461260

12471261
// 保存先のリストを取得する。
12481262
if (!app_key.QueryDword(L"SaveToCount", dwValue)) {
@@ -1371,6 +1385,9 @@ bool __fastcall XgSaveSettings(void)
13711385
app_key.SetSz(L"SoundFile1", xg_aszSoundFiles[1]);
13721386
app_key.SetSz(L"SoundFile2", xg_aszSoundFiles[2]);
13731387

1388+
app_key.SetSz(L"NumberingFilename1", xg_szNumberingFileName1);
1389+
app_key.SetSz(L"NumberingFilename2", xg_szNumberingFileName2);
1390+
13741391
// 保存先のリストを設定する。
13751392
nCount = static_cast<int>(xg_dirs_save_to.size());
13761393
app_key.SetDword(L"SaveToCount", nCount);
@@ -2797,6 +2814,60 @@ BOOL __fastcall XgOnOpen(HWND hwnd)
27972814
return FALSE;
27982815
}
27992816

2817+
XGStringW __fastcall XgGenerateNumberingFilename(HWND hwnd, LPCWSTR pszText, LPSYSTEMTIME pLocalTime, INT iFile)
2818+
{
2819+
WCHAR szN[32], szN1[32], szN2[32], szN3[32], szN4[32], szN5[32], szN6[32];
2820+
WCHAR szW[32], szH[32];
2821+
WCHAR szYear[32], szMonth[32], szDay[32];
2822+
WCHAR szHour[32], szMinute[32], szSecond[32];
2823+
WCHAR szComputer[64], szUser[64];
2824+
2825+
XGStringW str = pszText;
2826+
2827+
StringCchPrintfW(szN, _countof(szN), L"%d", iFile);
2828+
StringCchPrintfW(szN1, _countof(szN1), L"%01d", iFile);
2829+
StringCchPrintfW(szN2, _countof(szN2), L"%02d", iFile);
2830+
StringCchPrintfW(szN3, _countof(szN3), L"%03d", iFile);
2831+
StringCchPrintfW(szN4, _countof(szN4), L"%04d", iFile);
2832+
StringCchPrintfW(szN5, _countof(szN5), L"%05d", iFile);
2833+
StringCchPrintfW(szN6, _countof(szN6), L"%06d", iFile);
2834+
xg_str_replace_all(str, L"%N", szN);
2835+
xg_str_replace_all(str, L"%1N", szN1);
2836+
xg_str_replace_all(str, L"%2N", szN2);
2837+
xg_str_replace_all(str, L"%3N", szN3);
2838+
xg_str_replace_all(str, L"%4N", szN4);
2839+
xg_str_replace_all(str, L"%5N", szN5);
2840+
xg_str_replace_all(str, L"%6N", szN6);
2841+
2842+
StringCchPrintfW(szW, _countof(szW), L"%d", xg_nCols);
2843+
StringCchPrintfW(szH, _countof(szH), L"%d", xg_nRows);
2844+
xg_str_replace_all(str, L"%W", szW);
2845+
xg_str_replace_all(str, L"%H", szH);
2846+
2847+
StringCchPrintfW(szYear, _countof(szYear), L"%04d", pLocalTime->wYear);
2848+
StringCchPrintfW(szMonth, _countof(szMonth), L"%02d", pLocalTime->wMonth);
2849+
StringCchPrintfW(szDay, _countof(szDay), L"%02d", pLocalTime->wDay);
2850+
StringCchPrintfW(szHour, _countof(szHour), L"%02d", pLocalTime->wHour);
2851+
StringCchPrintfW(szMinute, _countof(szMinute), L"%02d", pLocalTime->wMinute);
2852+
StringCchPrintfW(szSecond, _countof(szSecond), L"%02d", pLocalTime->wSecond);
2853+
xg_str_replace_all(str, L"%Y", szYear);
2854+
xg_str_replace_all(str, L"%M", szMonth);
2855+
xg_str_replace_all(str, L"%D", szDay);
2856+
xg_str_replace_all(str, L"%h", szHour);
2857+
xg_str_replace_all(str, L"%m", szMinute);
2858+
xg_str_replace_all(str, L"%s", szSecond);
2859+
2860+
DWORD cchComputer = _countof(szComputer);
2861+
GetComputerNameW(szComputer, &cchComputer);
2862+
xg_str_replace_all(str, L"%C", szComputer);
2863+
2864+
DWORD cchUser = _countof(szUser);
2865+
GetUserNameW(szUser, &cchUser);
2866+
xg_str_replace_all(str, L"%U", szUser);
2867+
2868+
return str;
2869+
}
2870+
28002871
// 連番保存。
28012872
BOOL __fastcall XgNumberingSave(HWND hwnd, BOOL bPattern)
28022873
{
@@ -2807,19 +2878,34 @@ BOOL __fastcall XgNumberingSave(HWND hwnd, BOOL bPattern)
28072878
WCHAR szFormat[MAX_PATH];
28082879
StringCchCopyW(szFormat, _countof(szFormat), pszDir);
28092880
if (bPattern)
2810-
PathAppendW(szFormat, L"Pat-%dx%d-%04u.xd");
2881+
PathAppendW(szFormat, xg_szNumberingFileName2);
28112882
else
2812-
PathAppendW(szFormat, L"Crossword-%dx%d-%04u.xd");
2883+
PathAppendW(szFormat, xg_szNumberingFileName1);
2884+
2885+
// 現在の日時を取得。
2886+
SYSTEMTIME stNow;
2887+
::GetLocalTime(&stNow);
28132888

28142889
WCHAR szPath[MAX_PATH];
2890+
XGStringW strPath, oldName;
28152891
for (INT iFile = 0; iFile <= 99999; ++iFile) {
2816-
StringCchPrintfW(szPath, _countof(szPath), szFormat, xg_nCols, xg_nRows, iFile);
2817-
if (!PathFileExistsW(szPath))
2892+
strPath = XgGenerateNumberingFilename(hwnd, szFormat, &stNow, iFile);
2893+
if (oldName == strPath)
2894+
{
2895+
StringCchCopyW(szPath, _countof(szPath), strPath.c_str());
2896+
XGStringW strDotExt = PathFindExtensionW(szPath);
2897+
PathRemoveExtensionW(szPath);
2898+
StringCchCatW(szPath, _countof(szPath), L"~");
2899+
PathAddExtensionW(szPath, strDotExt.c_str());
2900+
strPath = szPath;
2901+
}
2902+
if (!PathFileExistsW(strPath.c_str()))
28182903
break;
2904+
oldName = strPath;
28192905
}
28202906

28212907
// 保存する。
2822-
xg_strFileName = szPath;
2908+
xg_strFileName = strPath;
28232909
if (!XgOnSave(hwnd))
28242910
return FALSE;
28252911

GUI.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,9 @@ extern BOOL xg_bNoWriteLooks;
105105
// 「テーマ」ダイアログを表示する。
106106
void __fastcall XgTheme(HWND hwnd);
107107

108+
// 連番ファイル名1。
109+
extern WCHAR xg_szNumberingFileName1[MAX_PATH];
110+
// 連番ファイル名2。
111+
extern WCHAR xg_szNumberingFileName2[MAX_PATH];
112+
108113
//////////////////////////////////////////////////////////////////////////////

HISTORY.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@
315315
- Fixed the board not updating when dropping a LOOKS file.
316316
- Fixed the reading and writing of block image in LOOKS files.
317317
- 2024-XX-YY ver.5.2.4
318+
- The serial number file name can be specified by the settings of file.
318319

319320
# 開発履歴 (Japanese)
320321

@@ -949,3 +950,4 @@
949950
- LOOKSファイルをドロップしたときに盤面が更新されなかったのを修正。
950951
- LOOKSファイルの黒マス画像の読み書きを修正。
951952
- 2024年XX月YY日 ver.5.2.4
953+
- ファイルの設定で連番ファイル名を指定可能にした。

XG_WordListDialog.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class XG_WordListDialog : public XG_Dialog
7878

7979
// 単語リストと辞書を取得する。
8080
std::vector<XGStringW> items;
81-
mstr_split(items, str, L" \t\r\n\x3000");
81+
mstr_split(items, str, XG_WHITE_SPACES);
8282
for (auto& item : items) {
8383
// ハイフン、アポストロフィ、ピリオド、カンマ、カッコを取り除く。
8484
XGStringW tmp;

XgFileSettings.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
INT_PTR CALLBACK
33
XgFileSettingsDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
44
{
5+
HWND hCmb2, hCmb3;
56
switch (uMsg)
67
{
78
case WM_INITDIALOG:
@@ -22,6 +23,18 @@ XgFileSettingsDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2223
SendDlgItemMessage(hwnd, cmb1, CB_ADDSTRING, 0, (LPARAM)dir.c_str());
2324
}
2425
SendDlgItemMessage(hwnd, cmb1, CB_SETCURSEL, 0, 0);
26+
// 連番ファイル名1。
27+
hCmb2 = GetDlgItem(hwnd, cmb2);
28+
ComboBox_AddString(hCmb2, L"Crossword-%Wx%H-%4N.xd");
29+
ComboBox_AddString(hCmb2, L"Crossword-%5N.xd");
30+
ComboBox_AddString(hCmb2, L"Crossword-%Y%M%D-%h%m%s-%2N.xd");
31+
ComboBox_SetText(hCmb2, xg_szNumberingFileName1);
32+
// 連番ファイル名2。
33+
hCmb3 = GetDlgItem(hwnd, cmb3);
34+
ComboBox_AddString(hCmb3, L"Pat-%Wx%H-%4N.xd");
35+
ComboBox_AddString(hCmb3, L"Pat-%5N.xd");
36+
ComboBox_AddString(hCmb3, L"Pat-%Y%M%D-%h%m%s-%2N.xd");
37+
ComboBox_SetText(hCmb3, xg_szNumberingFileName2);
2538
// ドラッグ&ドロップを受け付ける。
2639
DragAcceptFiles(hwnd, TRUE);
2740
return TRUE;
@@ -40,6 +53,8 @@ XgFileSettingsDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
4053
}
4154
break;
4255
case cmb1:
56+
case cmb2:
57+
case cmb3:
4358
if (HIWORD(wParam) == CBN_EDITCHANGE ||
4459
HIWORD(wParam) == CBN_SELCHANGE ||
4560
HIWORD(wParam) == CBN_SELENDOK)
@@ -113,6 +128,8 @@ XgFileSettingsDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
113128
// テキストを取得する。
114129
WCHAR szFile[MAX_PATH];
115130
::GetDlgItemTextW(hwnd, cmb1, szFile, _countof(szFile));
131+
// 前後の空白を取り除く。
132+
StrTrimW(szFile, XG_WHITE_SPACES);
116133

117134
// 一致する項目を削除する。
118135
INT i = 0;
@@ -126,6 +143,23 @@ XgFileSettingsDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
126143

127144
// 先頭に挿入。
128145
xg_dirs_save_to.insert(xg_dirs_save_to.begin(), szFile);
146+
147+
// 連番ファイル名のテキストを取得する。
148+
::GetDlgItemTextW(hwnd, cmb2, xg_szNumberingFileName1, _countof(xg_szNumberingFileName1));
149+
::GetDlgItemTextW(hwnd, cmb3, xg_szNumberingFileName2, _countof(xg_szNumberingFileName2));
150+
151+
// 前後の空白を取り除く。
152+
StrTrimW(xg_szNumberingFileName1, XG_WHITE_SPACES);
153+
StrTrimW(xg_szNumberingFileName2, XG_WHITE_SPACES);
154+
155+
// 必要なら拡張子を付ける。
156+
LPWSTR pch;
157+
pch = PathFindExtensionW(xg_szNumberingFileName1);
158+
if (!pch || !*pch)
159+
PathAddExtensionW(xg_szNumberingFileName1, L".xd");
160+
pch = PathFindExtensionW(xg_szNumberingFileName2);
161+
if (!pch || !*pch)
162+
PathAddExtensionW(xg_szNumberingFileName2, L".xd");
129163
}
130164
break;
131165
}

XgViewSettings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ XgViewSettingsDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
182182
WCHAR szText2[128];
183183
::LCMapStringW(::GetUserDefaultLCID(), LCMAP_HALFWIDTH, szText, _countof(szText),
184184
szText2, _countof(szText2));
185-
StrTrimW(szText2, L" \t\r\n\x3000");
185+
StrTrimW(szText2, XG_WHITE_SPACES);
186186
INT nRate = _wtoi(szText2);
187187
if (nRate == 0)
188188
nRate = 100;

lang/en_US.rc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ LANGUAGE LANG_ENGLISH, SUBLANG_DEFAULT
2121
MENUITEM "&Open...\tCtrl+O", ID_OPEN
2222
MENUITEM "Save\tCtrl+S", ID_SAVE
2323
MENUITEM "Save &as...\tCtrl+Shift+S", ID_SAVEAS
24-
MENUITEM "&Numbering save\tCtrl+Alt+S", ID_NUMBERINGSAVE
24+
MENUITEM "Serial &numbering save\tCtrl+Alt+S", ID_NUMBERINGSAVE
2525
MENUITEM SEPARATOR
2626
MENUITEM "Save as &image...\tCtrl+I", ID_SAVEPROBASIMAGE
2727
MENUITEM "Save answer &as image...\tCtrl+B", ID_SAVEANSASIMAGE
@@ -1504,6 +1504,10 @@ FONT 9, "Tahoma"
15041504
PUSHBUTTON "Open &Folder", psh2, 110, 100, 95, 15
15051505
AUTOCHECKBOX "Do not &read LOOKS information from file", chx4, 10, 125, 195, 15
15061506
AUTOCHECKBOX "Do not &write LOOKS information to file", chx5, 10, 145, 195, 15
1507+
LTEXT "Serial numbering filename &1:", -1, 10, 180, 110, 15, SS_CENTERIMAGE | NOT WS_GROUP
1508+
COMBOBOX cmb2, 10, 200, 110, 300, CBS_HASSTRINGS | CBS_AUTOHSCROLL | CBS_DROPDOWN | WS_VSCROLL | WS_TABSTOP
1509+
LTEXT "Serial numbering filename &2:", -1, 140, 180, 110, 15, SS_CENTERIMAGE | NOT WS_GROUP
1510+
COMBOBOX cmb3, 140, 200, 110, 300, CBS_HASSTRINGS | CBS_AUTOHSCROLL | CBS_DROPDOWN | WS_VSCROLL | WS_TABSTOP
15071511
}
15081512

15091513
IDD_VIEWSETTINGS DIALOG 0, 0, 220, 190

lang/ja_JP.rc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,6 +1508,10 @@ FONT 9, "MS UI Gothic"
15081508
PUSHBUTTON "フォルダを開く(&F)", psh2, 110, 100, 95, 15
15091509
AUTOCHECKBOX "ファイルからLOOKS情報を読み込まない(&R)", chx4, 10, 125, 195, 15
15101510
AUTOCHECKBOX "ファイルへLOOKS情報を書き込まない(&W)", chx5, 10, 145, 195, 15
1511+
LTEXT "連番ファイル名&1:", -1, 10, 180, 110, 15, SS_CENTERIMAGE
1512+
COMBOBOX cmb2, 10, 200, 110, 300, CBS_HASSTRINGS | CBS_AUTOHSCROLL | CBS_DROPDOWN | WS_VSCROLL | WS_TABSTOP
1513+
LTEXT "連番ファイル名&2:", -1, 140, 180, 110, 15, SS_CENTERIMAGE
1514+
COMBOBOX cmb3, 140, 200, 110, 300, CBS_HASSTRINGS | CBS_AUTOHSCROLL | CBS_DROPDOWN | WS_VSCROLL | WS_TABSTOP
15111515
}
15121516

15131517
IDD_VIEWSETTINGS DIALOG 0, 0, 220, 190

0 commit comments

Comments
 (0)