Skip to content

Commit

Permalink
add setting of serial numbering filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
katahiromz committed Apr 18, 2024
1 parent 9f34582 commit bd34d15
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 8 deletions.
96 changes: 91 additions & 5 deletions GUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,11 @@ enum {
// 音声ファイル。
WCHAR xg_aszSoundFiles[I_SOUND_MAX][MAX_PATH];

// 連番ファイル名1。
WCHAR xg_szNumberingFileName1[MAX_PATH];
// 連番ファイル名2。
WCHAR xg_szNumberingFileName2[MAX_PATH];

//////////////////////////////////////////////////////////////////////////////
// static variables

Expand Down Expand Up @@ -955,6 +960,9 @@ void XgResetSettings(void)
for (auto& item : xg_aszSoundFiles) {
item[0] = 0;
}

StringCchCopyW(xg_szNumberingFileName1, _countof(xg_szNumberingFileName1), L"Crossword-%Wx%H-%4N.xd");
StringCchCopyW(xg_szNumberingFileName2, _countof(xg_szNumberingFileName2), L"Pat-%Wx%H-%4N.xd");
}

// 設定を読み込む。
Expand Down Expand Up @@ -1243,6 +1251,12 @@ bool __fastcall XgLoadSettings(void)
StringCchCopy(xg_aszSoundFiles[2], _countof(xg_aszSoundFiles[2]), sz);
}
}
if (!app_key.QuerySz(L"NumberingFilename1", sz, _countof(sz))) {
StringCchCopy(xg_szNumberingFileName1, _countof(xg_szNumberingFileName1), sz);
}
if (!app_key.QuerySz(L"NumberingFilename2", sz, _countof(sz))) {
StringCchCopy(xg_szNumberingFileName2, _countof(xg_szNumberingFileName2), sz);
}

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

app_key.SetSz(L"NumberingFilename1", xg_szNumberingFileName1);
app_key.SetSz(L"NumberingFilename2", xg_szNumberingFileName2);

// 保存先のリストを設定する。
nCount = static_cast<int>(xg_dirs_save_to.size());
app_key.SetDword(L"SaveToCount", nCount);
Expand Down Expand Up @@ -2797,6 +2814,60 @@ BOOL __fastcall XgOnOpen(HWND hwnd)
return FALSE;
}

XGStringW __fastcall XgGenerateNumberingFilename(HWND hwnd, LPCWSTR pszText, LPSYSTEMTIME pLocalTime, INT iFile)
{
WCHAR szN[32], szN1[32], szN2[32], szN3[32], szN4[32], szN5[32], szN6[32];
WCHAR szW[32], szH[32];
WCHAR szYear[32], szMonth[32], szDay[32];
WCHAR szHour[32], szMinute[32], szSecond[32];
WCHAR szComputer[64], szUser[64];

XGStringW str = pszText;

StringCchPrintfW(szN, _countof(szN), L"%d", iFile);
StringCchPrintfW(szN1, _countof(szN1), L"%01d", iFile);
StringCchPrintfW(szN2, _countof(szN2), L"%02d", iFile);
StringCchPrintfW(szN3, _countof(szN3), L"%03d", iFile);
StringCchPrintfW(szN4, _countof(szN4), L"%04d", iFile);
StringCchPrintfW(szN5, _countof(szN5), L"%05d", iFile);
StringCchPrintfW(szN6, _countof(szN6), L"%06d", iFile);
xg_str_replace_all(str, L"%N", szN);
xg_str_replace_all(str, L"%1N", szN1);
xg_str_replace_all(str, L"%2N", szN2);
xg_str_replace_all(str, L"%3N", szN3);
xg_str_replace_all(str, L"%4N", szN4);
xg_str_replace_all(str, L"%5N", szN5);
xg_str_replace_all(str, L"%6N", szN6);

StringCchPrintfW(szW, _countof(szW), L"%d", xg_nCols);
StringCchPrintfW(szH, _countof(szH), L"%d", xg_nRows);
xg_str_replace_all(str, L"%W", szW);
xg_str_replace_all(str, L"%H", szH);

StringCchPrintfW(szYear, _countof(szYear), L"%04d", pLocalTime->wYear);
StringCchPrintfW(szMonth, _countof(szMonth), L"%02d", pLocalTime->wMonth);
StringCchPrintfW(szDay, _countof(szDay), L"%02d", pLocalTime->wDay);
StringCchPrintfW(szHour, _countof(szHour), L"%02d", pLocalTime->wHour);
StringCchPrintfW(szMinute, _countof(szMinute), L"%02d", pLocalTime->wMinute);
StringCchPrintfW(szSecond, _countof(szSecond), L"%02d", pLocalTime->wSecond);
xg_str_replace_all(str, L"%Y", szYear);
xg_str_replace_all(str, L"%M", szMonth);
xg_str_replace_all(str, L"%D", szDay);
xg_str_replace_all(str, L"%h", szHour);
xg_str_replace_all(str, L"%m", szMinute);
xg_str_replace_all(str, L"%s", szSecond);

DWORD cchComputer = _countof(szComputer);
GetComputerNameW(szComputer, &cchComputer);
xg_str_replace_all(str, L"%C", szComputer);

DWORD cchUser = _countof(szUser);
GetUserNameW(szUser, &cchUser);
xg_str_replace_all(str, L"%U", szUser);

return str;
}

