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
= (WCHAR
*)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
)
154 HMENU hPopupMenu
= GetSubMenu(LoadMenuW(hInst
, MAKEINTRESOURCEW(MenuID
)), 0);
159 SetForegroundWindow(hwnd
);
160 TrackPopupMenu(hPopupMenu
, 0, pt
.x
, pt
.y
, 0, hMainWnd
, NULL
);
162 DestroyMenu(hPopupMenu
);
166 StartProcess(LPWSTR lpPath
, BOOL Wait
)
168 PROCESS_INFORMATION pi
;
173 ZeroMemory(&si
, sizeof(si
));
175 si
.dwFlags
= STARTF_USESHOWWINDOW
;
176 si
.wShowWindow
= SW_SHOW
;
178 if (!CreateProcessW(NULL
, lpPath
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
))
183 CloseHandle(pi
.hThread
);
184 if (Wait
) EnableWindow(hMainWnd
, FALSE
);
188 dwRet
= MsgWaitForMultipleObjects(1, &pi
.hProcess
, FALSE
, INFINITE
, QS_ALLEVENTS
);
189 if (dwRet
== WAIT_OBJECT_0
+ 1)
191 while (PeekMessageW(&msg
, NULL
, 0, 0, PM_REMOVE
))
193 TranslateMessage(&msg
);
194 DispatchMessage(&msg
);
199 if (dwRet
== WAIT_OBJECT_0
|| dwRet
== WAIT_FAILED
)
204 CloseHandle(pi
.hProcess
);
208 EnableWindow(hMainWnd
, TRUE
);
209 SetForegroundWindow(hMainWnd
);
217 GetStorageDirectory(PWCHAR lpDirectory
, DWORD cch
)
222 if (!SHGetSpecialFolderPathW(NULL
, lpDirectory
, CSIDL_LOCAL_APPDATA
, TRUE
))
225 if (FAILED(StringCchCatW(lpDirectory
, cch
, L
"\\rapps")))
228 if (!CreateDirectoryW(lpDirectory
, NULL
) &&
229 GetLastError() != ERROR_ALREADY_EXISTS
)
238 ExtractFilesFromCab(LPWSTR lpCabName
, LPWSTR lpOutputPath
)
240 HINSTANCE hCabinetDll
;
241 CHAR szCabName
[MAX_PATH
];
245 hCabinetDll
= LoadLibraryW(L
"cabinet.dll");
248 pfnExtract
= (void *) GetProcAddress(hCabinetDll
, "Extract");
251 ZeroMemory(&Dest
, sizeof(SESSION
));
253 WideCharToMultiByte(CP_ACP
, 0, lpOutputPath
, -1, Dest
.Destination
, MAX_PATH
, NULL
, NULL
);
254 WideCharToMultiByte(CP_ACP
, 0, lpCabName
, -1, szCabName
, MAX_PATH
, NULL
, NULL
);
255 Dest
.Operation
= EXTRACT_FILLFILELIST
;
257 Result
= pfnExtract(&Dest
, szCabName
);
260 Dest
.Operation
= EXTRACT_EXTRACTFILES
;
261 Result
= pfnExtract(&Dest
, szCabName
);
264 FreeLibrary(hCabinetDll
);
269 FreeLibrary(hCabinetDll
);
278 WCHAR szBuf
[MAX_PATH
] = L
"SYSTEM\\CurrentControlSet\\Services\\EventLog\\ReactOS Application Manager\\ReactOS Application Manager";
279 WCHAR szPath
[MAX_PATH
];
280 DWORD dwCategoryNum
= 1;
281 DWORD dwDisp
, dwData
;
284 if (!SettingsInfo
.bLogEnabled
) return;
286 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE
,
288 REG_OPTION_NON_VOLATILE
,
289 KEY_WRITE
, NULL
, &hKey
, &dwDisp
) != ERROR_SUCCESS
)
294 if (!GetModuleFileName(NULL
, szPath
, sizeof(szPath
) / sizeof(szPath
[0])))
297 if (RegSetValueExW(hKey
,
302 (DWORD
)(wcslen(szPath
) + 1) * sizeof(WCHAR
)) != ERROR_SUCCESS
)
308 dwData
= EVENTLOG_ERROR_TYPE
| EVENTLOG_WARNING_TYPE
|
309 EVENTLOG_INFORMATION_TYPE
;
311 if (RegSetValueExW(hKey
,
316 sizeof(DWORD
)) != ERROR_SUCCESS
)
322 if (RegSetValueExW(hKey
,
323 L
"CategoryMessageFile",
327 (DWORD
)(wcslen(szPath
) + 1) * sizeof(WCHAR
)) != ERROR_SUCCESS
)
333 if (RegSetValueExW(hKey
,
337 (LPBYTE
)&dwCategoryNum
,
338 sizeof(DWORD
)) != ERROR_SUCCESS
)
346 hLog
= RegisterEventSourceW(NULL
, L
"ReactOS Application Manager");
353 if (hLog
) DeregisterEventSource(hLog
);
358 WriteLogMessage(WORD wType
, DWORD dwEventID
, LPWSTR lpMsg
)
360 if (!SettingsInfo
.bLogEnabled
) return TRUE
;
362 if (!ReportEventW(hLog
,