2 * PROJECT: ReactOS Applications Manager
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * FILE: base/applications/rapps/winmain.cpp
5 * PURPOSE: Main program
6 * COPYRIGHT: Copyright 2009 Dmitry Chapyshev (dmitry@reactos.org)
7 * Copyright 2015 Ismael Ferreras Morezuelas (swyterzone+ros@gmail.com)
8 * Copyright 2017 Alexander Shaposhnikov (sanchaez@reactos.org)
12 #include "unattended.h"
18 INT SelectedEnumType
= ENUM_ALL_INSTALLED
;
19 SETTINGS_INFO SettingsInfo
;
21 class CRAppsModule
: public CComModule
26 BEGIN_OBJECT_MAP(ObjectMap
)
30 CAtlWinModule gWinModule
;
32 static VOID
InitializeAtlModule(HINSTANCE hInstance
, BOOL bInitialize
)
36 gModule
.Init(ObjectMap
, hInstance
, NULL
);
44 VOID
FillDefaultSettings(PSETTINGS_INFO pSettingsInfo
)
46 ATL::CStringW szDownloadDir
;
47 ZeroMemory(pSettingsInfo
, sizeof(SETTINGS_INFO
));
49 pSettingsInfo
->bSaveWndPos
= TRUE
;
50 pSettingsInfo
->bUpdateAtStart
= FALSE
;
51 pSettingsInfo
->bLogEnabled
= TRUE
;
53 if (FAILED(SHGetFolderPathW(NULL
, CSIDL_PERSONAL
, NULL
, SHGFP_TYPE_CURRENT
, szDownloadDir
.GetBuffer(MAX_PATH
))))
55 szDownloadDir
.ReleaseBuffer();
56 if (!szDownloadDir
.GetEnvironmentVariableW(L
"SystemDrive"))
58 szDownloadDir
= L
"C:";
63 szDownloadDir
.ReleaseBuffer();
66 szDownloadDir
+= L
"\\RAPPS Downloads";
67 ATL::CStringW::CopyChars(pSettingsInfo
->szDownloadDir
,
68 _countof(pSettingsInfo
->szDownloadDir
),
69 szDownloadDir
.GetString(),
70 szDownloadDir
.GetLength() + 1);
72 pSettingsInfo
->bDelInstaller
= FALSE
;
73 pSettingsInfo
->Maximized
= FALSE
;
74 pSettingsInfo
->Left
= CW_USEDEFAULT
;
75 pSettingsInfo
->Top
= CW_USEDEFAULT
;
76 pSettingsInfo
->Width
= 680;
77 pSettingsInfo
->Height
= 450;
80 static BOOL
LoadSettings()
85 if (RegKey
.Open(HKEY_CURRENT_USER
, L
"Software\\ReactOS\\rapps", KEY_READ
) == ERROR_SUCCESS
)
87 dwSize
= sizeof(SettingsInfo
);
88 bResult
= (RegKey
.QueryBinaryValue(L
"Settings", (PVOID
) &SettingsInfo
, &dwSize
) == ERROR_SUCCESS
);
96 VOID
SaveSettings(HWND hwnd
)
101 if (SettingsInfo
.bSaveWndPos
)
103 wp
.length
= sizeof(wp
);
104 GetWindowPlacement(hwnd
, &wp
);
106 SettingsInfo
.Left
= wp
.rcNormalPosition
.left
;
107 SettingsInfo
.Top
= wp
.rcNormalPosition
.top
;
108 SettingsInfo
.Width
= wp
.rcNormalPosition
.right
- wp
.rcNormalPosition
.left
;
109 SettingsInfo
.Height
= wp
.rcNormalPosition
.bottom
- wp
.rcNormalPosition
.top
;
110 SettingsInfo
.Maximized
= (wp
.showCmd
== SW_MAXIMIZE
111 || (wp
.showCmd
== SW_SHOWMINIMIZED
112 && (wp
.flags
& WPF_RESTORETOMAXIMIZED
)));
115 if (RegKey
.Create(HKEY_CURRENT_USER
, L
"Software\\ReactOS\\rapps", NULL
,
116 REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, NULL
) == ERROR_SUCCESS
)
118 RegKey
.SetBinaryValue(L
"Settings", (const PVOID
) &SettingsInfo
, sizeof(SettingsInfo
));
123 INT WINAPI
wWinMain(HINSTANCE hInstance
, HINSTANCE hPrevInstance
, LPWSTR lpCmdLine
, INT nShowCmd
)
125 LPCWSTR szWindowClass
= L
"ROSAPPMGR";
129 InitializeAtlModule(hInstance
, TRUE
);
131 if (GetUserDefaultUILanguage() == MAKELANGID(LANG_HEBREW
, SUBLANG_DEFAULT
))
133 SetProcessDefaultLayout(LAYOUT_RTL
);
138 hMutex
= CreateMutexW(NULL
, FALSE
, szWindowClass
);
139 if ((!hMutex
) || (GetLastError() == ERROR_ALREADY_EXISTS
))
141 /* If already started, it is found its window */
142 HWND hWindow
= FindWindowW(szWindowClass
, NULL
);
144 /* Activate window */
145 ShowWindow(hWindow
, SW_SHOWNORMAL
);
146 SetForegroundWindow(hWindow
);
149 bIsFirstLaunch
= !LoadSettings();
152 FillDefaultSettings(&SettingsInfo
);
156 InitCommonControls();
158 // skip window creation if there were some keys
159 if (!UseCmdParameters(GetCommandLineW()))
161 if (SettingsInfo
.bUpdateAtStart
|| bIsFirstLaunch
)
162 CAvailableApps::ForceUpdateAppsDB();
164 ShowMainWindow(nShowCmd
);
170 InitializeAtlModule(hInstance
, FALSE
);