diff options
Diffstat (limited to 'c')
-rw-r--r-- | c/data.h | 6 | ||||
-rw-r--r-- | c/datalistview.cpp | 56 | ||||
-rw-r--r-- | c/datalistview.h | 4 | ||||
-rw-r--r-- | c/episodelistview.h | 4 | ||||
-rw-r--r-- | c/test.cpp | 33 |
5 files changed, 69 insertions, 34 deletions
@@ -13,7 +13,7 @@ * should be regarded as immutable. If the format needs to be changed * in the future, then new structs ending with B should be added. */ -/* Note that unsigned chars are 1-byte-aligned, wchar_t are +/* Note that unsigned chars are 1-byte-aligned, shorts and wchar_t are * 2-byte-aligned and ints are 4-byte-aligned (on x86 Windows). */ /* Basic episode data presented in episode list view. */ @@ -31,6 +31,8 @@ struct ElvDataA /* Extra episode data presented in data list view. */ struct DlvDataA { + unsigned char version = 'a'; + unsigned char pad[3] = {0}; wchar_t date[32] = {0}; wchar_t source[48] = {0}; wchar_t screenwriter[48] = {0}; @@ -45,7 +47,7 @@ struct CfgA unsigned char bViewWatched = 1; unsigned char bViewTVOriginal = 1; signed char iSortCol = 1; - unsigned short cEp = 0; + unsigned short cEp = 4096; unsigned short iFocus = 0; unsigned short heightDlv = 0; wchar_t limitScreenwriter[64] = {0}; diff --git a/c/datalistview.cpp b/c/datalistview.cpp index 6d3d79c..6e598f5 100644 --- a/c/datalistview.cpp +++ b/c/datalistview.cpp @@ -5,11 +5,11 @@ #include <SWI-Prolog.h> #include "resource.h" +#include "data.h" #include "datalistview.h" #include "episodelistview.h" #include "listview.h" #include "layout.h" -#include "pl.h" #include "wcharptr.h" DataListView::DataListView(const HWND hWndParent) @@ -53,35 +53,34 @@ void DataListView::SetHeight(int h) void DataListView::ShowEpisode(const int iEpisode) { - extern EpisodeListView* const g_elv; + const DlvDataA& d = m_fv[iEpisode]; ListView_DeleteAllItems(hWnd); - - Frame f; - const int arity = 3; - const term_t t = PL_new_term_refs(arity); - if (!PlPut(t, iEpisode)) return; - - Query q (nullptr, PL_predicate("episode_datum", arity, "episode_data"), t); - LVITEM lviKey = {LVIF_TEXT}; - LVITEM lviValue = {LVIF_TEXT}; - - for (int i = 0; q.NextSolution(std::nothrow); i++) { - WcharPtr key; - WcharPtr value; - - if (!(PlGet(t+1, &key) && PlGet(t+2, &value))) - continue; - - lviKey.iItem = i; - lviKey.iSubItem = 0; - lviKey.pszText = key; - ListView_InsertItem(hWnd, &lviKey); - - lviValue.iItem = i; - lviValue.iSubItem = 1; - lviValue.pszText = value; - ListView_SetItem(hWnd, &lviValue); + if (d.version == Version<DlvDataA>) { + const wchar_t* v[] = { + L"Date", d.date, + L"Source", d.source, + L"Hint", d.hint, + L"Screenwriter", d.screenwriter}; + + LVITEM lviKey = {LVIF_TEXT}; + LVITEM lviValue = {LVIF_TEXT}; + + for (size_t i = 0, j = 0; i < sizeof(v)/sizeof(*v); i += 2) { + if (v[i+1][0]) { + lviKey.iItem = j; + lviKey.iSubItem = 0; + lviKey.pszText = const_cast<wchar_t*>(v[i]); + ListView_InsertItem(hWnd, &lviKey); + + lviValue.iItem = j; + lviValue.iSubItem = 1; + lviValue.pszText = const_cast<wchar_t*>(v[i+1]); + ListView_SetItem(hWnd, &lviValue); + + j++; + } + } } UpdateLayout(); @@ -89,6 +88,7 @@ void DataListView::ShowEpisode(const int iEpisode) LVFINDINFO lvfi; lvfi.flags = LVFI_PARAM; lvfi.lParam = iEpisode; + extern EpisodeListView* const g_elv; int iItem = ListView_FindItem(g_elv->hWnd, -1, &lvfi); if (iItem != -1) ListView_EnsureVisible(g_elv->hWnd, iItem, TRUE); diff --git a/c/datalistview.h b/c/datalistview.h index 26ba8c9..3a59d41 100644 --- a/c/datalistview.h +++ b/c/datalistview.h @@ -1,11 +1,14 @@ #ifndef DATALISTVIEW_H #define DATALISTVIEW_H +#include "data.h" #include "listview.h" #define DLVSIKEY 0 #define DLVSIVALUE 1 +extern CfgA& g_cfg; + struct DataListView : public ListView { DataListView(HWND hWndParent); @@ -18,6 +21,7 @@ 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.h b/c/episodelistview.h index 88c8c9e..f94803c 100644 --- a/c/episodelistview.h +++ b/c/episodelistview.h @@ -12,7 +12,7 @@ #define ELVSITITLE 1 #define ELVSIRATING 2 -#define ELVMAX 8192 +extern CfgA& g_cfg; struct EpisodeListView : public ListView { @@ -35,7 +35,7 @@ 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", ELVMAX}; + FileView<ElvDataA> m_fv{L"elvdata.dat", g_cfg.cEp+128u}; }; #endif @@ -4,6 +4,8 @@ #include "util.h" #include "win.h" +extern CfgA& g_cfg; + struct Test { const char* name = {0}; @@ -115,7 +117,7 @@ TESTS return; { - FileView<ElvDataA> fv{L"tmp.dat", ELVMAX}; + FileView<ElvDataA> fv{L"tmp.dat", g_cfg.cEp+128u}; ElvDataA* p = fv; for (int iEp = 1; iEp <= cEp; iEp++) { @@ -126,7 +128,7 @@ TESTS } } { - FileView<ElvDataA> fv{L"tmp.dat", 8192}; + FileView<ElvDataA> fv{L"tmp.dat", g_cfg.cEp+128u}; ElvDataA& e = fv.At(9); if (wcscmp(e.title, L"Pro Soccer Player Blackmail Case") != 0) FAIL("title is not correct"); @@ -167,6 +169,32 @@ TESTS // Wcscpy(fvb->glob, fva->glob); // Wcscpy(fvb->url, fva->url); // } + + TEST(MigrateDlvDataFromPrologToDisk) + { + int cEp; + if (!Pl("episode_data","episode_count",&cEp)) + return; + + { + FileView<DlvDataA> fv{L"tmp.dat", g_cfg.cEp+128u}; + DlvDataA* p = fv; + + for (int iEp = 1; iEp <= cEp; iEp++) { + DlvDataA d; + FromProlog(iEp, d); + memcpy(p, &d, sizeof(d)); + p++; + } + } + { + FileView<DlvDataA> fv{L"tmp.dat", g_cfg.cEp+128u}; + DlvDataA& e = fv.At(9); + if (wcscmp(e.date, L"March 11, 1996") != 0) + FAIL("date is not correct"); + } + //DeleteFile(L"tmp.dat"); + } }; int RunTests() @@ -179,6 +207,7 @@ int RunTests() //MigrateElvDataFromPrologToDisk{}, SampleConfigurationToDisk{}, //MigrateCfg{} + MigrateDlvDataFromPrologToDisk{}, }; printf("Results (%llu tests):\n", sizeof(tests)/sizeof(*tests)); |