-
Notifications
You must be signed in to change notification settings - Fork 2
/
cfgfile.cpp
123 lines (97 loc) · 2.68 KB
/
cfgfile.cpp
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
117
118
119
120
121
122
123
#include "stdafx.h"
#include "cfgfile.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define CFGHEADER1 (0x464E4F43) //'CONF'
// #define CFGHEADER2_170 (0xCCA2AA03) //Ver Info, before 1.71, ABANDONED
#define CFGHEADER2 (0xCCD2A5BC) //Ver Info
// #define CFGOLDLENGTH 116 //.cfg file size before v1.40, ABANDONED
// #define CFGOLDLENGTH 160 //.cfg file size before v1.70, ABANDONED
#define CFGOLDLENGTH 164 //.cfg file size before v1.85
CONFIG cfg;
CONFIG::CONFIG() {
InfoCode = 932;
CommentCode = 932;
CommentCodeForEdit = 0;
InfoFont.lfFaceName[0] = 0; // ÎÞ×ÖÌå
dwOptions = CFG_CONFIRM | CFG_ANYDRAG | CFG_SHOWPLAYTIME | CFG_SHOWSLOWRATE;
_dontuse = 0;
byteAlphaForFileList = byteAlpha = (BYTE)255;
WinPlace_FileList.length = WinPlace.length = 0; // ÎÞЧ windowplacement
}
BOOL CONFIG::loadFont(LOGFONT* pLogFont)
{
if (this->InfoFont.lfFaceName[0] != 0) {
memcpy(pLogFont, &this->InfoFont, sizeof(LOGFONT));
return TRUE;
}
return FALSE;
}
void CONFIG::saveFont(LOGFONT* pLogFont)
{
memcpy(&this->InfoFont, pLogFont, sizeof(LOGFONT));
}
void CONFIG::set(DWORD dwOption, BOOL bState)
{
if (bState) {
this->dwOptions |= dwOption;
}
else {
this->dwOptions &= ~dwOption;
}
}
CONFIG& CONFIG::operator=(const CONFIG& other)
{
if (this != &other) { // self-assignment check expected
memmove(this, &other, sizeof(*this));
}
return *this;
}
/////////////////// END CONFIG implementation /////////////////////
static TCHAR cfgfilename[MAX_PATH] = {0};
struct CFGCONTENTS
{
DWORD h1;
DWORD h2;
CONFIG cfg;
};
void SetConfigFilename(LPCTSTR filename)
{
_tcsncpy(cfgfilename, filename, MAX_PATH);
cfgfilename[MAX_PATH-1] = _T('\0');
}
BOOL LoadConfig()
{
CFile cfile;
if (!cfile.Open(cfgfilename, CFile::modeRead | CFile::shareDenyWrite | CFile::typeBinary))
return FALSE;
CFGCONTENTS cfgcontents;
const UINT uBytesRead = cfile.Read(&cfgcontents, sizeof(cfgcontents));
cfile.Close();
//Check counts of bytes read and header
if ( (uBytesRead == sizeof(cfgcontents) || uBytesRead == CFGOLDLENGTH)
&& cfgcontents.h1==CFGHEADER1 && (cfgcontents.h2==CFGHEADER2) )
{
// Use the configuration read from .cfg file
cfg = cfgcontents.cfg;
return TRUE;
}
else
return FALSE;
}
BOOL SaveConfig()
{
CFile cfile;
if (!cfile.Open(cfgfilename, CFile::modeCreate | CFile::modeWrite | CFile::shareDenyRead | CFile::typeBinary))
return FALSE;
CFGCONTENTS cfgcontents;
cfgcontents.h1 = CFGHEADER1;
cfgcontents.h2 = CFGHEADER2;
cfgcontents.cfg = cfg;
cfile.Write(&cfgcontents, sizeof(cfgcontents));
cfile.Close();
return TRUE;
}