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_COMPONENTS
;
19 SETTINGS_INFO SettingsInfo
;
21 ATL::CStringW szSearchPattern
;
23 class CRAppsModule
: public CComModule
28 BEGIN_OBJECT_MAP(ObjectMap
)
32 CAtlWinModule gWinModule
;
34 //void *operator new (size_t, void *buf)
39 static VOID
InitializeAtlModule(HINSTANCE hInstance
, BOOL bInitialize
)
43 gModule
.Init(ObjectMap
, hInstance
, NULL
);
51 VOID
FillDefaultSettings(PSETTINGS_INFO pSettingsInfo
)
53 ATL::CStringW szDownloadDir
;
55 pSettingsInfo
->bSaveWndPos
= TRUE
;
56 pSettingsInfo
->bUpdateAtStart
= FALSE
;
57 pSettingsInfo
->bLogEnabled
= TRUE
;
59 if (FAILED(SHGetFolderPathW(NULL
, CSIDL_PERSONAL
, NULL
, SHGFP_TYPE_CURRENT
, szDownloadDir
.GetBuffer(MAX_PATH
))))
61 szDownloadDir
.ReleaseBuffer();
62 if (!szDownloadDir
.GetEnvironmentVariableW(L
"SystemDrive"))
64 szDownloadDir
= L
"C:";
69 szDownloadDir
.ReleaseBuffer();
72 szDownloadDir
+= L
"\\RAPPS Downloads";
73 ATL::CStringW::CopyChars(pSettingsInfo
->szDownloadDir
,
74 _countof(pSettingsInfo
->szDownloadDir
),
75 szDownloadDir
.GetString(),
76 szDownloadDir
.GetLength() + 1);
78 pSettingsInfo
->bDelInstaller
= FALSE
;
79 pSettingsInfo
->Maximized
= FALSE
;
80 pSettingsInfo
->Left
= CW_USEDEFAULT
;
81 pSettingsInfo
->Top
= CW_USEDEFAULT
;
82 pSettingsInfo
->Width
= 680;
83 pSettingsInfo
->Height
= 450;
84 pSettingsInfo
->Proxy
= 0;
86 pSettingsInfo
->szProxyServer
[0] = UNICODE_NULL
;
87 pSettingsInfo
->szNoProxyFor
[0] = UNICODE_NULL
;
90 static BOOL
LoadSettings()
95 if (RegKey
.Open(HKEY_CURRENT_USER
, L
"Software\\ReactOS\\rapps", KEY_READ
) == ERROR_SUCCESS
)
97 dwSize
= sizeof(SettingsInfo
);
98 bResult
= (RegKey
.QueryBinaryValue(L
"Settings", (PVOID
) &SettingsInfo
, &dwSize
) == ERROR_SUCCESS
);
106 VOID
SaveSettings(HWND hwnd
)
111 if (SettingsInfo
.bSaveWndPos
)
113 wp
.length
= sizeof(wp
);
114 GetWindowPlacement(hwnd
, &wp
);
116 SettingsInfo
.Left
= wp
.rcNormalPosition
.left
;
117 SettingsInfo
.Top
= wp
.rcNormalPosition
.top
;
118 SettingsInfo
.Width
= wp
.rcNormalPosition
.right
- wp
.rcNormalPosition
.left
;
119 SettingsInfo
.Height
= wp
.rcNormalPosition
.bottom
- wp
.rcNormalPosition
.top
;
120 SettingsInfo
.Maximized
= (wp
.showCmd
== SW_MAXIMIZE
121 || (wp
.showCmd
== SW_SHOWMINIMIZED
122 && (wp
.flags
& WPF_RESTORETOMAXIMIZED
)));
125 if (RegKey
.Create(HKEY_CURRENT_USER
, L
"Software\\ReactOS\\rapps", NULL
,
126 REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, NULL
) == ERROR_SUCCESS
)
128 RegKey
.SetBinaryValue(L
"Settings", (const PVOID
) &SettingsInfo
, sizeof(SettingsInfo
));
133 INT WINAPI
wWinMain(HINSTANCE hInstance
, HINSTANCE hPrevInstance
, LPWSTR lpCmdLine
, int nShowCmd
)
135 LPCWSTR szWindowClass
= L
"ROSAPPMGR";
140 InitializeAtlModule(hInstance
, TRUE
);
142 if (GetUserDefaultUILanguage() == MAKELANGID(LANG_HEBREW
, SUBLANG_DEFAULT
))
144 SetProcessDefaultLayout(LAYOUT_RTL
);
149 hMutex
= CreateMutexW(NULL
, FALSE
, szWindowClass
);
150 if ((!hMutex
) || (GetLastError() == ERROR_ALREADY_EXISTS
))
152 /* If already started, it is found its window */
153 HWND hWindow
= FindWindowW(szWindowClass
, NULL
);
155 /* Activate window */
156 ShowWindow(hWindow
, SW_SHOWNORMAL
);
157 SetForegroundWindow(hWindow
);
163 FillDefaultSettings(&SettingsInfo
);
168 InitCommonControls();
170 //skip window creation if there were some keys
171 if (!CmdParser(lpCmdLine
))
173 hMainWnd
= CreateMainWindow();
176 /* Maximize it if we must */
177 ShowWindow(hMainWnd
, (SettingsInfo
.bSaveWndPos
&& SettingsInfo
.Maximized
? SW_MAXIMIZE
: nShowCmd
));
178 UpdateWindow(hMainWnd
);
180 //TODO: get around the ugliness
181 if (SettingsInfo
.bUpdateAtStart
)
182 GetAvailableApps()->UpdateAppsDB();
184 /* Load the menu hotkeys */
185 KeyBrd
= LoadAcceleratorsW(NULL
, MAKEINTRESOURCEW(HOTKEYS
));
188 while (GetMessageW(&Msg
, NULL
, 0, 0))
190 if (!TranslateAcceleratorW(hMainWnd
, KeyBrd
, &Msg
))
192 TranslateMessage(&Msg
);
193 DispatchMessageW(&Msg
);
202 InitializeAtlModule(hInstance
, FALSE
);