[RAPPS] Replaced my @gmail.com email with @reactos,org one & Removed my copyright...
[reactos.git] / reactos / base / applications / rapps / winmain.cpp
index 32dfe36..5531cd7 100644 (file)
@@ -1,22 +1,21 @@
 /*
- * PROJECT:         ReactOS Applications Manager
- * LICENSE:         GPL - See COPYING in the top level directory
- * FILE:            base/applications/rapps/winmain.cpp
- * PURPOSE:         Main program
- * PROGRAMMERS:     Dmitry Chapyshev           (dmitry@reactos.org)
- *                  Ismael Ferreras Morezuelas (swyterzone+ros@gmail.com)
- *                  Alexander Shaposhnikov     (chaez.san@gmail.com)
+ * PROJECT:     ReactOS Applications Manager
+ * LICENSE:     GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
+ * FILE:        base/applications/rapps/winmain.cpp
+ * PURPOSE:     Main program
+ * COPYRIGHT:   Copyright 2009 Dmitry Chapyshev            (dmitry@reactos.org)
+ *              Copyright 2015 Ismael Ferreras Morezuelas  (swyterzone+ros@gmail.com)
+ *              Copyright 2017 Alexander Shaposhnikov      (sanchaez@reactos.org)
  */
-
+#include "defines.h"
 #include "rapps.h"
+#include "unattended.h"
 
-#include <atlbase.h>
 #include <atlcom.h>
-#include <shellapi.h>
 
 HWND hMainWnd;
 HINSTANCE hInst;
-INT SelectedEnumType = ENUM_ALL_COMPONENTS;
+INT SelectedEnumType = ENUM_ALL_INSTALLED;
 SETTINGS_INFO SettingsInfo;
 
 ATL::CStringW szSearchPattern;
@@ -32,11 +31,6 @@ END_OBJECT_MAP()
 CRAppsModule gModule;
 CAtlWinModule gWinModule;
 
-//void *operator new (size_t, void *buf)
-//{
-//    return buf;
-//}
-
 static VOID InitializeAtlModule(HINSTANCE hInstance, BOOL bInitialize)
 {
     if (bInitialize)
@@ -49,10 +43,11 @@ static VOID InitializeAtlModule(HINSTANCE hInstance, BOOL bInitialize)
     }
 }
 
-VOID
-FillDefaultSettings(PSETTINGS_INFO pSettingsInfo)
+VOID FillDefaultSettings(PSETTINGS_INFO pSettingsInfo)
 {
     ATL::CStringW szDownloadDir;
+    ZeroMemory(pSettingsInfo, sizeof(SETTINGS_INFO));
+
     pSettingsInfo->bSaveWndPos = TRUE;
     pSettingsInfo->bUpdateAtStart = FALSE;
     pSettingsInfo->bLogEnabled = TRUE;
@@ -66,10 +61,12 @@ FillDefaultSettings(PSETTINGS_INFO pSettingsInfo)
         }
     }
     else
+    {
         szDownloadDir.ReleaseBuffer();
+    }
 
     szDownloadDir += L"\\RAPPS Downloads";
-    ATL::CStringW::CopyChars(pSettingsInfo->szDownloadDir, 
+    ATL::CStringW::CopyChars(pSettingsInfo->szDownloadDir,
                              _countof(pSettingsInfo->szDownloadDir),
                              szDownloadDir.GetString(),
                              szDownloadDir.GetLength() + 1);
@@ -80,38 +77,28 @@ FillDefaultSettings(PSETTINGS_INFO pSettingsInfo)
     pSettingsInfo->Top = CW_USEDEFAULT;
     pSettingsInfo->Width = 680;
     pSettingsInfo->Height = 450;
-    pSettingsInfo->Proxy = 0;
-
-    pSettingsInfo->szProxyServer[0] = UNICODE_NULL;
-    pSettingsInfo->szNoProxyFor[0] = UNICODE_NULL;
 }
 
-static BOOL
-LoadSettings(VOID)
+static BOOL LoadSettings()
 {
-    HKEY hKey;
+    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;
-        }
+        bResult = (RegKey.QueryBinaryValue(L"Settings", (PVOID) &SettingsInfo, &dwSize) == ERROR_SUCCESS);
 
