[RAPPS] More code improvements
authorAlexander Shaposhnikov <sanchaez@reactos.org>
Wed, 12 Jul 2017 22:59:26 +0000 (22:59 +0000)
committerAlexander Shaposhnikov <sanchaez@reactos.org>
Wed, 12 Jul 2017 22:59:26 +0000 (22:59 +0000)
- Replaced some functions with their Wide versions
- Generalized `GetInstalledVersion` function so it could accept NULL
- Minor cleanup

svn path=/branches/GSoC_2017/rapps/; revision=75324

reactos/base/applications/rapps/available.cpp
reactos/base/applications/rapps/crichedit.h
reactos/base/applications/rapps/gui.cpp
reactos/base/applications/rapps/installed.cpp
reactos/base/applications/rapps/rapps.h
reactos/base/applications/rapps/settingsdlg.cpp

index ac1ca30..d0f66b0 100644 (file)
@@ -42,43 +42,30 @@ inline BOOL GetString(LPCWSTR lpKeyName, ATL::CStringW& ReturnedString, const AT
     }
     return TRUE;
 }
+//Check both registry keys in 64bit system
+//TODO: check system type beforehand to avoid double checks?
 
-//App is "installed" if the RegName or Name is in the registry
-inline BOOL IsAppInstalledKey(PAPPLICATION_INFO Info, REGSAM key)
+inline BOOL GetInstalledVersionEx(PAPPLICATION_INFO Info, ATL::CStringW* szVersion, REGSAM key)
 {
     return (!Info->szRegName.IsEmpty()
-            && (IsInstalledApplication(Info->szRegName, TRUE, key)
-                || IsInstalledApplication(Info->szRegName, FALSE, key)))
+            && (GetInstalledVersion_WowUser(szVersion, Info->szRegName, TRUE, key)
+                || GetInstalledVersion_WowUser(szVersion, Info->szRegName, FALSE, key)))
         || (!Info->szName.IsEmpty()
-            && (IsInstalledApplication(Info->szName, TRUE, key)
-                || IsInstalledApplication(Info->szName, FALSE, key)));
+            && (GetInstalledVersion_WowUser(szVersion, Info->szName, TRUE, key)
+                || GetInstalledVersion_WowUser(szVersion, Info->szName, FALSE, key)));
 }
 
-
-//Check both registry keys in 64bit system
-//TODO: check system type beforehand to avoid double checks?
-inline BOOL IsAppInstalled(PAPPLICATION_INFO Info)
+inline BOOL GetInstalledVersion(PAPPLICATION_INFO Info, ATL::CStringW* szVersion)
 {
-    return  IsAppInstalledKey(Info, KEY_WOW64_32KEY)
-        || IsAppInstalledKey(Info, KEY_WOW64_64KEY);
+    return  GetInstalledVersionEx(Info, szVersion, KEY_WOW64_32KEY)
+        || GetInstalledVersionEx(Info, szVersion, KEY_WOW64_64KEY);
 }
 
-//App is "installed" if the RegName or Name is in the registry
-inline BOOL GetInstalledVersionWithKey(PAPPLICATION_INFO Info, ATL::CStringW& szVersion, REGSAM key)
+inline BOOL IsAppInstalled(PAPPLICATION_INFO Info)
 {
-    return (!Info->szRegName.IsEmpty()
-            && (InstalledVersion(szVersion, Info->szRegName, TRUE, key)
-                || InstalledVersion(szVersion, Info->szRegName, FALSE, key)))
-        || (!Info->szName.IsEmpty()
-            && (InstalledVersion(szVersion, Info->szName, TRUE, key)
-                || InstalledVersion(szVersion, Info->szName, FALSE, key)));
+    return GetInstalledVersion(Info, NULL);
 }
 
-inline BOOL GetInstalledVersion(PAPPLICATION_INFO Info, ATL::CStringW& szVersion)
-{
-    return  GetInstalledVersionWithKey(Info, szVersion, KEY_WOW64_32KEY)
-        || GetInstalledVersionWithKey(Info, szVersion, KEY_WOW64_64KEY);
-}
 
 LIST_ENTRY CachedEntriesHead = {&CachedEntriesHead, &CachedEntriesHead};
 PLIST_ENTRY pCachedEntry = &CachedEntriesHead;
@@ -90,7 +77,7 @@ ShowAvailableAppInfo(INT Index)
     ATL::CStringW szVersion;
     ATL::CStringW szLicense;
     BOOL bIsInstalled = IsAppInstalled(Info),
