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
)
114 if(OpenClipboard(NULL
))
120 ClipBuffer
= GlobalAlloc(GMEM_DDESHARE
, (wcslen(lpszText
) + 1) * sizeof(TCHAR
));
121 Buffer
= (WCHAR
*)GlobalLock(ClipBuffer
);
122 wcscpy(Buffer
, lpszText
);
123 GlobalUnlock(ClipBuffer
);
125 SetClipboardData(CF_UNICODETEXT
, ClipBuffer
);
134 WCHAR szText
[MAX_STR_LEN
*3];
136 LoadStringW(hInst
, IDS_WELCOME_TITLE
, szText
, sizeof(szText
) / sizeof(WCHAR
));
137 NewRichEditText(szText
, CFE_BOLD
);
139 LoadStringW(hInst
, IDS_WELCOME_TEXT
, szText
, sizeof(szText
) / sizeof(WCHAR
));
140 InsertRichEditText(szText
, 0);
142 LoadStringW(hInst
, IDS_WELCOME_URL
, szText
, sizeof(szText
) / sizeof(WCHAR
));
143 InsertRichEditText(szText
, CFM_LINK
);
147 ShowPopupMenu(HWND hwnd
, UINT MenuID
)
149 HMENU hPopupMenu
= GetSubMenu(LoadMenuW(hInst
, MAKEINTRESOURCEW(MenuID
)), 0);
154 SetForegroundWindow(hwnd
);
155 TrackPopupMenu(hPopupMenu
, 0, pt
.x
, pt
.y
, 0, hMainWnd
, NULL
);
157 DestroyMenu(hPopupMenu
);
161 StartProcess(LPWSTR lpPath
, BOOL Wait
)
163 PROCESS_INFORMATION pi
;
168 ZeroMemory(&si
, sizeof(si
));
170 si
.dwFlags
= STARTF_USESHOWWINDOW
;
171 si
.wShowWindow
= SW_SHOW
;
173 if (!CreateProcessW(NULL
, lpPath
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
))
178 CloseHandle(pi
.hThread
);
179 if (Wait
) EnableWindow(hMainWnd
, FALSE
);
183 dwRet
= MsgWaitForMultipleObjects(1, &pi
.hProcess
, FALSE
, INFINITE
, QS_ALLEVENTS
);
184 if (dwRet
== WAIT_OBJECT_0
+ 1)
186 while (PeekMessageW(&msg
, NULL
, 0, 0, PM_REMOVE
))
188 TranslateMessage(&msg
);
189 DispatchMessage(&msg
);
194 if (dwRet
== WAIT_OBJECT_0
|| dwRet
== WAIT_FAILED
)
199 CloseHandle(pi
.hProcess
);
203 EnableWindow(hMainWnd
, TRUE
);
204 SetForegroundWindow(hMainWnd
);
212 GetStorageDirectory(PWCHAR lpDirectory
, DWORD cch
)
217 if (!SHGetSpecialFolderPathW(NULL
, lpDirectory
, CSIDL_LOCAL_APPDATA
, TRUE
))
220 if (FAILED(StringCchCatW(lpDirectory
, cch
, L
"\\rapps")))
223 if (!CreateDirectoryW(lpDirectory
, NULL
) &&
224 GetLastError() != ERROR_ALREADY_EXISTS
)
233 ExtractFilesFromCab(LPWSTR lpCabName
, LPWSTR lpOutputPath
)
235 HINSTANCE hCabinetDll
;
236 CHAR szCabName
[MAX_PATH
];
240 hCabinetDll
= LoadLibraryW(L
"cabinet.dll");
243 pfnExtract
= (void *) GetProcAddress(hCabinetDll
, "Extract");
246 ZeroMemory(&Dest
, sizeof(SESSION
));
248 WideCharToMultiByte(CP_ACP
, 0, lpOutputPath
, -1, Dest
.Destination
, MAX_PATH
, NULL
, NULL
);
249 WideCharToMultiByte(CP_ACP
, 0, lpCabName
, -1, szCabName
, MAX_PATH
, NULL
, NULL
);
250 Dest
.Operation
= EXTRACT_FILLFILELIST
;
252 Result
= pfnExtract(&Dest
, szCabName
);
255 Dest
.Operation
= EXTRACT_EXTRACTFILES
;
256 Result
= pfnExtract(&Dest
, szCabName
);
259 FreeLibrary(hCabinetDll
);
264 FreeLibrary(hCabinetDll
);
273 WCHAR szBuf
[MAX_PATH
] = L
"SYSTEM\\CurrentControlSet\\Services\\EventLog\\ReactOS Application Manager\\ReactOS Application Manager";
274 WCHAR szPath
[MAX_PATH
];
275 DWORD dwCategoryNum
= 1;
276 DWORD dwDisp
, dwData
;
279 if (!SettingsInfo
.bLogEnabled
) return;
281 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE
,
283 REG_OPTION_NON_VOLATILE
,
284 KEY_WRITE
, NULL
, &hKey
, &dwDisp
) != ERROR_SUCCESS
)
289 if (!GetModuleFileName(NULL
, szPath
, sizeof(szPath
) / sizeof(szPath
[0])))
292 if (RegSetValueExW(hKey
,
297 (DWORD
)(wcslen(szPath
) + 1) * sizeof(WCHAR
)) != ERROR_SUCCESS
)
303 dwData
= EVENTLOG_ERROR_TYPE
| EVENTLOG_WARNING_TYPE
|
304 EVENTLOG_INFORMATION_TYPE
;
306 if (RegSetValueExW(hKey
,
311 sizeof(DWORD
)) != ERROR_SUCCESS
)
317 if (RegSetValueExW(hKey
,
318 L
"CategoryMessageFile",
322 (DWORD
)(wcslen(szPath
) + 1) * sizeof(WCHAR
)) != ERROR_SUCCESS
)
328 if (RegSetValueExW(hKey
,
332 (LPBYTE
)&dwCategoryNum
,
333 sizeof(DWORD
)) != ERROR_SUCCESS
)
341 hLog
= RegisterEventSourceW(NULL
, L
"ReactOS Application Manager");
348 if (hLog
) DeregisterEventSource(hLog
);
353 WriteLogMessage(WORD wType
, DWORD dwEventID
, LPWSTR lpMsg
)
355 if (!SettingsInfo
.bLogEnabled
) return TRUE
;
357 if (!ReportEventW(hLog
,