2 * PROJECT: ReactOS Applications Manager
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/rapps/misc.c
5 * PURPOSE: Misc functions
6 * PROGRAMMERS: Dmitry Chapyshev (dmitry@reactos.org)
11 /* SESSION Operation */
12 #define EXTRACT_FILLFILELIST 0x00000001
13 #define EXTRACT_EXTRACTFILES 0x00000002
15 static HANDLE hLog
= NULL
;
27 struct FILELIST
*next
;
35 struct FILELIST
*FileList
;
38 CHAR Destination
[MAX_PATH
];
39 CHAR CurrentFile
[MAX_PATH
];
40 CHAR Reserved
[MAX_PATH
];
41 struct FILELIST
*FilterList
;
44 HRESULT (WINAPI
*pfnExtract
)(SESSION
*dest
, LPCSTR szCabName
);
48 GetSystemColorDepth(VOID
)
53 pDevMode
.dmSize
= sizeof(DEVMODE
);
54 pDevMode
.dmDriverExtra
= 0;
56 if (!EnumDisplaySettings(NULL
, ENUM_CURRENT_SETTINGS
, &pDevMode
))
58 /* TODO: Error message */
62 switch (pDevMode
.dmBitsPerPel
)
64 case 32: ColorDepth
= ILC_COLOR32
; break;
65 case 24: ColorDepth
= ILC_COLOR24
; break;
66 case 16: ColorDepth
= ILC_COLOR16
; break;
67 case 8: ColorDepth
= ILC_COLOR8
; break;
68 case 4: ColorDepth
= ILC_COLOR4
; break;
69 default: ColorDepth
= ILC_COLOR
; break;
76 GetWindowWidth(HWND hwnd
)
80 GetWindowRect(hwnd
, &Rect
);
81 return (Rect
.right
- Rect
.left
);
85 GetWindowHeight(HWND hwnd
)
89 GetWindowRect(hwnd
, &Rect
);
90 return (Rect
.bottom
- Rect
.top
);
94 GetClientWindowWidth(HWND hwnd
)
98 GetClientRect(hwnd
, &Rect
);
99 return (Rect
.right
- Rect
.left
);
103 GetClientWindowHeight(HWND hwnd
)
107 GetClientRect(hwnd
, &Rect
);
108 return (Rect
.bottom
- Rect
.top
);
112 CopyTextToClipboard(LPCWSTR lpszText
)
116 if (OpenClipboard(NULL
))
123 cchBuffer
= wcslen(lpszText
) + 1;
124 ClipBuffer
= GlobalAlloc(GMEM_DDESHARE
, cchBuffer
* sizeof(WCHAR
));
125 Buffer
= GlobalLock(ClipBuffer
);
126 hr
= StringCchCopyW(Buffer
, cchBuffer
, lpszText
);
127 GlobalUnlock(ClipBuffer
);
130 SetClipboardData(CF_UNICODETEXT
, ClipBuffer
);
139 WCHAR szText
[MAX_STR_LEN
*3];
141 LoadStringW(hInst
, IDS_WELCOME_TITLE
, szText
, sizeof(szText
) / sizeof(WCHAR
));
142 NewRichEditText(szText
, CFE_BOLD
);
144 LoadStringW(hInst
, IDS_WELCOME_TEXT
, szText
, sizeof(szText
) / sizeof(WCHAR
));
145 InsertRichEditText(szText
, 0);
147 LoadStringW(hInst
, IDS_WELCOME_URL
, szText
, sizeof(szText
) / sizeof(WCHAR
));
148 InsertRichEditText(szText
, CFM_LINK
);
152 ShowPopupMenu(HWND hwnd
, UINT MenuID
, UINT DefaultItem
)
161 hMenu
= LoadMenuW(hInst
, MAKEINTRESOURCEW(MenuID
));
162 hPopupMenu
= GetSubMenu(hMenu
, 0);
165 hPopupMenu
= GetMenu(hwnd
);
167 ZeroMemory(&mii
, sizeof(mii
));
168 mii
.cbSize
= sizeof(mii
);
169 mii
.fMask
= MIIM_STATE
;
170 GetMenuItemInfo(hPopupMenu
, DefaultItem
, FALSE
, &mii
);
171 if (!(mii
.fState
& MFS_GRAYED
))
172 SetMenuDefaultItem(hPopupMenu
, DefaultItem
, FALSE
);
176 SetForegroundWindow(hwnd
);
177 TrackPopupMenu(hPopupMenu
, 0, pt
.x
, pt
.y
, 0, hMainWnd
, NULL
);
184 StartProcess(LPWSTR lpPath
, BOOL Wait
)
186 PROCESS_INFORMATION pi
;
191 ZeroMemory(&si
, sizeof(si
));
193 si
.dwFlags
= STARTF_USESHOWWINDOW
;
194 si
.wShowWindow
= SW_SHOW
;
196 if (!CreateProcessW(NULL
, lpPath
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
))
201 CloseHandle(pi
.hThread
);
202 if (Wait
) EnableWindow(hMainWnd
, FALSE
);
206 dwRet
= MsgWaitForMultipleObjects(1, &pi
.hProcess
, FALSE
, INFINITE
, QS_ALLEVENTS
);
207 if (dwRet
== WAIT_OBJECT_0
+ 1)
209 while (PeekMessageW(&msg
, NULL
, 0, 0, PM_REMOVE
))
211 TranslateMessage(&msg
);
212 DispatchMessage(&msg
);
217 if (dwRet
== WAIT_OBJECT_0
|| dwRet
== WAIT_FAILED
)
222 CloseHandle(pi
.hProcess
);
226 EnableWindow(hMainWnd
, TRUE
);
227 SetForegroundWindow(hMainWnd
);
235 GetStorageDirectory(PWCHAR lpDirectory
, DWORD cch
)
240 if (!SHGetSpecialFolderPathW(NULL
, lpDirectory
, CSIDL_LOCAL_APPDATA
, TRUE
))
243 if (FAILED(StringCchCatW(lpDirectory
, cch
, L
"\\rapps")))
246 if (!CreateDirectoryW(lpDirectory
, NULL
) &&
247 GetLastError() != ERROR_ALREADY_EXISTS
)
256 ExtractFilesFromCab(LPWSTR lpCabName
, LPWSTR lpOutputPath
)
258 HINSTANCE hCabinetDll
;
259 CHAR szCabName
[MAX_PATH
];
263 hCabinetDll
= LoadLibraryW(L
"cabinet.dll");
266 pfnExtract
= (void *) GetProcAddress(hCabinetDll
, "Extract");
269 ZeroMemory(&Dest
, sizeof(SESSION
));
271 WideCharToMultiByte(CP_ACP
, 0, lpOutputPath
, -1, Dest
.Destination
, MAX_PATH
, NULL
, NULL
);
272 WideCharToMultiByte(CP_ACP
, 0, lpCabName
, -1, szCabName
, MAX_PATH
, NULL
, NULL
);
273 Dest
.Operation
= EXTRACT_FILLFILELIST
;
275 Result
= pfnExtract(&Dest
, szCabName
);
278 Dest
.Operation
= EXTRACT_EXTRACTFILES
;
279 Result
= pfnExtract(&Dest
, szCabName
);
282 FreeLibrary(hCabinetDll
);
287 FreeLibrary(hCabinetDll
);
296 WCHAR szBuf
[MAX_PATH
] = L
"SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\ReactOS Application Manager";
297 WCHAR szPath
[MAX_PATH
];
298 DWORD dwCategoryNum
= 1;
299 DWORD dwDisp
, dwData
;
302 if (!SettingsInfo
.bLogEnabled
) return;
304 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE
,
306 REG_OPTION_NON_VOLATILE
,
307 KEY_WRITE
, NULL
, &hKey
, &dwDisp
) != ERROR_SUCCESS
)
312 if (!GetModuleFileName(NULL
, szPath
, sizeof(szPath
) / sizeof(szPath
[0])))
315 if (RegSetValueExW(hKey
,
320 (DWORD
)(wcslen(szPath
) + 1) * sizeof(WCHAR
)) != ERROR_SUCCESS
)
326 dwData
= EVENTLOG_ERROR_TYPE
| EVENTLOG_WARNING_TYPE
|
327 EVENTLOG_INFORMATION_TYPE
;
329 if (RegSetValueExW(hKey
,
334 sizeof(DWORD
)) != ERROR_SUCCESS
)
340 if (RegSetValueExW(hKey
,
341 L
"CategoryMessageFile",
345 (DWORD
)(wcslen(szPath
) + 1) * sizeof(WCHAR
)) != ERROR_SUCCESS
)
351 if (RegSetValueExW(hKey
,
355 (LPBYTE
)&dwCategoryNum
,
356 sizeof(DWORD
)) != ERROR_SUCCESS
)
364 hLog
= RegisterEventSourceW(NULL
, L
"ReactOS Application Manager");
371 if (hLog
) DeregisterEventSource(hLog
);
376 WriteLogMessage(WORD wType
, DWORD dwEventID
, LPWSTR lpMsg
)
378 if (!SettingsInfo
.bLogEnabled
) return TRUE
;
380 if (!ReportEventW(hLog
,