-        bHasVersion = GetInstalledVersion(Info, szVersion);
+        bHasVersion = GetInstalledVersion(Info, &szVersion);
 
     if (!Info) return FALSE;
 
@@ -222,7 +209,6 @@ EnumAvailableApplications(INT EnumType, AVAILENUMPROC lpEnumProc)
     ATL::CStringW szCabPath;
     PAPPLICATION_INFO Info;
 
-
     if (!GetStorageDirectory(szPath))
         return FALSE;
 
@@ -301,7 +287,6 @@ EnumAvailableApplications(INT EnumType, AVAILENUMPROC lpEnumProc)
         InfoList.AddTail(Info);
 
 skip_if_cached:
-
         if (Info->Category == FALSE)
             continue;
 
@@ -349,10 +334,8 @@ VOID FreeCachedAvailableEntries(VOID)
     {
         Info = InfoList.GetAt(InfoListPosition);
         InfoList.RemoveHead();
-
-        /* flush them down the toilet :D */
-        delete Info;
-
         InfoListPosition = InfoList.GetHeadPosition();
+        
+        delete Info;
     }
 }
\ No newline at end of file
index 2961dfb..1ba88ea 100644 (file)
@@ -22,7 +22,7 @@ class CRichEdit :
 public:
     VOID SetRangeFormatting(LONG Start, LONG End, DWORD dwEffects)
     {
-        CHARFORMAT2 CharFormat;
+        CHARFORMAT2W CharFormat;
 
         SendMessageW(EM_SETSEL, Start, End);
 
index 3b870c4..5d90c3e 100644 (file)
@@ -37,12 +37,12 @@ class CMainToolbar :
     {
         HICON hImage;
 
-        if (!(hImage = (HICON) LoadImage(hInst,
-                                         MAKEINTRESOURCE(ImageIndex),
-                                         IMAGE_ICON,
-                                         TOOLBAR_HEIGHT,
-                                         TOOLBAR_HEIGHT,
-                                         0)))
+        if (!(hImage = (HICON) LoadImageW(hInst,
+                                          MAKEINTRESOURCE(ImageIndex),
+                                          IMAGE_ICON,
+                                          TOOLBAR_HEIGHT,
+                                          TOOLBAR_HEIGHT,
+                                          0)))
         {
             /* TODO: Error message */
         }
@@ -266,7 +266,7 @@ public:
     INT CompareFunc(LPARAM lParam1, LPARAM lParam2, INT iSubItem)
     {
         ATL::CStringW Item1, Item2;
-        LVFINDINFO IndexInfo;
+        LVFINDINFOW IndexInfo;
         INT Index;
 
         IndexInfo.flags = LVFI_PARAM;
@@ -366,7 +366,7 @@ class CSearchBar :
 public:
     VOID SetText(LPCWSTR lpszText)
     {
-        SendMessage(SB_SETTEXT, SBT_NOBORDERS, (LPARAM) lpszText);
+        SendMessageW(SB_SETTEXT, SBT_NOBORDERS, (LPARAM) lpszText);
     }
 
     HWND Create(HWND hwndParent)
@@ -626,21 +626,31 @@ private:
         /* Size tool bar */
         m_Toolbar->AutoSize();
 
-
         RECT r = {0, 0, LOWORD(lParam), HIWORD(lParam)};
-
         HDWP hdwp = NULL;
-
         int count = m_ClientPanel->CountSizableChildren();
+
         hdwp = BeginDeferWindowPos(count);
-        if (hdwp) hdwp = m_ClientPanel->OnParentSize(r, hdwp);
-        if (hdwp) EndDeferWindowPos(hdwp);
+        if (hdwp)
+        {
+            hdwp = m_ClientPanel->OnParentSize(r, hdwp);
+        }
+        if (hdwp)
+        {
+            EndDeferWindowPos(hdwp);
+        }
 
         // TODO: Sub-layouts for children of children
         count = m_SearchBar->CountSizableChildren();
         hdwp = BeginDeferWindowPos(count);
-        if (hdwp) hdwp = m_SearchBar->OnParentSize(r, hdwp);
-        if (hdwp) EndDeferWindowPos(hdwp);
+        if (hdwp)
+        {
+            hdwp = m_SearchBar->OnParentSize(r, hdwp);
+        }
+        if (hdwp)
+        {
+            EndDeferWindowPos(hdwp);
+        }
     }
 
     BOOL ProcessWindowMessage(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam, LRESULT& theResult, DWORD dwMapId)
@@ -781,10 +791,10 @@ private:
                     EnableMenuItem(lvwMenu, ID_UNINSTALL, MF_ENABLED);
                     EnableMenuItem(lvwMenu, ID_MODIFY, MF_ENABLED);
 
-                    m_Toolbar->SendMessage(TB_ENABLEBUTTON, ID_REGREMOVE, TRUE);
-                    m_Toolbar->SendMessage(TB_ENABLEBUTTON, ID_INSTALL, FALSE);
-                    m_Toolbar->SendMessage(TB_ENABLEBUTTON, ID_UNINSTALL, TRUE);
-                    m_Toolbar->SendMessage(TB_ENABLEBUTTON, ID_MODIFY, TRUE);
+                    m_Toolbar->SendMessageW(TB_ENABLEBUTTON, ID_REGREMOVE, TRUE);
+                    m_Toolbar->SendMessageW(TB_ENABLEBUTTON, ID_INSTALL, FALSE);
+                    m_Toolbar->SendMessageW(TB_ENABLEBUTTON, ID_UNINSTALL, TRUE);
+                    m_Toolbar->SendMessageW(TB_ENABLEBUTTON, ID_MODIFY, TRUE);
                 }
                 else
                 {
@@ -798,10 +808,10 @@ private:
                     EnableMenuItem(lvwMenu, ID_UNINSTALL, MF_GRAYED);
                     EnableMenuItem(lvwMenu, ID_MODIFY, MF_GRAYED);
 
-                    m_Toolbar->SendMessage(TB_ENABLEBUTTON, ID_REGREMOVE, FALSE);
-                    m_Toolbar->SendMessage(TB_ENABLEBUTTON, ID_INSTALL, TRUE);
-                    m_Toolbar->SendMessage(TB_ENABLEBUTTON, ID_UNINSTALL, FALSE);
-                    m_Toolbar->SendMessage(TB_ENABLEBUTTON, ID_MODIFY, FALSE);
+                    m_Toolbar->SendMessageW(TB_ENABLEBUTTON, ID_REGREMOVE, FALSE);
+                    m_Toolbar->SendMessageW(TB_ENABLEBUTTON, ID_INSTALL, TRUE);
+                    m_Toolbar->SendMessageW(TB_ENABLEBUTTON, ID_UNINSTALL, FALSE);
+                    m_Toolbar->SendMessageW(TB_ENABLEBUTTON, ID_MODIFY, FALSE);
                 }
             }
             break;
