Author: ashaposhnikov
Date: Tue Aug  8 21:32:11 2017
New Revision: 75512

URL: http://svn.reactos.org/svn/reactos?rev=75512&view=rev
Log:
[RAPPS]
- Refactoring
- A template for a future parameters parser

Modified:
    branches/GSoC_2017/rapps/reactos/base/applications/rapps/aboutdlg.cpp
    branches/GSoC_2017/rapps/reactos/base/applications/rapps/available.cpp
    branches/GSoC_2017/rapps/reactos/base/applications/rapps/loaddlg.cpp
    branches/GSoC_2017/rapps/reactos/base/applications/rapps/misc.cpp
    branches/GSoC_2017/rapps/reactos/base/applications/rapps/settingsdlg.cpp
    branches/GSoC_2017/rapps/reactos/base/applications/rapps/winmain.cpp

Modified: branches/GSoC_2017/rapps/reactos/base/applications/rapps/aboutdlg.cpp
URL: 
http://svn.reactos.org/svn/reactos/branches/GSoC_2017/rapps/reactos/base/applications/rapps/aboutdlg.cpp?rev=75512&r1=75511&r2=75512&view=diff
==============================================================================
--- branches/GSoC_2017/rapps/reactos/base/applications/rapps/aboutdlg.cpp       
[iso-8859-1] (original)
+++ branches/GSoC_2017/rapps/reactos/base/applications/rapps/aboutdlg.cpp       
[iso-8859-1] Tue Aug  8 21:32:11 2017
@@ -4,32 +4,21 @@
  * FILE:            base/applications/rapps/aboutdlg.cpp
  * PURPOSE:         About Dialog
  * PROGRAMMERS:     Dmitry Chapyshev (dmi...@reactos.org)
+ *                  Alexander Shaposhikov (chaez....@gmail.com)
  */
 #include "defines.h"
 
-static
-INT_PTR CALLBACK
-AboutDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
+static INT_PTR CALLBACK AboutDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, 
LPARAM lParam)
 {
-    switch (Msg)
+    if (Msg == WM_COMMAND && LOWORD(wParam) == IDOK)
     {
-        case WM_COMMAND:
-        {
-            switch (LOWORD(wParam))
-            {
-                case IDOK:
-                    EndDialog(hDlg, LOWORD(wParam));
-                    break;
-            }
-        }
-        break;
+        return EndDialog(hDlg, LOWORD(wParam));
     }
 
     return FALSE;
 }
 
