[misc] code cleanup

* Also fix WDK compilation issues
This commit is contained in:
Pete Batard 2017-04-25 20:25:50 +01:00
parent afec69c428
commit 55b7d5c2da
9 changed files with 39 additions and 34 deletions

View File

@ -155,7 +155,7 @@ static __inline void ToUpper(char* str)
{
size_t i;
for (i = 0; i < safe_strlen(str); i++)
str[i] = toupper(str[i]);
str[i] = (char)toupper(str[i]);
}
BOOL GetOpticalMedia(IMG_SAVE* img_save)

View File

@ -363,7 +363,7 @@ iso9660_set_ltime_with_timezone(const struct tm *p_tm,
if (!p_tm) return;
snprintf(_pvd_date, 17,
_snprintf(_pvd_date, 17,
"%4.4d%2.2d%2.2d" "%2.2d%2.2d%2.2d" "%2.2d",
p_tm->tm_year + 1900, p_tm->tm_mon + 1, p_tm->tm_mday,
p_tm->tm_hour, p_tm->tm_min, p_tm->tm_sec,
@ -1111,7 +1111,7 @@ iso9660_pathname_isofy (const char pathname[], uint16_t version)
cdio_assert (strlen (pathname) < (sizeof (tmpbuf) - sizeof (";65535")));
snprintf (tmpbuf, sizeof(tmpbuf), "%s;%d", pathname, version);
_snprintf (tmpbuf, sizeof(tmpbuf), "%s;%d", pathname, version);
return strdup (tmpbuf);
}

View File

@ -1437,7 +1437,7 @@ find_lsn_recurse (void *p_image, iso9660_readdir_t iso9660_readdir,
if (*ppsz_full_filename != NULL) free(*ppsz_full_filename);
*ppsz_full_filename = calloc(1, len);
snprintf (*ppsz_full_filename, len, "%s%s/", psz_path, psz_filename);
_snprintf (*ppsz_full_filename, len, "%s%s/", psz_path, psz_filename);
if (statbuf->type == _STAT_DIR
&& strcmp ((char *) statbuf->filename, ".")

View File

@ -648,7 +648,7 @@ WORD get_language_id(loc_cmd* lcmd)
// Find if the selected language is the user default
for (i = 0; i<lcmd->unum_size; i++) {
if (lcmd->unum[i] == lang_id) {
ubpushf("Will use default UI locale 0x%04X", lang_id);
ubprintf("Will use default UI locale 0x%04X", lang_id);
return MAKELANGID(lang_id, SUBLANG_DEFAULT);
}
}
@ -662,12 +662,12 @@ WORD get_language_id(loc_cmd* lcmd)
// boolean to tell us that we found what we were after.
EnumUILanguages(EnumUILanguagesProc, 0x4, (LONG_PTR)wlang); // 0x04 = MUI_LANGUAGE_ID
if (found_lang) {
ubpushf("Detected installed Windows Language Pack for 0x%04X (%s)", lcmd->unum[i], lcmd->txt[1]);
ubprintf("Detected installed Windows Language Pack for 0x%04X (%s)", lcmd->unum[i], lcmd->txt[1]);
return MAKELANGID(lcmd->unum[i], SUBLANG_DEFAULT);
}
}
ubpushf("NOTE: No Windows Language Pack is installed for %s on this system.\r\n"
ubprintf("NOTE: No Windows Language Pack is installed for %s on this system.\r\n"
"This means that some controls may still be displayed using the system locale.", lcmd->txt[1]);
return MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT);
}

View File

@ -1743,7 +1743,7 @@ static void InitDialog(HWND hDlg)
embedded_sl_version_str[1], embedded_sl_version_ext[1]);
uprintf("Grub versions: %s, %s", GRUB4DOS_VERSION, GRUB2_PACKAGE_VERSION);
uprintf("System locale ID: 0x%04X", GetUserDefaultUILanguage());
ubpop();
ubflush();
if (selected_locale->ctrl_id & LOC_NEEDS_UPDATE) {
uprintf("NOTE: The %s translation requires an update, but the current translator hasn't submitted "
"one. Because of this, some messages will only be displayed in English.", selected_locale->txt[1]);
@ -3174,7 +3174,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
}
relaunch:
ubpushf("Localization set to '%s'", selected_locale->txt[0]);
ubprintf("Localization set to '%s'", selected_locale->txt[0]);
right_to_left_mode = ((selected_locale->ctrl_id) & LOC_RIGHT_TO_LEFT);
SetProcessDefaultLayout(right_to_left_mode?LAYOUT_RTL:0);
if (get_loc_data_file(loc_file, selected_locale))
@ -3452,7 +3452,7 @@ out:
SetLGP(TRUE, &existing_key, ep_reg, "NoDriveTypeAutorun", 0);
if ((nWindowsVersion > WINDOWS_XP) && (!automount) && (!SetAutoMount(FALSE)))
uprintf("Failed to restore AutoMount to disabled");
ubpop();
ubflush();
// Unconditional delete with retry, just in case...
for (i = 0; (!DeleteFileA(cmdline_hogger)) && (i <= 10); i++)
Sleep(200);

View File

@ -35,7 +35,7 @@
#pragma once
/* Program options */
#define RUFUS_DEBUG // print debug info to Debug facility
#define RUFUS_LOGGING // print info to logging facility
/* Features not ready for prime time and that may *DESTROY* your data - USE AT YOUR OWN RISKS! */
// #define RUFUS_TEST
@ -119,17 +119,17 @@
#define safe_vsnprintf vsnprintf
#endif
#ifdef RUFUS_DEBUG
#ifdef RUFUS_LOGGING
extern void _uprintf(const char *format, ...);
#define uprintf(...) _uprintf(__VA_ARGS__)
#define ubpushf(...) do { safe_sprintf(&ubuffer[ubuffer_pos], UBUFFER_SIZE - ubuffer_pos - 2, __VA_ARGS__); \
ubuffer_pos = strlen(ubuffer); ubuffer[ubuffer_pos++] = '\r'; ubuffer[ubuffer_pos++] = '\n'; \
ubuffer[ubuffer_pos] = 0; } while(0)
#define ubpop() do { if (ubuffer_pos) uprintf("%s", ubuffer); ubuffer_pos = 0; } while(0)
#define vuprintf(...) if (verbose) _uprintf(__VA_ARGS__)
#define vvuprintf(...) if (verbose > 1) _uprintf(__VA_ARGS__)
#define suprintf(...) if (!bSilent) _uprintf(__VA_ARGS__)
#define uuprintf(...) if (usb_debug) _uprintf(__VA_ARGS__)
#define ubprintf(...) do { safe_sprintf(&ubuffer[ubuffer_pos], UBUFFER_SIZE - ubuffer_pos - 2, __VA_ARGS__); \
ubuffer_pos = strlen(ubuffer); ubuffer[ubuffer_pos++] = '\r'; ubuffer[ubuffer_pos++] = '\n'; \
ubuffer[ubuffer_pos] = 0; } while(0)
#define ubflush() do { if (ubuffer_pos) uprintf("%s", ubuffer); ubuffer_pos = 0; } while(0)
#ifdef _DEBUG
#define duprintf(...) _uprintf(__VA_ARGS__)
#else
@ -141,6 +141,11 @@ extern void _uprintf(const char *format, ...);
#define vvuprintf(...)
#define duprintf(...)
#define suprintf(...)
#define uuprintf(...)
#define duprintf(...)
#define ubprintf(...)
#define ubflush()
#define _uprintf NULL
#endif
/* Custom Windows messages */

