[RAPPS] Some fixes
authorAlexander Shaposhnikov <sanchaez@reactos.org>
Mon, 10 Jul 2017 22:26:01 +0000 (22:26 +0000)
committerAlexander Shaposhnikov <sanchaez@reactos.org>
Mon, 10 Jul 2017 22:26:01 +0000 (22:26 +0000)
- winmain.cpp, loaddlg.cpp, installed.cpp:
  Changed string-related opreations
- installed.cpp: Fixed buffer sizing when calling RegQueryValueExW()
- misc.cpp: Removed unused function
- rosui.h: Made use of GetWindowTextLength()

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

reactos/base/applications/rapps/installed.cpp
reactos/base/applications/rapps/loaddlg.cpp
reactos/base/applications/rapps/misc.cpp
reactos/base/applications/rapps/rosui.h
reactos/base/applications/rapps/winmain.cpp

index 12f729c..578087b 100644 (file)
@@ -32,7 +32,7 @@ GetApplicationString(HKEY hKey, LPCWSTR lpKeyName, LPWSTR szString)
         return TRUE;
     }
 
-    szString = L"---";
+    StringCchCopyW(szString, MAX_PATH, L"---");
     return FALSE;
 }
 
@@ -44,8 +44,8 @@ IsInstalledApplication(const ATL::CStringW &RegName, BOOL IsUserKey, REGSAM keyW
     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)
+                      szPath, 0, keyWow | KEY_READ,
+                      &hKey) == ERROR_SUCCESS)
     {
         IsInstalled = TRUE;
     }
@@ -62,17 +62,17 @@ InstalledVersion(ATL::CStringW& szVersionResult, const ATL::CStringW& RegName, B
     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)