@@ -905,10 +915,10 @@ private:
         case WM_SYSCOLORCHANGE:
         {
             /* Forward WM_SYSCOLORCHANGE to common controls */
-            m_ListView->SendMessage(WM_SYSCOLORCHANGE, 0, 0);
-            m_TreeView->SendMessage(WM_SYSCOLORCHANGE, 0, 0);
-            m_Toolbar->SendMessage(WM_SYSCOLORCHANGE, 0, 0);
-            m_ListView->SendMessage(EM_SETBKGNDCOLOR, 0, GetSysColor(COLOR_BTNFACE));
+            m_ListView->SendMessageW(WM_SYSCOLORCHANGE, 0, 0);
+            m_TreeView->SendMessageW(WM_SYSCOLORCHANGE, 0, 0);
+            m_Toolbar->SendMessageW(WM_SYSCOLORCHANGE, 0, 0);
+            m_ListView->SendMessageW(EM_SETBKGNDCOLOR, 0, GetSysColor(COLOR_BTNFACE));
         }
         break;
 
@@ -1028,7 +1038,7 @@ private:
                 }
 
                 DWORD dwDelay;
-                SystemParametersInfo(SPI_GETMENUSHOWDELAY, 0, &dwDelay, 0);
+                SystemParametersInfoW(SPI_GETMENUSHOWDELAY, 0, &dwDelay, 0);
                 SetTimer(SEARCH_TIMER_ID, dwDelay);
             }
             break;
@@ -1186,7 +1196,7 @@ private:
         if (!hIcon)
         {
             /* Load default icon */
-            hIcon = (HICON) LoadIcon(hInst, MAKEINTRESOURCEW(IDI_MAIN));
+            hIcon = (HICON) LoadIconW(hInst, MAKEINTRESOURCEW(IDI_MAIN));
         }
         Index = ImageList_AddIcon(hImageListView, hIcon);
         DestroyIcon(hIcon);
@@ -1208,7 +1218,7 @@ private:
         ATL::CStringW szBuffer1, szBuffer2;
         HIMAGELIST hImageListView = NULL;
 