View File

@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_DIALOG DIALOGEX 12, 12, 242, 376
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_ACCEPTFILES
CAPTION "Rufus 2.15.1092"
CAPTION "Rufus 2.15.1093"
FONT 8, "Segoe UI Symbol", 400, 0, 0x0
BEGIN
LTEXT "Device",IDS_DEVICE_TXT,9,6,200,8
@ -334,8 +334,8 @@ END
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 2,15,1092,0
PRODUCTVERSION 2,15,1092,0
FILEVERSION 2,15,1093,0
PRODUCTVERSION 2,15,1093,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@ -352,13 +352,13 @@ BEGIN
BEGIN
VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)"
VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "2.15.1092"
VALUE "FileVersion", "2.15.1093"
VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "© 2011-2017 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html"
VALUE "OriginalFilename", "rufus.exe"
VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "2.15.1092"
VALUE "ProductVersion", "2.15.1093"
END
END
BLOCK "VarFileInfo"

View File

@ -717,19 +717,19 @@ DWORD WINAPI SetLGPThread(LPVOID param)
// We need an IGroupPolicyObject instance to set a Local Group Policy
hr = CoCreateInstance(&my_CLSID_GroupPolicyObject, NULL, CLSCTX_INPROC_SERVER, &my_IID_IGroupPolicyObject, (LPVOID*)&pLGPO);
if (FAILED(hr)) {
ubpushf("SetLGP: CoCreateInstance failed; hr = %x", hr);
ubprintf("SetLGP: CoCreateInstance failed; hr = %x", hr);
goto error;
}
hr = pLGPO->lpVtbl->OpenLocalMachineGPO(pLGPO, GPO_OPEN_LOAD_REGISTRY);
if (FAILED(hr)) {
ubpushf("SetLGP: OpenLocalMachineGPO failed - error %x", hr);
ubprintf("SetLGP: OpenLocalMachineGPO failed - error %x", hr);
goto error;
}
hr = pLGPO->lpVtbl->GetRegistryKey(pLGPO, GPO_SECTION_MACHINE, &path_key);
if (FAILED(hr)) {
ubpushf("SetLGP: GetRegistryKey failed - error %x", hr);
ubprintf("SetLGP: GetRegistryKey failed - error %x", hr);
goto error;
}
@ -737,7 +737,7 @@ DWORD WINAPI SetLGPThread(LPVOID param)
r = RegCreateKeyExA(path_key, p->szPath, 0, NULL, 0, KEY_SET_VALUE | KEY_QUERY_VALUE,
NULL, &policy_key, &disp);
if (r != ERROR_SUCCESS) {
ubpushf("SetLGP: Failed to open LGPO path %s - error %x", p->szPath, hr);
ubprintf("SetLGP: Failed to open LGPO path %s - error %x", p->szPath, hr);
policy_key = NULL;
goto error;
}
@ -751,7 +751,7 @@ DWORD WINAPI SetLGPThread(LPVOID param)
// The Key exists but not its value, which is OK
*(p->bExistingKey) = FALSE;
} else if (r != ERROR_SUCCESS) {
ubpushf("SetLGP: Failed to read original %s policy value - error %x", p->szPolicy, r);
ubprintf("SetLGP: Failed to read original %s policy value - error %x", p->szPolicy, r);
}
}
@ -762,7 +762,7 @@ DWORD WINAPI SetLGPThread(LPVOID param)
r = RegDeleteValueA(policy_key, p->szPolicy);
}
if (r != ERROR_SUCCESS) {
ubpushf("SetLGP: RegSetValueEx / RegDeleteValue failed - error %x", r);
ubprintf("SetLGP: RegSetValueEx / RegDeleteValue failed - error %x", r);
}
RegCloseKey(policy_key);
policy_key = NULL;
@ -770,13 +770,13 @@ DWORD WINAPI SetLGPThread(LPVOID param)
// Apply policy
hr = pLGPO->lpVtbl->Save(pLGPO, TRUE, (p->bRestore)?FALSE:TRUE, &ext_guid, &snap_guid);
if (hr != S_OK) {
ubpushf("SetLGP: Unable to apply %s policy - error %x", p->szPolicy, hr);
ubprintf("SetLGP: Unable to apply %s policy - error %x", p->szPolicy, hr);
goto error;
} else {
if ((!p->bRestore) || (*(p->bExistingKey))) {
ubpushf("SetLGP: Successfully %s %s policy to 0x%08X", (p->bRestore)?"restored":"set", p->szPolicy, val);
ubprintf("SetLGP: Successfully %s %s policy to 0x%08X", (p->bRestore)?"restored":"set", p->szPolicy, val);
} else {
ubpushf("SetLGP: Successfully removed %s policy key", p->szPolicy);
ubprintf("SetLGP: Successfully removed %s policy key", p->szPolicy);
}
}
@ -800,17 +800,17 @@ BOOL SetLGP(BOOL bRestore, BOOL* bExistingKey, const char* szPath, const char* s
HANDLE thread_id;
if (ReadSettingBool(SETTING_DISABLE_LGP)) {
ubpushf("LPG handling disabled, per settings");
ubprintf("LPG handling disabled, per settings");
return FALSE;
}
thread_id = CreateThread(NULL, 0, SetLGPThread, (LPVOID)&params, 0, NULL);
if (thread_id == NULL) {
ubpushf("SetLGP: Unable to start thread");
ubprintf("SetLGP: Unable to start thread");
return FALSE;
}
if (WaitForSingleObject(thread_id, 5000) != WAIT_OBJECT_0) {
ubpushf("SetLGP: Killing stuck thread!");
ubprintf("SetLGP: Killing stuck thread!");
TerminateThread(thread_id, 0);
CloseHandle(thread_id);
return FALSE;

View File

@ -41,7 +41,7 @@ HWND hStatus;
size_t ubuffer_pos = 0;
char ubuffer[UBUFFER_SIZE]; // Buffer for ubpushf() messages we don't log right away
#ifdef RUFUS_DEBUG
#ifdef RUFUS_LOGGING
void _uprintf(const char *format, ...)
{
static char buf[4096];