From 694be2da8d2b52a7d51628cb965623722186b4da Mon Sep 17 00:00:00 2001 From: JustAnotherGuid <46401660+JustAnotherGuid@users.noreply.github.com> Date: Sat, 5 Jan 2019 20:20:21 +0100 Subject: [PATCH] Clean-up mpqapi_set_hidden (#552) * Clean-up mpqapi_set_hidden Co-Authored-By: JustAnotherGuid <46401660+JustAnotherGuid@users.noreply.github.com> --- Source/mpqapi.cpp | 24 +++++++++--------------- Source/mpqapi.h | 2 +- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/Source/mpqapi.cpp b/Source/mpqapi.cpp index aa6ceb33c..520e6abdf 100644 --- a/Source/mpqapi.cpp +++ b/Source/mpqapi.cpp @@ -15,25 +15,19 @@ BOOLEAN save_archive_open; // weak HANDLE sghArchive = (HANDLE)0xFFFFFFFF; // idb -BOOLEAN __fastcall mpqapi_set_hidden(const char *pszArchive, BOOLEAN hidden) +BOOL __fastcall mpqapi_set_hidden(const char *pszArchive, BOOL hidden) { - const char *v2; // edi - BOOL v3; // esi - DWORD v4; // eax - BOOLEAN result; // al - DWORD v6; // esi + DWORD dwFileAttributes; + DWORD dwFileAttributesToSet; - v2 = pszArchive; - v3 = hidden; - v4 = GetFileAttributes(pszArchive); - if (v4 == -1) + dwFileAttributes = GetFileAttributes(pszArchive); + if (dwFileAttributes == INVALID_FILE_ATTRIBUTES) return GetLastError() == ERROR_FILE_NOT_FOUND; - v6 = v3 != 0 ? FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN : 0; - if (v4 == v6) - result = 1; + dwFileAttributesToSet = hidden ? FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN : 0; + if (dwFileAttributes == dwFileAttributesToSet) + return TRUE; else - result = SetFileAttributes(v2, v6); - return result; + return SetFileAttributes(pszArchive, dwFileAttributesToSet); } void __fastcall mpqapi_store_creation_time(const char *pszArchive, int dwChar) diff --git a/Source/mpqapi.h b/Source/mpqapi.h index dd9bf91b3..c95bf88fe 100644 --- a/Source/mpqapi.h +++ b/Source/mpqapi.h @@ -9,7 +9,7 @@ extern BOOLEAN save_archive_modified; // weak extern _BLOCKENTRY *sgpBlockTbl; extern BOOLEAN save_archive_open; // weak -BOOLEAN __fastcall mpqapi_set_hidden(char *pszArchive, BOOLEAN hidden); +BOOL __fastcall mpqapi_set_hidden(char *pszArchive, BOOL hidden); void __fastcall mpqapi_store_creation_time(const char *pszArchive, int dwChar); BOOLEAN __fastcall mpqapi_reg_load_modification_time(char *dst, int size); void __fastcall mpqapi_xor_buf(char *pbData);