// 連番保存。
BOOL __fastcall XgNumberingSave(HWND hwnd, BOOL bPattern)
{
Expand All @@ -2807,19 +2878,34 @@ BOOL __fastcall XgNumberingSave(HWND hwnd, BOOL bPattern)
WCHAR szFormat[MAX_PATH];
StringCchCopyW(szFormat, _countof(szFormat), pszDir);
if (bPattern)
PathAppendW(szFormat, L"Pat-%dx%d-%04u.xd");
PathAppendW(szFormat, xg_szNumberingFileName2);
else
PathAppendW(szFormat, L"Crossword-%dx%d-%04u.xd");
PathAppendW(szFormat, xg_szNumberingFileName1);

// 現在の日時を取得。
SYSTEMTIME stNow;
::GetLocalTime(&stNow);

WCHAR szPath[MAX_PATH];
XGStringW strPath, oldName;
for (INT iFile = 0; iFile <= 99999; ++iFile) {
StringCchPrintfW(szPath, _countof(szPath), szFormat, xg_nCols, xg_nRows, iFile);
if (!PathFileExistsW(szPath))
strPath = XgGenerateNumberingFilename(hwnd, szFormat, &stNow, iFile);
if (oldName == strPath)
{
StringCchCopyW(szPath, _countof(szPath), strPath.c_str());
XGStringW strDotExt = PathFindExtensionW(szPath);
PathRemoveExtensionW(szPath);
StringCchCatW(szPath, _countof(szPath), L"~");
PathAddExtensionW(szPath, strDotExt.c_str());
strPath = szPath;
}
if (!PathFileExistsW(strPath.c_str()))
break;
oldName = strPath;
}

// 保存する。
xg_strFileName = szPath;
xg_strFileName = strPath;
if (!XgOnSave(hwnd))
return FALSE;

Expand Down
5 changes: 5 additions & 0 deletions GUI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,9 @@ extern BOOL xg_bNoWriteLooks;
// 「テーマ」ダイアログを表示する。
void __fastcall XgTheme(HWND hwnd);

// 連番ファイル名1。
extern WCHAR xg_szNumberingFileName1[MAX_PATH];
// 連番ファイル名2。
extern WCHAR xg_szNumberingFileName2[MAX_PATH];

//////////////////////////////////////////////////////////////////////////////
2 changes: 2 additions & 0 deletions HISTORY.txt
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@
- Fixed the board not updating when dropping a LOOKS file.
- Fixed the reading and writing of block image in LOOKS files.
- 2024-XX-YY ver.5.2.4
- The serial number file name can be specified by the settings of file.

# 開発履歴 (Japanese)

Expand Down Expand Up @@ -949,3 +950,4 @@
- LOOKSファイルをドロップしたときに盤面が更新されなかったのを修正。
- LOOKSファイルの黒マス画像の読み書きを修正。
- 2024年XX月YY日 ver.5.2.4
- ファイルの設定で連番ファイル名を指定可能にした。
2 changes: 1 addition & 1 deletion XG_WordListDialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class XG_WordListDialog : public XG_Dialog

// 単語リストと辞書を取得する。
std::vector<XGStringW> items;
mstr_split(items, str, L" \t\r\n\x3000");
mstr_split(items, str, XG_WHITE_SPACES);
for (auto& item : items) {
// ハイフン、アポストロフィ、ピリオド、カンマ、カッコを取り除く。
XGStringW tmp;
Expand Down
34 changes: 34 additions & 0 deletions XgFileSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
INT_PTR CALLBACK
XgFileSettingsDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
HWND hCmb2, hCmb3;
switch (uMsg)
{
case WM_INITDIALOG:
Expand All @@ -22,6 +23,18 @@ XgFileSettingsDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
SendDlgItemMessage(hwnd, cmb1, CB_ADDSTRING, 0, (LPARAM)dir.c_str());
}
SendDlgItemMessage(hwnd, cmb1, CB_SETCURSEL, 0, 0);
// 連番ファイル名1。
hCmb2 = GetDlgItem(hwnd, cmb2);
ComboBox_AddString(hCmb2, L"Crossword-%Wx%H-%4N.xd");
ComboBox_AddString(hCmb2, L"Crossword-%5N.xd");
ComboBox_AddString(hCmb2, L"Crossword-%Y%M%D-%h%m%s-%2N.xd");
ComboBox_SetText(hCmb2, xg_szNumberingFileName1);
// 連番ファイル名2。
hCmb3 = GetDlgItem(hwnd, cmb3);
ComboBox_AddString(hCmb3, L"Pat-%Wx%H-%4N.xd");
ComboBox_AddString(hCmb3, L"Pat-%5N.xd");
ComboBox_AddString(hCmb3, L"Pat-%Y%M%D-%h%m%s-%2N.xd");
ComboBox_SetText(hCmb3, xg_szNumberingFileName2);
// ドラッグ&ドロップを受け付ける。
DragAcceptFiles(hwnd, TRUE);
return TRUE;
Expand All @@ -40,6 +53,8 @@ XgFileSettingsDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
}
break;
case cmb1:
case cmb2:
case cmb3:
if (HIWORD(wParam) == CBN_EDITCHANGE ||
HIWORD(wParam) == CBN_SELCHANGE ||
HIWORD(wParam) == CBN_SELENDOK)
Expand Down Expand Up @@ -113,6 +128,8 @@ XgFileSettingsDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
// テキストを取得する。
WCHAR szFile[MAX_PATH];
::GetDlgItemTextW(hwnd, cmb1, szFile, _countof(szFile));
// 前後の空白を取り除く。
StrTrimW(szFile, XG_WHITE_SPACES);

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

// 先頭に挿入。
xg_dirs_save_to.insert(xg_dirs_save_to.begin(), szFile);

// 連番ファイル名のテキストを取得する。
::GetDlgItemTextW(hwnd, cmb2, xg_szNumberingFileName1, _countof(xg_szNumberingFileName1));
::GetDlgItemTextW(hwnd, cmb3, xg_szNumberingFileName2, _countof(xg_szNumberingFileName2));

// 前後の空白を取り除く。
StrTrimW(xg_szNumberingFileName1, XG_WHITE_SPACES);
StrTrimW(xg_szNumberingFileName2, XG_WHITE_SPACES);

// 必要なら拡張子を付ける。
LPWSTR pch;
pch = PathFindExtensionW(xg_szNumberingFileName1);
if (!pch || !*pch)
PathAddExtensionW(xg_szNumberingFileName1, L".xd");
pch = PathFindExtensionW(xg_szNumberingFileName2);
if (!pch || !*pch)
PathAddExtensionW(xg_szNumberingFileName2, L".xd");
}
break;
}
Expand Down
2 changes: 1 addition & 1 deletion XgViewSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ XgViewSettingsDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
WCHAR szText2[128];
::LCMapStringW(::GetUserDefaultLCID(), LCMAP_HALFWIDTH, szText, _countof(szText),
szText2, _countof(szText2));
StrTrimW(szText2, L" \t\r\n\x3000");
StrTrimW(szText2, XG_WHITE_SPACES);
INT nRate = _wtoi(szText2);
if (nRate == 0)
nRate = 100;
Expand Down
6 changes: 5 additions & 1 deletion lang/en_US.rc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ LANGUAGE LANG_ENGLISH, SUBLANG_DEFAULT
MENUITEM "&Open...\tCtrl+O", ID_OPEN
MENUITEM "Save\tCtrl+S", ID_SAVE
MENUITEM "Save &as...\tCtrl+Shift+S", ID_SAVEAS
MENUITEM "&Numbering save\tCtrl+Alt+S", ID_NUMBERINGSAVE
MENUITEM "Serial &numbering save\tCtrl+Alt+S", ID_NUMBERINGSAVE
MENUITEM SEPARATOR
MENUITEM "Save as &image...\tCtrl+I", ID_SAVEPROBASIMAGE
MENUITEM "Save answer &as image...\tCtrl+B", ID_SAVEANSASIMAGE
Expand Down Expand Up @@ -1504,6 +1504,10 @@ FONT 9, "Tahoma"
PUSHBUTTON "Open &Folder", psh2, 110, 100, 95, 15
AUTOCHECKBOX "Do not &read LOOKS information from file", chx4, 10, 125, 195, 15
AUTOCHECKBOX "Do not &write LOOKS information to file", chx5, 10, 145, 195, 15
LTEXT "Serial numbering filename &1:", -1, 10, 180, 110, 15, SS_CENTERIMAGE | NOT WS_GROUP
COMBOBOX cmb2, 10, 200, 110, 300, CBS_HASSTRINGS | CBS_AUTOHSCROLL | CBS_DROPDOWN | WS_VSCROLL | WS_TABSTOP
LTEXT "Serial numbering filename &2:", -1, 140, 180, 110, 15, SS_CENTERIMAGE | NOT WS_GROUP
COMBOBOX cmb3, 140, 200, 110, 300, CBS_HASSTRINGS | CBS_AUTOHSCROLL | CBS_DROPDOWN | WS_VSCROLL | WS_TABSTOP
}

