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)
12 /* SESSION Operation */
13 #define EXTRACT_FILLFILELIST 0x00000001
14 #define EXTRACT_EXTRACTFILES 0x00000002
16 static HANDLE hLog
= NULL
;
28 struct FILELIST
*next
;
36 struct FILELIST
*FileList
;
39 CHAR Destination
[MAX_PATH
];
40 CHAR CurrentFile
[MAX_PATH
];
41 CHAR Reserved
[MAX_PATH
];
42 struct FILELIST
*FilterList
;
45 HRESULT (WINAPI
*pfnExtract
)(SESSION
*dest
, LPCSTR szCabName
);
49 GetSystemColorDepth(VOID
)
54 pDevMode
.dmSize
= sizeof(DEVMODE
);
55 pDevMode
.dmDriverExtra
= 0;
57 if (!EnumDisplaySettings(NULL
, ENUM_CURRENT_SETTINGS
, &pDevMode
))
59 /* TODO: Error message */
63 switch (pDevMode
.dmBitsPerPel
)
65 case 32: ColorDepth
= ILC_COLOR32
; break;
66 case 24: ColorDepth
= ILC_COLOR24
; break;
67 case 16: ColorDepth
= ILC_COLOR16
; break;
68 case 8: ColorDepth
= ILC_COLOR8
; break;
69 case 4: ColorDepth
= ILC_COLOR4
; break;
70 default: ColorDepth
= ILC_COLOR
; break;
77 GetWindowWidth(HWND hwnd
)
81 GetWindowRect(hwnd
, &Rect
);
82 return (Rect
.right
- Rect
.left
);
86 GetWindowHeight(HWND hwnd
)
90 GetWindowRect(hwnd
, &Rect
);
91 return (Rect
.bottom
- Rect
.top
);
95 GetClientWindowWidth(HWND hwnd
)
99 GetClientRect(hwnd
, &Rect
);
100 return (Rect
.right
- Rect
.left
);
104 GetClientWindowHeight(HWND hwnd
)
108 GetClientRect(hwnd
, &Rect
);
109 return (Rect
.bottom
- Rect
.top
);
113 CopyTextToClipboard(LPCWSTR lpszText
)
115 if(OpenClipboard(NULL
))
121 ClipBuffer
= GlobalAlloc(GMEM_DDESHARE
, (wcslen(lpszText
) + 1) * sizeof(TCHAR
));
122 Buffer
= (WCHAR
*)GlobalLock(ClipBuffer
);
123 wcscpy(Buffer
, lpszText
);
124 GlobalUnlock(ClipBuffer
);
126 SetClipboardData(CF_UNICODETEXT
, ClipBuffer
);
135 WCHAR szText
[MAX_STR_LEN
*3];
137 LoadStringW(hInst
, IDS_WELCOME_TITLE
, szText
, sizeof(szText
) / sizeof(WCHAR
));
138 NewRichEditText(szText
, CFE_BOLD
);
140 LoadStringW(hInst
, IDS_WELCOME_TEXT
, szText
, sizeof(szText
) / sizeof(WCHAR
));
141 InsertRichEditText(szText
, 0);
143 LoadStringW(hInst
, IDS_WELCOME_URL
, szText
, sizeof(szText
) / sizeof(WCHAR
));
144 InsertRichEditText(szText
, CFM_LINK
);
148 ShowPopupMenu(HWND hwnd
, UINT MenuID
)
150 HMENU hPopupMenu
= GetSubMenu(LoadMenuW(hInst
, MAKEINTRESOURCEW(MenuID
)), 0);
155 SetForegroundWindow(hwnd
);
156 TrackPopupMenu(hPopupMenu
, 0, pt
.x
, pt
.y
, 0, hMainWnd
, NULL
);
158 DestroyMenu(hPopupMenu
);
162 StartProcess(LPWSTR lpPath
, BOOL Wait
)
164 PROCESS_INFORMATION pi
;
169 ZeroMemory(&si
, sizeof(si
));
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
);
213 ExtractFilesFromCab(LPWSTR lpCabName
, LPWSTR lpOutputPath
)
215 HINSTANCE hCabinetDll
;
216 CHAR szCabName
[MAX_PATH
];
220 hCabinetDll
= LoadLibraryW(L
"cabinet.dll");
223 pfnExtract
= (void *) GetProcAddress(hCabinetDll
, "Extract");
226 ZeroMemory(&Dest
, sizeof(SESSION
));
228 WideCharToMultiByte(CP_ACP
, 0, lpOutputPath
, -1, Dest
.Destination
, MAX_PATH
, NULL
, NULL
);
229 WideCharToMultiByte(CP_ACP
, 0, lpCabName
, -1, szCabName
, MAX_PATH
, NULL
, NULL
);
230 Dest
.Operation
= EXTRACT_FILLFILELIST
;
232 Result
= pfnExtract(&Dest
, szCabName
);
235 Dest
.Operation
= EXTRACT_EXTRACTFILES
;
236 Result
= pfnExtract(&Dest
, szCabName
);
239 FreeLibrary(hCabinetDll
);
244 FreeLibrary(hCabinetDll
);
253 WCHAR szBuf
[MAX_PATH
] = L
"SYSTEM\\CurrentControlSet\\Services\\EventLog\\ReactOS Application Manager\\ReactOS Application Manager";
254 WCHAR szPath
[MAX_PATH
];
255 DWORD dwCategoryNum
= 1;
256 DWORD dwDisp
, dwData
;
259 if (!SettingsInfo
.bLogEnabled
) return;
261 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE
,
263 REG_OPTION_NON_VOLATILE
,
264 KEY_WRITE
, NULL
, &hKey
, &dwDisp
) != ERROR_SUCCESS
)
269 if (!GetCurrentDirectoryW(MAX_PATH
, szPath
)) return;
270 wcscat(szPath
, L
"\\rapps.exe");
272 if (RegSetValueExW(hKey
,
277 (DWORD
)(wcslen(szPath
) + 1) * sizeof(WCHAR
)) != ERROR_SUCCESS
)
283 dwData
= EVENTLOG_ERROR_TYPE
| EVENTLOG_WARNING_TYPE
|
284 EVENTLOG_INFORMATION_TYPE
;
286 if (RegSetValueExW(hKey
,
291 sizeof(DWORD
)) != ERROR_SUCCESS
)
297 if (RegSetValueExW(hKey
,
298 L
"CategoryMessageFile",
302 (DWORD
)(wcslen(szPath
) + 1) * sizeof(WCHAR
)) != ERROR_SUCCESS
)
308 if (RegSetValueExW(hKey
,
312 (LPBYTE
)&dwCategoryNum
,
313 sizeof(DWORD
)) != ERROR_SUCCESS
)
321 hLog
= RegisterEventSourceW(NULL
, L
"ReactOS Application Manager");
328 if (hLog
) DeregisterEventSource(hLog
);
333 WriteLogMessage(WORD wType
, DWORD dwEventID
, LPWSTR lpMsg
)
335 if (!SettingsInfo
.bLogEnabled
) return TRUE
;
337 if (!ReportEventW(hLog
,