mirror of
https://github.com/reactos/reactos.git
synced 2025-01-07 06:45:24 +00:00
[REGEDIT]
- Katayama Hirofumi: Unicodify regedit, add support for import/export of v5 reg files. Based on Wine regedit. svn path=/trunk/; revision=48933
This commit is contained in:
parent
219137196e
commit
26adfda6bd
11 changed files with 1200 additions and 1140 deletions
|
@ -227,8 +227,8 @@ static void SuggestKeys(HKEY hRootKey, LPCTSTR pszKeyPath, LPTSTR pszSuggestions
|
|||
bFound = FALSE;
|
||||
|
||||
/* Check default key */
|
||||
if (RegQueryStringValue(hRootKey, pszKeyPath, NULL,
|
||||
szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0])) == ERROR_SUCCESS)
|
||||
if (QueryStringValue(hRootKey, pszKeyPath, NULL,
|
||||
szBuffer, COUNT_OF(szBuffer)) == ERROR_SUCCESS)
|
||||
{
|
||||
/* Sanity check this key; it cannot be empty, nor can it be a
|
||||
* loop back */
|
||||
|
@ -259,8 +259,8 @@ static void SuggestKeys(HKEY hRootKey, LPCTSTR pszKeyPath, LPTSTR pszSuggestions
|
|||
/* Check CLSID key */
|
||||
if (RegOpenKey(hRootKey, pszKeyPath, &hSubKey) == ERROR_SUCCESS)
|
||||
{
|
||||
if (RegQueryStringValue(hSubKey, TEXT("CLSID"), NULL,
|
||||
szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0])) == ERROR_SUCCESS)
|
||||
if (QueryStringValue(hSubKey, TEXT("CLSID"), NULL, szBuffer,
|
||||
COUNT_OF(szBuffer)) == ERROR_SUCCESS)
|
||||
{
|
||||
lstrcpyn(pszSuggestions, TEXT("HKCR\\CLSID\\"), (int) iSuggestionsLength);
|
||||
i = _tcslen(pszSuggestions);
|
||||
|
@ -535,8 +535,8 @@ LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa
|
|||
}
|
||||
else
|
||||
{
|
||||
if (RegRenameKey(hRootKey, keyPath, ptvdi->item.pszText) != ERROR_SUCCESS)
|
||||
lResult = FALSE;
|
||||
if (RenameKey(hRootKey, keyPath, ptvdi->item.pszText) != ERROR_SUCCESS)
|
||||
lResult = FALSE;
|
||||
}
|
||||
return lResult;
|
||||
}
|
||||
|
|
|
@ -702,6 +702,91 @@ done:
|
|||
return result;
|
||||
}
|
||||
|
||||
static LONG CopyKey(HKEY hDestKey, LPCTSTR lpDestSubKey, HKEY hSrcKey, LPCTSTR lpSrcSubKey)
|
||||
{
|
||||
LONG lResult;
|
||||
DWORD dwDisposition;
|
||||
HKEY hDestSubKey = NULL;
|
||||
HKEY hSrcSubKey = NULL;
|
||||
DWORD dwIndex, dwType, cbName, cbData;
|
||||
TCHAR szSubKey[256];
|
||||
TCHAR szValueName[256];
|
||||
BYTE szValueData[512];
|
||||
|
||||
FILETIME ft;
|
||||
|
||||
/* open the source subkey, if specified */
|
||||
if (lpSrcSubKey)
|
||||
{
|
||||
lResult = RegOpenKeyEx(hSrcKey, lpSrcSubKey, 0, KEY_ALL_ACCESS, &hSrcSubKey);
|
||||
if (lResult)
|
||||
goto done;
|
||||
hSrcKey = hSrcSubKey;
|
||||
}
|
||||
|
||||
/* create the destination subkey */
|
||||
lResult = RegCreateKeyEx(hDestKey, lpDestSubKey, 0, NULL, 0, KEY_WRITE, NULL,
|
||||
&hDestSubKey, &dwDisposition);
|
||||
if (lResult)
|
||||
goto done;
|
||||
|
||||
/* copy all subkeys */
|
||||
dwIndex = 0;
|
||||
do
|
||||
{
|
||||
cbName = sizeof(szSubKey) / sizeof(szSubKey[0]);
|
||||
lResult = RegEnumKeyEx(hSrcKey, dwIndex++, szSubKey, &cbName, NULL, NULL, NULL, &ft);
|
||||
if (lResult == ERROR_SUCCESS)
|
||||
{
|
||||
lResult = CopyKey(hDestSubKey, szSubKey, hSrcKey, szSubKey);
|
||||
if (lResult)
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
while(lResult == ERROR_SUCCESS);
|
||||
|
||||
/* copy all subvalues */
|
||||
dwIndex = 0;
|
||||
do
|
||||
{
|
||||
cbName = sizeof(szValueName) / sizeof(szValueName[0]);
|
||||
cbData = sizeof(szValueData) / sizeof(szValueData[0]);
|
||||
lResult = RegEnumValue(hSrcKey, dwIndex++, szValueName, &cbName, NULL, &dwType, szValueData, &cbData);
|
||||
if (lResult == ERROR_SUCCESS)
|
||||
{
|
||||
lResult = RegSetValueEx(hDestSubKey, szValueName, 0, dwType, szValueData, cbData);
|
||||
if (lResult)
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
while(lResult == ERROR_SUCCESS);
|
||||
|
||||
lResult = ERROR_SUCCESS;
|
||||
|
||||
done:
|
||||
if (hSrcSubKey)
|
||||
RegCloseKey(hSrcSubKey);
|
||||
if (hDestSubKey)
|
||||
RegCloseKey(hDestSubKey);
|
||||
if (lResult != ERROR_SUCCESS)
|
||||
SHDeleteKey(hDestKey, lpDestSubKey);
|
||||
return lResult;
|
||||
}
|
||||
|
||||
static LONG MoveKey(HKEY hDestKey, LPCTSTR lpDestSubKey, HKEY hSrcKey, LPCTSTR lpSrcSubKey)
|
||||
{
|
||||
LONG lResult;
|
||||
|
||||
if (!lpSrcSubKey)
|
||||
return ERROR_INVALID_FUNCTION;
|
||||
|
||||
lResult = CopyKey(hDestKey, lpDestSubKey, hSrcKey, lpSrcSubKey);
|
||||
if (lResult == ERROR_SUCCESS)
|
||||
SHDeleteKey(hSrcKey, lpSrcSubKey);
|
||||
|
||||
return lResult;
|
||||
}
|
||||
|
||||
BOOL DeleteKey(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath)
|
||||
{
|
||||
TCHAR msg[128], caption[128];
|
||||
|
@ -732,3 +817,128 @@ done:
|
|||
RegCloseKey(hKey);
|
||||
return result;
|
||||
}
|
||||
|
||||
LONG RenameKey(HKEY hKey, LPCTSTR lpSubKey, LPCTSTR lpNewName)
|
||||
{
|
||||
LPCTSTR s;
|
||||
LPTSTR lpNewSubKey = NULL;
|
||||
LONG Ret = 0;
|
||||
|
||||
if (!lpSubKey)
|
||||
return Ret;
|
||||
|
||||
s = _tcsrchr(lpSubKey, _T('\\'));
|
||||
if (s)
|
||||
{
|
||||
s++;
|
||||
lpNewSubKey = (LPTSTR) HeapAlloc(GetProcessHeap(), 0, (s - lpSubKey + _tcslen(lpNewName) + 1) * sizeof(TCHAR));
|
||||
if (lpNewSubKey != NULL)
|
||||
{
|
||||
memcpy(lpNewSubKey, lpSubKey, (s - lpSubKey) * sizeof(TCHAR));
|
||||
lstrcpy(lpNewSubKey + (s - lpSubKey), lpNewName);
|
||||
lpNewName = lpNewSubKey;
|
||||
}
|
||||
else
|
||||
return ERROR_NOT_ENOUGH_MEMORY;
|
||||
}
|
||||
|
||||
Ret = MoveKey(hKey, lpNewName, hKey, lpSubKey);
|
||||
|
||||
if (lpNewSubKey)
|
||||
{
|
||||
HeapFree(GetProcessHeap(), 0, lpNewSubKey);
|
||||
}
|
||||
return Ret;
|
||||
}
|
||||
|
||||
LONG RenameValue(HKEY hKey, LPCTSTR lpSubKey, LPCTSTR lpDestValue, LPCTSTR lpSrcValue)
|
||||
{
|
||||
LONG lResult;
|
||||
HKEY hSubKey = NULL;
|
||||
DWORD dwType, cbData;
|
||||
BYTE data[512];
|
||||
|
||||
if (lpSubKey)
|
||||
{
|
||||
lResult = RegOpenKey(hKey, lpSubKey, &hSubKey);
|
||||
if (lResult != ERROR_SUCCESS)
|
||||
goto done;
|
||||
hKey = hSubKey;
|
||||
}
|
||||
|
||||
cbData = sizeof(data);
|
||||
lResult = RegQueryValueEx(hKey, lpSrcValue, NULL, &dwType, data, &cbData);
|
||||
if (lResult != ERROR_SUCCESS)
|
||||
goto done;
|
||||
|
||||
lResult = RegSetValueEx(hKey, lpDestValue, 0, dwType, data, cbData);
|
||||
if (lResult != ERROR_SUCCESS)
|
||||
goto done;
|
||||
|
||||
RegDeleteValue(hKey, lpSrcValue);
|
||||
|
||||
done:
|
||||
if (hSubKey)
|
||||
RegCloseKey(hSubKey);
|
||||
return lResult;
|
||||
}
|
||||
|
||||
LONG QueryStringValue(HKEY hKey, LPCTSTR lpSubKey, LPCTSTR lpValueName, LPTSTR pszBuffer, DWORD dwBufferLen)
|
||||
{
|
||||
LONG lResult;
|
||||
HKEY hSubKey = NULL;
|
||||
DWORD cbData, dwType;
|
||||
|
||||
if (lpSubKey)
|
||||
{
|
||||
lResult = RegOpenKey(hKey, lpSubKey, &hSubKey);
|
||||
if (lResult != ERROR_SUCCESS)
|
||||
goto done;
|
||||
hKey = hSubKey;
|
||||
}
|
||||
|
||||
cbData = (dwBufferLen - 1) * sizeof(*pszBuffer);
|
||||
lResult = RegQueryValueEx(hKey, lpValueName, NULL, &dwType, (LPBYTE) pszBuffer, &cbData);
|
||||
if (lResult != ERROR_SUCCESS)
|
||||
goto done;
|
||||
if (dwType != REG_SZ)
|
||||
{
|
||||
lResult = -1;
|
||||
goto done;
|
||||
}
|
||||
|
||||
pszBuffer[cbData / sizeof(*pszBuffer)] = _T('\0');
|
||||
|
||||
done:
|
||||
if (lResult != ERROR_SUCCESS)
|
||||
pszBuffer[0] = _T('\0');
|
||||
if (hSubKey)
|
||||
RegCloseKey(hSubKey);
|
||||
return lResult;
|
||||
}
|
||||
|
||||
BOOL GetKeyName(LPTSTR pszDest, size_t iDestLength, HKEY hRootKey, LPCTSTR lpSubKey)
|
||||
{
|
||||
LPCTSTR pszRootKey;
|
||||
|
||||
if (hRootKey == HKEY_CLASSES_ROOT)
|
||||
pszRootKey = TEXT("HKEY_CLASSES_ROOT");
|
||||
else if (hRootKey == HKEY_CURRENT_USER)
|
||||
pszRootKey = TEXT("HKEY_CURRENT_USER");
|
||||
else if (hRootKey == HKEY_LOCAL_MACHINE)
|
||||
pszRootKey = TEXT("HKEY_LOCAL_MACHINE");
|
||||
else if (hRootKey == HKEY_USERS)
|
||||
pszRootKey = TEXT("HKEY_USERS");
|
||||
else if (hRootKey == HKEY_CURRENT_CONFIG)
|
||||
pszRootKey = TEXT("HKEY_CURRENT_CONFIG");
|
||||
else if (hRootKey == HKEY_DYN_DATA)
|
||||
pszRootKey = TEXT("HKEY_DYN_DATA");
|
||||
else
|
||||
return FALSE;
|
||||
|
||||
if (lpSubKey[0])
|
||||
_sntprintf(pszDest, iDestLength, TEXT("%s\\%s"), pszRootKey, lpSubKey);
|
||||
else
|
||||
_sntprintf(pszDest, iDestLength, TEXT("%s"), pszRootKey);
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,12 @@
|
|||
|
||||
#include <regedit.h>
|
||||
|
||||
#define RSF_WHOLESTRING 0x00000001
|
||||
#define RSF_LOOKATKEYS 0x00000002
|
||||
#define RSF_LOOKATVALUES 0x00000004
|
||||
#define RSF_LOOKATDATA 0x00000008
|
||||
#define RSF_MATCHCASE 0x00010000
|
||||
|
||||
static TCHAR s_szFindWhat[256];
|
||||
static const TCHAR s_szFindFlags[] = _T("FindFlags");
|
||||
static const TCHAR s_szFindFlagsR[] = _T("FindFlagsReactOS");
|
||||
|
@ -677,7 +683,7 @@ BOOL FindNext(HWND hWnd)
|
|||
|
||||
if (fSuccess)
|
||||
{
|
||||
RegKeyGetName(szFullKey, COUNT_OF(szFullKey), hKeyRoot, pszFoundSubKey);
|
||||
GetKeyName(szFullKey, COUNT_OF(szFullKey), hKeyRoot, pszFoundSubKey);
|
||||
SelectNode(g_pChildWnd->hTreeWnd, szFullKey);
|
||||
SetValueName(g_pChildWnd->hListWnd, pszFoundValueName);
|
||||
free(pszFoundSubKey);
|
||||
|
|
|
@ -278,6 +278,7 @@ static BOOL InitOpenFileName(HWND hWnd, OPENFILENAME* pofn)
|
|||
pofn->lpstrFileTitle = FileTitleBuffer;
|
||||
pofn->nMaxFileTitle = _MAX_PATH;
|
||||
pofn->Flags = OFN_HIDEREADONLY;
|
||||
pofn->lpstrDefExt = TEXT("reg");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -285,38 +286,33 @@ static BOOL ImportRegistryFile(HWND hWnd)
|
|||
{
|
||||
OPENFILENAME ofn;
|
||||
TCHAR Caption[128];
|
||||
LPCTSTR pszKeyPath;
|
||||
HKEY hRootKey;
|
||||
|
||||
InitOpenFileName(hWnd, &ofn);
|
||||
LoadString(hInst, IDS_IMPORT_REG_FILE, Caption, sizeof(Caption)/sizeof(TCHAR));
|
||||
LoadString(hInst, IDS_IMPORT_REG_FILE, Caption, COUNT_OF(Caption));
|
||||
ofn.lpstrTitle = Caption;
|
||||
ofn.Flags |= OFN_ENABLESIZING;
|
||||
/* ofn.lCustData = ;*/
|
||||
if (GetOpenFileName(&ofn)) {
|
||||
/* FIXME - convert to ascii */
|
||||
if (!import_registry_file(ofn.lpstrFile)) {
|
||||
/*printf("Can't open file \"%s\"\n", ofn.lpstrFile);*/
|
||||
FILE *fp = _wfopen(ofn.lpstrFile, L"r");
|
||||
if (fp == NULL || !import_registry_file(fp)) {
|
||||
LPSTR p = GetMultiByteString(ofn.lpstrFile);
|
||||
fprintf(stderr, "Can't open file \"%s\"\n", p);
|
||||
HeapFree(GetProcessHeap(), 0, p);
|
||||
if (fp != NULL)
|
||||
fclose(fp);
|
||||
return FALSE;
|
||||
}
|
||||
#if 0
|
||||
get_file_name(&s, filename, MAX_PATH);
|
||||
if (!filename[0]) {
|
||||
printf("No file name is specified\n%s", usage);
|
||||
return FALSE;
|
||||
/*exit(1);*/
|
||||
}
|
||||
while (filename[0]) {
|
||||
if (!import_registry_file(filename)) {
|
||||
perror("");
|
||||
printf("Can't open file \"%s\"\n", filename);
|
||||
return FALSE;
|
||||
/*exit(1);*/
|
||||
}
|
||||
get_file_name(&s, filename, MAX_PATH);
|
||||
}
|
||||
#endif
|
||||
|
||||
fclose(fp);
|
||||
} else {
|
||||
CheckCommDlgError(hWnd);
|
||||
}
|
||||
|
||||
RefreshTreeView(g_pChildWnd->hTreeWnd);
|
||||
pszKeyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hRootKey);
|
||||
RefreshListView(g_pChildWnd->hListWnd, hRootKey, pszKeyPath);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -384,8 +380,7 @@ BOOL ExportRegistryFile(HWND hWnd)
|
|||
|
||||
/* Figure out which key path we are exporting */
|
||||
pszKeyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hKeyRoot);
|
||||
RegKeyGetName(ExportKeyPath, sizeof(ExportKeyPath) / sizeof(ExportKeyPath[0]),
|
||||
hKeyRoot, pszKeyPath);
|
||||
GetKeyName(ExportKeyPath, COUNT_OF(ExportKeyPath), hKeyRoot, pszKeyPath);
|
||||
|
||||
InitOpenFileName(hWnd, &ofn);
|
||||
LoadString(hInst, IDS_EXPORT_REG_FILE, Caption, sizeof(Caption)/sizeof(TCHAR));
|
||||
|
@ -396,44 +391,24 @@ BOOL ExportRegistryFile(HWND hWnd)
|
|||
{
|
||||
ofn.lCustData = (LPARAM) ExportKeyPath;
|
||||
}
|
||||
ofn.Flags = OFN_ENABLETEMPLATE | OFN_EXPLORER | OFN_ENABLEHOOK;
|
||||
ofn.Flags = OFN_ENABLETEMPLATE | OFN_EXPLORER | OFN_ENABLEHOOK | OFN_OVERWRITEPROMPT;
|
||||
ofn.lpfnHook = ExportRegistryFile_OFNHookProc;
|
||||
ofn.lpTemplateName = MAKEINTRESOURCE(IDD_EXPORTRANGE);
|
||||
if (GetSaveFileName(&ofn)) {
|
||||
BOOL result;
|
||||
LPSTR pszExportKeyPath;
|
||||
#ifdef UNICODE
|
||||
CHAR buffer[_MAX_PATH];
|
||||
|
||||
WideCharToMultiByte(CP_ACP, 0, ExportKeyPath, -1, buffer, sizeof(buffer), NULL, NULL);
|
||||
pszExportKeyPath = buffer;
|
||||
#else
|
||||
pszExportKeyPath = ExportKeyPath;
|
||||
#endif
|
||||
|
||||
result = export_registry_key(ofn.lpstrFile, pszExportKeyPath);
|
||||
DWORD format;
|
||||
|
||||
if (ofn.nFilterIndex == 1)
|
||||
format = REG_FORMAT_5;
|
||||
else
|
||||
format = REG_FORMAT_4;
|
||||
result = export_registry_key(ofn.lpstrFile, ExportKeyPath, format);
|
||||
if (!result) {
|
||||
/*printf("Can't open file \"%s\"\n", ofn.lpstrFile);*/
|
||||
LPSTR p = GetMultiByteString(ofn.lpstrFile);
|
||||
fprintf(stderr, "Can't open file \"%s\"\n", p);
|
||||
HeapFree(GetProcessHeap(), 0, p);
|
||||
return FALSE;
|
||||
}
|
||||
#if 0
|
||||
TCHAR filename[MAX_PATH];
|
||||
filename[0] = '\0';
|
||||
get_file_name(&s, filename, MAX_PATH);
|
||||
if (!filename[0]) {
|
||||
printf("No file name is specified\n%s", usage);
|
||||
return FALSE;
|
||||
/*exit(1);*/
|
||||
}
|
||||
if (s[0]) {
|
||||
TCHAR reg_key_name[KEY_MAX_LEN];
|
||||
get_file_name(&s, reg_key_name, KEY_MAX_LEN);
|
||||
export_registry_key((CHAR)filename, reg_key_name);
|
||||
} else {
|
||||
export_registry_key(filename, NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
} else {
|
||||
CheckCommDlgError(hWnd);
|
||||
}
|
||||
|
@ -543,7 +518,7 @@ BOOL CopyKeyName(HWND hWnd, HKEY hRootKey, LPCTSTR keyName)
|
|||
if (!EmptyClipboard())
|
||||
goto done;
|
||||
|
||||
if (!RegKeyGetName(szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]), hRootKey, keyName))
|
||||
if (!GetKeyName(szBuffer, COUNT_OF(szBuffer), hRootKey, keyName))
|
||||
goto done;
|
||||
|
||||
hGlobal = GlobalAlloc(GMEM_MOVEABLE, (_tcslen(szBuffer) + 1) * sizeof(TCHAR));
|
||||
|
|
|
@ -455,7 +455,7 @@ BOOL ListWndNotifyProc(HWND hWnd, WPARAM wParam, LPARAM lParam, BOOL *Result)
|
|||
LONG lResult;
|
||||
|
||||
keyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hKeyRoot);
|
||||
lResult = RegRenameValue(hKeyRoot, keyPath, Info->item.pszText, lineinfo->name);
|
||||
lResult = RenameValue(hKeyRoot, keyPath, Info->item.pszText, lineinfo->name);
|
||||
lineinfo->name = realloc(lineinfo->name, (_tcslen(Info->item.pszText)+1)*sizeof(TCHAR));
|
||||
if (lineinfo->name != NULL)
|
||||
_tcscpy(lineinfo->name, Info->item.pszText);
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
#include <regedit.h>
|
||||
|
||||
BOOL ProcessCmdLine(LPSTR lpCmdLine);
|
||||
BOOL ProcessCmdLine(LPWSTR lpCmdLine);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
|
@ -143,9 +143,8 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
|
|||
}
|
||||
|
||||
/* Restore position */
|
||||
if (RegQueryStringValue(HKEY_CURRENT_USER, g_szGeneralRegKey,
|
||||
_T("LastKey"),
|
||||
szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0])) == ERROR_SUCCESS)
|
||||
if (QueryStringValue(HKEY_CURRENT_USER, g_szGeneralRegKey, _T("LastKey"),
|
||||
szBuffer, COUNT_OF(szBuffer)) == ERROR_SUCCESS)
|
||||
{
|
||||
SelectNode(g_pChildWnd->hTreeWnd, szBuffer);
|
||||
}
|
||||
|
@ -183,31 +182,16 @@ BOOL TranslateChildTabMessage(MSG *msg)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
int APIENTRY WinMain(HINSTANCE hInstance,
|
||||
HINSTANCE hPrevInstance,
|
||||
LPSTR lpCmdLine,
|
||||
int nCmdShow)
|
||||
int APIENTRY wWinMain(HINSTANCE hInstance,
|
||||
HINSTANCE hPrevInstance,
|
||||
LPWSTR lpCmdLine,
|
||||
int nCmdShow)
|
||||
{
|
||||
MSG msg;
|
||||
HACCEL hAccel;
|
||||
|
||||
UNREFERENCED_PARAMETER(hPrevInstance);
|
||||
|
||||
/*
|
||||
int hCrt;
|
||||
FILE *hf;
|
||||
AllocConsole();
|
||||
hCrt = _open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE), _O_TEXT);
|
||||
hf = _fdopen(hCrt, "w");
|
||||
*stdout = *hf;
|
||||
setvbuf(stdout, NULL, _IONBF, 0);
|
||||
|
||||
wprintf(L"command line exit, hInstance = %d\n", hInstance);
|
||||
getch();
|
||||
FreeConsole();
|
||||
return 0;
|
||||
*/
|
||||
|
||||
if (ProcessCmdLine(lpCmdLine)) {
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -124,3 +124,10 @@ extern void DestroyMainMenu( void );
|
|||
/* edit.c */
|
||||
extern BOOL ModifyValue(HWND hwnd, HKEY hKey, LPCTSTR valueName, BOOL EditBin);
|
||||
extern BOOL DeleteKey(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath);
|
||||
extern LONG RenameKey(HKEY hKey, LPCTSTR lpSubKey, LPCTSTR lpNewName);
|
||||
extern LONG RenameValue(HKEY hKey, LPCTSTR lpSubKey, LPCTSTR lpDestValue, LPCTSTR lpSrcValue);
|
||||
extern LONG QueryStringValue(HKEY hKey, LPCTSTR lpSubKey, LPCTSTR lpValueName, LPTSTR pszBuffer, DWORD dwBufferLen);
|
||||
extern BOOL GetKeyName(LPTSTR pszDest, size_t iDestLength, HKEY hRootKey, LPCTSTR lpSubKey);
|
||||
|
||||
/* security.c */
|
||||
extern BOOL RegKeyEditPermissions(HWND hWndOwner, HKEY hKey, LPCTSTR lpMachine, LPCTSTR lpKeyName);
|
||||
|
|
|
@ -56,7 +56,136 @@ typedef enum {
|
|||
ACTION_UNDEF, ACTION_ADD, ACTION_EXPORT, ACTION_DELETE
|
||||
} REGEDIT_ACTION;
|
||||
|
||||
BOOL PerformRegAction(REGEDIT_ACTION action, LPSTR s);
|
||||
|
||||
const CHAR *getAppName(void)
|
||||
{
|
||||
return "regedit";
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Copies file name from command line string to the buffer.
|
||||
* Rewinds the command line string pointer to the next non-space character
|
||||
* after the file name.
|
||||
* Buffer contains an empty string if no filename was found;
|
||||
*
|
||||
* params:
|
||||
* command_line - command line current position pointer
|
||||
* where *s[0] is the first symbol of the file name.
|
||||
* file_name - buffer to write the file name to.
|
||||
*/
|
||||
void get_file_name(LPWSTR *command_line, LPWSTR file_name)
|
||||
{
|
||||
WCHAR *s = *command_line;
|
||||
int pos = 0; /* position of pointer "s" in *command_line */
|
||||
file_name[0] = 0;
|
||||
|
||||
if (!s[0]) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (s[0] == L'"') {
|
||||
s++;
|
||||
(*command_line)++;
|
||||
while(s[0] != L'"') {
|
||||
if (!s[0]) {
|
||||
fprintf(stderr, "%s: Unexpected end of file name!\n", getAppName());
|
||||
exit(1);
|
||||
}
|
||||
s++;
|
||||
pos++;
|
||||
}
|
||||
} else {
|
||||
while(s[0] && !iswspace(s[0])) {
|
||||
s++;
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
memcpy(file_name, *command_line, pos * sizeof((*command_line)[0]));
|
||||
/* remove the last backslash */
|
||||
if (file_name[pos - 1] == L'\\') {
|
||||
file_name[pos - 1] = L'\0';
|
||||
} else {
|
||||
file_name[pos] = L'\0';
|
||||
}
|
||||
|
||||
if (s[0]) {
|
||||
s++;
|
||||
pos++;
|
||||
}
|
||||
while(s[0] && iswspace(s[0])) {
|
||||
s++;
|
||||
pos++;
|
||||
}
|
||||
(*command_line) += pos;
|
||||
}
|
||||
|
||||
BOOL PerformRegAction(REGEDIT_ACTION action, LPWSTR s)
|
||||
{
|
||||
switch (action) {
|
||||
case ACTION_ADD: {
|
||||
WCHAR filename[MAX_PATH];
|
||||
FILE *fp;
|
||||
|
||||
get_file_name(&s, filename);
|
||||
if (!filename[0]) {
|
||||
fprintf(stderr, "%s: No file name is specified\n", getAppName());
|
||||
fprintf(stderr, usage);
|
||||
exit(4);
|
||||
}
|
||||
|
||||
while(filename[0]) {
|
||||
fp = _wfopen(filename, L"r");
|
||||
if (fp == NULL)
|
||||
{
|
||||
LPSTR p = GetMultiByteString(filename);
|
||||
perror("");
|
||||
fprintf(stderr, "%s: Can't open file \"%s\"\n", getAppName(), p);
|
||||
HeapFree(GetProcessHeap(), 0, p);
|
||||
exit(5);
|
||||
}
|
||||
import_registry_file(fp);
|
||||
get_file_name(&s, filename);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ACTION_DELETE: {
|
||||
WCHAR reg_key_name[KEY_MAX_LEN];
|
||||
get_file_name(&s, reg_key_name);
|
||||
if (!reg_key_name[0]) {
|
||||
fprintf(stderr, "%s: No registry key is specified for removal\n", getAppName());
|
||||
fprintf(stderr, usage);
|
||||
exit(6);
|
||||
}
|
||||
delete_registry_key(reg_key_name);
|
||||
break;
|
||||
}
|
||||
case ACTION_EXPORT: {
|
||||
WCHAR filename[MAX_PATH];
|
||||
|
||||
filename[0] = _T('\0');
|
||||
get_file_name(&s, filename);
|
||||
if (!filename[0]) {
|
||||
fprintf(stderr, "%s: No file name is specified\n", getAppName());
|
||||
fprintf(stderr, usage);
|
||||
exit(7);
|
||||
}
|
||||
|
||||
if (s[0]) {
|
||||
WCHAR reg_key_name[KEY_MAX_LEN];
|
||||
get_file_name(&s, reg_key_name);
|
||||
export_registry_key(filename, reg_key_name, REG_FORMAT_4);
|
||||
} else {
|
||||
export_registry_key(filename, NULL, REG_FORMAT_4);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
fprintf(stderr, "%s: Unhandled action!\n", getAppName());
|
||||
exit(8);
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process unknown switch.
|
||||
|
@ -65,46 +194,47 @@ BOOL PerformRegAction(REGEDIT_ACTION action, LPSTR s);
|
|||
* chu - the switch character in upper-case.
|
||||
* s - the command line string where s points to the switch character.
|
||||
*/
|
||||
static void error_unknown_switch(char chu, char *s)
|
||||
static void error_unknown_switch(WCHAR chu, LPWSTR s)
|
||||
{
|
||||
if (isalpha(chu)) {
|
||||
fprintf(stderr,"%s: Undefined switch /%c!\n", getAppName(), chu);
|
||||
if (iswalpha(chu)) {
|
||||
fprintf(stderr, "%s: Undefined switch /%c!\n", getAppName(), chu);
|
||||
} else {
|
||||
fprintf(stderr,"%s: Alphabetic character is expected after '%c' "
|
||||
fprintf(stderr, "%s: Alphabetic character is expected after '%c' "
|
||||
"in swit ch specification\n", getAppName(), *(s - 1));
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
|
||||
BOOL ProcessCmdLine(LPSTR lpCmdLine)
|
||||
BOOL ProcessCmdLine(LPWSTR lpCmdLine)
|
||||
{
|
||||
REGEDIT_ACTION action = ACTION_UNDEF;
|
||||
LPSTR s = lpCmdLine; /* command line pointer */
|
||||
CHAR ch = *s; /* current character */
|
||||
LPWSTR s = lpCmdLine; /* command line pointer */
|
||||
WCHAR ch = *s; /* current character */
|
||||
|
||||
setAppName("regedit");
|
||||
while (ch && ((ch == '-') || (ch == '/'))) {
|
||||
char chu;
|
||||
char ch2;
|
||||
while (ch && ((ch == L'-') || (ch == L'/')))
|
||||
{
|
||||
WCHAR chu;
|
||||
WCHAR ch2;
|
||||
|
||||
s++;
|
||||
ch = *s;
|
||||
ch2 = *(s+1);
|
||||
chu = (CHAR) toupper(ch);
|
||||
if (!ch2 || isspace(ch2)) {
|
||||
if (chu == 'S' || chu == 'V') {
|
||||
ch2 = *(s + 1);
|
||||
chu = (WCHAR)towupper(ch);
|
||||
if (!ch2 || iswspace(ch2)) {
|
||||
if (chu == L'S' || chu == L'V')
|
||||
{
|
||||
/* ignore these switches */
|
||||
} else {
|
||||
switch (chu) {
|
||||
case 'D':
|
||||
case L'D':
|
||||
action = ACTION_DELETE;
|
||||
break;
|
||||
case 'E':
|
||||
case L'E':
|
||||
action = ACTION_EXPORT;
|
||||
break;
|
||||
case '?':
|
||||
fprintf(stderr,usage);
|
||||
exit(0);
|
||||
case L'?':
|
||||
fprintf(stderr, usage);
|
||||
exit(3);
|
||||
break;
|
||||
default:
|
||||
error_unknown_switch(chu, s);
|
||||
|
@ -113,13 +243,13 @@ BOOL ProcessCmdLine(LPSTR lpCmdLine)
|
|||
}
|
||||
s++;
|
||||
} else {
|
||||
if (ch2 == ':') {
|
||||
if (ch2 == L':') {
|
||||
switch (chu) {
|
||||
case 'L':
|
||||
case L'L':
|
||||
/* fall through */
|
||||
case 'R':
|
||||
case L'R':
|
||||
s += 2;
|
||||
while (*s && !isspace(*s)) {
|
||||
while (*s && !iswspace(*s)) {
|
||||
s++;
|
||||
}
|
||||
break;
|
||||
|
@ -135,7 +265,7 @@ BOOL ProcessCmdLine(LPSTR lpCmdLine)
|
|||
}
|
||||
/* skip spaces to the next parameter */
|
||||
ch = *s;
|
||||
while (ch && isspace(ch)) {
|
||||
while (ch && iswspace(ch)) {
|
||||
s++;
|
||||
ch = *s;
|
||||
}
|
||||
|
@ -149,85 +279,3 @@ BOOL ProcessCmdLine(LPSTR lpCmdLine)
|
|||
|
||||
return PerformRegAction(action, s);
|
||||
}
|
||||
|
||||
BOOL PerformRegAction(REGEDIT_ACTION action, LPSTR s)
|
||||
{
|
||||
switch (action) {
|
||||
case ACTION_ADD: {
|
||||
CHAR filename[MAX_PATH];
|
||||
FILE *reg_file;
|
||||
|
||||
get_file_name(&s, filename);
|
||||
if (!filename[0]) {
|
||||
fprintf(stderr,"%s: No file name is specified\n", getAppName());
|
||||
fprintf(stderr,usage);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
while(filename[0]) {
|
||||
reg_file = fopen(filename, "r");
|
||||
if (reg_file) {
|
||||
processRegLines(reg_file, doSetValue);
|
||||
fclose(reg_file);
|
||||
} else {
|
||||
perror("");
|
||||
fprintf(stderr,"%s: Can't open file \"%s\"\n", getAppName(), filename);
|
||||
exit(1);
|
||||
}
|
||||
get_file_name(&s, filename);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ACTION_DELETE: {
|
||||
CHAR reg_key_name[KEY_MAX_LEN];
|
||||
|
||||
get_file_name(&s, reg_key_name);
|
||||
if (!reg_key_name[0]) {
|
||||
fprintf(stderr,"%s: No registry key is specified for removal\n",
|
||||
getAppName());
|
||||
fprintf(stderr,usage);
|
||||
exit(1);
|
||||
}
|
||||
delete_registry_key(reg_key_name);
|
||||
break;
|
||||
}
|
||||
case ACTION_EXPORT: {
|
||||
CHAR filename[MAX_PATH];
|
||||
LPCTSTR pszFilename;
|
||||
#ifdef UNICODE
|
||||
WCHAR filename_wide[MAX_PATH];
|
||||
#endif
|
||||
|
||||
filename[0] = '\0';
|
||||
get_file_name(&s, filename);
|
||||
if (!filename[0]) {
|
||||
fprintf(stderr,"%s: No file name is specified\n", getAppName());
|
||||
fprintf(stderr,usage);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
#ifdef UNICODE
|
||||
MultiByteToWideChar(CP_ACP, 0, filename, -1, filename_wide,
|
||||
sizeof(filename_wide) / sizeof(filename_wide[0]));
|
||||
pszFilename = filename_wide;
|
||||
#else
|
||||
pszFilename = filename;
|
||||
#endif
|
||||
|
||||
if (s[0]) {
|
||||
CHAR reg_key_name[KEY_MAX_LEN];
|
||||
|
||||
get_file_name(&s, reg_key_name);
|
||||
export_registry_key(pszFilename, reg_key_name);
|
||||
} else {
|
||||
export_registry_key(pszFilename, NULL);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
fprintf(stderr,"%s: Unhandled action!\n", getAppName());
|
||||
exit(1);
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0"?>
|
||||
<!DOCTYPE group SYSTEM "../../../tools/rbuild/project.dtd">
|
||||
<group xmlns:xi="http://www.w3.org/2001/XInclude">
|
||||
<module name="regedit" type="win32gui" installname="regedit.exe">
|
||||
<module name="regedit" type="win32gui" installname="regedit.exe" unicode="yes">
|
||||
<include base="regedit">.</include>
|
||||
<define name="UNICODE" />
|
||||
<define name="_UNICODE" />
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -17,81 +17,15 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
* Defines and consts
|
||||
*/
|
||||
#define KEY_MAX_LEN 1024
|
||||
|
||||
/* Return values */
|
||||
#define SUCCESS 0
|
||||
#define KEY_VALUE_ALREADY_SET 2
|
||||
#define REG_FORMAT_5 1
|
||||
#define REG_FORMAT_4 2
|
||||
|
||||
extern HINSTANCE hInst;
|
||||
|
||||
typedef void (*CommandAPI)(LPSTR lpsLine);
|
||||
|
||||
void doSetValue(LPSTR lpsLine);
|
||||
void doDeleteValue(LPSTR lpsLine);
|
||||
void doCreateKey(LPSTR lpsLine);
|
||||
void doDeleteKey(LPSTR lpsLine);
|
||||
void doRegisterDLL(LPSTR lpsLine);
|
||||
void doUnregisterDLL(LPSTR lpsLine);
|
||||
|
||||
BOOL export_registry_key(const TCHAR *file_name, CHAR *reg_key_name);
|
||||
BOOL import_registry_file(LPTSTR filename);
|
||||
void delete_registry_key(CHAR *reg_key_name);
|
||||
|
||||
void setAppName(const CHAR *name);
|
||||
const CHAR *getAppName(void);
|
||||
|
||||
void processRegLines(FILE *in, CommandAPI command);
|
||||
|
||||
/*
|
||||
* Generic prototypes
|
||||
*/
|
||||
char* getToken(char** str, const char* delims);
|
||||
void get_file_name(CHAR **command_line, CHAR *filename);
|
||||
LPSTR convertHexToHexCSV( BYTE *buf, ULONG len);
|
||||
LPSTR convertHexToDWORDStr( BYTE *buf, ULONG len);
|
||||
LPSTR getRegKeyName(LPSTR lpLine);
|
||||
BOOL getRegClass(LPSTR lpLine, HKEY* hkey);
|
||||
DWORD getDataType(LPSTR *lpValue, DWORD* parse_type);
|
||||
LPSTR getArg(LPSTR arg);
|
||||
HRESULT openKey(LPSTR stdInput);
|
||||
void closeKey(void);
|
||||
|
||||
/*
|
||||
* api setValue prototypes
|
||||
*/
|
||||
void processSetValue(LPSTR cmdline);
|
||||
HRESULT setValue(LPSTR val_name, LPSTR val_data);
|
||||
|
||||
/*
|
||||
* Permission prototypes
|
||||
*/
|
||||
|
||||
BOOL InitializeAclUiDll(VOID);
|
||||
VOID UnloadAclUiDll(VOID);
|
||||
BOOL RegKeyEditPermissions(HWND hWndOwner, HKEY hKey, LPCTSTR lpMachine, LPCTSTR lpKeyName);
|
||||
|
||||
/*
|
||||
* Processing
|
||||
*/
|
||||
LONG RegCopyKey(HKEY hDestKey, LPCTSTR lpDestSubKey, HKEY hSrcKey, LPCTSTR lpSrcSubKey);
|
||||
LONG RegMoveKey(HKEY hDestKey, LPCTSTR lpDestSubKey, HKEY hSrcKey, LPCTSTR lpSrcSubKey);
|
||||
LONG RegRenameKey(HKEY hKey, LPCTSTR lpSubKey, LPCTSTR lpNewName);
|
||||
LONG RegRenameValue(HKEY hKey, LPCTSTR lpSubKey, LPCTSTR lpDestValue, LPCTSTR lpSrcValue);
|
||||
LONG RegQueryStringValue(HKEY hKey, LPCTSTR lpSubKey, LPCTSTR lpValueName, LPTSTR pszBuffer, DWORD dwBufferLen);
|
||||
|
||||
/*
|
||||
* Miscellaneous
|
||||
*/
|
||||
#define RSF_WHOLESTRING 0x00000001
|
||||
#define RSF_LOOKATKEYS 0x00000002
|
||||
#define RSF_LOOKATVALUES 0x00000004
|
||||
#define RSF_LOOKATDATA 0x00000008
|
||||
#define RSF_MATCHCASE 0x00010000
|
||||
|
||||
BOOL RegKeyGetName(LPTSTR pszDest, size_t iDestLength, HKEY hRootKey, LPCTSTR lpSubKey);
|
||||
|
||||
/* EOF */
|
||||
BOOL export_registry_key(WCHAR *file_name, WCHAR *reg_key_name, DWORD format);
|
||||
BOOL import_registry_file(FILE* reg_file);
|
||||
void delete_registry_key(LPTSTR reg_key_name);
|
||||
WCHAR* GetWideString(const char* strA);
|
||||
CHAR* GetMultiByteString(const WCHAR* strW);
|
||||
|
|
Loading…
Reference in a new issue