IDD_VIEWSETTINGS DIALOG 0, 0, 220, 190
Expand Down
4 changes: 4 additions & 0 deletions lang/ja_JP.rc
Original file line number Diff line number Diff line change
Expand Up @@ -1508,6 +1508,10 @@ FONT 9, "MS UI Gothic"
PUSHBUTTON "フォルダを開く(&F)", psh2, 110, 100, 95, 15
AUTOCHECKBOX "ファイルからLOOKS情報を読み込まない(&R)", chx4, 10, 125, 195, 15
AUTOCHECKBOX "ファイルへLOOKS情報を書き込まない(&W)", chx5, 10, 145, 195, 15
LTEXT "連番ファイル名&1:", -1, 10, 180, 110, 15, SS_CENTERIMAGE
COMBOBOX cmb2, 10, 200, 110, 300, CBS_HASSTRINGS | CBS_AUTOHSCROLL | CBS_DROPDOWN | WS_VSCROLL | WS_TABSTOP
LTEXT "連番ファイル名&2:", -1, 140, 180, 110, 15, SS_CENTERIMAGE
COMBOBOX cmb3, 140, 200, 110, 300, CBS_HASSTRINGS | CBS_AUTOHSCROLL | CBS_DROPDOWN | WS_VSCROLL | WS_TABSTOP
}

IDD_VIEWSETTINGS DIALOG 0, 0, 220, 190
Expand Down

0 comments on commit bd34d15

Please sign in to comment.