-
Notifications
You must be signed in to change notification settings - Fork 0
/
Errors.h
95 lines (85 loc) · 2.92 KB
/
Errors.h
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
#include "Main.h"
struct Logger
{
HANDLE logfile;
HANDLE tempfile;
TCHAR temp_filepath[MAX_PATH];
Logger()
{
DWORD result;
TCHAR temp_path[MAX_PATH];
this->logfile = CreateFile( _T("screeny.log"), GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
if( this->logfile == INVALID_HANDLE_VALUE )
{
TCHAR errstr[256];
_stprintf( errstr, _T("Logger::Logger()::CreateFile( screeny.log ) error: %x"), GetLastError() );
MessageBox( NULL, errstr, _T("Screeny Error"), MB_ICONERROR|MB_SETFOREGROUND );
return;
}
result = GetTempPath( MAX_PATH, temp_path );
if( result == 0 || result > MAX_PATH )
{
TCHAR errstr[256];
_stprintf( errstr, _T("Logger::Logger()::GetTempPath() error: %x"), GetLastError() );
MessageBox( NULL, errstr, _T("Screeny Error"), MB_ICONERROR|MB_SETFOREGROUND );
return;
}
result = GetTempFileName( temp_path, _T("screeny"), 74365, this->temp_filepath );
if( result == 0 || result == ERROR_BUFFER_OVERFLOW )
{
TCHAR errstr[256];
_stprintf( errstr, _T("Logger::Logger()::GetTempFileName() error: %x"), GetLastError() );
MessageBox( NULL, errstr, _T("Screeny Error"), MB_ICONERROR|MB_SETFOREGROUND );
return;
}
this->tempfile = CreateFile( this->temp_filepath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
if( this->tempfile == INVALID_HANDLE_VALUE )
{
TCHAR errstr[256];
_stprintf( errstr, _T("Logger::Logger()::CreateFile( temp_filepath ) error: %x"), GetLastError() );
MessageBox( NULL, errstr, _T("Screeny Error"), MB_ICONERROR|MB_SETFOREGROUND );
return;
}
}
~Logger()
{
if( logfile != NULL || logfile != INVALID_HANDLE_VALUE )
{
if( !FlushFileBuffers( logfile ) )
{
TCHAR errstr[256];
_stprintf( errstr, _T("Logger::~Logger()::FlushFileBuffers( logfile ) error: %x"), GetLastError() );
MessageBox( NULL, errstr, _T("Screeny Error"), MB_ICONERROR|MB_SETFOREGROUND );
return;
}
}
if( tempfile != NULL || tempfile != INVALID_HANDLE_VALUE )
{
if( !FlushFileBuffers( tempfile ) )
{
TCHAR errstr[256];
_stprintf( errstr, _T("Logger::~Logger()::FlushFileBuffers( tempfile ) error: %x"), GetLastError() );
MessageBox( NULL, errstr, _T("Screeny Error"), MB_ICONERROR|MB_SETFOREGROUND );
return;
}
}
if( !CloseHandle( logfile ) )
{
TCHAR errstr[256];
_stprintf( errstr, _T("Logger::~Logger()::CloseHandle( logfile ) error: %x"), GetLastError() );
MessageBox( NULL, errstr, _T("Screeny Error"), MB_ICONERROR|MB_SETFOREGROUND );
return;
}
if( !CloseHandle( tempfile ) )
{
TCHAR errstr[256];
_stprintf( errstr, _T("Logger::~Logger()::CloseHandle( tempfile ) error: %x"), GetLastError() );
MessageBox( NULL, errstr, _T("Screeny Error"), MB_ICONERROR|MB_SETFOREGROUND );
return;
}
}
bool Initialize();
bool _cdecl printf( const TCHAR *msg, ... );
bool _cdecl printfA( const char *msg, ... );
};
extern Logger logger;