-VOID
-ShowAboutDialog(VOID)
+VOID ShowAboutDialog()
 {
     DialogBoxW(hInst,
               MAKEINTRESOURCEW(IDD_ABOUT_DIALOG),

Modified: branches/GSoC_2017/rapps/reactos/base/applications/rapps/available.cpp
URL: 
http://svn.reactos.org/svn/reactos/branches/GSoC_2017/rapps/reactos/base/applications/rapps/available.cpp?rev=75512&r1=75511&r2=75512&view=diff
==============================================================================
--- branches/GSoC_2017/rapps/reactos/base/applications/rapps/available.cpp      
[iso-8859-1] (original)
+++ branches/GSoC_2017/rapps/reactos/base/applications/rapps/available.cpp      
[iso-8859-1] Tue Aug  8 21:32:11 2017
@@ -288,7 +288,10 @@
     if (hFind == INVALID_HANDLE_VALUE)
     {
         if (GetFileAttributesW(m_szCabPath) == INVALID_FILE_ATTRIBUTES)
+        {
             CDownloadManager::DownloadApplicationsDB(APPLICATION_DATABASE_URL);
+        }
+
 
         ExtractFilesFromCab(m_szCabPath, m_szAppsPath);
         hFind = FindFirstFileW(m_szSearchPath.GetString(), &FindFileData);

Modified: branches/GSoC_2017/rapps/reactos/base/applications/rapps/loaddlg.cpp
URL: 
http://svn.reactos.org/svn/reactos/branches/GSoC_2017/rapps/reactos/base/applications/rapps/loaddlg.cpp?rev=75512&r1=75511&r2=75512&view=diff
==============================================================================
--- branches/GSoC_2017/rapps/reactos/base/applications/rapps/loaddlg.cpp        
[iso-8859-1] (original)
+++ branches/GSoC_2017/rapps/reactos/base/applications/rapps/loaddlg.cpp        
[iso-8859-1] Tue Aug  8 21:32:11 2017
@@ -43,6 +43,7 @@
 
 #include "rosui.h"
 #include "dialogs.h"
+#include "misc.h"
 
 #ifdef USE_CERT_PINNING
     #define CERT_ISSUER_INFO "BE\r\nGlobalSign nv-sa\r\nGlobalSign Domain 
Validation CA - SHA256 - G2"
@@ -336,8 +337,7 @@
 }
 #endif
 
-inline VOID
-MessageBox_LoadString(HWND hMainWnd, INT StringID)
+inline VOID MessageBox_LoadString(HWND hMainWnd, INT StringID)
 {
     ATL::CString szMsgText;
     if (szMsgText.LoadStringW(hInst, StringID))

Modified: branches/GSoC_2017/rapps/reactos/base/applications/rapps/misc.cpp
URL: 
http://svn.reactos.org/svn/reactos/branches/GSoC_2017/rapps/reactos/base/applications/rapps/misc.cpp?rev=75512&r1=75511&r2=75512&view=diff
==============================================================================
--- branches/GSoC_2017/rapps/reactos/base/applications/rapps/misc.cpp   
[iso-8859-1] (original)
+++ branches/GSoC_2017/rapps/reactos/base/applications/rapps/misc.cpp   
[iso-8859-1] Tue Aug  8 21:32:11 2017
@@ -18,12 +18,12 @@
 
 static HANDLE hLog = NULL;
 
-typedef struct
+struct ERF
 {
     int erfOper;
     int erfType;
     BOOL fError;
-} ERF, *PERF;
+};
 
 struct FILELIST
 {
@@ -48,9 +48,7 @@
 typedef HRESULT(WINAPI *fnExtract)(SESSION *dest, LPCSTR szCabName);
 fnExtract pfnExtract;
 
-
-int
-GetWindowWidth(HWND hwnd)
+INT GetWindowWidth(HWND hwnd)
 {
     RECT Rect;
 
@@ -58,8 +56,7 @@
     return (Rect.right - Rect.left);
 }
 
-int
-GetWindowHeight(HWND hwnd)
+INT GetWindowHeight(HWND hwnd)
 {
     RECT Rect;
 
@@ -67,8 +64,7 @@
     return (Rect.bottom - Rect.top);
 }
 
-int
-GetClientWindowWidth(HWND hwnd)
+INT GetClientWindowWidth(HWND hwnd)
 {
     RECT Rect;
 
@@ -76,8 +72,7 @@
     return (Rect.right - Rect.left);
 }
 
-int
-GetClientWindowHeight(HWND hwnd)
+INT GetClientWindowHeight(HWND hwnd)
 {
     RECT Rect;
 
@@ -85,33 +80,33 @@
     return (Rect.bottom - Rect.top);
 }
 
-VOID
-CopyTextToClipboard(LPCWSTR lpszText)
-{
+VOID CopyTextToClipboard(LPCWSTR lpszText)
+{
+    if (!OpenClipboard(NULL))
+    {
+        return;
+    }
+
     HRESULT hr;
-
-    if (OpenClipboard(NULL))
-    {
-        HGLOBAL ClipBuffer;
-        WCHAR *Buffer;
-        DWORD cchBuffer;
-
-        EmptyClipboard();
-        cchBuffer = wcslen(lpszText) + 1;
-        ClipBuffer = GlobalAlloc(GMEM_DDESHARE, cchBuffer * sizeof(WCHAR));
-        Buffer = (PWCHAR) GlobalLock(ClipBuffer);
-        hr = StringCchCopyW(Buffer, cchBuffer, lpszText);
-        GlobalUnlock(ClipBuffer);
-
-        if (SUCCEEDED(hr))
-            SetClipboardData(CF_UNICODETEXT, ClipBuffer);
-
-        CloseClipboard();
-    }
-}
-
-VOID
-SetWelcomeText(VOID)
+    HGLOBAL ClipBuffer;
+    LPWSTR Buffer;
+    DWORD cchBuffer;
+
+    EmptyClipboard();
+    cchBuffer = wcslen(lpszText) + 1;
+    ClipBuffer = GlobalAlloc(GMEM_DDESHARE, cchBuffer * sizeof(WCHAR));
+
+    Buffer = (PWCHAR) GlobalLock(ClipBuffer);
+    hr = StringCchCopyW(Buffer, cchBuffer, lpszText);
+    GlobalUnlock(ClipBuffer);
+
+    if (SUCCEEDED(hr))
+        SetClipboardData(CF_UNICODETEXT, ClipBuffer);
+
+    CloseClipboard();
+}
+
+VOID SetWelcomeText()
 {
     ATL::CStringW szText;
 
@@ -125,12 +120,11 @@
     InsertRichEditText(szText, CFM_LINK);
 }
 
-VOID
-ShowPopupMenu(HWND hwnd, UINT MenuID, UINT DefaultItem)
+VOID ShowPopupMenu(HWND hwnd, UINT MenuID, UINT DefaultItem)
 {
     HMENU hMenu = NULL;
     HMENU hPopupMenu;
-    MENUITEMINFO mii;
+    MENUITEMINFO ItemInfo;
     POINT pt;
 
     if (MenuID)
@@ -139,15 +133,20 @@
         hPopupMenu = GetSubMenu(hMenu, 0);
     }
     else
+    {
         hPopupMenu = GetMenu(hwnd);
-
-    ZeroMemory(&mii, sizeof(mii));
-    mii.cbSize = sizeof(mii);
-    mii.fMask = MIIM_STATE;
-    GetMenuItemInfoW(hPopupMenu, DefaultItem, FALSE, &mii);
-
-    if (!(mii.fState & MFS_GRAYED))
+    }
+
+    ZeroMemory(&ItemInfo, sizeof(ItemInfo));
+    ItemInfo.cbSize = sizeof(ItemInfo);
+    ItemInfo.fMask = MIIM_STATE;
+
+    GetMenuItemInfoW(hPopupMenu, DefaultItem, FALSE, &ItemInfo);
+
+    if (!(ItemInfo.fState & MFS_GRAYED))
+    {
         SetMenuDefaultItem(hPopupMenu, DefaultItem, FALSE);
+    }
 
     GetCursorPos(&pt);
 
@@ -155,18 +154,17 @@
     TrackPopupMenu(hPopupMenu, 0, pt.x, pt.y, 0, hMainWnd, NULL);
 
     if (hMenu)
+    {
         DestroyMenu(hMenu);
-}
-
-BOOL
-StartProcess(ATL::CStringW &Path, BOOL Wait)
-{
-    BOOL result = StartProcess(const_cast<LPWSTR>(Path.GetString()), Wait);
-    return result;
-}
-
-BOOL
-StartProcess(LPWSTR lpPath, BOOL Wait)
+    }
+}
+
+BOOL StartProcess(ATL::CStringW &Path, BOOL Wait)
+{ 
+    return StartProcess(const_cast<LPWSTR>(Path.GetString()), Wait);;
+}
+
+BOOL StartProcess(LPWSTR lpPath, BOOL Wait)
 {
     PROCESS_INFORMATION pi;
     STARTUPINFOW si;
@@ -184,7 +182,11 @@
     }
 
     CloseHandle(pi.hThread);
-    if (Wait) EnableWindow(hMainWnd, FALSE);
+
+    if (Wait)
+    {
+        EnableWindow(hMainWnd, FALSE);
+    }
 
     while (Wait)
     {
@@ -194,7 +196,7 @@
             while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE))
             {
                 TranslateMessage(&msg);
-                DispatchMessage(&msg);
+                DispatchMessageW(&msg);
             }
         }
         else
