[REGEDIT]
[reactos.git] / reactos / base / applications / regedit / framewnd.c
index 1f5023d..8f7d488 100644 (file)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#include <regedit.h>
+#include "regedit.h"
+
+#include <commdlg.h>
+#include <cderr.h>
+#include <objsel.h>
 
 /********************************************************************************
  * Global and Local Variables:
@@ -85,8 +89,7 @@ static void OnInitMenu(HWND hWnd)
     }
     else
     {
-        while(RemoveMenu(hMenu, s_nFavoriteMenuSubPos, MF_BYPOSITION))
-            ;
+        while(RemoveMenu(hMenu, s_nFavoriteMenuSubPos, MF_BYPOSITION)) ;
     }
 
     lResult = RegOpenKeyW(HKEY_CURRENT_USER, s_szFavoritesRegKey, &hKey);
@@ -250,9 +253,9 @@ BuildFilterStrings(WCHAR *Filter, PFILTERPAIR Pairs, int PairCount)
     c = 0;
     for(i = 0; i < PairCount; i++)
     {
-        c += LoadStringW(hInst, Pairs[i].DisplayID, &Filter[c], 255 * sizeof(WCHAR));
+        c += LoadStringW(hInst, Pairs[i].DisplayID, &Filter[c], 255);
         Filter[++c] = L'\0';
-        c += LoadStringW(hInst, Pairs[i].FilterID, &Filter[c], 255 * sizeof(WCHAR));
+        c += LoadStringW(hInst, Pairs[i].FilterID, &Filter[c], 255);
         Filter[++c] = L'\0';
     }
     Filter[++c] = L'\0';
@@ -289,20 +292,21 @@ static BOOL InitOpenFileName(HWND hWnd, OPENFILENAME* pofn)
     return TRUE;
 }
 
+#define LOADHIVE_KEYNAMELENGTH 128
+
 static INT_PTR CALLBACK LoadHive_KeyNameInHookProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 {
     static LPWSTR sKey = NULL;
-    static INT sLength = 0;
     switch(uMsg)
     {
     case WM_INITDIALOG:
         sKey = (LPWSTR)lParam;
-        sLength = 128; /* FIXME: Ugly hack! */
+        break;
     case WM_COMMAND:
         switch(LOWORD(wParam))
         {
         case IDOK:
-            if(GetDlgItemTextW(hWndDlg, IDC_EDIT_KEY, sKey, sLength))
+            if(GetDlgItemTextW(hWndDlg, IDC_EDIT_KEY, sKey, LOADHIVE_KEYNAMELENGTH))
                 return EndDialog(hWndDlg, -1);
             else
                 return EndDialog(hWndDlg, 0);
@@ -349,7 +353,7 @@ static BOOL LoadHive(HWND hWnd)
     OPENFILENAME ofn;
     WCHAR Caption[128];
     LPCWSTR pszKeyPath;
-    WCHAR xPath[128];
+    WCHAR xPath[LOADHIVE_KEYNAMELENGTH];
     HKEY hRootKey;
     WCHAR Filter[1024];
     FILTERPAIR filter;
@@ -360,7 +364,7 @@ static BOOL LoadHive(HWND hWnd)
     /* build the "All Files" filter up */
     filter.DisplayID = IDS_FLT_ALLFILES;
     filter.FilterID = IDS_FLT_ALLFILES_FLT;
-    BuildFilterStrings(Filter, &filter, sizeof(filter));
+    BuildFilterStrings(Filter, &filter, 1);
     ofn.lpstrFilter = Filter;
     /* load and set the caption and flags for dialog */
     LoadStringW(hInst, IDS_LOAD_HIVE, Caption, COUNT_OF(Caption));
@@ -370,7 +374,8 @@ static BOOL LoadHive(HWND hWnd)
     /* now load the hive */
     if (GetOpenFileName(&ofn))
     {
-        if(DialogBoxParamW(hInst, MAKEINTRESOURCEW(IDD_LOADHIVE), hWnd, &LoadHive_KeyNameInHookProc, (LPARAM)xPath))
+        if (DialogBoxParamW(hInst, MAKEINTRESOURCEW(IDD_LOADHIVE), hWnd,
+                            &LoadHive_KeyNameInHookProc, (LPARAM)xPath))
         {
             LONG regLoadResult;
 
@@ -436,7 +441,7 @@ static BOOL ImportRegistryFile(HWND hWnd)
 {
     BOOL bRet = FALSE;
     OPENFILENAME ofn;
-    WCHAR Caption[128], szTitle[256], szText[256];
+    WCHAR Caption[128], szTitle[512], szText[512];
     HKEY hKeyRoot;
     LPCWSTR pszKeyPath;
 
@@ -452,17 +457,18 @@ static BOOL ImportRegistryFile(HWND hWnd)
     {
         /* Look at the extension of the file to determine its type */
         if (ofn.nFileExtension >= 1 &&
-            wcsicmp(ofn.lpstrFile + ofn.nFileExtension, L"reg") == 0) /* REGEDIT4 or Windows Registry Editor Version 5.00 */
+            _wcsicmp(ofn.lpstrFile + ofn.nFileExtension, L"reg") == 0) /* REGEDIT4 or Windows Registry Editor Version 5.00 */
         {
             /* Open the file */
-            FILE *fp = _wfopen(ofn.lpstrFile, L"r");
+            FILEfp = _wfopen(ofn.lpstrFile, L"r");
 
             /* Import it */
             if (fp == NULL || !import_registry_file(fp))
             {
-                LPSTR p = GetMultiByteString(ofn.lpstrFile);
-                fwprintf(stderr, L"Can't open file \"%s\"\n", p);
-                HeapFree(GetProcessHeap(), 0, p);
+                /* Error opening the file */
+                LoadStringW(hInst, IDS_APP_TITLE, szTitle, COUNT_OF(szTitle));
+                LoadStringW(hInst, IDS_IMPORT_ERROR, szText, COUNT_OF(szText));
+                InfoMessageBox(hWnd, MB_OK | MB_ICONERROR, szTitle, szText, ofn.lpstrFile);
                 bRet = FALSE;
             }
             else
@@ -470,7 +476,7 @@ static BOOL ImportRegistryFile(HWND hWnd)
                 /* Show successful import */
                 LoadStringW(hInst, IDS_APP_TITLE, szTitle, COUNT_OF(szTitle));
                 LoadStringW(hInst, IDS_IMPORT_OK, szText, COUNT_OF(szText));
-                MessageBoxW(NULL, szText, szTitle, MB_OK);
+                InfoMessageBox(hWnd, MB_OK | MB_ICONINFORMATION, szTitle, szText, ofn.lpstrFile);
                 bRet = TRUE;
             }
 
@@ -581,8 +587,8 @@ BOOL ExportRegistryFile(HWND hWnd)
 {
     BOOL bRet = FALSE;
     OPENFILENAME ofn;
-    WCHAR ExportKeyPath[_MAX_PATH];
-    WCHAR Caption[128];
+    WCHAR ExportKeyPath[_MAX_PATH] = {0};
+    WCHAR Caption[128], szTitle[512], szText[512];
     HKEY hKeyRoot;
     LPCWSTR pszKeyPath;
 
@@ -664,9 +670,10 @@ BOOL ExportRegistryFile(HWND hWnd)
                                          (ofn.nFilterIndex == 3 ? REG_FORMAT_4
                                                                 : REG_FORMAT_5)))
                 {
-                    LPSTR p = GetMultiByteString(ofn.lpstrFile);
-                    fwprintf(stderr, L"Can't open file \"%s\"\n", p);
-                    HeapFree(GetProcessHeap(), 0, p);
+                    /* Error creating the file */
+                    LoadStringW(hInst, IDS_APP_TITLE, szTitle, COUNT_OF(szTitle));
+                    LoadStringW(hInst, IDS_EXPORT_ERROR, szText, COUNT_OF(szText));
+                    InfoMessageBox(hWnd, MB_OK | MB_ICONERROR, szTitle, szText, ofn.lpstrFile);
                     bRet = FALSE;
                 }
                 else
@@ -850,10 +857,19 @@ static BOOL CreateNewValue(HKEY hRootKey, LPCWSTR pszKeyPath, DWORD dwType)
             cbData = sizeof(WCHAR);
             break;
         case REG_MULTI_SZ:
-            cbData = sizeof(WCHAR) * 2;
+            /*
+             * WARNING: An empty multi-string has only one null char.
+             * Indeed, multi-strings are built in the following form:
+             * str1\0str2\0...strN\0\0
+             * where each strI\0 is a null-terminated string, and it
+             * ends with a terminating empty string.
+             * Therefore an empty multi-string contains only the terminating
+             * empty string, that is, one null char.
+             */
+            cbData = sizeof(WCHAR);
             break;
-        case REG_QWORD:
-            cbData = sizeof(DWORD) * 2;
+        case REG_QWORD: /* REG_QWORD_LITTLE_ENDIAN */
+            cbData = sizeof(DWORDLONG); // == sizeof(DWORD) * 2;
             break;
         default:
             cbData = 0;
@@ -1246,7 +1262,7 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
         if ((LOWORD(wParam) >= ID_FAVORITES_MIN) && (LOWORD(wParam) <= ID_FAVORITES_MAX))
         {
             HMENU hMenu;
-            MENUITEMINFO mii;
+            MENUITEMINFOW mii;
             WCHAR szFavorite[512];
 
             hMenu = GetSubMenu(GetMenu(hWnd), FAVORITES_MENU_POSITION);