-        m_ListView->SendMessage(WM_SETREDRAW, FALSE, 0);
+        m_ListView->SendMessageW(WM_SETREDRAW, FALSE, 0);
 
         if (EnumType < 0) EnumType = SelectedEnumType;
 
@@ -1244,7 +1254,7 @@ private:
         if (ListView_GetItemCount(hListView) > 0)
             ListView_SetColumnWidth(hListView, 0, LVSCW_AUTOSIZE);
 
-        SendMessage(hListView, WM_SETREDRAW, TRUE, 0);
+        SendMessageW(hListView, WM_SETREDRAW, TRUE, 0);
     }
 
 public:
@@ -1253,12 +1263,20 @@ public:
         DWORD csStyle = CS_VREDRAW | CS_HREDRAW;
         static ATL::CWndClassInfo wc =
         {
-            { sizeof(WNDCLASSEX), csStyle, StartWindowProc,
-            0, 0, NULL,
-            LoadIcon(_AtlBaseModule.GetModuleInstance(), MAKEINTRESOURCE(IDI_MAIN)),
-            LoadCursor(NULL, IDC_ARROW),
-            (HBRUSH) (COLOR_BTNFACE + 1), MAKEINTRESOURCE(IDR_MAINMENU),
-            L"RAppsWnd", NULL },
+            { 
+                sizeof(WNDCLASSEX), 
+                csStyle, 
+                StartWindowProc,
+                0, 
+                0, 
+                NULL,
+                LoadIconW(_AtlBaseModule.GetModuleInstance(), MAKEINTRESOURCEW(IDI_MAIN)),
+                LoadCursorW(NULL, IDC_ARROW),
+                (HBRUSH) (COLOR_BTNFACE + 1), 
+                MAKEINTRESOURCEW(IDR_MAINMENU),
+                L"RAppsWnd", 
+                NULL
+            },
             NULL, NULL, IDC_ARROW, TRUE, 0, _T("")
         };
         return wc;
index 578087b..298c610 100644 (file)
@@ -37,27 +37,10 @@ GetApplicationString(HKEY hKey, LPCWSTR lpKeyName, LPWSTR szString)
 }
 
 BOOL
-IsInstalledApplication(const ATL::CStringW &RegName, BOOL IsUserKey, REGSAM keyWow)
-{
-    HKEY hKey = NULL;
-    BOOL IsInstalled = FALSE;
-    ATL::CStringW szPath = L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + RegName;
-
-    if (RegOpenKeyExW(IsUserKey ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE,
-                      szPath, 0, keyWow | KEY_READ,
-                      &hKey) == ERROR_SUCCESS)
-    {
-        IsInstalled = TRUE;
-    }
-    RegCloseKey(hKey);
-    return IsInstalled;
-}
-
-BOOL
-InstalledVersion(ATL::CStringW& szVersionResult, const ATL::CStringW& RegName, BOOL IsUserKey, REGSAM keyWow)
+GetInstalledVersion_WowUser(_Out_opt_ ATL::CStringW* szVersionResult, _In_z_ const ATL::CStringW& RegName, _In_ BOOL IsUserKey, _In_ REGSAM keyWow)
 {
     HKEY hKey;
-    BOOL bHasVersion = FALSE;
+    BOOL bHasSucceded = FALSE;
     ATL::CStringW szVersion;
     ATL::CStringW szPath = L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + RegName;
 
@@ -65,27 +48,36 @@ InstalledVersion(ATL::CStringW& szVersionResult, const ATL::CStringW& RegName, B
                       szPath.GetString(), 0, keyWow | KEY_READ,
                       &hKey) == ERROR_SUCCESS)
     {
-        DWORD dwSize = MAX_PATH * sizeof(WCHAR);
-        DWORD dwType = REG_SZ;
-        if (RegQueryValueExW(hKey,
-                             L"DisplayVersion",
-                             NULL,
-                             &dwType,
-                             (LPBYTE) szVersion.GetBuffer(MAX_PATH),
-                             &dwSize) == ERROR_SUCCESS)
+        if (szVersionResult)
         {
-            szVersion.ReleaseBuffer();
-            szVersionResult = szVersion;
-            bHasVersion = TRUE;
+            DWORD dwSize = MAX_PATH * sizeof(WCHAR);
+            DWORD dwType = REG_SZ;
+            if (RegQueryValueExW(hKey,
+                                 L"DisplayVersion",
+                                 NULL,
+                                 &dwType,
+                                 (LPBYTE) szVersion.GetBuffer(MAX_PATH),
+                                 &dwSize) == ERROR_SUCCESS)
+            {
+                szVersion.ReleaseBuffer();
+                *szVersionResult = szVersion;
+                bHasSucceded = TRUE;
+            }
+            else
+            {
+                szVersion.ReleaseBuffer();
+            }
         }
         else
         {
+            bHasSucceded = TRUE;
             szVersion.ReleaseBuffer();
         }
+        
     }
 
     RegCloseKey(hKey);