@@ -216,8 +218,7 @@
     return TRUE;
 }
 
-BOOL
-GetStorageDirectory(ATL::CStringW& Directory)
+BOOL GetStorageDirectory(ATL::CStringW& Directory)
 {
     if (!SHGetSpecialFolderPathW(NULL, Directory.GetBuffer(MAX_PATH), 
CSIDL_LOCAL_APPDATA, TRUE))
     {
@@ -231,14 +232,12 @@
     return (CreateDirectoryW(Directory.GetString(), NULL) || GetLastError() == 
ERROR_ALREADY_EXISTS);
 }
 
-BOOL
-ExtractFilesFromCab(const ATL::CStringW &CabName, const ATL::CStringW 
&OutputPath)
+BOOL ExtractFilesFromCab(const ATL::CStringW &CabName, const ATL::CStringW 
&OutputPath)
 {
     return ExtractFilesFromCab(CabName.GetString(), OutputPath.GetString());
 }
 
-BOOL
-ExtractFilesFromCab(LPCWSTR lpCabName, LPCWSTR lpOutputPath)
+BOOL ExtractFilesFromCab(LPCWSTR lpCabName, LPCWSTR lpOutputPath)
 {
     HINSTANCE hCabinetDll;
     CHAR szCabName[MAX_PATH];
@@ -275,92 +274,67 @@
     return FALSE;
 }
 
-VOID
-InitLogs(VOID)
-{
-    WCHAR szBuf[MAX_PATH] = 
L"SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\ReactOS 
Application Manager";
+VOID InitLogs()
+{
+    if (!SettingsInfo.bLogEnabled)
+    {
+        return;
+    }
+
     WCHAR szPath[MAX_PATH];
     DWORD dwCategoryNum = 1;
     DWORD dwDisp, dwData;
-    HKEY hKey;
-
-    if (!SettingsInfo.bLogEnabled) return;
-
-    if (RegCreateKeyExW(HKEY_LOCAL_MACHINE,
-                        szBuf, 0, NULL,
-                        REG_OPTION_NON_VOLATILE,
-                        KEY_WRITE, NULL, &hKey, &dwDisp) != ERROR_SUCCESS)
+    ATL::CRegKey key;
+
+    if (key.Create(HKEY_LOCAL_MACHINE,
+                   
L"SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\ReactOS 
Application Manager",
+                   REG_NONE, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, 
&dwDisp) != ERROR_SUCCESS)
     {
         return;
     }
 
     if (!GetModuleFileNameW(NULL, szPath, _countof(szPath)))
-        return;
-
-    if (RegSetValueExW(hKey,
-                       L"EventMessageFile",
-                       0,
-                       REG_EXPAND_SZ,
-                       (LPBYTE) szPath,
-                       (DWORD) (wcslen(szPath) + 1) * sizeof(WCHAR)) != 
ERROR_SUCCESS)
-    {
-        RegCloseKey(hKey);
+    {
         return;
     }
 
     dwData = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE |
         EVENTLOG_INFORMATION_TYPE;
 
-    if (RegSetValueExW(hKey,
-                       L"TypesSupported",
-                       0,
-                       REG_DWORD,
-                       (LPBYTE) &dwData,
-                       sizeof(DWORD)) != ERROR_SUCCESS)
-    {
-        RegCloseKey(hKey);
-        return;
-    }
-
-    if (RegSetValueExW(hKey,
-                       L"CategoryMessageFile",
-                       0,
-                       REG_EXPAND_SZ,
-                       (LPBYTE) szPath,
-                       (DWORD) (wcslen(szPath) + 1) * sizeof(WCHAR)) != 
ERROR_SUCCESS)
-    {
-        RegCloseKey(hKey);
-        return;
-    }
-
-    if (RegSetValueExW(hKey,
-                       L"CategoryCount",
-                       0,
-                       REG_DWORD,
-                       (LPBYTE) &dwCategoryNum,
-                       sizeof(DWORD)) != ERROR_SUCCESS)
-    {
-        RegCloseKey(hKey);
-        return;
-    }
-
-    RegCloseKey(hKey);
-
-    hLog = RegisterEventSourceW(NULL, L"ReactOS Application Manager");
-}
-
-
-VOID
-FreeLogs(VOID)
-{
-    if (hLog) DeregisterEventSource(hLog);
-}
-
-
-BOOL
-WriteLogMessage(WORD wType, DWORD dwEventID, LPCWSTR lpMsg)
-{
-    if (!SettingsInfo.bLogEnabled) return TRUE;
+    if ((key.SetStringValue(L"EventMessageFile",
+                            szPath,
+                            REG_EXPAND_SZ) == ERROR_SUCCESS)
+        && (key.SetStringValue(L"CategoryMessageFile",
+                               szPath,
+                               REG_EXPAND_SZ) == ERROR_SUCCESS)
+        && (key.SetDWORDValue(L"TypesSupported",
+                              dwData) == ERROR_SUCCESS)
+        && (key.SetDWORDValue(L"CategoryCount",
+                              dwCategoryNum) == ERROR_SUCCESS))
+
+    {
+        hLog = RegisterEventSourceW(NULL, L"ReactOS Application Manager");
+    }
+
+    key.Close();
+}
+
+
+VOID FreeLogs()
+{
+    if (hLog)
+    {
+        DeregisterEventSource(hLog);
+    }
+}
+
+
+BOOL WriteLogMessage(WORD wType, DWORD dwEventID, LPCWSTR lpMsg)
+{
+    if (!SettingsInfo.bLogEnabled)
+    {
+        return TRUE;
+    }
 
     if (!ReportEventW(hLog, wType, 0, dwEventID,
                       NULL, 1, 0, &lpMsg, NULL))
@@ -371,54 +345,51 @@
     return TRUE;
 }
 
-BOOL
-GetInstalledVersion_WowUser(_Out_opt_ ATL::CStringW* szVersionResult,
-                            _In_z_ const ATL::CStringW& RegName,
-                            _In_ BOOL IsUserKey,
-                            _In_ REGSAM keyWow)
-{
-    HKEY hKey;
+BOOL GetInstalledVersion_WowUser(ATL::CStringW* szVersionResult,
+                                 const ATL::CStringW& RegName,
+                                 BOOL IsUserKey,
+                                 REGSAM keyWow)
+{
     BOOL bHasSucceded = FALSE;
+    ATL::CRegKey key;
     ATL::CStringW szVersion;
     ATL::CStringW szPath = 
L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + RegName;
 
-    if (RegOpenKeyExW(IsUserKey ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE,
-                      szPath.GetString(), 0, keyWow | KEY_READ,
-                      &hKey) == ERROR_SUCCESS)
-    {
-        if (szVersionResult != NULL)
-        {
-            DWORD dwSize = MAX_PATH * sizeof(WCHAR);
-            DWORD dwType = REG_SZ;
-            if (RegQueryValueExW(hKey,
-                                 L"DisplayVersion",
-                                 NULL,
-                                 &dwType,
-                                 (LPBYTE) szVersion.GetBuffer(MAX_PATH),
+    if (key.Open(IsUserKey ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE,
+                 szPath.GetString(),
+                 keyWow | KEY_READ) != ERROR_SUCCESS)
+    {
+        return FALSE;
+    }
+
+    if (szVersionResult != NULL)
+    {
+        ULONG dwSize = MAX_PATH * sizeof(WCHAR);
+
+        if (key.QueryStringValue(L"DisplayVersion",
+                                 szVersion.GetBuffer(MAX_PATH),
                                  &dwSize) == ERROR_SUCCESS)
-            {
-                szVersion.ReleaseBuffer();
-                *szVersionResult = szVersion;
-                bHasSucceded = TRUE;
-            }
-            else
-            {
-                szVersion.ReleaseBuffer();
-            }
+        {
+            szVersion.ReleaseBuffer();
+            *szVersionResult = szVersion;
+            bHasSucceded = TRUE;
         }
         else
         {
-            bHasSucceded = TRUE;
             szVersion.ReleaseBuffer();
         }
-
-    }
-
-    RegCloseKey(hKey);
+    }
+    else
+    {
+        bHasSucceded = TRUE;
+        szVersion.ReleaseBuffer();
+    }
+    key.Close();
+
     return bHasSucceded;
 }
 
-BOOL GetInstalledVersion(ATL::CStringW * pszVersion, const ATL::CStringW & 
szRegName)
+BOOL GetInstalledVersion(ATL::CStringW *pszVersion, const ATL::CStringW 
&szRegName)
 {
     return (!szRegName.IsEmpty()
             && (GetInstalledVersion_WowUser(pszVersion, szRegName, TRUE, 
KEY_WOW64_32KEY)

Modified: 
branches/GSoC_2017/rapps/reactos/base/applications/rapps/settingsdlg.cpp
URL: 
http://svn.reactos.org/svn/reactos/branches/GSoC_2017/rapps/reactos/base/applications/rapps/settingsdlg.cpp?rev=75512&r1=75511&r2=75512&view=diff
==============================================================================
--- branches/GSoC_2017/rapps/reactos/base/applications/rapps/settingsdlg.cpp    
[iso-8859-1] (original)
+++ branches/GSoC_2017/rapps/reactos/base/applications/rapps/settingsdlg.cpp    
[iso-8859-1] Tue Aug  8 21:32:11 2017
@@ -19,7 +19,7 @@
 ChooseFolder(HWND hwnd)
 {
     BOOL bRet = FALSE;
-    BROWSEINFO bi;
+    BROWSEINFOW bi;
     ATL::CStringW szBuf;
 
     szBuf.LoadStringW(hInst, IDS_CHOOSE_FOLDER_TEXT);
@@ -53,8 +53,7 @@
     return bRet;
 }
 
-static VOID
-InitSettingsControls(HWND hDlg, PSETTINGS_INFO Info)
+static VOID InitSettingsControls(HWND hDlg, PSETTINGS_INFO Info)
 {
     SendDlgItemMessageW(hDlg, IDC_SAVE_WINDOW_POS, BM_SETCHECK, 
Info->bSaveWndPos, 0);
     SendDlgItemMessageW(hDlg, IDC_UPDATE_AVLIST, BM_SETCHECK, 
Info->bUpdateAtStart, 0);
@@ -76,9 +75,7 @@
     SetWindowTextW(GetDlgItem(hDlg, IDC_NO_PROXY_FOR), Info->szNoProxyFor);
 }
 
-static
-INT_PTR CALLBACK
-SettingsDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
+static INT_PTR CALLBACK SettingsDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, 
LPARAM lParam)
 {
     switch (Msg)
     {
@@ -208,8 +205,7 @@
     return FALSE;
 }
 
-VOID
-CreateSettingsDlg(HWND hwnd)
+VOID CreateSettingsDlg(HWND hwnd)
 {
     DialogBoxW(hInst,
                MAKEINTRESOURCEW(IDD_SETTINGS_DIALOG),

Modified: branches/GSoC_2017/rapps/reactos/base/applications/rapps/winmain.cpp
URL: 
http://svn.reactos.org/svn/reactos/branches/GSoC_2017/rapps/reactos/base/applications/rapps/winmain.cpp?rev=75512&r1=75511&r2=75512&view=diff
==============================================================================
--- branches/GSoC_2017/rapps/reactos/base/applications/rapps/winmain.cpp        
[iso-8859-1] (original)
+++ branches/GSoC_2017/rapps/reactos/base/applications/rapps/winmain.cpp        
[iso-8859-1] Tue Aug  8 21:32:11 2017
@@ -50,10 +50,10 @@
     }
 }
 
-VOID
-FillDefaultSettings(PSETTINGS_INFO pSettingsInfo)
+VOID FillDefaultSettings(PSETTINGS_INFO pSettingsInfo)
 {
     ATL::CStringW szDownloadDir;
+
     pSettingsInfo->bSaveWndPos = TRUE;
     pSettingsInfo->bUpdateAtStart = FALSE;
     pSettingsInfo->bLogEnabled = TRUE;
@@ -67,7 +67,9 @@
         }
     }
     else
+    {
         szDownloadDir.ReleaseBuffer();
+    }
 
     szDownloadDir += L"\\RAPPS Downloads";
     ATL::CStringW::CopyChars(pSettingsInfo->szDownloadDir, 
@@ -87,32 +89,26 @@
     pSettingsInfo->szNoProxyFor[0] = UNICODE_NULL;
 }
 
-static BOOL
-LoadSettings(VOID)
-{
-    HKEY hKey;
+static BOOL LoadSettings()
+{
+    ATL::CRegKey RegKey;
     DWORD dwSize;
-
-    if (RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\ReactOS\\rapps", 0, 
KEY_READ, &hKey) == ERROR_SUCCESS)
+    BOOL bResult = FALSE;
+    if (RegKey.Open(HKEY_CURRENT_USER, L"Software\\ReactOS\\rapps", KEY_READ) 
== ERROR_SUCCESS)
     {
         dwSize = sizeof(SettingsInfo);
-        if (RegQueryValueExW(hKey, L"Settings", NULL, NULL, (LPBYTE) 
&SettingsInfo, &dwSize) == ERROR_SUCCESS)
-        {
-            RegCloseKey(hKey);
-            return TRUE;
-        }
-
-        RegCloseKey(hKey);
-    }
-
-    return FALSE;
-}
-
-VOID
-SaveSettings(HWND hwnd)
+        bResult = (RegKey.QueryBinaryValue(L"Settings", (PVOID) &SettingsInfo, 
&dwSize) == ERROR_SUCCESS);
+
+        RegKey.Close();
+    }
+
+    return bResult;
+}
+
+VOID SaveSettings(HWND hwnd)
 {
     WINDOWPLACEMENT wp;
-    HKEY hKey;
+    ATL::CRegKey RegKey;
 
     if (SettingsInfo.bSaveWndPos)
     {
@@ -123,35 +119,49 @@
         SettingsInfo.Top = wp.rcNormalPosition.top;
         SettingsInfo.Width = wp.rcNormalPosition.right - 
wp.rcNormalPosition.left;
         SettingsInfo.Height = wp.rcNormalPosition.bottom - 
wp.rcNormalPosition.top;
-        SettingsInfo.Maximized = (wp.showCmd == SW_MAXIMIZE || (wp.showCmd == 
SW_SHOWMINIMIZED && (wp.flags & WPF_RESTORETOMAXIMIZED)));
-    }
-
-    if (RegCreateKeyExW(HKEY_CURRENT_USER, L"Software\\ReactOS\\rapps", 0, 
NULL,
-                        REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL) 
== ERROR_SUCCESS)
-    {
-        RegSetValueExW(hKey, L"Settings", 0, REG_BINARY, (LPBYTE) 
&SettingsInfo, sizeof(SettingsInfo));
-        RegCloseKey(hKey);
-    }
-}
-
-int WINAPI
-wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int 
nShowCmd)
-{
-    WCHAR szWindowClass[] = L"ROSAPPMGR";
+        SettingsInfo.Maximized = (wp.showCmd == SW_MAXIMIZE 
+                                  || (wp.showCmd == SW_SHOWMINIMIZED 
+                                      && (wp.flags & WPF_RESTORETOMAXIMIZED)));
+    }
+
+    if (RegKey.Create(HKEY_CURRENT_USER, L"Software\\ReactOS\\rapps", NULL,
+                        REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, NULL) == 
ERROR_SUCCESS)
+    {
+        RegKey.SetBinaryValue(L"Settings", (const PVOID) &SettingsInfo, 
sizeof(SettingsInfo));
+        RegKey.Close();
+    }
+}
+
+
+#define CMD_KEY_SETUP L"//SETUP"
+
+VOID CmdParser(LPWSTR lpCmdLine)
+{
+    INT argc;
+    LPWSTR* argv = CommandLineToArgvW(lpCmdLine, &argc);
+    if (!argv || argc < 2)
+    {
+        return;
+    }
+    
+    if (!StrCmpW(argv[0], CMD_KEY_SETUP))
+    {
+        //TODO: call cmd app installation
+    }
+}
+
+INT WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR 
lpCmdLine, int nShowCmd)
+{
+    LPCWSTR szWindowClass = L"ROSAPPMGR";
     HANDLE hMutex = NULL;
     HACCEL KeyBrd;
     MSG Msg;
 
     InitializeAtlModule(hInstance, TRUE);
 
-    switch (GetUserDefaultUILanguage())
-    {
-    case MAKELANGID(LANG_HEBREW, SUBLANG_DEFAULT):
+    if (GetUserDefaultUILanguage() == MAKELANGID(LANG_HEBREW, SUBLANG_DEFAULT))
+    {
         SetProcessDefaultLayout(LAYOUT_RTL);
-        break;
-
-    default:
-        break;
     }
 
     hInst = hInstance;
@@ -178,30 +188,30 @@
     InitCommonControls();
 
     hMainWnd = CreateMainWindow();
-    if (!hMainWnd) goto Exit;
-
-    /* Maximize it if we must */
-    ShowWindow(hMainWnd, (SettingsInfo.bSaveWndPos && SettingsInfo.Maximized ? 
SW_MAXIMIZE : nShowCmd));
-    UpdateWindow(hMainWnd);
-
-    //TODO: get around the ugliness
-    if (SettingsInfo.bUpdateAtStart)
-        GetAvailableApps()->UpdateAppsDB();
-
-    /* Load the menu hotkeys */
-    KeyBrd = LoadAcceleratorsW(NULL, MAKEINTRESOURCEW(HOTKEYS));
-
-    /* Message Loop */
-    while (GetMessageW(&Msg, NULL, 0, 0))
-    {
-        if (!TranslateAcceleratorW(hMainWnd, KeyBrd, &Msg))
+    if (hMainWnd)
+    {
+        /* Maximize it if we must */
+        ShowWindow(hMainWnd, (SettingsInfo.bSaveWndPos && 
SettingsInfo.Maximized ? SW_MAXIMIZE : nShowCmd));
+        UpdateWindow(hMainWnd);
+
+        //TODO: get around the ugliness
+        if (SettingsInfo.bUpdateAtStart)
+            GetAvailableApps()->UpdateAppsDB();
+
+        /* Load the menu hotkeys */
+        KeyBrd = LoadAcceleratorsW(NULL, MAKEINTRESOURCEW(HOTKEYS));
+
+        /* Message Loop */
+        while (GetMessageW(&Msg, NULL, 0, 0))
         {
-            TranslateMessage(&Msg);
-            DispatchMessageW(&Msg);
+            if (!TranslateAcceleratorW(hMainWnd, KeyBrd, &Msg))
+            {
+                TranslateMessage(&Msg);
+                DispatchMessageW(&Msg);
+            }
         }
     }
 
-Exit:
     if (hMutex)
         CloseHandle(hMutex);
 


Reply via email to