acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
aaa_shell.h
1#pragma once
2
3
4#define WH_SHSTDAPI(type) type
5
6
7namespace universal_windows
8{
9
10
11 class CLASS_DECL_ACME shell
12 {
13 public:
14 shell();
15 virtual ~shell();
16
17
18 static shell theWindowsShell;
19
20 static bool Initialize();
21
22 /*
23 static BOOL WINAPI _SHGetPathFromIDList(LPCITEMIDLIST pidl, wide_character * pszPath);
24 static HANDLE WINAPI _FindFirstFile(const wide_character * pcsz, WIN32_FIND_DATAW * lpdata);
25 static BOOL WINAPI _FindNextFile(HANDLE handle, WIN32_FIND_DATAW * lpdata);
26 static BOOL WINAPI _MoveFile(const wide_character * lpExistingFileName, const wide_character * lpNewFileName);
27 static ::u32 WINAPI _GetFullPathName(const wide_character * lpFileName, ::u32 nBufferLength, wide_character * lpBuffer, wide_character * * lpFilePart);
28 static WCHAR * __cdecl __fullpath(WCHAR *UserBuf, const WCHAR *path, size_t maxlen);
29 static BOOL WINAPI _GetVolumeInformation(
30 const wide_character * lpRootPathName, // root directory
31 wide_character * lpVolumeNameBuffer, // volume name buffer
32 ::u32 nVolumeNameSize, // length of name buffer
33 LPDWORD lpVolumeSerialNumber, // volume serial number
34 LPDWORD lpMaximumComponentLength, // maximum file name length
35 LPDWORD lpFileSystemFlags, // file system options
36 wide_character * lpFileSystemNameBuffer, // file system name buffer
37 ::u32 nFileSystemNameSize); // length of file system name buffer
38 static dword_ptr __stdcall _SHGetFileInfo(
39 const wide_character * pszPath,
40 ::u32 dwFileAttributes,
41 SHFILEINFOW *psfi,
42 ::u32 cbFileInfo,
43 ::u32 uFlags);
44 static BOOL __stdcall _GetStringTypeEx(
45 LCID Locale,
46 ::u32 dwInfoType,
47 const wide_character * lpSrcStr,
48 ::i32 cchSrc,
49 LPWORD lpCharType);
50 static ::u32 WINAPI _GetTempPath(
51 ::u32 nBufferLength,
52 wide_character * lpBuffer);
53 static ::u32 WINAPI _GetTempFileName(
54 const wide_character * lpPathName,
55 const wide_character * lpPrefixString,
56 ::u32 uUnique,
57 wide_character * lpTempFileName);
58 static HANDLE WINAPI _CreateFile(
59 const wide_character * lpFileName,
60 ::u32 dwDesiredAccess,
61 ::u32 dwShareMode,
62 LPSECURITY_ATTRIBUTES lpSecurityAttributes,
63 ::u32 dwCreationDisposition,
64 ::u32 dwFlagsAndAttributes,
65 HANDLE hTemplateFile
66 );
67 static ::u32 WINAPI _GetModuleFileName(
68 HMODULE hModule,
69 wide_character * lpFilename,
70 ::u32 nSize
71 );
72 static BOOL WINAPI _GetClassInfo(
73 HINSTANCE hInstance ,
74 const wide_character * lpClassName,
75 LPWNDCLASSW lpWndClass);
76 static ATOM WINAPI _RegisterClass(
77 const WNDCLASSW *lpWndClass);
78
79 static oswindow WINAPI _CreateWindowEx(
80 ::u32 dwExStyle,
81 const wide_character * lpClassName,
82 const wide_character * lpWindowName,
83 ::u32 uStyle,
84 ::i32 x,
85 ::i32 y,
86 ::i32 nWidth,
87 ::i32 nHeight,
88 oswindow hWndParent,
89 HMENU hMenu,
90 HINSTANCE hInstance,
91 LPVOID lpParam);
92
93 */
94
95
96
97 //BOOL (WINAPI * m_pfnSHGetPathFromIDList)(LPCITEMIDLIST pidl, wide_character * pszPath);
98 HANDLE (WINAPI * m_pfnFindFirstFile)(const wide_character * pcsz, WIN32_FIND_DATAW * lpdata);
99 BOOL (WINAPI * m_pfnFindNextFile)(HANDLE handle, WIN32_FIND_DATAW * lpdata);
100 BOOL (WINAPI * m_pfnMoveFile)(const wide_character * lpExistingFileName, const wide_character * lpNewFileName);
101 WCHAR * (__cdecl * m_pfn_fullpath)(WCHAR *UserBuf, const WCHAR *path, size_t maxlen);
102 ::u32 (WINAPI * m_pfnGetFullPathName)(const wide_character * lpFileName, ::u32 nBufferLength, wide_character * lpBuffer, wide_character * * lpFilePart);
103 BOOL (WINAPI * m_pfnGetVolumeInformation)(
104 const wide_character * lpRootPathName, // root directory
105 wide_character * lpVolumeNameBuffer, // volume name buffer
106 ::u32 nVolumeNameSize, // length of name buffer
107 LPDWORD lpVolumeSerialNumber, // volume serial number
108 LPDWORD lpMaximumComponentLength, // maximum file name length
109 LPDWORD lpFileSystemFlags, // file system options
110 wide_character * lpFileSystemNameBuffer, // file system name buffer
111 ::u32 nFileSystemNameSize); // length of file system name buffer
112
113 /* dword_ptr (WINAPI * m_pfnSHGetFileInfo)(
114 const wide_character * pszPath,
115 ::u32 dwFileAttributes,
116 SHFILEINFOW *psfi,
117 ::u32 cbFileInfo,
118 ::u32 uFlags);*/
119 BOOL (WINAPI * m_pfnGetStringTypeEx)(
120 LCID Locale,
121 ::u32 dwInfoType,
122 const wide_character * lpSrcStr,
123 ::i32 cchSrc,
124 LPWORD lpCharType);
125 ::u32 (WINAPI * m_pfnGetTempPath)(
126 ::u32 nBufferLength,
127 wide_character * lpBuffer);
128 ::u32 (WINAPI * m_pfnGetTempFileName)(
129 const wide_character * lpPathName,
130 const wide_character * lpPrefixString,
131 ::u32 uUnique,
132 wide_character * lpTempFileName);
133 HANDLE (WINAPI * m_pfnCreateFile)(
134 const wide_character * lpFileName,
135 ::u32 dwDesiredAccess,
136 ::u32 dwShareMode,
137 LPSECURITY_ATTRIBUTES lpSecurityAttributes,
138 ::u32 dwCreationDisposition,
139 ::u32 dwFlagsAndAttributes,
140 HANDLE hTemplateFile
141 );
142
143 ::u32 (WINAPI * m_pfnGetModuleFileName)(
144 HMODULE hModule,
145 wide_character * lpFilename,
146 ::u32 nSize
147 );
148
149 /* BOOL (WINAPI * m_pfnGetClassInfo)(
150 HINSTANCE hInstance ,
151 const wide_character * lpClassName,
152 LPWNDCLASSW lpWndClass);
153
154 ATOM (WINAPI * m_pfnRegisterClass)(
155 const WNDCLASSW *lpWndClass);*/
156
157 oswindow (WINAPI * m_pfnCreateWindowEx)(
158 ::u32 dwExStyle,
159 const wide_character * lpClassName,
160 const wide_character * lpWindowName,
161 ::u32 uStyle,
162 ::i32 x,
163 ::i32 y,
164 ::i32 nWidth,
165 ::i32 nHeight,
166 oswindow hWndParent,
167 HMENU hMenu,
168 HINSTANCE hInstance,
169 LPVOID lpParam);
170
171
172
173
174
175
176
177
178 // static bool SHGetPathFromIDList(LPCITEMIDLIST pidl, string & str);
179 // static bool SHGetPathFromIDList(LPCITEMIDLIST pidl, wide_character * pszPath);
180 static HANDLE FindFirstFile(const wide_character * pcsz, WIN32_FIND_DATAW * lpdata);
181 static bool WINAPI FindNextFile(HANDLE handle, WIN32_FIND_DATAW * lpdata);
182 static bool MoveFile(const wide_character * lpExistingFileName, const wide_character * lpNewFileName);
183 static WCHAR * __cdecl _fullpath(WCHAR *UserBuf, const WCHAR *path, size_t maxlen);
184 static ::u32 GetFullPathName(const wide_character * lpFileName, ::u32 nBufferLength, wide_character * lpBuffer, wide_character * * lpFilePart);
185 static bool GetVolumeInformation(
186 const wide_character * lpRootPathName, // root directory
187 wide_character * lpVolumeNameBuffer, // volume name buffer
188 ::u32 nVolumeNameSize, // length of name buffer
189 LPDWORD lpVolumeSerialNumber, // volume serial number
190 LPDWORD lpMaximumComponentLength, // maximum file name length
191 LPDWORD lpFileSystemFlags, // file system options
192 wide_character * lpFileSystemNameBuffer, // file system name buffer
193 ::u32 nFileSystemNameSize); // length of file system name buffer
194
195 /* static WH_SHSTDAPI(::u32) SHGetFileInfo(
196 const wide_character * pszPath,
197 ::u32 dwFileAttributes,
198 SHFILEINFOW *psfi,
199 ::u32 cbFileInfo,
200 ::u32 uFlags);
201 */
202
203 static bool GetStringTypeEx(
204 LCID Locale,
205 ::u32 dwInfoType,
206 const_char_pointer lpSrcStr,
207 ::i32 cchSrc,
208 LPWORD lpCharType);
209
210 static ::u32 GetTempPathW(
211 ::u32 nBufferLength,
212 wide_character * lpBuffer);
213
214 static ::u32 GetTempFileNameW(
215 const wide_character * lpPathName,
216 const wide_character * lpPrefixString,
217 ::u32 uUnique,
218 wide_character * lpTempFileName);
219
220 static HANDLE CreateFile(
221 const wide_character * lpFileName,
222 ::u32 dwDesiredAccess,
223 ::u32 dwShareMode,
224 LPSECURITY_ATTRIBUTES lpSecurityAttributes,
225 ::u32 dwCreationDisposition,
226 ::u32 dwFlagsAndAttributes,
227 HANDLE hTemplateFile);
228
229 static ::u32 WINAPI GetModuleFileName(
230 HMODULE hModule,
231 wide_character * lpFilename,
232 ::u32 nSize
233 );
234
235 /* static bool WINAPI GetClassInfo(
236 HINSTANCE hInstance ,
237 const wide_character * lpClassName,
238 LPWNDCLASSW lpWndClass);
239 */
240
241
242 /* static ATOM WINAPI RegisterClass(
243 const WNDCLASSW *lpWndClass);
244 */
245
246 static oswindow WINAPI CreateWindowEx(
247 ::u32 dwExStyle,
248 const wide_character * lpClassName,
249 const wide_character * lpWindowName,
250 ::u32 uStyle,
251 ::i32 x,
252 ::i32 y,
253 ::i32 nWidth,
254 ::i32 nHeight,
255 oswindow hWndParent,
256 HMENU hMenu,
257 HINSTANCE hInstance,
258 LPVOID lpParam);
259
260 /*
261 static WH_SHSTDAPI(::u32) SHGetFileInfo(
262 const ::file::path & path,
263 ::u32 dwFileAttributes,
264 SHFILEINFO *psfi,
265 ::u32 cbFileInfo,
266 ::u32 uFlags);
267
268 */
269
270 static ::u32 GetTempPath(string & str);
271
272 static ::u32 GetTempFileName(
273 const_char_pointer lpPathName,
274 const_char_pointer lpPrefixString,
275 ::u32 uUnique,
276 string & str);
277
278 static bool MoveFile(const_char_pointer lpExistingFileName, const_char_pointer lpNewFileName);
279
280 };
281
282 /*inline bool shell::SHGetPathFromIDList(LPCITEMIDLIST pidl, string & str)
283 {
284 wide_character * pwszPath = (wide_character * ) malloc(sizeof(unichar) * MAX_PATH * 4);
285 if(!(*theWindowsShell.m_pfnSHGetPathFromIDList)(pidl, pwszPath))
286 {
287 free(pwszPath);
288 return false;
289 }
290 unicode_to_utf8(str, pwszPath);
291 free(pwszPath);
292 return true;
293 }
294 */
295
296 /*
297 inline bool shell::SHGetPathFromIDList(LPCITEMIDLIST pidl, wide_character * pszPath)
298 {
299 return (*theWindowsShell.m_pfnSHGetPathFromIDList)(pidl, pszPath) != false;
300 }
301 */
302
303 inline HANDLE shell::FindFirstFile(const wide_character * pcsz, WIN32_FIND_DATAW * lpdata)
304 {
305 return (*theWindowsShell.m_pfnFindFirstFile)(pcsz, lpdata);
306 }
307
308 inline bool shell::FindNextFile(HANDLE handle, WIN32_FIND_DATAW * lpdata)
309 {
310 return (*theWindowsShell.m_pfnFindNextFile)(handle, lpdata) != false;
311 }
312
313 inline WCHAR * shell::_fullpath(WCHAR *UserBuf, const WCHAR *path, size_t maxlen)
314 {
315 return (*theWindowsShell.m_pfn_fullpath)(UserBuf, path, maxlen);
316 }
317
318 inline ::u32 shell::GetFullPathName(const wide_character * lpFileName, ::u32 nBufferLength, wide_character * lpBuffer, wide_character * * lpFilePart)
319 {
320 return (*theWindowsShell.m_pfnGetFullPathName)(lpFileName, nBufferLength, lpBuffer, lpFilePart);
321 }
322
323
324 inline bool shell::MoveFile(const wide_character * lpExistingFileName, const wide_character * lpNewFileName)
325 {
326 return (*theWindowsShell.m_pfnMoveFile)(lpExistingFileName, lpNewFileName) != false;
327 }
328
329 inline bool shell::GetVolumeInformation(
330 const wide_character * lpRootPathName, // root directory
331 wide_character * lpVolumeNameBuffer, // volume name buffer
332 ::u32 nVolumeNameSize, // length of name buffer
333 LPDWORD lpVolumeSerialNumber, // volume serial number
334 LPDWORD lpMaximumComponentLength, // maximum file name length
335 LPDWORD lpFileSystemFlags, // file system options
336 wide_character * lpFileSystemNameBuffer, // file system name buffer
337 ::u32 nFileSystemNameSize) // length of file system name buffer
338 {
339 return (*theWindowsShell.m_pfnGetVolumeInformation)(
340 lpRootPathName, // root directory
341 lpVolumeNameBuffer, // volume name buffer
342 nVolumeNameSize, // length of name buffer
343 lpVolumeSerialNumber, // volume serial number
344 lpMaximumComponentLength, // maximum file name length
345 lpFileSystemFlags, // file system options
346 lpFileSystemNameBuffer, // file system name buffer
347 nFileSystemNameSize) != false; // length of file system name buffer
348 }
349
350 /*
351 inline ::u32 shell::SHGetFileInfo(
352 const wide_character * pszPath,
353 ::u32 dwFileAttributes,
354 SHFILEINFOW *psfi,
355 ::u32 cbFileInfo,
356 ::u32 uFlags)
357 {
358 return (::u32) (*theWindowsShell.m_pfnSHGetFileInfo)(
359 pszPath,
360 dwFileAttributes,
361 psfi,
362 cbFileInfo,
363 uFlags);
364 }
365 */
366
367
368 inline ::u32 shell::GetTempPathW(
369 ::u32 nBufferLength,
370 wide_character * lpBuffer)
371 {
372 return (*theWindowsShell.m_pfnGetTempPath)(
373 nBufferLength,
374 lpBuffer);
375 }
376
377 inline ::u32 shell::GetTempFileNameW(
378 const wide_character * lpPathName,
379 const wide_character * lpPrefixString,
380 ::u32 uUnique,
381 wide_character * lpTempFileName)
382 {
383 return (*theWindowsShell.m_pfnGetTempFileName)(
384 lpPathName,
385 lpPrefixString,
386 uUnique,
387 lpTempFileName);
388 }
389
390 inline HANDLE shell::CreateFile(
391 const wide_character * lpFileName,
392 ::u32 dwDesiredAccess,
393 ::u32 dwShareMode,
394 LPSECURITY_ATTRIBUTES lpSecurityAttributes,
395 ::u32 dwCreationDisposition,
396 ::u32 dwFlagsAndAttributes,
397 HANDLE hTemplateFile)
398 {
399 return (*theWindowsShell.m_pfnCreateFile)(
400 lpFileName,
401 dwDesiredAccess,
402 dwShareMode,
403 lpSecurityAttributes,
404 dwCreationDisposition,
405 dwFlagsAndAttributes,
406 hTemplateFile);
407 }
408
409 inline ::u32 shell::GetModuleFileName(
410 HMODULE hModule,
411 wide_character * lpFilename,
412 ::u32 nSize
413 )
414 {
415 return (*theWindowsShell.m_pfnGetModuleFileName)(
416 hModule,
417 lpFilename,
418 nSize);
419 }
420
421 /*
422 inline bool shell::GetClassInfo(
423 HINSTANCE hInstance ,
424 const wide_character * lpClassName,
425 LPWNDCLASSW lpWndClass)
426 {
427 return (*theWindowsShell.m_pfnGetClassInfo)(hInstance, lpClassName, lpWndClass) != false;
428 }
429
430 inline ATOM shell::RegisterClass(
431 const WNDCLASSW *lpWndClass)
432 {
433 return (*theWindowsShell.m_pfnRegisterClass)(
434 lpWndClass);
435 }
436 */
437
438
439 inline oswindow shell::CreateWindowEx(
440 ::u32 dwExStyle,
441 const wide_character * lpClassName,
442 const wide_character * lpWindowName,
443 ::u32 uStyle,
444 ::i32 x,
445 ::i32 y,
446 ::i32 nWidth,
447 ::i32 nHeight,
448 oswindow hWndParent,
449 HMENU hMenu,
450 HINSTANCE hInstance,
451 LPVOID lpParam)
452 {
453 return (*theWindowsShell.m_pfnCreateWindowEx)(
454 dwExStyle,
455 lpClassName,
456 lpWindowName,
457 uStyle,
458 x,
459 y,
460 nWidth,
461 nHeight,
462 hWndParent,
463 hMenu,
464 hInstance,
465 lpParam);
466
467 }
468
469 inline ::u32 shell::GetTempPath(string & str)
470 {
471 wide_character * pwsz = (wide_character * ) malloc(sizeof(unichar) * MAX_PATH * 4);
472 ::u32 dwResult = (*theWindowsShell.m_pfnGetTempPath)(sizeof(unichar) * MAX_PATH * 4, pwsz);
473 unicode_to_utf8(str, pwsz);
474 free(pwsz);
475 return dwResult;
476 }
477
478 inline ::u32 shell::GetTempFileName(const_char_pointer lpPathName, const_char_pointer lpPrefixString, ::u32 uUnique, string & str)
479 {
480 wstring wstrPathName = utf8_to_unicode(lpPathName);
481 wstring wstrPrefixString = utf8_to_unicode(lpPrefixString);
482 wstring wstr;
483 wstr.get_buffer(MAX_PATH * 4);
484 ::u32 uResult = (*theWindowsShell.m_pfnGetTempFileName)(wstrPathName, wstrPrefixString, uUnique, wstr);
485 unicode_to_utf8(str, wstr);
486 return uiResult;
487 }
488
489 inline bool shell::MoveFile(const_char_pointer lpExistingFileName, const_char_pointer lpNewFileName)
490 {
491 return MoveFile(utf8_to_unicode(lpExistingFileName), utf8_to_unicode(lpNewFileName));
492 }
493
494
495} // namespace universal_windows
496
497
498
499