Browse Source

Use INVALID_HANDLE_VALUE

pull/114/head
Anders Jenbo 7 years ago
parent
commit
b797cdf0cf
  1. 6
      Source/logging.cpp
  2. 14
      Source/mpqapi.cpp
  3. 8
      Source/nthread.cpp

6
Source/logging.cpp

@ -12,7 +12,7 @@ DWORD nNumberOfBytesToWrite; // idb
/* data */ /* data */
int log_not_created = 1; // weak int log_not_created = 1; // weak
HANDLE log_file = (HANDLE)0xFFFFFFFF; // idb HANDLE log_file = INVALID_HANDLE_VALUE;
void __cdecl log_flush(BOOL force_close) void __cdecl log_flush(BOOL force_close)
{ {
@ -72,11 +72,11 @@ HANDLE log_create()
file_info.dwProductVersionLS >> 16, file_info.dwProductVersionLS >> 16,
_LOWORD(file_info.dwProductVersionLS)); _LOWORD(file_info.dwProductVersionLS));
} }
v1 = (HANDLE)-1; v1 = INVALID_HANDLE_VALUE;
for (pcbBuffer = log_not_created == 0; (signed int)pcbBuffer < 2; ++pcbBuffer) { for (pcbBuffer = log_not_created == 0; (signed int)pcbBuffer < 2; ++pcbBuffer) {
v2 = CreateFile(FileName, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); v2 = CreateFile(FileName, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
v1 = v2; v1 = v2;
if (v2 != (HANDLE)-1) { if (v2 != INVALID_HANDLE_VALUE) {
if (GetFileSize(v2, 0) > 0x10000) if (GetFileSize(v2, 0) > 0x10000)
SetEndOfFile(v1); SetEndOfFile(v1);
break; break;

14
Source/mpqapi.cpp

@ -12,7 +12,7 @@ BOOLEAN save_archive_open; // weak
/* data */ /* data */
HANDLE sghArchive = (HANDLE)0xFFFFFFFF; // idb HANDLE sghArchive = INVALID_HANDLE_VALUE;
BOOL mpqapi_set_hidden(const char *pszArchive, BOOL hidden) BOOL mpqapi_set_hidden(const char *pszArchive, BOOL hidden)
{ {
@ -43,7 +43,7 @@ void mpqapi_store_creation_time(const char *pszArchive, int dwChar)
if (gbMaxPlayers != 1) { if (gbMaxPlayers != 1) {
mpqapi_reg_load_modification_time(dst, 160); mpqapi_reg_load_modification_time(dst, 160);
v4 = FindFirstFile(v3, &FindFileData); v4 = FindFirstFile(v3, &FindFileData);
if (v4 != (HANDLE)-1) { if (v4 != INVALID_HANDLE_VALUE) {
FindClose(v4); FindClose(v4);
v5 = 16 * v2; v5 = 16 * v2;
*(_DWORD *)&dst[v5] = FindFileData.ftCreationTime.dwLowDateTime; *(_DWORD *)&dst[v5] = FindFileData.ftCreationTime.dwLowDateTime;
@ -99,7 +99,7 @@ void mpqapi_xor_buf(char *pbData)
void mpqapi_store_default_time(DWORD dwChar) void mpqapi_store_default_time(DWORD dwChar)
{ {
/* /*
DWORD idx; DWORD idx;
char dst[160]; char dst[160];
@ -504,9 +504,9 @@ BOOL mpqapi_open_archive(const char *pszArchive, BOOL hidden, int dwChar) // Ope
v6 = (unsigned char)gbMaxPlayers > 1u ? FILE_FLAG_WRITE_THROUGH : 0; v6 = (unsigned char)gbMaxPlayers > 1u ? FILE_FLAG_WRITE_THROUGH : 0;
save_archive_open = 0; save_archive_open = 0;
sghArchive = CreateFile(v3, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, v6, NULL); sghArchive = CreateFile(v3, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, v6, NULL);
if (sghArchive == (HANDLE)-1) { if (sghArchive == INVALID_HANDLE_VALUE) {
sghArchive = CreateFile(lpFileName, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, v6 | (v4 != 0 ? FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN : 0), NULL); sghArchive = CreateFile(lpFileName, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, v6 | (v4 != 0 ? FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN : 0), NULL);
if (sghArchive == (HANDLE)-1) if (sghArchive == INVALID_HANDLE_VALUE)
return 0; return 0;
save_archive_open = 1; save_archive_open = 1;
save_archive_modified = 1; save_archive_modified = 1;
@ -623,7 +623,7 @@ void mpqapi_store_modified_time(const char *pszArchive, int dwChar)
if (gbMaxPlayers != 1) { if (gbMaxPlayers != 1) {
mpqapi_reg_load_modification_time(dst, 160); mpqapi_reg_load_modification_time(dst, 160);
v4 = FindFirstFile(v3, &FindFileData); v4 = FindFirstFile(v3, &FindFileData);
if (v4 != (HANDLE)-1) { if (v4 != INVALID_HANDLE_VALUE) {
FindClose(v4); FindClose(v4);
v5 = 16 * v2; v5 = 16 * v2;
*(_DWORD *)&dst[v5 + 8] = FindFileData.ftLastWriteTime.dwLowDateTime; *(_DWORD *)&dst[v5 + 8] = FindFileData.ftLastWriteTime.dwLowDateTime;
@ -636,7 +636,7 @@ void mpqapi_store_modified_time(const char *pszArchive, int dwChar)
void mpqapi_flush_and_close(const char *pszArchive, BOOL bFree, int dwChar) void mpqapi_flush_and_close(const char *pszArchive, BOOL bFree, int dwChar)
{ {
if (sghArchive != (HANDLE)-1) { if (sghArchive != INVALID_HANDLE_VALUE) {
if (save_archive_modified) { if (save_archive_modified) {
if (mpqapi_can_seek()) { if (mpqapi_can_seek()) {
if (mpqapi_write_header()) { if (mpqapi_write_header()) {

8
Source/nthread.cpp

@ -178,7 +178,7 @@ void nthread_start(BOOL set_turn_upper_bit)
#endif #endif
nthread_should_run = 1; nthread_should_run = 1;
sghThread = (HANDLE)_beginthreadex(NULL, 0, nthread_handler, NULL, 0, &glpNThreadId); sghThread = (HANDLE)_beginthreadex(NULL, 0, nthread_handler, NULL, 0, &glpNThreadId);
if (sghThread == (HANDLE)-1) { if (sghThread == INVALID_HANDLE_VALUE) {
err2 = TraceLastError(); err2 = TraceLastError();
app_fatal("nthread2:\n%s", err2); app_fatal("nthread2:\n%s", err2);
} }
@ -237,7 +237,7 @@ void nthread_cleanup()
gdwTurnsInTransit = 0; gdwTurnsInTransit = 0;
gdwNormalMsgSize = 0; gdwNormalMsgSize = 0;
gdwLargestMsgSize = 0; gdwLargestMsgSize = 0;
if (sghThread != (HANDLE)-1 && glpNThreadId != GetCurrentThreadId()) { if (sghThread != INVALID_HANDLE_VALUE && glpNThreadId != GetCurrentThreadId()) {
#ifdef __cplusplus #ifdef __cplusplus
if (!sgbThreadIsRunning) if (!sgbThreadIsRunning)
sgMemCrit.Leave(); sgMemCrit.Leave();
@ -246,13 +246,13 @@ void nthread_cleanup()
app_fatal("nthread3:\n(%s)", TraceLastError()); app_fatal("nthread3:\n(%s)", TraceLastError());
} }
CloseHandle(sghThread); CloseHandle(sghThread);
sghThread = (HANDLE)-1; sghThread = INVALID_HANDLE_VALUE;
} }
} }
void nthread_ignore_mutex(BOOL bStart) void nthread_ignore_mutex(BOOL bStart)
{ {
if (sghThread != (HANDLE)-1) { if (sghThread != INVALID_HANDLE_VALUE) {
#ifdef __cplusplus #ifdef __cplusplus
if (bStart) if (bStart)
sgMemCrit.Leave(); sgMemCrit.Leave();

Loading…
Cancel
Save