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 SETTINGS_INFO SettingsInfo
;
20 class CRAppsModule
: public CComModule
25 BEGIN_OBJECT_MAP(ObjectMap
)
29 CAtlWinModule gWinModule
;
31 static VOID
InitializeAtlModule(HINSTANCE hInstance
, BOOL bInitialize
)
35 gModule
.Init(ObjectMap
, hInstance
, NULL
);
43 VOID
FillDefaultSettings(PSETTINGS_INFO pSettingsInfo
)
45 ATL::CStringW szDownloadDir
;
46 ZeroMemory(pSettingsInfo
, sizeof(SETTINGS_INFO
));
48 pSettingsInfo
->bSaveWndPos
= TRUE
;
49 pSettingsInfo
->bUpdateAtStart
= FALSE
;
50 pSettingsInfo
->bLogEnabled
= TRUE
;
52 if (FAILED(SHGetFolderPathW(NULL
, CSIDL_PERSONAL
, NULL
, SHGFP_TYPE_CURRENT
, szDownloadDir
.GetBuffer(MAX_PATH
))))
54 szDownloadDir
.ReleaseBuffer();
55 if (!szDownloadDir
.GetEnvironmentVariableW(L
"SystemDrive"))
57 szDownloadDir
= L
"C:";
62 szDownloadDir
.ReleaseBuffer();
65 szDownloadDir
+= L
"\\RAPPS Downloads";
66 ATL::CStringW::CopyChars(pSettingsInfo
->szDownloadDir
,
67 _countof(pSettingsInfo
->szDownloadDir
),
68 szDownloadDir
.GetString(),
69 szDownloadDir
.GetLength() + 1);
71 pSettingsInfo
->bDelInstaller
= FALSE
;
72 pSettingsInfo
->Maximized
= FALSE
;
73 pSettingsInfo
->Left
= CW_USEDEFAULT
;
74 pSettingsInfo
->Top
= CW_USEDEFAULT
;
75 pSettingsInfo
->Width
= 680;
76 pSettingsInfo
->Height
= 450;
79 static BOOL
LoadSettings()
84 if (RegKey
.Open(HKEY_CURRENT_USER
, L
"Software\\ReactOS\\rapps", KEY_READ
) == ERROR_SUCCESS
)
86 dwSize
= sizeof(SettingsInfo
);
87 bResult
= (RegKey
.QueryBinaryValue(L
"Settings", (PVOID
) &SettingsInfo
, &dwSize
) == ERROR_SUCCESS
);
95 VOID
SaveSettings(HWND hwnd
)
100 if (SettingsInfo
.bSaveWndPos
)
102 wp
.length
= sizeof(wp
);
103 GetWindowPlacement(hwnd
, &wp
);
105 SettingsInfo
.Left
= wp
.rcNormalPosition
.left
;
106 SettingsInfo
.Top
= wp
.rcNormalPosition
.top
;
107 SettingsInfo
.Width
= wp
.rcNormalPosition
.right
- wp
.rcNormalPosition
.left
;
108 SettingsInfo
.Height
= wp
.rcNormalPosition
.bottom
- wp
.rcNormalPosition
.top
;
109 SettingsInfo
.Maximized
= (wp
.showCmd
== SW_MAXIMIZE
110 || (wp
.showCmd
== SW_SHOWMINIMIZED
111 && (wp
.flags
& WPF_RESTORETOMAXIMIZED
)));
114 if (RegKey
.Create(HKEY_CURRENT_USER
, L
"Software\\ReactOS\\rapps", NULL
,
115 REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, NULL
) == ERROR_SUCCESS
)
117 RegKey
.SetBinaryValue(L
"Settings", (const PVOID
) &SettingsInfo
, sizeof(SettingsInfo
));
122 INT WINAPI
wWinMain(HINSTANCE hInstance
, HINSTANCE hPrevInstance
, LPWSTR lpCmdLine
, INT nShowCmd
)
124 LPCWSTR szWindowClass
= L
"ROSAPPMGR";
128 InitializeAtlModule(hInstance
, TRUE
);
130 if (GetUserDefaultUILanguage() == MAKELANGID(LANG_HEBREW
, SUBLANG_DEFAULT
))
132 SetProcessDefaultLayout(LAYOUT_RTL
);
137 hMutex
= CreateMutexW(NULL
, FALSE
, szWindowClass
);
138 if ((!hMutex
) || (GetLastError() == ERROR_ALREADY_EXISTS
))
140 /* If already started, it is found its window */
141 HWND hWindow
= FindWindowW(szWindowClass
, NULL
);
143 /* Activate window */
144 ShowWindow(hWindow
, SW_SHOWNORMAL
);
145 SetForegroundWindow(hWindow
);
148 bIsFirstLaunch
= !LoadSettings();
151 FillDefaultSettings(&SettingsInfo
);
155 InitCommonControls();
157 // skip window creation if there were some keys
158 if (!UseCmdParameters(GetCommandLineW()))
160 if (SettingsInfo
.bUpdateAtStart
|| bIsFirstLaunch
)
161 CAvailableApps::ForceUpdateAppsDB();
163 ShowMainWindow(nShowCmd
);
169 InitializeAtlModule(hInstance
, FALSE
);