[RAPPS] Improvements & multiple selections
[reactos.git] / reactos / base / applications / rapps / winmain.cpp
index 23e5a34..a24e5cf 100644 (file)
@@ -5,6 +5,7 @@
  * PURPOSE:         Main program
  * PROGRAMMERS:     Dmitry Chapyshev           (dmitry@reactos.org)
  *                  Ismael Ferreras Morezuelas (swyterzone+ros@gmail.com)
+ *                  Alexander Shaposhnikov     (chaez.san@gmail.com)
  */
 
 #include "rapps.h"
@@ -18,7 +19,7 @@ HINSTANCE hInst;
 INT SelectedEnumType = ENUM_ALL_COMPONENTS;
 SETTINGS_INFO SettingsInfo;
 
-WCHAR szSearchPattern[MAX_STR_LEN] = L"";
+ATL::CStringW szSearchPattern;
 
 class CRAppsModule : public CComModule
 {
@@ -28,13 +29,13 @@ public:
 BEGIN_OBJECT_MAP(ObjectMap)
 END_OBJECT_MAP()
 
-CRAppsModule                             gModule;
-CAtlWinModule                               gWinModule;
+CRAppsModule gModule;
+CAtlWinModule gWinModule;
 
-void *operator new (size_t, void *buf)
-{
-    return buf;
-}
+//void *operator new (size_t, void *buf)
+//{
+//    return buf;
+//}
 
 static VOID InitializeAtlModule(HINSTANCE hInstance, BOOL bInitialize)
 {
@@ -51,23 +52,38 @@ static VOID InitializeAtlModule(HINSTANCE hInstance, BOOL bInitialize)
 VOID
 FillDefaultSettings(PSETTINGS_INFO pSettingsInfo)
 {
+    ATL::CStringW szDownloadDir;
     pSettingsInfo->bSaveWndPos = TRUE;
     pSettingsInfo->bUpdateAtStart = FALSE;
     pSettingsInfo->bLogEnabled = TRUE;
-    StringCbCopyW(pSettingsInfo->szDownloadDir,
-                  sizeof(pSettingsInfo->szDownloadDir),
-                  L"C:\\Downloads");
-    pSettingsInfo->bDelInstaller = FALSE;
 
+    if (FAILED(SHGetFolderPathW(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, szDownloadDir.GetBuffer(MAX_PATH))))
+    {
+        szDownloadDir.ReleaseBuffer();
+        if (!szDownloadDir.GetEnvironmentVariableW(L"SystemDrive"))
+        {
+            szDownloadDir = L"C:";
+        }
+    }
+    else
+        szDownloadDir.ReleaseBuffer();
+
+    szDownloadDir += L"\\RAPPS Downloads";
+    ATL::CStringW::CopyChars(pSettingsInfo->szDownloadDir, 
+                             _countof(pSettingsInfo->szDownloadDir),
+                             szDownloadDir.GetString(),
+                             szDownloadDir.GetLength() + 1);
+
+    pSettingsInfo->bDelInstaller = FALSE;
     pSettingsInfo->Maximized = FALSE;
     pSettingsInfo->Left = CW_USEDEFAULT;
     pSettingsInfo->Top = CW_USEDEFAULT;
     pSettingsInfo->Width = 680;
     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
@@ -79,7 +95,7 @@ LoadSettings(VOID)
     if (RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\ReactOS\\rapps", 0, KEY_READ, &hKey) == ERROR_SUCCESS)
     {
         dwSize = sizeof(SettingsInfo);
-        if (RegQueryValueExW(hKey, L"Settings", NULL, NULL, (LPBYTE)&SettingsInfo, &dwSize) == ERROR_SUCCESS)
+        if (RegQueryValueExW(hKey, L"Settings", NULL, NULL, (LPBYTE) &SettingsInfo, &dwSize) == ERROR_SUCCESS)
         {
             RegCloseKey(hKey);
             return TRUE;
@@ -103,16 +119,16 @@ SaveSettings(HWND hwnd)
         GetWindowPlacement(hwnd, &wp);
 
         SettingsInfo.Left = wp.rcNormalPosition.left;
-        SettingsInfo.Top  = wp.rcNormalPosition.top;
-        SettingsInfo.Width  = wp.rcNormalPosition.right - wp.rcNormalPosition.left;
+        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)
+                        REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS)
     {
-        RegSetValueExW(hKey, L"Settings", 0, REG_BINARY, (LPBYTE)&SettingsInfo, sizeof(SettingsInfo));
+        RegSetValueExW(hKey, L"Settings", 0, REG_BINARY, (LPBYTE) &SettingsInfo, sizeof(SettingsInfo));
         RegCloseKey(hKey);
     }
 }
@@ -129,12 +145,12 @@ wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nSh
 
     switch (GetUserDefaultUILanguage())
     {
-        case MAKELANGID(LANG_HEBREW, SUBLANG_DEFAULT):
-            SetProcessDefaultLayout(LAYOUT_RTL);
-            break;
+    case MAKELANGID(LANG_HEBREW, SUBLANG_DEFAULT):
+        SetProcessDefaultLayout(LAYOUT_RTL);
+        break;
 
-        default:
-            break;
+    default:
+        break;
     }
 
     hInst = hInstance;
@@ -167,19 +183,20 @@ wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nSh
     ShowWindow(hMainWnd, (SettingsInfo.bSaveWndPos && SettingsInfo.Maximized ? SW_MAXIMIZE : nShowCmd));
     UpdateWindow(hMainWnd);
 
+    //TODO: get around the ugliness
     if (SettingsInfo.bUpdateAtStart)
-        UpdateAppsDB();
+        GetAvailableApps()->UpdateAppsDB();
 
     /* Load the menu hotkeys */
-    KeyBrd = LoadAccelerators(NULL, MAKEINTRESOURCE(HOTKEYS));
+    KeyBrd = LoadAcceleratorsW(NULL, MAKEINTRESOURCE(HOTKEYS));
 
     /* Message Loop */
     while (GetMessage(&Msg, NULL, 0, 0))
     {
-        if (!TranslateAccelerator(hMainWnd, KeyBrd, &Msg))
+        if (!TranslateAcceleratorW(hMainWnd, KeyBrd, &Msg))
         {
             TranslateMessage(&Msg);
-            DispatchMessage(&Msg);
+            DispatchMessageW(&Msg);
         }
     }