ReactOS  0.4.15-dev-448-gd6c4411
winmain.cpp
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Applications Manager
3  * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4  * FILE: base/applications/rapps/winmain.cpp
5  * PURPOSE: Main program
6  * COPYRIGHT: Copyright 2009 Dmitry Chapyshev (dmitry@reactos.org)
7  * Copyright 2015 Ismael Ferreras Morezuelas (swyterzone+ros@gmail.com)
8  * Copyright 2017 Alexander Shaposhnikov (sanchaez@reactos.org)
9  */
10 #include "rapps.h"
11 
12 #include "unattended.h"
13 
14 #include <atlcom.h>
15 
19 
20 class CRAppsModule : public CComModule
21 {
22 public:
23 };
24 
25 BEGIN_OBJECT_MAP(ObjectMap)
27 
30 
32 {
33  if (bInitialize)
34  {
35  gModule.Init(ObjectMap, hInstance, NULL);
36  }
37  else
38  {
39  gModule.Term();
40  }
41 }
42 
44 {
45  ATL::CStringW szDownloadDir;
46  ZeroMemory(pSettingsInfo, sizeof(SETTINGS_INFO));
47 
48  pSettingsInfo->bSaveWndPos = TRUE;
49  pSettingsInfo->bUpdateAtStart = FALSE;
50  pSettingsInfo->bLogEnabled = TRUE;
51  pSettingsInfo->bUseSource = FALSE;
52 
54  {
55  szDownloadDir.ReleaseBuffer();
56  if (!szDownloadDir.GetEnvironmentVariableW(L"SystemDrive"))
57  {
58  szDownloadDir = L"C:";
59  }
60  }
61  else
62  {
63  szDownloadDir.ReleaseBuffer();
64  }
65 
66  PathAppendW(szDownloadDir.GetBuffer(MAX_PATH), L"\\RAPPS Downloads");
67  szDownloadDir.ReleaseBuffer();
68 
70  _countof(pSettingsInfo->szDownloadDir),
71  szDownloadDir.GetString(),
72  szDownloadDir.GetLength() + 1);
73 
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;
80 }
81 
83 {
84  ATL::CRegKey RegKey;
85  DWORD dwSize;
86  BOOL bResult = FALSE;
87  if (RegKey.Open(HKEY_CURRENT_USER, L"Software\\ReactOS\\rapps", KEY_READ) == ERROR_SUCCESS)
88  {
89  dwSize = sizeof(SettingsInfo);
90  bResult = (RegKey.QueryBinaryValue(L"Settings", (PVOID) &SettingsInfo, &dwSize) == ERROR_SUCCESS);
91 
92  RegKey.Close();
93  }
94 
95  return bResult;
96 }
97 
99 {
100  WINDOWPLACEMENT wp;
101  ATL::CRegKey RegKey;
102 
104  {
105  wp.length = sizeof(wp);
106  GetWindowPlacement(hwnd, &wp);
107 
113  || (wp.showCmd == SW_SHOWMINIMIZED
114  && (wp.flags & WPF_RESTORETOMAXIMIZED)));
115  }
116 
117  if (RegKey.Create(HKEY_CURRENT_USER, L"Software\\ReactOS\\rapps", NULL,
119  {
120  RegKey.SetBinaryValue(L"Settings", (const PVOID) &SettingsInfo, sizeof(SettingsInfo));
121  RegKey.Close();
122  }
123 }
124 
125 INT WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, INT nShowCmd)
126 {
127  LPCWSTR szWindowClass = L"ROSAPPMGR";
128  HANDLE hMutex;
129  BOOL bIsFirstLaunch;
130 
132 
134  {
136  }
137 
138  hInst = hInstance;
139 
141  if ((!hMutex) || (GetLastError() == ERROR_ALREADY_EXISTS))
142  {
143  /* If already started, it is found its window */
144  HWND hWindow = FindWindowW(szWindowClass, NULL);
145 
146  /* Activate window */
147  ShowWindow(hWindow, SW_SHOWNORMAL);
148  SetForegroundWindow(hWindow);
149  return 1;
150  }
151  bIsFirstLaunch = !LoadSettings();
152  if (bIsFirstLaunch)
153  {
155  }
156 
157  InitLogs();
159 
160  // skip window creation if there were some keys
162  {
163  if (SettingsInfo.bUpdateAtStart || bIsFirstLaunch)
165 
166  ShowMainWindow(nShowCmd);
167  }
168 
169  if (hMutex)
171 
173 
174  return 0;
175 }
int GetLength() const
Definition: atlsimpstr.h:356
LONG QueryBinaryValue(LPCTSTR pszValueName, void *pValue, ULONG *pnBytes)
Definition: atlbase.h:1138
BOOL bUpdateAtStart
Definition: winmain.h:9
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
LANGID WINAPI GetUserDefaultUILanguage(void)
Definition: lang.c:806
#define TRUE
Definition: types.h:120
static VOID InitializeAtlModule(HINSTANCE hInstance, BOOL bInitialize)
Definition: winmain.cpp:31
#define CloseHandle
Definition: compat.h:407
VOID ShowMainWindow(INT nShowCmd)
Definition: gui.cpp:1891
#define LAYOUT_RTL
Definition: wingdi.h:1370
#define ERROR_SUCCESS
Definition: deptool.c:10
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define KEY_READ
Definition: nt_native.h:1023
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define SUBLANG_DEFAULT
Definition: nls.h:168
INT Height
Definition: winmain.h:18
CAtlWinModule gWinModule
Definition: winmain.cpp:29
INT WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, INT nShowCmd)
Definition: winmain.cpp:125
LONG top
Definition: windef.h:307
LONG SetBinaryValue(LPCTSTR pszValueName, const void *pValue, ULONG nBytes)
Definition: atlbase.h:1253
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define ZeroMemory
Definition: winbase.h:1648
HINSTANCE hInst
Definition: winmain.cpp:17
#define WPF_RESTORETOMAXIMIZED
Definition: winuser.h:2507
LONG left
Definition: windef.h:306
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define SW_SHOWMINIMIZED
Definition: winuser.h:765
LONG right
Definition: windef.h:308
BOOL Maximized
Definition: winmain.h:14
LONG Close()
Definition: atlbase.h:1053
int32_t INT
Definition: typedefs.h:57
#define LANG_HEBREW
Definition: nls.h:67
void Term()
Definition: atlbase.h:820
BOOL WINAPI PathAppendW(LPWSTR lpszPath, LPCWSTR lpszAppend)
Definition: path.c:121
WCHAR szDownloadDir[MAX_PATH]
Definition: winmain.h:11
HRESULT Init(_ATL_OBJMAP_ENTRY *p, HINSTANCE, const GUID *plibid)
Definition: atlbase.h:797
BOOL bUseSource
Definition: winmain.h:24
const TCHAR szWindowClass[]
Definition: magnifier.c:28
HINSTANCE hInstance
Definition: charmap.c:20
VOID InitLogs()
Definition: misc.cpp:186
void ReleaseBuffer(_In_ int nNewLength=-1)
Definition: atlsimpstr.h:372
unsigned int BOOL
Definition: ntddk_ex.h:94
VOID FillDefaultSettings(PSETTINGS_INFO pSettingsInfo)
Definition: winmain.cpp:43
VOID SaveSettings(HWND hwnd)
Definition: winmain.cpp:98
LPWSTR WINAPI GetCommandLineW(VOID)
Definition: proc.c:2015
#define CW_USEDEFAULT
Definition: winuser.h:225
smooth NULL
Definition: ftsmooth.c:416
HANDLE hMutex
Definition: mutex.c:11
BOOL WINAPI GetWindowPlacement(_In_ HWND, _Inout_ WINDOWPLACEMENT *)
BOOL WINAPI SetProcessDefaultLayout(DWORD dwDefaultLayout)
Definition: window.c:1720
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define KEY_WRITE
Definition: nt_native.h:1031
BOOL UseCmdParameters(LPWSTR lpCmdLine)
Definition: unattended.cpp:16
HWND WINAPI FindWindowW(_In_opt_ LPCWSTR, _In_opt_ LPCWSTR)
#define _countof(array)
Definition: sndvol32.h:68
#define MAX_PATH
Definition: compat.h:26
#define WINAPI
Definition: msvc.h:6
PCXSTR GetString() const
Definition: atlsimpstr.h:361
LONG Open(HKEY hKeyParent, LPCTSTR lpszKeyName, REGSAM samDesired=KEY_READ|KEY_WRITE)
Definition: atlbase.h:1070
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
LONG Create(HKEY hKeyParent, LPCTSTR lpszKeyName, LPTSTR lpszClass=REG_NONE, DWORD dwOptions=REG_OPTION_NON_VOLATILE, REGSAM samDesired=KEY_READ|KEY_WRITE, LPSECURITY_ATTRIBUTES lpSecAttr=NULL, LPDWORD lpdwDisposition=NULL)
Definition: atlbase.h:1091
static BOOL ForceUpdateAppsDB()
Definition: available.cpp:319
#define SW_SHOWNORMAL
Definition: winuser.h:764
BOOL bLogEnabled
Definition: winmain.h:10
static BOOL LoadSettings()
Definition: winmain.cpp:82
HANDLE WINAPI DECLSPEC_HOTPATCH CreateMutexW(IN LPSECURITY_ATTRIBUTES lpMutexAttributes OPTIONAL, IN BOOL bInitialOwner, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:576
static void __cdecl CopyChars(_Out_writes_to_(nDestLen, nChars) XCHAR *pchDest, _In_ size_t nDestLen, _In_reads_opt_(nChars) const XCHAR *pchSrc, _In_ int nChars)
Definition: atlsimpstr.h:423
HWND hMainWnd
Definition: winmain.cpp:16
BOOL bDelInstaller
Definition: winmain.h:12
RECT rcNormalPosition
Definition: winuser.h:3270
#define CSIDL_PERSONAL
Definition: shlobj.h:2017
HRESULT WINAPI SHGetFolderPathW(HWND hwndOwner, int nFolder, HANDLE hToken, DWORD dwFlags, LPWSTR pszPath)
Definition: shellpath.c:2208
BOOL bSaveWndPos
Definition: winmain.h:8
#define MAKELANGID(p, s)
Definition: nls.h:15
BOOL WINAPI SetForegroundWindow(_In_ HWND)
LONG bottom
Definition: windef.h:309
#define BEGIN_OBJECT_MAP(x)
Definition: atlcom.h:649
VOID WINAPI InitCommonControls(void)
Definition: commctrl.c:863
#define ERROR_ALREADY_EXISTS
Definition: disk.h:80
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define SW_MAXIMIZE
Definition: winuser.h:766
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
CRAppsModule gModule
Definition: winmain.cpp:28
#define END_OBJECT_MAP()
Definition: atlcom.h:651
SETTINGS_INFO SettingsInfo
Definition: winmain.cpp:18