summaryrefslogtreecommitdiff
path: root/src/T2SysInfoDlg.cpp
blob: a9db052047dd667a3466fa79aa89d682ac491405 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include "StdAfx.h"
#include "T2DLL/T2PluginLoader.h"
#include "T2DLL/T2PluginSpecifier.h"
#include "T2SysInfoDlg.h"
#include "T2TowerDoc.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

T2SysInfoDlg::T2SysInfoDlg(CWnd *pParent)
    : CDialog(IDD, pParent)
{
    //{{AFX_DATA_INIT(T2SysInfoDlg)
    //}}AFX_DATA_INIT
}

/*virtual*/ void T2SysInfoDlg::DoDataExchange(CDataExchange *pDX) {
    CWnd::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(T2SysInfoDlg)
    DDX_Control(pDX, IDC_USED_MEMORY, mUsedMemory);
    DDX_Control(pDX, IDC_FREE_MEMORY, mFreeMemory);
    DDX_Control(pDX, IDC_PLUGIN_LIST, mPluginList);
    //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(T2SysInfoDlg, CDialog)
    //{{AFX_MSG_MAP(T2SysInfoDlg)
    ON_NOTIFY(LVN_COLUMNCLICK, IDC_PLUGIN_LIST, OnColumnClick)
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

void T2SysInfoDlg::SetDocument(T2TowerDoc *inDoc) {
    mDocument = inDoc;
}

BOOL T2SysInfoDlg::OnInitDialog() {
    CDialog::OnInitDialog();

    MEMORYSTATUS theGlobalMemStats;
    theGlobalMemStats.dwLength = sizeof(theGlobalMemStats);
    GlobalMemoryStatus(&theGlobalMemStats);

    CString str;

    str.Format("%d", theGlobalMemStats.dwAvailPageFile >> 10);
    mFreeMemory.SetWindowText(str);

    str.Format("%d", (theGlobalMemStats.dwTotalVirtual - theGlobalMemStats.dwAvailVirtual) >> 10);
    mUsedMemory.SetWindowText(str);

    RECT rect;
    mPluginList.GetClientRect(&rect);
    int width = rect.right;

    mPluginList.InsertColumn(0, "Name", LVCFMT_LEFT, (width * 6) / 20);
    mPluginList.InsertColumn(1, "Type", LVCFMT_LEFT, (width * 3) / 20);
    mPluginList.InsertColumn(2, "Lv", LVCFMT_LEFT, width / 20);
    mPluginList.InsertColumn(3, "Stat", LVCFMT_LEFT, (width * 3) / 20);
    mPluginList.InsertColumn(4, "File", LVCFMT_LEFT, width);

    POSITION pos;
    T2PluginSpecifier *specifier;
    mDocument->mT2PluginLoader->SetTypeFilter(pos, 0);

    while ((specifier = mDocument->mT2PluginLoader->GetNext(pos))) {
        int index = mPluginList.InsertItem(0, specifier->mPluginName);

        CString text;
        text = (char) ((specifier->mType >> 24) & 0xFF);
        text += (char) ((specifier->mType >> 16) & 0xFF);
        text += (char) ((specifier->mType >> 8) & 0xFF);
        text += (char) (specifier->mType & 0xFF);
        mPluginList.SetItemText(index, 1, text);

        text.Format("%d", specifier->mGameLevel);
        mPluginList.SetItemText(index, 2, text);

        CString stat;
        if (specifier->mIsLoaded)
            stat = "Loaded";
        mPluginList.SetItemText(index, 3, stat);

        mPluginList.SetItemText(index, 4, specifier->mPath);

        mPluginList.SetItemData(index, (DWORD) specifier);
    }

    return true;
}

int CALLBACK doCompare(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) {
    T2PluginSpecifier *specifierL = (T2PluginSpecifier *) lParam1;
    T2PluginSpecifier *specifierR = (T2PluginSpecifier *) lParam2;
    int compare = 0;

    if (lParamSort == 0)
        compare = strcmp(specifierL->mPluginName, specifierR->mPluginName);
    else if (lParamSort == 1)
        compare = specifierL->mType - specifierR->mType;
    else if (lParamSort == 2)
        compare = specifierR->mIsLoaded - specifierL->mIsLoaded;
    else if (lParamSort == 3)
        compare = strcmp(specifierL->mPath, specifierR->mPath);

    return compare;
}

void T2SysInfoDlg::OnColumnClick(NMHDR *pHdr, LRESULT *pResult) {
    NMLISTVIEW *pnmv = (NMLISTVIEW *) pHdr;

    mPluginList.SortItems(doCompare, pnmv->iSubItem);
    *pResult = 0;
}