2015-04-22 16:53:55 +00:00
|
|
|
/*
|
2017-09-09 20:38:06 +00:00
|
|
|
* 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)
|
2017-09-09 20:44:43 +00:00
|
|
|
* Copyright 2017 Alexander Shaposhnikov (sanchaez@reactos.org)
|
2015-04-22 16:53:55 +00:00
|
|
|
*/
|
|
|
|
#include "rapps.h"
|
2017-09-10 23:44:22 +00:00
|
|
|
|
2017-08-15 19:36:23 +00:00
|
|
|
#include "unattended.h"
|
2015-04-22 16:53:55 +00:00
|
|
|
|
2015-04-23 23:08:21 +00:00
|
|
|
#include <atlcom.h>
|
2015-04-22 16:53:55 +00:00
|
|
|
|
|
|
|
HWND hMainWnd;
|
|
|
|
HINSTANCE hInst;
|
2017-09-03 21:10:24 +00:00
|
|
|
INT SelectedEnumType = ENUM_ALL_INSTALLED;
|
2015-04-22 16:53:55 +00:00
|
|
|
SETTINGS_INFO SettingsInfo;
|
|
|
|
|
2017-07-10 21:02:24 +00:00
|
|
|
ATL::CStringW szSearchPattern;
|
2015-04-22 16:53:55 +00:00
|
|
|
|
2015-04-23 23:08:21 +00:00
|
|
|
class CRAppsModule : public CComModule
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
};
|
|
|
|
|
|
|
|
BEGIN_OBJECT_MAP(ObjectMap)
|
|
|
|
END_OBJECT_MAP()
|
|
|
|
|
2017-07-10 21:02:24 +00:00
|
|
|
CRAppsModule gModule;
|
|
|
|
CAtlWinModule gWinModule;
|
2015-04-23 23:08:21 +00:00
|
|
|
|
|
|
|
static VOID InitializeAtlModule(HINSTANCE hInstance, BOOL bInitialize)
|
|
|
|
{
|
|
|
|
if (bInitialize)
|
|
|
|
{
|
|
|
|
gModule.Init(ObjectMap, hInstance, NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gModule.Term();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-08 21:32:11 +00:00
|
|
|
VOID FillDefaultSettings(PSETTINGS_INFO pSettingsInfo)
|
2015-04-22 16:53:55 +00:00
|
|
|
{
|
2017-07-10 21:02:24 +00:00
|
|
|
ATL::CStringW szDownloadDir;
|
2017-08-15 22:35:45 +00:00
|
|
|
ZeroMemory(pSettingsInfo, sizeof(SETTINGS_INFO));
|
2017-08-08 21:32:11 +00:00
|
|
|
|
2015-04-22 16:53:55 +00:00
|
|
|
pSettingsInfo->bSaveWndPos = TRUE;
|
|
|
|
pSettingsInfo->bUpdateAtStart = FALSE;
|
|
|
|
pSettingsInfo->bLogEnabled = TRUE;
|
2017-07-10 21:02:24 +00:00
|
|
|
|
|
|
|
if (FAILED(SHGetFolderPathW(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, szDownloadDir.GetBuffer(MAX_PATH))))
|
2017-06-29 18:57:52 +00:00
|
|
|
{
|
2017-07-10 21:02:24 +00:00
|
|
|
szDownloadDir.ReleaseBuffer();
|
|
|
|
if (!szDownloadDir.GetEnvironmentVariableW(L"SystemDrive"))
|
|
|
|
{
|
|
|
|
szDownloadDir = L"C:";
|
|
|
|
}
|
2017-06-29 18:57:52 +00:00
|
|
|
}
|
2017-07-10 21:02:24 +00:00
|
|
|
else
|
2017-08-08 21:32:11 +00:00
|
|
|
{
|
2017-07-10 21:02:24 +00:00
|
|
|
szDownloadDir.ReleaseBuffer();
|
2017-08-08 21:32:11 +00:00
|
|
|
}
|
2017-06-29 18:57:52 +00:00
|
|
|
|
2017-07-10 21:02:24 +00:00
|
|
|
szDownloadDir += L"\\RAPPS Downloads";
|
2017-08-14 17:00:20 +00:00
|
|
|
ATL::CStringW::CopyChars(pSettingsInfo->szDownloadDir,
|
2017-07-10 22:26:01 +00:00
|
|
|
_countof(pSettingsInfo->szDownloadDir),
|
|
|
|
szDownloadDir.GetString(),
|
|
|
|
szDownloadDir.GetLength() + 1);
|
2015-04-22 16:53:55 +00:00
|
|
|
|
2017-07-10 21:02:24 +00:00
|
|
|
pSettingsInfo->bDelInstaller = FALSE;
|
2015-04-22 16:53:55 +00:00
|
|
|
pSettingsInfo->Maximized = FALSE;
|
|
|
|
pSettingsInfo->Left = CW_USEDEFAULT;
|
|
|
|
pSettingsInfo->Top = CW_USEDEFAULT;
|
|
|
|
pSettingsInfo->Width = 680;
|
|
|
|
pSettingsInfo->Height = 450;
|
|
|
|
}
|
|
|
|
|
2017-08-08 21:32:11 +00:00
|
|
|
static BOOL LoadSettings()
|
2015-04-22 16:53:55 +00:00
|
|
|
{
|
2017-08-08 21:32:11 +00:00
|
|
|
ATL::CRegKey RegKey;
|
2015-04-22 16:53:55 +00:00
|
|
|
DWORD dwSize;
|
2017-08-08 21:32:11 +00:00
|
|
|
BOOL bResult = FALSE;
|
|
|
|
if (RegKey.Open(HKEY_CURRENT_USER, L"Software\\ReactOS\\rapps", KEY_READ) == ERROR_SUCCESS)
|
2015-04-22 16:53:55 +00:00
|
|
|
{
|
2016-10-06 12:22:32 +00:00
|
|
|
dwSize = sizeof(SettingsInfo);
|
2017-08-08 21:32:11 +00:00
|
|
|
bResult = (RegKey.QueryBinaryValue(L"Settings", (PVOID) &SettingsInfo, &dwSize) == ERROR_SUCCESS);
|
2015-04-22 16:53:55 +00:00
|
|
|
|
2017-08-08 21:32:11 +00:00
|
|
|
RegKey.Close();
|
2015-04-22 16:53:55 +00:00
|
|
|
}
|
|
|
|
|
2017-08-08 21:32:11 +00:00
|
|
|
return bResult;
|
2015-04-22 16:53:55 +00:00
|
|
|
}
|
|
|
|
|
2017-08-08 21:32:11 +00:00
|
|
|
VOID SaveSettings(HWND hwnd)
|
2015-04-22 16:53:55 +00:00
|
|
|
{
|
|
|
|
WINDOWPLACEMENT wp;
|
2017-08-08 21:32:11 +00:00
|
|
|
ATL::CRegKey RegKey;
|
2015-04-22 16:53:55 +00:00
|
|
|
|
|
|
|
if (SettingsInfo.bSaveWndPos)
|
|
|
|
{
|
2016-10-06 12:22:32 +00:00
|
|
|
wp.length = sizeof(wp);
|
2015-04-22 16:53:55 +00:00
|
|
|
GetWindowPlacement(hwnd, &wp);
|
|
|
|
|
|
|
|
SettingsInfo.Left = wp.rcNormalPosition.left;
|
2017-07-10 21:02:24 +00:00
|
|
|
SettingsInfo.Top = wp.rcNormalPosition.top;
|
|
|
|
SettingsInfo.Width = wp.rcNormalPosition.right - wp.rcNormalPosition.left;
|
2015-04-22 16:53:55 +00:00
|
|
|
SettingsInfo.Height = wp.rcNormalPosition.bottom - wp.rcNormalPosition.top;
|
2017-08-14 17:00:20 +00:00
|
|
|
SettingsInfo.Maximized = (wp.showCmd == SW_MAXIMIZE
|
|
|
|
|| (wp.showCmd == SW_SHOWMINIMIZED
|
2017-08-08 21:32:11 +00:00
|
|
|
&& (wp.flags & WPF_RESTORETOMAXIMIZED)));
|
2015-04-22 16:53:55 +00:00
|
|
|
}
|
|
|
|
|
2017-08-08 21:32:11 +00:00
|
|
|
if (RegKey.Create(HKEY_CURRENT_USER, L"Software\\ReactOS\\rapps", NULL,
|
2017-08-14 17:00:20 +00:00
|
|
|
REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, NULL) == ERROR_SUCCESS)
|
2015-04-22 16:53:55 +00:00
|
|
|
{
|
2017-08-08 21:32:11 +00:00
|
|
|
RegKey.SetBinaryValue(L"Settings", (const PVOID) &SettingsInfo, sizeof(SettingsInfo));
|
|
|
|
RegKey.Close();
|
2015-04-22 16:53:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-15 22:35:45 +00:00
|
|
|
INT WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, INT nShowCmd)
|
2017-08-08 21:32:11 +00:00
|
|
|
{
|
|
|
|
LPCWSTR szWindowClass = L"ROSAPPMGR";
|
2017-08-15 19:36:23 +00:00
|
|
|
HANDLE hMutex;
|
|
|
|
HACCEL KeyBrd;
|
2015-04-22 16:53:55 +00:00
|
|
|
MSG Msg;
|
2017-08-26 08:39:42 +00:00
|
|
|
BOOL bIsFirstLaunch;
|
2015-04-22 16:53:55 +00:00
|
|
|
|
2015-04-23 23:08:21 +00:00
|
|
|
InitializeAtlModule(hInstance, TRUE);
|
|
|
|
|
2017-08-08 21:32:11 +00:00
|
|
|
if (GetUserDefaultUILanguage() == MAKELANGID(LANG_HEBREW, SUBLANG_DEFAULT))
|
2015-04-22 16:53:55 +00:00
|
|
|
{
|
2017-07-10 21:02:24 +00:00
|
|
|
SetProcessDefaultLayout(LAYOUT_RTL);
|
2015-04-22 16:53:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
hInst = hInstance;
|
|
|
|
|
|
|
|
hMutex = CreateMutexW(NULL, FALSE, szWindowClass);
|
|
|
|
if ((!hMutex) || (GetLastError() == ERROR_ALREADY_EXISTS))
|
|
|
|
{
|
|
|
|
/* If already started, it is found its window */
|
|
|
|
HWND hWindow = FindWindowW(szWindowClass, NULL);
|
|
|
|
|
|
|
|
/* Activate window */
|
|
|
|
ShowWindow(hWindow, SW_SHOWNORMAL);
|
|
|
|
SetForegroundWindow(hWindow);
|
|
|
|
return 1;
|
|
|
|
}
|
2017-08-26 08:39:42 +00:00
|
|
|
bIsFirstLaunch = !LoadSettings();
|
|
|
|
if (bIsFirstLaunch)
|
2015-04-22 16:53:55 +00:00
|
|
|
{
|
|
|
|
FillDefaultSettings(&SettingsInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
InitLogs();
|
|
|
|
InitCommonControls();
|
|
|
|
|
2017-08-24 22:04:44 +00:00
|
|
|
// skip window creation if there were some keys
|
2017-09-09 19:41:08 +00:00
|
|
|
if (!UseCmdParameters(lpCmdLine))
|
2017-08-08 21:32:11 +00:00
|
|
|
{
|
2017-08-26 08:39:42 +00:00
|
|
|
if (SettingsInfo.bUpdateAtStart || bIsFirstLaunch)
|
2017-08-24 22:04:44 +00:00
|
|
|
CAvailableApps::ForceUpdateAppsDB();
|
|
|
|
|
2017-08-14 17:00:20 +00:00
|
|
|
hMainWnd = CreateMainWindow();
|
2017-08-24 22:04:44 +00:00
|
|
|
|
2017-08-14 17:00:20 +00:00
|
|
|
if (hMainWnd)
|
|
|
|
{
|
|
|
|
/* Maximize it if we must */
|
2017-08-24 22:04:44 +00:00
|
|
|
ShowWindow(hMainWnd, ((SettingsInfo.bSaveWndPos && SettingsInfo.Maximized) ? SW_MAXIMIZE : nShowCmd));
|
2017-08-14 17:00:20 +00:00
|
|
|
UpdateWindow(hMainWnd);
|
2015-04-22 16:53:55 +00:00
|
|
|
|
2017-08-14 17:00:20 +00:00
|
|
|
/* Load the menu hotkeys */
|
|
|
|
KeyBrd = LoadAcceleratorsW(NULL, MAKEINTRESOURCEW(HOTKEYS));
|
2015-04-22 16:53:55 +00:00
|
|
|
|
2017-08-14 17:00:20 +00:00
|
|
|
/* Message Loop */
|
|
|
|
while (GetMessageW(&Msg, NULL, 0, 0))
|
2017-08-08 21:32:11 +00:00
|
|
|
{
|
2017-08-14 17:00:20 +00:00
|
|
|
if (!TranslateAcceleratorW(hMainWnd, KeyBrd, &Msg))
|
|
|
|
{
|
|
|
|
TranslateMessage(&Msg);
|
|
|
|
DispatchMessageW(&Msg);
|
|
|
|
}
|
2017-08-08 21:32:11 +00:00
|
|
|
}
|
2015-04-22 16:53:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hMutex)
|
|
|
|
CloseHandle(hMutex);
|
|
|
|
|
2015-04-23 23:08:21 +00:00
|
|
|
InitializeAtlModule(hInstance, FALSE);
|
|
|
|
|
2015-04-22 16:53:55 +00:00
|
|
|
return 0;
|
|
|
|
}
|