-        RegCloseKey(hKey);
+        RegKey.Close();
     }
 
-    return FALSE;
+    return bResult;
 }
 
-VOID
-SaveSettings(HWND hwnd)
+VOID SaveSettings(HWND hwnd)
 {
     WINDOWPLACEMENT wp;
-    HKEY hKey;
+    ATL::CRegKey RegKey;
 
     if (SettingsInfo.bSaveWndPos)
     {
@@ -122,35 +109,32 @@ SaveSettings(HWND hwnd)
         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)));
+        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)
+    if (RegKey.Create(HKEY_CURRENT_USER, L"Software\\ReactOS\\rapps", NULL,
+                      REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, NULL) == ERROR_SUCCESS)
     {
-        RegSetValueExW(hKey, L"Settings", 0, REG_BINARY, (LPBYTE) &SettingsInfo, sizeof(SettingsInfo));
-        RegCloseKey(hKey);
+        RegKey.SetBinaryValue(L"Settings", (const PVOID) &SettingsInfo, sizeof(SettingsInfo));
+        RegKey.Close();
     }
 }
 
-int WINAPI
-wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd)
+INT WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, INT nShowCmd)
 {
-    WCHAR szWindowClass[] = L"ROSAPPMGR";
-    HANDLE hMutex = NULL;
+    LPCWSTR szWindowClass = L"ROSAPPMGR";
+    HANDLE hMutex;
     HACCEL KeyBrd;
     MSG Msg;
+    BOOL bIsFirstLaunch;
 
     InitializeAtlModule(hInstance, TRUE);
 
-    switch (GetUserDefaultUILanguage())
+    if (GetUserDefaultUILanguage() == MAKELANGID(LANG_HEBREW, SUBLANG_DEFAULT))
     {
-    case MAKELANGID(LANG_HEBREW, SUBLANG_DEFAULT):
         SetProcessDefaultLayout(LAYOUT_RTL);
-        break;
-
-    default:
-        break;
     }
 
     hInst = hInstance;
@@ -166,41 +150,44 @@ wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nSh
         SetForegroundWindow(hWindow);
         return 1;
     }
-
-    if (!LoadSettings())
+    bIsFirstLaunch = !LoadSettings();
+    if (bIsFirstLaunch)
     {
         FillDefaultSettings(&SettingsInfo);
     }
 
     InitLogs();
-
     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();
+    // skip window creation if there were some keys
+    if (!UseCmdParameters(lpCmdLine))
+    {
+        if (SettingsInfo.bUpdateAtStart || bIsFirstLaunch)
+            CAvailableApps::ForceUpdateAppsDB();
 
-    /* Load the menu hotkeys */
-    KeyBrd = LoadAccelerators(NULL, MAKEINTRESOURCE(HOTKEYS));
+        hMainWnd = CreateMainWindow();
 
-    /* Message Loop */
-    while (GetMessage(&Msg, NULL, 0, 0))
-    {
-        if (!TranslateAccelerator(hMainWnd, KeyBrd, &Msg))
+        if (hMainWnd)
         {
-            TranslateMessage(&Msg);
-            DispatchMessage(&Msg);
+            /* Maximize it if we must */
+            ShowWindow(hMainWnd, ((SettingsInfo.bSaveWndPos && SettingsInfo.Maximized) ? SW_MAXIMIZE : nShowCmd));
+            UpdateWindow(hMainWnd);
+
+            /* Load the menu hotkeys */
+            KeyBrd = LoadAcceleratorsW(NULL, MAKEINTRESOURCEW(HOTKEYS));
+
+            /* Message Loop */
+            while (GetMessageW(&Msg, NULL, 0, 0))
+            {
+                if (!TranslateAcceleratorW(hMainWnd, KeyBrd, &Msg))
+                {
+                    TranslateMessage(&Msg);
+                    DispatchMessageW(&Msg);
+                }
+            }
         }
     }
 
-Exit:
     if (hMutex)
         CloseHandle(hMutex);