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)
20 INT SelectedEnumType
= ENUM_ALL_COMPONENTS
;
21 SETTINGS_INFO SettingsInfo
;
23 ATL::CStringW szSearchPattern
;
25 class CRAppsModule
: public CComModule
30 BEGIN_OBJECT_MAP(ObjectMap
)
34 CAtlWinModule gWinModule
;
36 //void *operator new (size_t, void *buf)
41 static VOID
InitializeAtlModule(HINSTANCE hInstance
, BOOL bInitialize
)
45 gModule
.Init(ObjectMap
, hInstance
, NULL
);
53 VOID
FillDefaultSettings(PSETTINGS_INFO pSettingsInfo
)
55 ATL::CStringW szDownloadDir
;
57 pSettingsInfo
->bSaveWndPos
= TRUE
;
58 pSettingsInfo
->bUpdateAtStart
= FALSE
;
59 pSettingsInfo
->bLogEnabled
= TRUE
;
61 if (FAILED(SHGetFolderPathW(NULL
, CSIDL_PERSONAL
, NULL
, SHGFP_TYPE_CURRENT
, szDownloadDir
.GetBuffer(MAX_PATH
))))
63 szDownloadDir
.ReleaseBuffer();
64 if (!szDownloadDir
.GetEnvironmentVariableW(L
"SystemDrive"))
66 szDownloadDir
= L
"C:";
71 szDownloadDir
.ReleaseBuffer();
74 szDownloadDir
+= L
"\\RAPPS Downloads";
75 ATL::CStringW::CopyChars(pSettingsInfo
->szDownloadDir
,
76 _countof(pSettingsInfo
->szDownloadDir
),
77 szDownloadDir
.GetString(),
78 szDownloadDir
.GetLength() + 1);
80 pSettingsInfo
->bDelInstaller
= FALSE
;
81 pSettingsInfo
->Maximized
= FALSE
;
82 pSettingsInfo
->Left
= CW_USEDEFAULT
;
83 pSettingsInfo
->Top
= CW_USEDEFAULT
;
84 pSettingsInfo
->Width
= 680;
85 pSettingsInfo
->Height
= 450;
86 pSettingsInfo
->Proxy
= 0;
88 pSettingsInfo
->szProxyServer
[0] = UNICODE_NULL
;
89 pSettingsInfo
->szNoProxyFor
[0] = UNICODE_NULL
;
92 static BOOL
LoadSettings()
97 if (RegKey
.Open(HKEY_CURRENT_USER
, L
"Software\\ReactOS\\rapps", KEY_READ
) == ERROR_SUCCESS
)
99 dwSize
= sizeof(SettingsInfo
);
100 bResult
= (RegKey
.QueryBinaryValue(L
"Settings", (PVOID
) &SettingsInfo
, &dwSize
) == ERROR_SUCCESS
);
108 VOID
SaveSettings(HWND hwnd
)
113 if (SettingsInfo
.bSaveWndPos
)
115 wp
.length
= sizeof(wp
);
116 GetWindowPlacement(hwnd
, &wp
);
118 SettingsInfo
.Left
= wp
.rcNormalPosition
.left
;
119 SettingsInfo
.Top
= wp
.rcNormalPosition
.top
;
120 SettingsInfo
.Width
= wp
.rcNormalPosition
.right
- wp
.rcNormalPosition
.left
;
121 SettingsInfo
.Height
= wp
.rcNormalPosition
.bottom
- wp
.rcNormalPosition
.top
;
122 SettingsInfo
.Maximized
= (wp
.showCmd
== SW_MAXIMIZE
123 || (wp
.showCmd
== SW_SHOWMINIMIZED
124 && (wp
.flags
& WPF_RESTORETOMAXIMIZED
)));
127 if (RegKey
.Create(HKEY_CURRENT_USER
, L
"Software\\ReactOS\\rapps", NULL
,
128 REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, NULL
) == ERROR_SUCCESS
)
130 RegKey
.SetBinaryValue(L
"Settings", (const PVOID
) &SettingsInfo
, sizeof(SettingsInfo
));
136 #define CMD_KEY_SETUP L"/SETUP"
138 // return TRUE if the SETUP key was valid
139 BOOL
CmdParser(LPWSTR lpCmdLine
)
142 LPWSTR
* argv
= CommandLineToArgvW(lpCmdLine
, &argc
);
144 PAPPLICATION_INFO appInfo
;
147 if (!argv
|| argc
< 2 || StrCmpW(argv
[0], CMD_KEY_SETUP
))
152 apps
.EnumAvailableApplications(ENUM_ALL_AVAILABLE
, NULL
);
153 appInfo
= apps
.FindInfo(argv
[1]);
156 CDownloadManager::DownloadApplication(appInfo
, TRUE
);
163 INT WINAPI
wWinMain(HINSTANCE hInstance
, HINSTANCE hPrevInstance
, LPWSTR lpCmdLine
, int nShowCmd
)
165 LPCWSTR szWindowClass
= L
"ROSAPPMGR";
166 HANDLE hMutex
= NULL
;
167 HACCEL KeyBrd
= NULL
;
170 InitializeAtlModule(hInstance
, TRUE
);
172 if (GetUserDefaultUILanguage() == MAKELANGID(LANG_HEBREW
, SUBLANG_DEFAULT
))
174 SetProcessDefaultLayout(LAYOUT_RTL
);
179 hMutex
= CreateMutexW(NULL
, FALSE
, szWindowClass
);
180 if ((!hMutex
) || (GetLastError() == ERROR_ALREADY_EXISTS
))
182 /* If already started, it is found its window */
183 HWND hWindow
= FindWindowW(szWindowClass
, NULL
);
185 /* Activate window */
186 ShowWindow(hWindow
, SW_SHOWNORMAL
);
187 SetForegroundWindow(hWindow
);
193 FillDefaultSettings(&SettingsInfo
);
198 InitCommonControls();
200 //skip window creation if there were some keys
201 if (!CmdParser(lpCmdLine
))
203 hMainWnd
= CreateMainWindow();
206 /* Maximize it if we must */
207 ShowWindow(hMainWnd
, (SettingsInfo
.bSaveWndPos
&& SettingsInfo
.Maximized
? SW_MAXIMIZE
: nShowCmd
));
208 UpdateWindow(hMainWnd
);
210 //TODO: get around the ugliness
211 if (SettingsInfo
.bUpdateAtStart
)
212 GetAvailableApps()->UpdateAppsDB();
214 /* Load the menu hotkeys */
215 KeyBrd
= LoadAcceleratorsW(NULL
, MAKEINTRESOURCEW(HOTKEYS
));
218 while (GetMessageW(&Msg
, NULL
, 0, 0))
220 if (!TranslateAcceleratorW(hMainWnd
, KeyBrd
, &Msg
))
222 TranslateMessage(&Msg
);
223 DispatchMessageW(&Msg
);
232 InitializeAtlModule(hInstance
, FALSE
);