aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-08-07 00:40:48 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-08-07 00:40:48 +0200
commite2d0b92ffc536c3d34ee751ba688946613bc5693 (patch)
treec944a70b4db4ed5b8ec9a440335a42fb86602972
parentbea4e9f8740c1bf3ebe80d95ab6e749cfb5de605 (diff)
downloadEpisodeBrowser-e2d0b92ffc536c3d34ee751ba688946613bc5693.tar.gz
Add Strcpy.
-rw-r--r--c/main.cpp27
-rw-r--r--c/util.h7
2 files changed, 21 insertions, 13 deletions
diff --git a/c/main.cpp b/c/main.cpp
index 449863b..5a7ec27 100644
--- a/c/main.cpp
+++ b/c/main.cpp
@@ -215,7 +215,7 @@ static LRESULT CALLBACK CBTProc(const int nCode, const WPARAM wParam, const LPAR
Mark m;
char* s;
if (Pl("cfg","get_limit_screenwriter",&s))
- strcpy_s(g_limitScreenwriter, sizeof(g_limitScreenwriter), s);
+ Strcpy(g_limitScreenwriter, s);
int dlvHeight = 0;
Pl("cfg","get_dlv_height",&dlvHeight);
@@ -418,18 +418,19 @@ void HandleMainMenu(const HWND hWnd, const WORD command)
g_elv->Update();
g_elv->EnsureFocusVisible();
break;
- case IDM_VIEW_OTHERS: /* Show/hide other screenwriters. */
- if (g_limitScreenwriter[0]) {
+ case IDM_VIEW_OTHERS:
+ if (g_limitScreenwriter[0]) { /* Show episodes by all screenwriters. */
CheckMenuItem(GetMenu(hWnd), IDM_VIEW_OTHERS, MF_CHECKED);
g_limitScreenwriter[0] = 0;
- } else {
- LVITEM lvi = {LVIF_PARAM, -1};
- if (!g_elv->FindNextItem(&lvi, LVNI_FOCUSED)) break;
-
+ } else { /* Hide episodes by other screenwriters than current. */
+ Mark m;
char* s;
- if (!Pl("episode_data","episode_datum",lvi.lParam,"Screenwriter",&s)) break;
- strcpy_s(g_limitScreenwriter, sizeof(g_limitScreenwriter), s);
- CheckMenuItem(GetMenu(hWnd), IDM_VIEW_OTHERS, MF_UNCHECKED);
+ LVITEM lvi = {LVIF_PARAM, -1};
+ if (g_elv->FindNextItem(&lvi, LVNI_FOCUSED)
+ && Pl("episode_data","episode_datum",lvi.lParam,"Screenwriter",&s)) {
+ Strcpy(g_limitScreenwriter, s);
+ CheckMenuItem(GetMenu(hWnd), IDM_VIEW_OTHERS, MF_UNCHECKED);
+ }
}
Pl("cfg","set_limit_screenwriter",g_limitScreenwriter);
g_elv->Update();
@@ -484,8 +485,7 @@ void HandleContextMenu(const HWND, const WORD command)
g_elv->Redraw();
if (cNotFound == 1) {
- EBMessageBox(L"Episode could not be opened locally.",
- L"Error", MB_ICONWARNING);
+ EBMessageBox(L"Episode could not be opened locally.", L"Error", MB_ICONWARNING);
} else if (cNotFound) {
wchar_t msg[64] = {0};
Swprintf(msg, L"%d episodes could not be opened locally.", cNotFound);
@@ -504,7 +504,8 @@ void WaitFor(const char* mod, const char* pred)
if (activePred) {
wchar_t msg[256] = {0};
- Swprintf(msg, L"Another task (%s) is active. "
+ Swprintf(msg,
+ L"Another task (%s) is active. "
L"Do you want to cancel the existing task and start a new one?",
static_cast<wchar_t*>(activePred));
if (EBMessageBox(msg, L"Error", MB_YESNO|MB_ICONWARNING) != IDYES)
diff --git a/c/util.h b/c/util.h
index 11840fa..51fd020 100644
--- a/c/util.h
+++ b/c/util.h
@@ -10,6 +10,13 @@ inline int Swprintf(wchar_t (&buf)[N], const wchar_t* const fmt, T... xs)
return _snwprintf_s(buf, N, _TRUNCATE, fmt, xs...);
}
+/* Copy to static narrow string buffer. */
+template <size_t N>
+inline int Strcpy(char (&dst)[N], const char* const src)
+{
+ return strcpy_s(dst, N, src);
+}
+
inline int Cmp(const int a, const int b)
{
if (a == b) return 0;