2 * PROJECT: ReactOS Applications Manager
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/rapps/winmain.cpp
5 * PURPOSE: Main program
6 * PROGRAMMERS: Dmitry Chapyshev (dmitry@reactos.org)
7 * Ismael Ferreras Morezuelas (swyterzone+ros@gmail.com)
8 * Alexander Shaposhnikov (chaez.san@gmail.com)
12 #include "unattended.h"
18 INT SelectedEnumType
= ENUM_ALL_INSTALLED
;
19 SETTINGS_INFO SettingsInfo
;
21 ATL::CStringW szSearchPattern
;
23 class CRAppsModule
: public CComModule
28 BEGIN_OBJECT_MAP(ObjectMap
)
32 CAtlWinModule gWinModule
;
34 static VOID
InitializeAtlModule(HINSTANCE hInstance
, BOOL bInitialize
)
38 gModule
.Init(ObjectMap
, hInstance
, NULL
);
46 VOID
FillDefaultSettings(PSETTINGS_INFO pSettingsInfo
)
48 ATL::CStringW szDownloadDir
;
49 ZeroMemory(pSettingsInfo
, sizeof(SETTINGS_INFO
));
51 pSettingsInfo
->bSaveWndPos
= TRUE
;
52 pSettingsInfo
->bUpdateAtStart
= FALSE
;
53 pSettingsInfo
->bLogEnabled
= TRUE
;
55 if (FAILED(SHGetFolderPathW(NULL
, CSIDL_PERSONAL
, NULL
, SHGFP_TYPE_CURRENT
, szDownloadDir
.GetBuffer(MAX_PATH
))))
57 szDownloadDir
.ReleaseBuffer();
58 if (!szDownloadDir
.GetEnvironmentVariableW(L
"SystemDrive"))
60 szDownloadDir
= L
"C:";
65 szDownloadDir
.ReleaseBuffer();
68 szDownloadDir
+= L
"\\RAPPS Downloads";
69 ATL::CStringW::CopyChars(pSettingsInfo
->szDownloadDir
,
70 _countof(pSettingsInfo
->szDownloadDir
),
71 szDownloadDir
.GetString(),
72 szDownloadDir
.GetLength() + 1);
74 pSettingsInfo
->bDelInstaller
= FALSE
;
75 pSettingsInfo
->Maximized
= FALSE
;
76 pSettingsInfo
->Left
= CW_USEDEFAULT
;
77 pSettingsInfo
->Top
= CW_USEDEFAULT
;
78 pSettingsInfo
->Width
= 680;
79 pSettingsInfo
->Height
= 450;
82 static BOOL
LoadSettings()
87 if (RegKey
.Open(HKEY_CURRENT_USER
, L
"Software\\ReactOS\\rapps", KEY_READ
) == ERROR_SUCCESS
)
89 dwSize
= sizeof(SettingsInfo
);
90 bResult
= (RegKey
.QueryBinaryValue(L
"Settings", (PVOID
) &SettingsInfo
, &dwSize
) == ERROR_SUCCESS
);
98 VOID
SaveSettings(HWND hwnd
)
103 if (SettingsInfo
.bSaveWndPos
)
105 wp
.length
= sizeof(wp
);
106 GetWindowPlacement(hwnd
, &wp
);
108 SettingsInfo
.Left
= wp
.rcNormalPosition
.left
;
109 SettingsInfo
.Top
= wp
.rcNormalPosition
.top
;
110 SettingsInfo
.Width
= wp
.rcNormalPosition
.right
- wp
.rcNormalPosition
.left
;
111 SettingsInfo
.Height
= wp
.rcNormalPosition
.bottom
- wp
.rcNormalPosition
.top
;
112 SettingsInfo
.Maximized
= (wp
.showCmd
== SW_MAXIMIZE
113 || (wp
.showCmd
== SW_SHOWMINIMIZED
114 && (wp
.flags
& WPF_RESTORETOMAXIMIZED
)));
117 if (RegKey
.Create(HKEY_CURRENT_USER
, L
"Software\\ReactOS\\rapps", NULL
,
118 REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, NULL
) == ERROR_SUCCESS
)
120 RegKey
.SetBinaryValue(L
"Settings", (const PVOID
) &SettingsInfo
, sizeof(SettingsInfo
));
125 INT WINAPI
wWinMain(HINSTANCE hInstance
, HINSTANCE hPrevInstance
, LPWSTR lpCmdLine
, INT nShowCmd
)
127 LPCWSTR szWindowClass
= L
"ROSAPPMGR";
133 InitializeAtlModule(hInstance
, TRUE
);
135 if (GetUserDefaultUILanguage() == MAKELANGID(LANG_HEBREW
, SUBLANG_DEFAULT
))
137 SetProcessDefaultLayout(LAYOUT_RTL
);
142 hMutex
= CreateMutexW(NULL
, FALSE
, szWindowClass
);
143 if ((!hMutex
) || (GetLastError() == ERROR_ALREADY_EXISTS
))
145 /* If already started, it is found its window */
146 HWND hWindow
= FindWindowW(szWindowClass
, NULL
);
148 /* Activate window */
149 ShowWindow(hWindow
, SW_SHOWNORMAL
);
150 SetForegroundWindow(hWindow
);
153 bIsFirstLaunch
= !LoadSettings();
156 FillDefaultSettings(&SettingsInfo
);
160 InitCommonControls();
162 // skip window creation if there were some keys
163 if (!CmdParser(lpCmdLine
))
165 if (SettingsInfo
.bUpdateAtStart
|| bIsFirstLaunch
)
166 CAvailableApps::ForceUpdateAppsDB();
168 hMainWnd
= CreateMainWindow();
172 /* Maximize it if we must */
173 ShowWindow(hMainWnd
, ((SettingsInfo
.bSaveWndPos
&& SettingsInfo
.Maximized
) ? SW_MAXIMIZE
: nShowCmd
));
174 UpdateWindow(hMainWnd
);
176 /* Load the menu hotkeys */
177 KeyBrd
= LoadAcceleratorsW(NULL
, MAKEINTRESOURCEW(HOTKEYS
));
180 while (GetMessageW(&Msg
, NULL
, 0, 0))
182 if (!TranslateAcceleratorW(hMainWnd
, KeyBrd
, &Msg
))
184 TranslateMessage(&Msg
);
185 DispatchMessageW(&Msg
);
194 InitializeAtlModule(hInstance
, FALSE
);