[REGEDIT] Improve error handling (#5833)

- Don't exit the main program on error.
- Improve output_message function.
- Use output_message instead of some
  error_exit function calls.
CORE-19188
This commit is contained in:
Katayama Hirofumi MZ 2023-10-26 19:57:42 +09:00 committed by GitHub
parent fea414b9ed
commit be8a6f8af1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 3 deletions

View file

@ -37,9 +37,7 @@ static void output_writeconsole(const WCHAR *str, DWORD wlen)
#ifdef __REACTOS__
/* This is win32gui application, don't ever try writing to console.
* For the console version we have a separate reg.exe application. */
WCHAR AppStr[255];
LoadStringW(hInst, IDS_APP_TITLE, AppStr, ARRAY_SIZE(AppStr));
MessageBoxW(NULL, str, AppStr, MB_OK | MB_ICONINFORMATION);
MessageBoxW(NULL, str, NULL, MB_ICONERROR);
#else
DWORD count;
@ -219,7 +217,11 @@ static void PerformRegAction(REGEDIT_ACTION action, WCHAR **argv, int *i)
break;
}
default:
#ifdef __REACTOS__
output_message(STRING_UNHANDLED_ACTION);
#else
error_exit(STRING_UNHANDLED_ACTION);
#endif
break;
}
}

View file

@ -1105,11 +1105,23 @@ void delete_registry_key(WCHAR *reg_key_name)
if (!(key_class = parse_key_name(reg_key_name, &key_name)))
{
if (key_name) *(key_name - 1) = 0;
#ifdef __REACTOS__
output_message(STRING_INVALID_SYSTEM_KEY, reg_key_name);
return;
#else
error_exit(STRING_INVALID_SYSTEM_KEY, reg_key_name);
#endif
}
if (!key_name || !*key_name)
#ifdef __REACTOS__
{
output_message(STRING_DELETE_FAILED, reg_key_name);
return;
}
#else
error_exit(STRING_DELETE_FAILED, reg_key_name);
#endif
#ifdef __REACTOS__
SHDeleteKey(key_class, key_name);
@ -1460,7 +1472,12 @@ static FILE *REGPROC_open_export_file(WCHAR *file_name, BOOL unicode)
if (!file)
{
_wperror(L"regedit");
#ifdef __REACTOS__
output_message(STRING_CANNOT_OPEN_FILE, file_name);
return NULL;
#else
error_exit(STRING_CANNOT_OPEN_FILE, file_name);
#endif
}
}
@ -1506,6 +1523,10 @@ static BOOL export_key(WCHAR *file_name, WCHAR *path, BOOL unicode)
return FALSE;
fp = REGPROC_open_export_file(file_name, unicode);
#ifdef __REACTOS__
if (!fp)
return TRUE; /* Error message is already displayed */
#endif
export_registry_data(fp, key, path, unicode);
export_newline(fp, unicode);
fclose(fp);
@ -1522,6 +1543,10 @@ static BOOL export_all(WCHAR *file_name, WCHAR *path, BOOL unicode)
WCHAR *class_name;
fp = REGPROC_open_export_file(file_name, unicode);
#ifdef __REACTOS__
if (!fp)
return TRUE; /* Error message is already displayed */
#endif
for (i = 0; i < ARRAY_SIZE(classes); i++)
{