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
);
54 FillDefaultSettings(PSETTINGS_INFO pSettingsInfo
)
56 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:";
70 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
;
96 if (RegOpenKeyExW(HKEY_CURRENT_USER
, L
"Software\\ReactOS\\rapps", 0, KEY_READ
, &hKey
) == ERROR_SUCCESS
)
98 dwSize
= sizeof(SettingsInfo
);
99 if (RegQueryValueExW(hKey
, L
"Settings", NULL
, NULL
, (LPBYTE
) &SettingsInfo
, &dwSize
) == ERROR_SUCCESS
)
112 SaveSettings(HWND hwnd
)
117 if (SettingsInfo
.bSaveWndPos
)
119 wp
.length
= sizeof(wp
);
120 GetWindowPlacement(hwnd
, &wp
);
122 SettingsInfo
.Left
= wp
.rcNormalPosition
.left
;
123 SettingsInfo
.Top
= wp
.rcNormalPosition
.top
;
124 SettingsInfo
.Width
= wp
.rcNormalPosition
.right
- wp
.rcNormalPosition
.left
;
125 SettingsInfo
.Height
= wp
.rcNormalPosition
.bottom
- wp
.rcNormalPosition
.top
;
126 SettingsInfo
.Maximized
= (wp
.showCmd
== SW_MAXIMIZE
|| (wp
.showCmd
== SW_SHOWMINIMIZED
&& (wp
.flags
& WPF_RESTORETOMAXIMIZED
)));
129 if (RegCreateKeyExW(HKEY_CURRENT_USER
, L
"Software\\ReactOS\\rapps", 0, NULL
,
130 REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
) == ERROR_SUCCESS
)
132 RegSetValueExW(hKey
, L
"Settings", 0, REG_BINARY
, (LPBYTE
) &SettingsInfo
, sizeof(SettingsInfo
));
138 wWinMain(HINSTANCE hInstance
, HINSTANCE hPrevInstance
, LPWSTR lpCmdLine
, int nShowCmd
)
140 WCHAR szWindowClass
[] = L
"ROSAPPMGR";
141 HANDLE hMutex
= NULL
;
145 InitializeAtlModule(hInstance
, TRUE
);
147 switch (GetUserDefaultUILanguage())
149 case MAKELANGID(LANG_HEBREW
, SUBLANG_DEFAULT
):
150 SetProcessDefaultLayout(LAYOUT_RTL
);
159 hMutex
= CreateMutexW(NULL
, FALSE
, szWindowClass
);
160 if ((!hMutex
) || (GetLastError() == ERROR_ALREADY_EXISTS
))
162 /* If already started, it is found its window */
163 HWND hWindow
= FindWindowW(szWindowClass
, NULL
);
165 /* Activate window */
166 ShowWindow(hWindow
, SW_SHOWNORMAL
);
167 SetForegroundWindow(hWindow
);
173 FillDefaultSettings(&SettingsInfo
);
178 InitCommonControls();
180 hMainWnd
= CreateMainWindow();
181 if (!hMainWnd
) goto Exit
;
183 /* Maximize it if we must */
184 ShowWindow(hMainWnd
, (SettingsInfo
.bSaveWndPos
&& SettingsInfo
.Maximized
? SW_MAXIMIZE
: nShowCmd
));
185 UpdateWindow(hMainWnd
);
187 //TODO: get around the ugliness
188 if (SettingsInfo
.bUpdateAtStart
)
189 GetAvailableApps()->UpdateAppsDB();
191 /* Load the menu hotkeys */
192 KeyBrd
= LoadAcceleratorsW(NULL
, MAKEINTRESOURCEW(HOTKEYS
));
195 while (GetMessageW(&Msg
, NULL
, 0, 0))
197 if (!TranslateAcceleratorW(hMainWnd
, KeyBrd
, &Msg
))
199 TranslateMessage(&Msg
);
200 DispatchMessageW(&Msg
);
208 InitializeAtlModule(hInstance
, FALSE
);