-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInit.cpp
More file actions
382 lines (339 loc) · 11.7 KB
/
Init.cpp
File metadata and controls
382 lines (339 loc) · 11.7 KB
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
#include "hydrofin.h"
//#include "init.h"
#include "stdafx.h"
HANDLE hndlInput;
HANDLE hndlOutput;
CONSOLE_SCREEN_BUFFER_INFO scbiOldCosoleInfo;
int iWindowsVersion; // Âåðñèÿ Windows
extern void print( char *strPrint, int x, int y);
extern void Print( char *strPrint, int x, int y);
extern void Print( char *strPrint );
extern void print( char *strPrint );
extern void SetCursorVisibility( bool bOnOff );
extern void SetCurPos( int x, int y );
extern int Error( char *strRrror );
extern void ExitGame( void );
extern char strHydrofinPath[MAX_PATH]; // ïóòü îòêóäà çàïóñêàåòñÿ ýòà ïðîãðàììà áåç íàçâàíèÿ ôàéëà (Ïðèìåð: "c:\tmp\hydrofin\" )
#define MAX_GAMES 2000 // ïîâòîðÿåòñÿ â iniFile.cpp, Hydrofin_Input.cpp, GameChestDlg.h, ColorsConfig.cpp
extern struct structIniFile {
struct {
char PythonDLLPath[MAX_PATH];
char HydraPath[MAX_PATH];
char PythonLibsPath[MAX_PATH];
int ConfigLanguage;
} ConfigGeneral;
struct {
int UndoSlots;
long UndoMemory;
int UndoMemoryLimitMethod;
int TextLines;
long TextMemory;
int TextLimitMethod;
} ConfigMemory;
struct {
char Text[255];
int Blinking;
int BlinkingTime;
int BlinkingBgColor;
int Lines;
} ConfigMore;
struct {
int Background;
int Normal;
int Italics;
int Bold;
int Underscore;
int Inverted;
int StatusLineBackground;
int StatusLineNormal;
int StatusLineItalics;
int StatusLineBold;
int StatusLineUnderscore;
int StatusLineInverted;
} ConfigColors;
struct {
int InsertModeLines;
int OverwriteModeLines;
} ConfigCursor;
struct {
int PTag;
int CyrillicR;
int Tabs;
} ConfigInputOutput;
struct {
char DefaultGamesDirectory[MAX_PATH];
char LastGamesDirectory[MAX_PATH];
int StartingGamesDirectorySavingMethod;
int ColumnWidth1;
int ColumnWidth2;
int ColumnWidth3;
int NumberOfGames;
char *pGame[MAX_GAMES]; // MAX_GAMES = 2000
} GameChest;
} iniFile;
void ClearScreen( void );
/*********************************************************************
* FUNCTION: resizeConBufAndWindow(HANDLE hConsole, SHORT xSize, *
* SHORT ySize) *
* *
* PURPOSE: resize both the console output buffer and the console *
* window to the given x and y size parameters *
* *
* INPUT: the console output handle to resize, and the required x and *
* y size to resize the buffer and window to. *
* *
* COMMENTS: Note that care must be taken to resize the correct item *
* first; you cannot have a console buffer that is smaller *
* than the console window. *
*********************************************************************/
CONSOLE_SCREEN_BUFFER_INFO resizeConBufAndWindow( HANDLE hConsole,
SHORT xSize, SHORT ySize,
bool bAllowError = true ) // äëÿ ïðåäîòâðàùåíèÿ ïîâòîðíîãî îñâîáîæäåíèÿ ïàìÿòè ïðè îøèáêå âîññòàíîâëåíèÿ êîíñîëè â ExitGame()
{
CONSOLE_SCREEN_BUFFER_INFO csbi, /* hold current console buffer info */
csbi1; // äëÿ ñîçðàíåíèÿ ïåðâîíà÷àëüíîãî çíà÷åíèÿ ðàçìåðà êîíñîëè
BOOL bSuccess;
SMALL_RECT srWindowRect; /* hold the new console size */
COORD coordScreen;
bSuccess = GetConsoleScreenBufferInfo(hConsole, &csbi);
if ( !bSuccess )
if ( bAllowError )
Error( "Fatal error: fail to GetConsoleScreenBufferInfo()" );
else {
printf( "Fatal error: fail to GetConsoleScreenBufferInfo()" );
return csbi;
}
csbi1 = csbi;
/* get the largest size we can size the console window to */
coordScreen = GetLargestConsoleWindowSize(hConsole);
if ( !(coordScreen.X | coordScreen.Y) )
if ( bAllowError )
Error( "Fatal error: fail to GetLargestConsoleWindowSize()" );
else {
printf( "Fatal error: fail to GetLargestConsoleWindowSize()" );
return csbi1;
}
/* define the new console window size and scroll position */
srWindowRect.Right = (SHORT) (min(xSize, coordScreen.X) - 1);
srWindowRect.Bottom = (SHORT) (min(ySize, coordScreen.Y) - 1);
srWindowRect.Left = srWindowRect.Top = (SHORT) 0;
/* define the new console buffer size */
coordScreen.X = xSize;
coordScreen.Y = ySize;
/* if the current buffer is larger than what we want, resize the */
/* console window first, then the buffer */
if ( (DWORD) csbi.dwSize.X * csbi.dwSize.Y > (DWORD) xSize * ySize )
{
bSuccess = SetConsoleWindowInfo(hConsole, TRUE, &srWindowRect);
if ( !bSuccess )
if ( bAllowError )
Error( "Fatal error: fail to SetConsoleWindowInfo()" );
else {
printf( "Fatal error: fail to SetConsoleWindowInfo()" );
return csbi1;
}
bSuccess = SetConsoleScreenBufferSize(hConsole, coordScreen);
if ( !bSuccess )
if ( bAllowError )
Error( "Fatal error: fail to SetConsoleScreenBufferSize()" );
else {
printf( "Fatal error: fail to SetConsoleScreenBufferSize()" );
return csbi1;
}
}
/* if the current buffer is smaller than what we want, resize the */
/* buffer first, then the console window */
if ( (DWORD) csbi.dwSize.X * csbi.dwSize.Y < (DWORD) xSize * ySize )
{
bSuccess = SetConsoleScreenBufferSize(hConsole, coordScreen);
if ( !bSuccess )
if ( bAllowError )
Error( "Fatal error: fail to SetConsoleScreenBufferSize()" );
else {
printf( "Fatal error: fail to SetConsoleScreenBufferSize()" );
return csbi1;
}
bSuccess = SetConsoleWindowInfo(hConsole, TRUE, &srWindowRect); // ïîä Win98 âðîäå ðàáîòàåò, íî âîçâðàùàåò bSuccsess == false
if ( !bSuccess )
if ( bAllowError )
Error( "Fatal error: fail to SetConsoleWindowInfo()" );
else {
printf( "Fatal error: fail to SetConsoleWindowInfo()" );
return csbi1;
}
}
/* if the current buffer *is* the size we want, don't do anything! */
return csbi1;
}
BOOL CtrlHandler( DWORD dwCtrlType ) {
switch ( dwCtrlType ) {
case CTRL_BREAK_EVENT:
case CTRL_C_EVENT: /* Handle the CTRL+C signal. */
// ïî÷åìó-òî íå ðàáîòàåò
case CTRL_CLOSE_EVENT: /* CTRL+CLOSE: confirm that the user wants to exit. */
// ïî÷åìó-òî íå ðàáîòàåò ïîä Win98
MessageBeep( MB_ICONEXCLAMATION );
ExitGame();
return TRUE;
/* Pass other signals to the next handler. */
case CTRL_LOGOFF_EVENT:
case CTRL_SHUTDOWN_EVENT:
default:
return FALSE;
}
}
void GetFileName( char *strIn, char *strOut, int iBufLen ) {
int iLastSlash = 0;
int i, j;
for ( i = 0; i < iBufLen && i < lstrlen( strIn ); i++ )
if ( strIn[i] == '\\' )
iLastSlash = i + 1;
for ( j = 0, i = iLastSlash; i < iBufLen && i < lstrlen( strIn ); i++, j++ )
strOut[j] = strIn[i];
strOut[j] = 0;
}
void GetFileTitle( char *strIn, char *strOut, int iBufLen ) {
GetFileName( strIn, strOut, iBufLen );
int i;
int iLastDot = lstrlen( strOut ) + 1;
for ( i = 0; i < iBufLen && i < lstrlen( strIn ); i++ )
if ( strIn[i] == '.' )
iLastDot = i + 1;
lstrcpyn( strOut, strIn, iLastDot );
// for ( i = 0; i < iLastDot && i < iBufLen; i++ )
// strOut[i] = strIn[i];
// strOut[i] = 0;
}
void Init( char *strHydrofinFile ) {
// SECURITY_ATTRIBUTES saOutput;
// COORD coordOutput;
// SMALL_RECT srctOutput;
char strTitle[255] = "";
char strTmp[1000];
hndlInput = GetStdHandle(STD_INPUT_HANDLE);
if ( hndlInput == INVALID_HANDLE_VALUE ) {
CharToOem( strTmp, "Fatal error: íåâîçìîæíî ïîëó÷èòü õýíäëåð \
ïîòîêà ââîäà\n");
printf( strTmp );
exit( 1 );
}
if ( !SetConsoleMode( hndlInput, 0L ) ) {
CharToOem( strTmp, "Fatal error: íåâîçìîæíî óñòàíîâèòü ðåæèì \
ïîòîêà ââîäà\n" );
printf( strTmp );
exit( 1 );
}
hndlOutput = GetStdHandle(STD_OUTPUT_HANDLE);
if ( hndlOutput == INVALID_HANDLE_VALUE ) {
CharToOem( strTmp, "Fatal error: íåâîçìîæíî ïîëó÷èòü õýíäëåð \
ïîòîêà âûâîäà\n");
printf( strTmp );
exit( 1 );
}
bool bSuccess = SetConsoleCtrlHandler( // Äëÿ ïåðåõâàòà ñîîáùåíèé òèïà CTRL+BREAK, CTRL_CLOSE_EVENT
(PHANDLER_ROUTINE) CtrlHandler, /* handler function */
TRUE ); /* add to list */
if ( !bSuccess ) {
CharToOem( strTmp, "Fatal error: íåâîçìîæíî óñòàíîâèòü õýíäëåð \
ñîîáùåíèé òèïà CTRL+BREAK, CTRL_CLOSE_EVENT\n" );
printf( strTmp );
exit( 1 );
}
scbiOldCosoleInfo = resizeConBufAndWindow( hndlOutput, 80, 25 );
GetFileTitle( strHydrofinFile, strTitle, MAX_PATH );
// lstrcpy( strTitle, strHydrofinFile );
lstrcat( strTitle, " - Hydrofin" );
SetConsoleTitle( strTitle ); // óñòàíàâëèâàåì çàãîëîâîê îêíà Hydrofin
/* Îêàçàëîñü, âñå ýòî íå íóæíî. Ïîêà íå íóæíî.
saOutput.nLength = sizeof(saOutput);
saOutput.lpSecurityDescriptor = NULL;
saOutput.bInheritHandle = TRUE;
hndlOutput = CreateConsoleScreenBuffer(
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
&saOutput,
CONSOLE_TEXTMODE_BUFFER,
NULL ) ;
if ( hndlOutput == INVALID_HANDLE_VALUE)
Error("Error: fail to set output handle\n");
CONSOLE_SCREEN_BUFFER_INFO csbiTmp;
if ( !GetConsoleScreenBufferInfo(hndlOutput, &csbiTmp) )
printf("Bad");
printf("%i %i %i %i %i",
csbiTmp.dwMaximumWindowSize.X, csbiTmp.dwCursorPosition.X,
csbiTmp.dwSize.X, csbiTmp.srWindow.Bottom, csbiTmp.wAttributes);
srctOutput.Top = 2;
srctOutput.Left = 2;
srctOutput.Bottom = 20;
srctOutput.Right = 79;
if ( !SetConsoleWindowInfo(hndlOutput, FALSE, &srctOutput) )
Error("Error: fail to set window size\n");
coordOutput.X = 79;
coordOutput.Y = 24;
if ( !SetConsoleScreenBufferSize(hndlOutput, coordOutput) )
Error("Error: fail to set buffer size\n");
*/
// SetStdHandle( STD_INPUT_HANDLE, hndlInput );
// SetCursorVisibility( false );
ClearScreen();
SetCurPos(0, 0);
}
void SetHydrofinPath( char *argv0 ) {
char strStartingTitle[MAX_PATH];
char strPathTmp[MAX_PATH];
GetFileName( argv0, strStartingTitle, MAX_PATH );
for ( int i = 0; i < lstrlen( argv0 ) - lstrlen( strStartingTitle ); i++ )
strHydrofinPath[i] = argv0[i];
strHydrofinPath[i] = 0;
switch( iWindowsVersion ) {
case 3: // Win 3.x ?
case 4: // Win98
break;
case 5: // Win2000
GetCurrentDirectory( MAX_PATH, strPathTmp );
lstrcat( strPathTmp, "\\" );
if ( lstrcmp( strHydrofinPath, strPathTmp ) && strHydrofinPath[1] != ':' ) { // ïîä Win2000 ïðè ñòàðòå íàïðèìåð èç FAR â argv[0] ïåðåäàåòñÿ îòíîñèòåëüíûé ïóòü
lstrcat( strPathTmp, strHydrofinPath );
lstrcpy( strHydrofinPath, strPathTmp );
}
// printf( "GetFileTitle():%s\n", strStartingTitle );
// printf( "argv0:%s\nGetCurrentDirectory():%s\nFindExecutable():%s\n",
// argv0, strPathTmp, strHydrofinPath );
// printf( "GetCommandLine():%s\n", GetCommandLine() );
// FindExecutable( argv0, strHydrofinPath, strPathTmp );
// printf( "FindExecutable()%s\n", strPathTmp );
case 6:
default:
break;
}
/*
LPSTR lp;
lp = &strHydrofinPath[0];
GetFullPathName( strStartingTitle, MAX_PATH, strHydrofinPath, &lp );
printf( "GetFullPathName():%s:%s\n", strPathTmp, lp );
WIN32_FIND_DATA wfdHydrofin;
HANDLE hSearch = FindFirstFile( argv0, &wfdHydrofin );
lstrcpy( strHydrofinPath, wfdHydrofin.cFileName );
printf( "FindFirstFile:%s\n", strHydrofinPath );
char *strTmp[200];
SearchPath( strPathTmp, strHydrofinPath, NULL, MAX_PATH, strStartingFile, strTmp );
printf( "SearchPath:%s\n", strStartingFile );
*/
}
void ClearScreen( void ) {
DWORD dwTmp;
COORD coordTmp;
coordTmp.X = 0;
coordTmp.Y = 0;
FillConsoleOutputAttribute( hndlOutput, iniFile.ConfigColors.Background |
iniFile.ConfigColors.Normal, 80*25, coordTmp, &dwTmp );
FillConsoleOutputCharacter( hndlOutput, ' ', 80*25, coordTmp, &dwTmp );
}
int GetWindowsVersion( void ) {
OSVERSIONINFO oviVersionInformation;
oviVersionInformation.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx( &oviVersionInformation );
iWindowsVersion = oviVersionInformation.dwMajorVersion;
printf( "Windows major version: %d\n", iWindowsVersion );
return iWindowsVersion;
}