-
Notifications
You must be signed in to change notification settings - Fork 0
/
GeneratorIniFile.cpp
214 lines (188 loc) · 7.24 KB
/
GeneratorIniFile.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#include "stdafx.h"
#include "Generator.h"
#include "GeneratorDlg.h"
#include "GeneratorIniFile.h"
CGeneratorIniFile::CGeneratorIniFile( void ) {
}
CGeneratorIniFile::~CGeneratorIniFile( void ) {
}
int CGeneratorIniFile::OpenGeneratorIniFile( void ) {
char strCmdLine[ 2007 ];
FILE * hndlIniFile = NULL;
lstrcpy( strCmdLine, GetCommandLine() );
SetGeneratorPath( strCmdLine );
l1:
if ( ( hndlIniFile = fopen( strGeneratorIniPath, "r" ) ) == NULL ) {
if ( !CreateDefaultIniFile( strGeneratorIniPath ) ) {
if ( MessageBox( NULL, "Íåâîçìîæíî îòêğûòü èëè ñîçäàòü \
ôàéë \"generator.ini\".\n\nÂû æåëàåòå ïîâòîğèòü ïîïûòêó?",
NULL, MB_ICONWARNING | MB_RETRYCANCEL ) == IDRETRY )
goto l1;
} else
MessageBox( NULL, "Çàãğóæåíû ñòàíäàğòíûå óñòàíîâêè.\n\n\
Ñîçäàí ôàéë \"generator.ini\".", "Âíèìàíèå", MB_ICONWARNING );
} else {
fclose( hndlIniFile );
ReadAllFromIniFile( strGeneratorIniPath );
}
return 0;
}
int CGeneratorIniFile::SaveGeneratorIniFile( void ) {
FILE * hndlIniFile = NULL;
l1:
if ( ( hndlIniFile = fopen( strGeneratorIniPath, "w" ) ) == NULL ) {
if ( !CreateDefaultIniFile( strGeneratorIniPath ) ) {
if ( MessageBox( NULL, "Íåâîçìîæíî ñîõğàíèòü \
ôàéë \"generator.ini\".\n\nÂû æåëàåòå ïîâòîğèòü ïîïûòêó?",
NULL, MB_ICONWARNING | MB_RETRYCANCEL ) == IDRETRY )
goto l1;
else
MessageBox( NULL, "Óñòàíîâêè íå áûëè çàïèñàíû â Ôàéë \
\"generator.ini\".", NULL, MB_ICONWARNING );
}
} else {
fclose( hndlIniFile );
IniFile.ChosenClasses.strDefaultClass = IniFile.ChosenClasses.strChosenClass[ 0 ];
WriteAllToIniFile( strGeneratorIniPath );
}
return 0;
}
void CGeneratorIniFile::SetGeneratorPath( char * argv0 ) {
char strPathTmp[ 2009 ];
char * pTmp;
int iPathLen = MAX_PATH;
// âûğåçàåì êóñîê â ïåğâûõ äâóõ êàâû÷êàõ
pTmp = strchr( argv0, '\"' );
if ( pTmp != NULL ) {
pTmp = strchr( pTmp + 1, '\"' );
iPathLen = pTmp - argv0 + 1;
if ( pTmp == NULL ) // " íå íàéäåíî
iPathLen = lstrlen( argv0 );
}
pTmp = strrchr( lstrcpyn( strPathTmp, argv0, iPathLen ), '\\' );
if ( pTmp == NULL || pTmp == strPathTmp ) { // âûçâàíà îòíîñèòåëüíûì ïóòåì
GetCurrentDirectory( MAX_PATH, strPathTmp );
strGeneratorIniPath = strPathTmp;
strGeneratorIniPath += "\\generator.ini";
return;
}
iPathLen = pTmp - strPathTmp + 1;
if ( pTmp == NULL ) // " íå íàéäåíî
iPathLen = lstrlen( strPathTmp );
pTmp = strchr( argv0, '\"' );
if ( pTmp == argv0 ) // " -- ïåğâûé ñèìâîë argv0
lstrcpyn( strPathTmp, argv0 + 1, iPathLen );
else
lstrcpyn( strPathTmp, argv0, iPathLen );
strGeneratorIniPath = strPathTmp;
strGeneratorIniPath += "generator.ini";
}
bool CGeneratorIniFile::CreateDefaultIniFile( CString strIniFile ) {
FILE * hndlIniFile = NULL;
if ( ( hndlIniFile = fopen( strIniFile, "w" ) ) == NULL ) {
ReadAllFromIniFile( strIniFile );
return false;
}
fclose( hndlIniFile );
ReadAllFromIniFile( strIniFile );
return true;
}
void CGeneratorIniFile::ReadAllFromIniFile( CString strIniFile ) {
char strBuf[ 2010 ];
// [ChosenClasses]
IniFile.ChosenClasses.iNumberOfChosenClasses = GetPrivateProfileInt( "Chosen Classes",
"NumberOfChosenClasses", -1, strIniFile );
if ( IniFile.ChosenClasses.iNumberOfChosenClasses == -1 ) { // -1 -- ôëàã, ÷òî Chosen Classes íå íàéäåíî
int i = 0;
int itmp;
CString str;
// çàïîëíÿåì ñïèñîê êëàññîâ
str.LoadString( IDS_CLASSSTRINGS );
while( 1 ) {
itmp = str.Find( '\n' );
if ( itmp == -1 )
break;
IniFile.ChosenClasses.strChosenClass[ i ] = str.Left( itmp );
i++;
str.Delete( 0, itmp + 1 );
}
IniFile.ChosenClasses.iNumberOfChosenClasses = i;
} else {
for ( int i = 0; i < IniFile.ChosenClasses.iNumberOfChosenClasses; i++ ) {
wsprintf( strBuf, "ChosenClass%d", i + 1 );
GetPrivateProfileString( "Chosen Classes", strBuf, "Error in generator.ini",
strBuf, MAX_PATH, strIniFile );
IniFile.ChosenClasses.strChosenClass[ i ] = strBuf;
}
}
old_IniFile_ChosenClasses_iNumberOfChosenClasses = IniFile.ChosenClasses.iNumberOfChosenClasses;
GetPrivateProfileString( "Chosen Classes", "DefaultClass", IniFile.ChosenClasses.strChosenClass[ 0 ],
strBuf, MAX_PATH, strIniFile );
IniFile.ChosenClasses.strDefaultClass = strBuf;
// [General]
// øğèôò:
if ( GetPrivateProfileStruct( "General", "Font",
&IniFile.Font.logfontLogFont, sizeof(IniFile.Font.logfontLogFont),
strIniFile ) == 0 ) { // åñëè íå óäàëîñü
lstrcpy( IniFile.Font.logfontLogFont.lfFaceName, "Courier New" );
IniFile.Font.logfontLogFont.lfClipPrecision = 0;
IniFile.Font.logfontLogFont.lfEscapement = 0;
IniFile.Font.logfontLogFont.lfCharSet = DEFAULT_CHARSET;
IniFile.Font.logfontLogFont.lfHeight = -13;
IniFile.Font.logfontLogFont.lfItalic = 0;
IniFile.Font.logfontLogFont.lfOrientation = 0;
IniFile.Font.logfontLogFont.lfOutPrecision = 0;
IniFile.Font.logfontLogFont.lfPitchAndFamily = 0;
IniFile.Font.logfontLogFont.lfQuality = 0;
IniFile.Font.logfontLogFont.lfStrikeOut = 0;
IniFile.Font.logfontLogFont.lfUnderline = 0;
IniFile.Font.logfontLogFont.lfWeight = 400;
IniFile.Font.logfontLogFont.lfWidth = 0;
}
if ( GetPrivateProfileStruct( "General", "FontColor", &IniFile.Font.FontColor,
sizeof(IniFile.Font.FontColor), strIniFile ) == 0 )
IniFile.Font.FontColor = 0;
// êîë-âî îòñòóïîâ â ctrlResEdit
IniFile.Tabs.iNumberOfTabs = GetPrivateProfileInt( "General",
"NumberOfTabs", 4, strIniFile );
IniFile.Tabs.iTabsOrSpaces = GetPrivateProfileInt( "General",
"TabsOrSpaces", 1, strIniFile );
}
void CGeneratorIniFile::WriteAllToIniFile( CString strIniFile ) {
char strBuf[ 2011 ];
// [ChosenClasses]
int itmp = 0;
for( int i = 0; i < IniFile.ChosenClasses.iNumberOfChosenClasses; i++ ) {
if ( IniFile.ChosenClasses.strChosenClass[ i ] != "" ) {
itmp++;
wsprintf( strBuf, "ChosenClass%d", itmp );
WritePrivateProfileString( "Chosen Classes", strBuf,
IniFile.ChosenClasses.strChosenClass[ i ], strIniFile );
}
}
if ( old_IniFile_ChosenClasses_iNumberOfChosenClasses > IniFile.ChosenClasses.iNumberOfChosenClasses )
for( int i = IniFile.ChosenClasses.iNumberOfChosenClasses; i < old_IniFile_ChosenClasses_iNumberOfChosenClasses; i++ ) {
wsprintf( strBuf, "ChosenClass%d", i + 1 );
WritePrivateProfileString( "Chosen Classes", strBuf,
NULL, strIniFile );
}
wsprintf( strBuf, "%d", itmp );
WritePrivateProfileString( "Chosen Classes", "NumberOfChosenClasses",
strBuf, strIniFile );
WritePrivateProfileString( "Chosen Classes", "DefaultClass",
IniFile.ChosenClasses.strDefaultClass, strIniFile );
// [General]
// øğèôò:
Font.GetLogFont( &IniFile.Font.logfontLogFont );
WritePrivateProfileStruct( "General", "Font", &IniFile.Font.logfontLogFont,
sizeof(IniFile.Font.logfontLogFont), strIniFile );
WritePrivateProfileStruct( "General", "FontColor", &IniFile.Font.FontColor,
sizeof(IniFile.Font.FontColor), strIniFile );
// êîë-âî îòñòóïîâ â ctrlResEdit
wsprintf( strBuf, "%d", IniFile.Tabs.iNumberOfTabs );
WritePrivateProfileString( "General", "NumberOfTabs",
strBuf, strIniFile );
wsprintf( strBuf, "%d", IniFile.Tabs.iTabsOrSpaces );
WritePrivateProfileString( "General", "TabsOrSpaces",
strBuf, strIniFile );
}