+                      szPath.GetString(), 0, keyWow | KEY_READ,
+                      &hKey) == ERROR_SUCCESS)
     {
-        DWORD dwSize = MAX_PATH;
+        DWORD dwSize = MAX_PATH * sizeof(WCHAR);
         DWORD dwType = REG_SZ;
         if (RegQueryValueExW(hKey,
-            L"DisplayVersion",
-            NULL,
-            &dwType,
-            (LPBYTE) szVersion.GetBuffer(dwSize),
-            &dwSize) == ERROR_SUCCESS)
+                             L"DisplayVersion",
+                             NULL,
+                             &dwType,
+                             (LPBYTE) szVersion.GetBuffer(MAX_PATH),
+                             &dwSize) == ERROR_SUCCESS)
         {
             szVersion.ReleaseBuffer();
             szVersionResult = szVersion;
@@ -126,11 +126,11 @@ UninstallApplication(INT Index, BOOL bModify)
     if (!ListView_GetItem(hListView, &Item))
         return FALSE;
 
-    ItemInfo = (PINSTALLED_INFO)Item.lParam;
+    ItemInfo = (PINSTALLED_INFO) Item.lParam;
     hKey = ItemInfo->hSubKey;
 
     dwType = REG_SZ;
-    dwSize = sizeof(szPath);
+    dwSize = MAX_PATH * sizeof(WCHAR);
     if (RegQueryValueExW(hKey,
                          bModify ? szModify : szUninstall,
                          NULL,
@@ -208,11 +208,14 @@ RemoveAppFromRegistry(INT Index)
 
     if (MessageBoxW(hMainWnd, szMsgText, szMsgTitle, MB_YESNO | MB_ICONQUESTION) == IDYES)
     {
-        wcsncat(szFullName, Info->szKeyName.GetString(), MAX_PATH - wcslen(szFullName));
+        ATL::CStringW::CopyChars(szFullName, 
+                                 MAX_PATH, 
+                                 Info->szKeyName.GetString(), 
+                                 MAX_PATH - wcslen(szFullName));
 
         if (RegDeleteKeyW(Info->hRootKey, szFullName) == ERROR_SUCCESS)
         {
-            (VOID) ListView_DeleteItem(hListView, ItemIndex);
+            ListView_DeleteItem(hListView, ItemIndex);
             return;
         }
 
@@ -267,21 +270,22 @@ EnumInstalledApplications(INT EnumType, BOOL IsUserKey, APPENUMPROC lpEnumProc)
             }
 
             dwType = REG_SZ;
-            dwSize = MAX_PATH;
+            dwSize = MAX_PATH * sizeof(WCHAR);
             bIsUpdate = (RegQueryValueExW(Info.hSubKey,
                                           L"ParentKeyName",
                                           NULL,
                                           &dwType,
-                                          (LPBYTE) szParentKeyName.GetBuffer(dwSize),
+                                          (LPBYTE) szParentKeyName.GetBuffer(MAX_PATH),
                                           &dwSize) == ERROR_SUCCESS);
             szParentKeyName.ReleaseBuffer();
 
-            dwSize = sizeof(szDisplayName);
+            dwType = REG_SZ;
+            dwSize = MAX_PATH * sizeof(WCHAR);
             if (RegQueryValueExW(Info.hSubKey,
                                  L"DisplayName",
                                  NULL,
                                  &dwType,
-                                 (LPBYTE) szDisplayName.GetBuffer(dwSize),
+                                 (LPBYTE) szDisplayName.GetBuffer(MAX_PATH),
                                  &dwSize) == ERROR_SUCCESS)
             {
                 szDisplayName.ReleaseBuffer();
index 6ce1a17..c0415c1 100644 (file)
@@ -366,8 +366,8 @@ ThreadFunc(LPVOID Context)
 
     memset(&urlComponents, 0, sizeof(urlComponents));
     urlComponents.dwStructSize = sizeof(urlComponents);
-
-    if (FAILED(StringCbLengthW(AppInfo->szUrlDownload, sizeof(AppInfo->szUrlDownload), &urlLength)))
+    
+    if (AppInfo->szUrlDownload.GetLength() > urlLength)
         goto end;
 
     urlLength /= sizeof(WCHAR);
index e7cb872..1115262 100644 (file)
@@ -493,10 +493,3 @@ UINT ParserGetInt(const ATL::CStringW& KeyName, const ATL::CStringW& FileName)
 
     return (UINT) Result;
 }
-
-LPWSTR HeapBufferFromCStringW(const ATL::CStringW& String)
-{
-    LPWSTR szBuffer = (LPWSTR) HeapAlloc(GetProcessHeap(), 0, MAX_PATH * sizeof(WCHAR));
-    ATL::CString::CopyChars(szBuffer, MAX_PATH, String.GetString(), String.GetLength() + 1);
-    return szBuffer;
-}
\ No newline at end of file
index 9456379..b372dfc 100644 (file)
@@ -495,7 +495,8 @@ public:
 
     void GetWindowTextW(ATL::CStringW& szText)
     {
-        CWindow::GetWindowText(szText.GetBuffer(MAX_STR_LEN), MAX_STR_LEN);
+        INT length = CWindow::GetWindowTextLengthW();
+        CWindow::GetWindowText(szText.GetBuffer(length), length);
         szText.ReleaseBuffer();
     }
 };
index 35fff2a..82fffaf 100644 (file)
@@ -69,7 +69,10 @@ FillDefaultSettings(PSETTINGS_INFO pSettingsInfo)
         szDownloadDir.ReleaseBuffer();
 
     szDownloadDir += L"\\RAPPS Downloads";
-    StringCchCopyW(pSettingsInfo->szDownloadDir, _countof(pSettingsInfo->szDownloadDir), szDownloadDir.GetString());
+    ATL::CStringW::CopyChars(pSettingsInfo->szDownloadDir, 
+                             _countof(pSettingsInfo->szDownloadDir),
+                             szDownloadDir.GetString(),
+                             szDownloadDir.GetLength() + 1);
 
     pSettingsInfo->bDelInstaller = FALSE;
     pSettingsInfo->Maximized = FALSE;
@@ -79,8 +82,8 @@ FillDefaultSettings(PSETTINGS_INFO pSettingsInfo)
     pSettingsInfo->Height = 450;
     pSettingsInfo->Proxy = 0;
 
-    StringCbCopyW(pSettingsInfo->szProxyServer, sizeof(pSettingsInfo->szProxyServer), L"");
-    StringCbCopyW(pSettingsInfo->szNoProxyFor, sizeof(pSettingsInfo->szNoProxyFor), L"");
+    pSettingsInfo->szProxyServer[0] = UNICODE_NULL;
+    pSettingsInfo->szNoProxyFor[0] = UNICODE_NULL;
 }
 
 static BOOL