aboutsummaryrefslogtreecommitdiff
path: root/c
diff options
context:
space:
mode:
Diffstat (limited to 'c')
-rw-r--r--c/data.h11
-rw-r--r--c/datalistview.cpp4
-rw-r--r--c/datalistview.h3
-rw-r--r--c/episodelistview.cpp19
-rw-r--r--c/episodelistview.h3
-rw-r--r--c/main.cpp2
6 files changed, 21 insertions, 21 deletions
diff --git a/c/data.h b/c/data.h
index 6d6edd3..da8d108 100644
--- a/c/data.h
+++ b/c/data.h
@@ -123,7 +123,8 @@ struct FileView
}
/* Access element by index, performing bounds check and, if
- * applicable for T, version validation. */
+ * applicable for T, version validation as well as
+ * initialization, if needed. */
T& At(size_t i)
{
if (i >= c)
@@ -131,9 +132,13 @@ struct FileView
T& t = view[i];
- if constexpr (HasVersion<T>)
- if (t.version != Version<T>)
+ if constexpr (HasVersion<T>) {
+ if (t.version == 0) {
+ T t_;
+ memcpy(&t, &t_, sizeof(T));
+ } else if (t.version != Version<T>)
throw std::runtime_error("invalid struct version");
+ }
/* TODO: Use a custom exception type that informs the
* user of possible data corruption. */
diff --git a/c/datalistview.cpp b/c/datalistview.cpp
index 3999b40..a71a270 100644
--- a/c/datalistview.cpp
+++ b/c/datalistview.cpp
@@ -12,6 +12,9 @@
#include "layout.h"
#include "wcharptr.h"
+extern CfgA& g_cfg;
+extern FileView<DlvDataA> g_fvDlv;
+
DataListView::DataListView(const HWND hWndParent)
: ListView(hWndParent, reinterpret_cast<HMENU>(IDC_DATALISTVIEW), LVS_NOCOLUMNHEADER)
{
@@ -29,7 +32,6 @@ DataListView::DataListView(const HWND hWndParent)
lvc.cx = 500;
ListView_InsertColumn(hWnd, DLVSIVALUE, &lvc);
- extern CfgA& g_cfg;
m_height = g_cfg.heightDlv;
}
diff --git a/c/datalistview.h b/c/datalistview.h
index 3a59d41..57cb565 100644
--- a/c/datalistview.h
+++ b/c/datalistview.h
@@ -7,8 +7,6 @@
#define DLVSIKEY 0
#define DLVSIVALUE 1
-extern CfgA& g_cfg;
-
struct DataListView : public ListView
{
DataListView(HWND hWndParent);
@@ -21,7 +19,6 @@ struct DataListView : public ListView
void ShowEpisode(int iEpisode);
private:
int m_height = 0;
- FileView<DlvDataA> m_fv{L"dlvdata.dat", g_cfg.cEp+128u};
};
#endif
diff --git a/c/episodelistview.cpp b/c/episodelistview.cpp
index db53be3..6caff99 100644
--- a/c/episodelistview.cpp
+++ b/c/episodelistview.cpp
@@ -13,6 +13,7 @@
#include "win.h"
extern CfgA& g_cfg;
+extern FileView<ElvDataA> g_fvElv;
EpisodeListView::EpisodeListView(const HWND hWndParent)
: ListView(hWndParent, reinterpret_cast<HMENU>(IDC_EPISODELISTVIEW), 0)
@@ -55,7 +56,7 @@ void EpisodeListView::HandleContextMenu(const WORD command)
LVITEM lvi = {LVIF_PARAM, -1};
while (FindNextItem(&lvi, LVNI_SELECTED)) {
- ElvDataA& e = m_fv.At(lvi.lParam-1);
+ ElvDataA& e = g_fvElv.At(lvi.lParam-1);
if (ID_SUBGROUP(command) == IDG_CTX_RATE) {
/* Process rate commands. */
@@ -117,7 +118,7 @@ LRESULT EpisodeListView::HandleNotify(const LPARAM lParam)
case LVN_GETDISPINFO: /* Display item. */
{
NMLVDISPINFO* const nm = reinterpret_cast<NMLVDISPINFO*>(lParam);
- ElvDataA& e = m_fv.At(nm->item.lParam-1);
+ ElvDataA& e = g_fvElv.At(nm->item.lParam-1);
wchar_t* vs[] = {e.siEp, e.title, e.sRating}; /* ELVSIEPISODE, ELVSITITLE, ELVSIRATING */
nm->item.pszText = vs[nm->item.iSubItem];
return 0;
@@ -166,7 +167,7 @@ LRESULT EpisodeListView::HandleNotify(const LPARAM lParam)
break;
case CDDS_ITEMPREPAINT:
{
- const ElvDataA& e = m_fv.At(nm->nmcd.lItemlParam-1);
+ const ElvDataA& e = g_fvElv.At(nm->nmcd.lItemlParam-1);
if (!e.bWatched) {
extern HFONT g_hfBold;
Require(SelectObject(nm->nmcd.hdc, g_hfBold));
@@ -329,8 +330,8 @@ int CALLBACK EpisodeListView::SortProc(const LPARAM iItem1, const LPARAM iItem2,
* If m_iSortCol is negative, the order is descending. */
const int order = Cmp(elv->m_iSortCol, 0);
- const ElvDataA& e1 = elv->m_fv[lvi1.lParam-1];
- const ElvDataA& e2 = elv->m_fv.At(lvi2.lParam-1);
+ const ElvDataA& e1 = g_fvElv[lvi1.lParam-1];
+ const ElvDataA& e2 = g_fvElv.At(lvi2.lParam-1);
switch (abs(elv->m_iSortCol)-1) {
case ELVSIEPISODE:
@@ -387,18 +388,14 @@ void EpisodeListView::Update()
}
{
- int cEp;
- if (!Pl("episode_data","episode_count",&cEp))
- return;
-
int cItem = 0;
LVITEM lviEpisode = {LVIF_TEXT|LVIF_PARAM};
/* Retrieve episode data and add list view items. */
SendMessage(hWnd, WM_SETREDRAW, FALSE, 0);
ListView_DeleteAllItems(hWnd);
- for (int iEp = 1; iEp <= cEp; iEp++) {
- ElvDataA e = m_fv.At(iEp-1);
+ for (int iEp = 1; iEp <= g_cfg.cEp; iEp++) {
+ ElvDataA e = g_fvElv.At(iEp-1);
if (!e.siEp[0])
continue;
diff --git a/c/episodelistview.h b/c/episodelistview.h
index f94803c..e6f2858 100644
--- a/c/episodelistview.h
+++ b/c/episodelistview.h
@@ -12,8 +12,6 @@
#define ELVSITITLE 1
#define ELVSIRATING 2
-extern CfgA& g_cfg;
-
struct EpisodeListView : public ListView
{
EpisodeListView(HWND hWndParent);
@@ -35,7 +33,6 @@ struct EpisodeListView : public ListView
private:
signed char m_iSortCol;
static int CALLBACK SortProc(LPARAM lParam1, LPARAM lParam2, LPARAM extra);
- FileView<ElvDataA> m_fv{L"elvdata.dat", g_cfg.cEp+128u};
};
#endif
diff --git a/c/main.cpp b/c/main.cpp
index 7a3e6a2..97b71b9 100644
--- a/c/main.cpp
+++ b/c/main.cpp
@@ -58,6 +58,8 @@ DlvDragger g_dragDlv;
/* File views. */
FileView<CfgA> g_fvCfg = FileView<CfgA>::Initialized(L"cfg.dat", 1);
CfgA& g_cfg = g_fvCfg.At(0);
+FileView<ElvDataA> g_fvElv{L"elvdata.dat", g_cfg.cEp+128u};
+FileView<DlvDataA> g_fvDlv{L"dlvdata.dat", g_cfg.cEp+128u};
/* Optional Windows functions. */
BOOL (*IsThemeActive)();