mirror of
https://github.com/pbatard/rufus.git
synced 2024-08-14 23:57:05 +00:00
[misc] improve genericity of registry functions
* Ensure that we can also handle non app specific keys
This commit is contained in:
parent
b82462bb7d
commit
03a97ee261
3 changed files with 67 additions and 22 deletions
|
@ -1,3 +1,12 @@
|
|||
o Version 2.8 (2016.03.??)
|
||||
Enable listing of non-USB card readers (EXPERIMENTAL)
|
||||
Major speed improvements for checksum computation
|
||||
Fix UI flicker during progress report
|
||||
Fix computation of FAT size for Large FAT32 (with thanks to Ady)
|
||||
Syslinux improvements
|
||||
Update GRUB to 2.02~beta3
|
||||
Switch to https when downloading updates
|
||||
|
||||
o Version 2.7 (2016.02.14)
|
||||
Add Thai translation, courtesy of Sippapas Wangsri
|
||||
Add Drag and Drop support, courtesy of SeymourApps
|
||||
|
|
|
@ -54,13 +54,14 @@ static __inline BOOL DeleteRegistryKey(HKEY key_root, const char* key_name)
|
|||
the application and create the app subkey if required */
|
||||
static __inline BOOL _GetRegistryKey(HKEY key_root, const char* key_name, DWORD reg_type, LPBYTE dest, DWORD dest_size)
|
||||
{
|
||||
const char software_prefix[] = "SOFTWARE\\";
|
||||
char long_key_name[MAX_PATH] = { 0 };
|
||||
BOOL r = FALSE;
|
||||
size_t i = 0;
|
||||
size_t i;
|
||||
LONG s;
|
||||
HKEY hSoftware = NULL, hApp = NULL;
|
||||
DWORD dwDisp, dwType = -1, dwSize = dest_size;
|
||||
// VS Code Analysis complains if we don't break our initialization into chars
|
||||
char long_key_name[256] = { 0 };
|
||||
|
||||
memset(dest, 0, dest_size);
|
||||
|
||||
if (key_name == NULL)
|
||||
|
@ -72,9 +73,15 @@ static __inline BOOL _GetRegistryKey(HKEY key_root, const char* key_name, DWORD
|
|||
}
|
||||
|
||||
if (i != 0) {
|
||||
strcpy(long_key_name, "SOFTWARE\\");
|
||||
safe_strcat(long_key_name, sizeof(long_key_name), key_name);
|
||||
long_key_name[sizeof("SOFTWARE\\") + i-1] = 0;
|
||||
// Prefix with "SOFTWARE" if needed
|
||||
if (_strnicmp(key_name, software_prefix, sizeof(software_prefix) - 1) != 0) {
|
||||
strcpy(long_key_name, software_prefix);
|
||||
safe_strcat(long_key_name, sizeof(long_key_name), key_name);
|
||||
long_key_name[sizeof(software_prefix) + i - 1] = 0;
|
||||
} else {
|
||||
safe_strcpy(long_key_name, sizeof(long_key_name), key_name);
|
||||
long_key_name[i] = 0;
|
||||
}
|
||||
i++;
|
||||
if (RegOpenKeyExA(key_root, long_key_name, 0, KEY_READ, &hApp) != ERROR_SUCCESS) {
|
||||
hApp = NULL;
|
||||
|
@ -108,25 +115,54 @@ out:
|
|||
/* Write a generic registry key value (create the key if it doesn't exist) */
|
||||
static __inline BOOL _SetRegistryKey(HKEY key_root, const char* key_name, DWORD reg_type, LPBYTE src, DWORD src_size)
|
||||
{
|
||||
const char software_prefix[] = "SOFTWARE\\";
|
||||
char long_key_name[MAX_PATH] = { 0 };
|
||||
BOOL r = FALSE;
|
||||
HKEY hSoftware = NULL, hApp = NULL;
|
||||
size_t i;
|
||||
HKEY hRoot = NULL, hApp = NULL;
|
||||
DWORD dwDisp, dwType = reg_type;
|
||||
|
||||
if (RegOpenKeyExA(key_root, "SOFTWARE", 0, KEY_READ|KEY_CREATE_SUB_KEY, &hSoftware) != ERROR_SUCCESS) {
|
||||
hSoftware = NULL;
|
||||
goto out;
|
||||
}
|
||||
if (RegCreateKeyExA(hSoftware, COMPANY_NAME "\\" APPLICATION_NAME, 0, NULL, 0,
|
||||
KEY_SET_VALUE|KEY_QUERY_VALUE|KEY_CREATE_SUB_KEY, NULL, &hApp, &dwDisp) != ERROR_SUCCESS) {
|
||||
hApp = NULL;
|
||||
if (RegOpenKeyExA(key_root, NULL, 0, KEY_READ|KEY_CREATE_SUB_KEY, &hRoot) != ERROR_SUCCESS) {
|
||||
hRoot = NULL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
r = (RegSetValueExA(hApp, key_name, 0, dwType, src, src_size) == ERROR_SUCCESS);
|
||||
// Find if we're dealing with a short key
|
||||
for (i = safe_strlen(key_name); i>0; i--) {
|
||||
if (key_name[i] == '\\')
|
||||
break;
|
||||
}
|
||||
|
||||
if (i == 0) {
|
||||
// If this is a short key name, store the value under our app sub-hive
|
||||
if (RegCreateKeyExA(hRoot, "SOFTWARE\\" COMPANY_NAME "\\" APPLICATION_NAME, 0, NULL, 0,
|
||||
KEY_SET_VALUE | KEY_QUERY_VALUE | KEY_CREATE_SUB_KEY, NULL, &hApp, &dwDisp) != ERROR_SUCCESS) {
|
||||
hApp = NULL;
|
||||
goto out;
|
||||
}
|
||||
} else {
|
||||
// Prefix with "SOFTWARE" if needed
|
||||
if (_strnicmp(key_name, software_prefix, sizeof(software_prefix) - 1) != 0) {
|
||||
strcpy(long_key_name, software_prefix);
|
||||
safe_strcat(long_key_name, sizeof(long_key_name), key_name);
|
||||
long_key_name[sizeof(software_prefix) + i - 1] = 0;
|
||||
} else {
|
||||
safe_strcpy(long_key_name, sizeof(long_key_name), key_name);
|
||||
long_key_name[i] = 0;
|
||||
}
|
||||
i++;
|
||||
if (RegCreateKeyExA(hRoot, long_key_name, 0, NULL, 0,
|
||||
KEY_SET_VALUE | KEY_QUERY_VALUE | KEY_CREATE_SUB_KEY, NULL, &hApp, &dwDisp) != ERROR_SUCCESS) {
|
||||
hApp = NULL;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
r = (RegSetValueExA(hApp, &key_name[i], 0, dwType, src, src_size) == ERROR_SUCCESS);
|
||||
|
||||
out:
|
||||
if (hSoftware != NULL)
|
||||
RegCloseKey(hSoftware);
|
||||
if (hRoot != NULL)
|
||||
RegCloseKey(hRoot);
|
||||
if (hApp != NULL)
|
||||
RegCloseKey(hApp);
|
||||
return r;
|
||||
|
|
10
src/rufus.rc
10
src/rufus.rc
|
@ -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.8.882"
|
||||
CAPTION "Rufus 2.8.883"
|
||||
FONT 8, "Segoe UI Symbol", 400, 0, 0x0
|
||||
BEGIN
|
||||
LTEXT "Device",IDS_DEVICE_TXT,9,6,200,8
|
||||
|
@ -320,8 +320,8 @@ END
|
|||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 2,8,882,0
|
||||
PRODUCTVERSION 2,8,882,0
|
||||
FILEVERSION 2,8,883,0
|
||||
PRODUCTVERSION 2,8,883,0
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
|
@ -338,13 +338,13 @@ BEGIN
|
|||
BEGIN
|
||||
VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)"
|
||||
VALUE "FileDescription", "Rufus"
|
||||
VALUE "FileVersion", "2.8.882"
|
||||
VALUE "FileVersion", "2.8.883"
|
||||
VALUE "InternalName", "Rufus"
|
||||
VALUE "LegalCopyright", "© 2011-2016 Pete Batard (GPL v3)"
|
||||
VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html"
|
||||
VALUE "OriginalFilename", "rufus.exe"
|
||||
VALUE "ProductName", "Rufus"
|
||||
VALUE "ProductVersion", "2.8.882"
|
||||
VALUE "ProductVersion", "2.8.883"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
|
|
Loading…
Reference in a new issue