-    return bHasVersion;
+    return bHasSucceded;
 }
 
 
index afa942e..9c90c59 100644 (file)
@@ -159,10 +159,9 @@ BOOL GetApplicationString(HKEY hKey, LPCWSTR RegName, ATL::CStringW& String);
 
 BOOL ShowInstalledAppInfo(INT Index);
 BOOL UninstallApplication(INT Index, BOOL bModify);
-BOOL IsInstalledApplication(const ATL::CStringW& RegName, BOOL IsUserKey, REGSAM keyWow);
 VOID RemoveAppFromRegistry(INT Index);
 
-BOOL InstalledVersion(ATL::CStringW& szVersionResult, const ATL::CStringW& RegName, BOOL IsUserKey, REGSAM keyWow);
+BOOL GetInstalledVersion_WowUser(ATL::CStringW* szVersionResult, const ATL::CStringW& RegName, BOOL IsUserKey, REGSAM keyWow);
 
 /* winmain.cpp */
 extern HWND hMainWnd;
index 10d3c0b..ea13f9c 100644 (file)
@@ -12,7 +12,7 @@
 SETTINGS_INFO NewSettingsInfo;
 
 #define IS_CHECKED(a, b) \
-    a = (SendDlgItemMessage(hDlg, b, BM_GETCHECK, 0, 0) == BST_CHECKED) ? TRUE : FALSE
+    a = (SendDlgItemMessageW(hDlg, b, BM_GETCHECK, 0, 0) == BST_CHECKED) ? TRUE : FALSE
 
 BOOL
 ChooseFolder(HWND hwnd)
@@ -32,13 +32,13 @@ ChooseFolder(HWND hwnd)
     szBuf.Empty();
     if (SUCCEEDED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED)))
     {
-        LPITEMIDLIST lpItemList = SHBrowseForFolder(&bi);
-        if (lpItemList && SHGetPathFromIDList(lpItemList, szBuf.GetBuffer(MAX_PATH)))
+        LPITEMIDLIST lpItemList = SHBrowseForFolderW(&bi);
+        if (lpItemList && SHGetPathFromIDListW(lpItemList, szBuf.GetBuffer(MAX_PATH)))
         {
             szBuf.ReleaseBuffer();
             if (!szBuf.IsEmpty())
             {
-                SetDlgItemTextW(hwnd, IDC_DOWNLOAD_DIR_EDIT, szBuf.GetString());
+                SetDlgItemTextW(hwnd, IDC_DOWNLOAD_DIR_EDIT, szBuf);
                 bRet = TRUE;
             }
         }
@@ -55,10 +55,10 @@ ChooseFolder(HWND hwnd)
 static VOID
 InitSettingsControls(HWND hDlg, PSETTINGS_INFO Info)
 {
-    SendDlgItemMessage(hDlg, IDC_SAVE_WINDOW_POS, BM_SETCHECK, Info->bSaveWndPos, 0);
-    SendDlgItemMessage(hDlg, IDC_UPDATE_AVLIST, BM_SETCHECK, Info->bUpdateAtStart, 0);
-    SendDlgItemMessage(hDlg, IDC_LOG_ENABLED, BM_SETCHECK, Info->bLogEnabled, 0);
-    SendDlgItemMessage(hDlg, IDC_DEL_AFTER_INSTALL, BM_SETCHECK, Info->bDelInstaller, 0);
+    SendDlgItemMessageW(hDlg, IDC_SAVE_WINDOW_POS, BM_SETCHECK, Info->bSaveWndPos, 0);
+    SendDlgItemMessageW(hDlg, IDC_UPDATE_AVLIST, BM_SETCHECK, Info->bUpdateAtStart, 0);
+    SendDlgItemMessageW(hDlg, IDC_LOG_ENABLED, BM_SETCHECK, Info->bLogEnabled, 0);
+    SendDlgItemMessageW(hDlg, IDC_DEL_AFTER_INSTALL, BM_SETCHECK, Info->bDelInstaller, 0);
 
     SetWindowTextW(GetDlgItem(hDlg, IDC_DOWNLOAD_DIR_EDIT),
                    Info->szDownloadDir);