2 * Copyright 2012 Alistair Leslie-Hughes
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
32 #include "scrrun_private.h"
34 #include "wine/debug.h"
35 #include "wine/unicode.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(scrrun
);
39 static const WCHAR bsW
[] = {'\\',0};
40 static const WCHAR utf16bom
= 0xfeff;
42 struct foldercollection
{
43 IFolderCollection IFolderCollection_iface
;
48 struct filecollection
{
49 IFileCollection IFileCollection_iface
;
54 struct drivecollection
{
55 IDriveCollection IDriveCollection_iface
;
66 struct foldercollection
*coll
;
71 struct filecollection
*coll
;
76 struct drivecollection
*coll
;
83 IEnumVARIANT IEnumVARIANT_iface
;
96 IFolder IFolder_iface
;
109 ITextStream ITextStream_iface
;
124 static inline struct drive
*impl_from_IDrive(IDrive
*iface
)
126 return CONTAINING_RECORD(iface
, struct drive
, IDrive_iface
);
129 static inline struct folder
*impl_from_IFolder(IFolder
*iface
)
131 return CONTAINING_RECORD(iface
, struct folder
, IFolder_iface
);
134 static inline struct file
*impl_from_IFile(IFile
*iface
)
136 return CONTAINING_RECORD(iface
, struct file
, IFile_iface
);
139 static inline struct textstream
*impl_from_ITextStream(ITextStream
*iface
)
141 return CONTAINING_RECORD(iface
, struct textstream
, ITextStream_iface
);
144 static inline struct foldercollection
*impl_from_IFolderCollection(IFolderCollection
*iface
)
146 return CONTAINING_RECORD(iface
, struct foldercollection
, IFolderCollection_iface
);
149 static inline struct filecollection
*impl_from_IFileCollection(IFileCollection
*iface
)
151 return CONTAINING_RECORD(iface
, struct filecollection
, IFileCollection_iface
);
154 static inline struct drivecollection
*impl_from_IDriveCollection(IDriveCollection
*iface
)
156 return CONTAINING_RECORD(iface
, struct drivecollection
, IDriveCollection_iface
);
159 static inline struct enumvariant
*impl_from_IEnumVARIANT(IEnumVARIANT
*iface
)
161 return CONTAINING_RECORD(iface
, struct enumvariant
, IEnumVARIANT_iface
);
164 static inline HRESULT
create_error(DWORD err
)
167 case ERROR_FILE_NOT_FOUND
: return CTL_E_FILENOTFOUND
;
168 case ERROR_PATH_NOT_FOUND
: return CTL_E_PATHNOTFOUND
;
169 case ERROR_ACCESS_DENIED
: return CTL_E_PERMISSIONDENIED
;
170 case ERROR_FILE_EXISTS
: return CTL_E_FILEALREADYEXISTS
;
171 case ERROR_ALREADY_EXISTS
: return CTL_E_FILEALREADYEXISTS
;
173 FIXME("Unsupported error code: %d\n", err
);
178 static HRESULT
create_folder(const WCHAR
*, IFolder
**);
179 static HRESULT
create_file(BSTR
, IFile
**);
180 static HRESULT
create_foldercoll_enum(struct foldercollection
*, IUnknown
**);
181 static HRESULT
create_filecoll_enum(struct filecollection
*, IUnknown
**);
183 static inline BOOL
is_dir_data(const WIN32_FIND_DATAW
*data
)
185 static const WCHAR dotdotW
[] = {'.','.',0};
186 static const WCHAR dotW
[] = {'.',0};
188 return (data
->dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) &&
189 strcmpW(data
->cFileName
, dotdotW
) &&
190 strcmpW(data
->cFileName
, dotW
);
193 static inline BOOL
is_file_data(const WIN32_FIND_DATAW
*data
)
195 return !(data
->dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
);
198 static BSTR
get_full_path(BSTR path
, const WIN32_FIND_DATAW
*data
)
200 int len
= SysStringLen(path
);
201 WCHAR buffW
[MAX_PATH
];
203 strcpyW(buffW
, path
);
204 if (path
[len
-1] != '\\')
206 strcatW(buffW
, data
->cFileName
);
208 return SysAllocString(buffW
);
211 static BOOL
textstream_check_iomode(struct textstream
*This
, enum iotype type
)
214 return This
->mode
== ForWriting
|| This
->mode
== ForAppending
;
216 return This
->mode
== ForReading
;
219 static HRESULT WINAPI
textstream_QueryInterface(ITextStream
*iface
, REFIID riid
, void **obj
)
221 struct textstream
*This
= impl_from_ITextStream(iface
);
223 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), obj
);
225 if (IsEqualIID(riid
, &IID_ITextStream
) ||
226 IsEqualIID(riid
, &IID_IDispatch
) ||
227 IsEqualIID(riid
, &IID_IUnknown
))
230 ITextStream_AddRef(iface
);
235 return E_NOINTERFACE
;
238 static ULONG WINAPI
textstream_AddRef(ITextStream
*iface
)
240 struct textstream
*This
= impl_from_ITextStream(iface
);
241 ULONG ref
= InterlockedIncrement(&This
->ref
);
242 TRACE("(%p)->(%d)\n", This
, ref
);
246 static ULONG WINAPI
textstream_Release(ITextStream
*iface
)
248 struct textstream
*This
= impl_from_ITextStream(iface
);
249 ULONG ref
= InterlockedDecrement(&This
->ref
);
250 TRACE("(%p)->(%d)\n", This
, ref
);
254 CloseHandle(This
->file
);
261 static HRESULT WINAPI
textstream_GetTypeInfoCount(ITextStream
*iface
, UINT
*pctinfo
)
263 struct textstream
*This
= impl_from_ITextStream(iface
);
264 TRACE("(%p)->(%p)\n", This
, pctinfo
);
269 static HRESULT WINAPI
textstream_GetTypeInfo(ITextStream
*iface
, UINT iTInfo
,
270 LCID lcid
, ITypeInfo
**ppTInfo
)
272 struct textstream
*This
= impl_from_ITextStream(iface
);
273 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
274 return get_typeinfo(ITextStream_tid
, ppTInfo
);
277 static HRESULT WINAPI
textstream_GetIDsOfNames(ITextStream
*iface
, REFIID riid
,
278 LPOLESTR
*rgszNames
, UINT cNames
,
279 LCID lcid
, DISPID
*rgDispId
)
281 struct textstream
*This
= impl_from_ITextStream(iface
);
285 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
, lcid
, rgDispId
);
287 hr
= get_typeinfo(ITextStream_tid
, &typeinfo
);
290 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
291 ITypeInfo_Release(typeinfo
);
297 static HRESULT WINAPI
textstream_Invoke(ITextStream
*iface
, DISPID dispIdMember
,
298 REFIID riid
, LCID lcid
, WORD wFlags
,
299 DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
,
300 EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
302 struct textstream
*This
= impl_from_ITextStream(iface
);
306 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
307 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
309 hr
= get_typeinfo(ITextStream_tid
, &typeinfo
);
312 hr
= ITypeInfo_Invoke(typeinfo
, iface
, dispIdMember
, wFlags
,
313 pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
314 ITypeInfo_Release(typeinfo
);
320 static HRESULT WINAPI
textstream_get_Line(ITextStream
*iface
, LONG
*line
)
322 struct textstream
*This
= impl_from_ITextStream(iface
);
323 FIXME("(%p)->(%p): stub\n", This
, line
);
327 static HRESULT WINAPI
textstream_get_Column(ITextStream
*iface
, LONG
*column
)
329 struct textstream
*This
= impl_from_ITextStream(iface
);
330 FIXME("(%p)->(%p): stub\n", This
, column
);
334 static HRESULT WINAPI
textstream_get_AtEndOfStream(ITextStream
*iface
, VARIANT_BOOL
*eos
)
336 struct textstream
*This
= impl_from_ITextStream(iface
);
337 LARGE_INTEGER pos
, dist
;
339 TRACE("(%p)->(%p)\n", This
, eos
);
344 if (textstream_check_iomode(This
, IORead
)) {
346 return CTL_E_BADFILEMODE
;
350 if (!SetFilePointerEx(This
->file
, dist
, &pos
, FILE_CURRENT
))
353 *eos
= This
->size
.QuadPart
== pos
.QuadPart
? VARIANT_TRUE
: VARIANT_FALSE
;
357 static HRESULT WINAPI
textstream_get_AtEndOfLine(ITextStream
*iface
, VARIANT_BOOL
*eol
)
359 struct textstream
*This
= impl_from_ITextStream(iface
);
360 FIXME("(%p)->(%p): stub\n", This
, eol
);
365 Reads 'toread' bytes from a file, converts if needed
366 BOM is skipped if 'bof' is set.
368 static HRESULT
textstream_read(struct textstream
*stream
, LONG toread
, BOOL bof
, BSTR
*text
)
376 *text
= SysAllocStringLen(NULL
, 0);
377 return *text
? S_FALSE
: E_OUTOFMEMORY
;
380 if (toread
< sizeof(WCHAR
))
381 return CTL_E_ENDOFFILE
;
383 buff
= heap_alloc(toread
);
385 return E_OUTOFMEMORY
;
387 ret
= ReadFile(stream
->file
, buff
, toread
, &read
, NULL
);
388 if (!ret
|| toread
!= read
) {
389 WARN("failed to read from file %d, %d, error %d\n", read
, toread
, GetLastError());
394 if (stream
->unicode
) {
398 if (bof
&& *(WCHAR
*)buff
== utf16bom
) {
399 read
-= sizeof(WCHAR
);
403 *text
= SysAllocStringLen(read
? (WCHAR
*)&buff
[i
] : NULL
, read
/sizeof(WCHAR
));
404 if (!*text
) hr
= E_OUTOFMEMORY
;
407 INT len
= MultiByteToWideChar(CP_ACP
, 0, buff
, read
, NULL
, 0);
408 *text
= SysAllocStringLen(NULL
, len
);
410 MultiByteToWideChar(CP_ACP
, 0, buff
, read
, *text
, len
);
419 static HRESULT WINAPI
textstream_Read(ITextStream
*iface
, LONG len
, BSTR
*text
)
421 struct textstream
*This
= impl_from_ITextStream(iface
);
422 LARGE_INTEGER start
, end
, dist
;
426 TRACE("(%p)->(%d %p)\n", This
, len
, text
);
433 return len
== 0 ? S_OK
: E_INVALIDARG
;
435 if (textstream_check_iomode(This
, IORead
))
436 return CTL_E_BADFILEMODE
;
438 if (!This
->first_read
) {
442 hr
= ITextStream_get_AtEndOfStream(iface
, &eos
);
446 if (eos
== VARIANT_TRUE
)
447 return CTL_E_ENDOFFILE
;
450 /* read everything from current position */
452 SetFilePointerEx(This
->file
, dist
, &start
, FILE_CURRENT
);
453 SetFilePointerEx(This
->file
, dist
, &end
, FILE_END
);
454 toread
= end
.QuadPart
- start
.QuadPart
;
456 dist
.QuadPart
= start
.QuadPart
;
457 SetFilePointerEx(This
->file
, dist
, NULL
, FILE_BEGIN
);
459 This
->first_read
= FALSE
;
460 if (This
->unicode
) len
*= sizeof(WCHAR
);
462 hr
= textstream_read(This
, min(toread
, len
), start
.QuadPart
== 0, text
);
466 return toread
<= len
? S_FALSE
: S_OK
;
469 static HRESULT WINAPI
textstream_ReadLine(ITextStream
*iface
, BSTR
*text
)
471 struct textstream
*This
= impl_from_ITextStream(iface
);
475 FIXME("(%p)->(%p): stub\n", This
, text
);
481 if (textstream_check_iomode(This
, IORead
))
482 return CTL_E_BADFILEMODE
;
485 hr
= ITextStream_get_AtEndOfStream(iface
, &eos
);
489 if (eos
== VARIANT_TRUE
)
490 return CTL_E_ENDOFFILE
;
495 static HRESULT WINAPI
textstream_ReadAll(ITextStream
*iface
, BSTR
*text
)
497 struct textstream
*This
= impl_from_ITextStream(iface
);
498 LARGE_INTEGER start
, end
, dist
;
502 TRACE("(%p)->(%p)\n", This
, text
);
508 if (textstream_check_iomode(This
, IORead
))
509 return CTL_E_BADFILEMODE
;
511 if (!This
->first_read
) {
515 hr
= ITextStream_get_AtEndOfStream(iface
, &eos
);
519 if (eos
== VARIANT_TRUE
)
520 return CTL_E_ENDOFFILE
;
523 /* read everything from current position */
525 SetFilePointerEx(This
->file
, dist
, &start
, FILE_CURRENT
);
526 SetFilePointerEx(This
->file
, dist
, &end
, FILE_END
);
527 toread
= end
.QuadPart
- start
.QuadPart
;
529 dist
.QuadPart
= start
.QuadPart
;
530 SetFilePointerEx(This
->file
, dist
, NULL
, FILE_BEGIN
);
532 This
->first_read
= FALSE
;
534 hr
= textstream_read(This
, toread
, start
.QuadPart
== 0, text
);
535 return FAILED(hr
) ? hr
: S_FALSE
;
538 static HRESULT
textstream_writestr(struct textstream
*stream
, BSTR text
)
543 if (stream
->unicode
) {
544 ret
= WriteFile(stream
->file
, text
, SysStringByteLen(text
), &written
, NULL
);
545 return (ret
&& written
== SysStringByteLen(text
)) ? S_OK
: create_error(GetLastError());
547 DWORD len
= WideCharToMultiByte(CP_ACP
, 0, text
, SysStringLen(text
), NULL
, 0, NULL
, NULL
);
551 buffA
= heap_alloc(len
);
553 return E_OUTOFMEMORY
;
555 WideCharToMultiByte(CP_ACP
, 0, text
, SysStringLen(text
), buffA
, len
, NULL
, NULL
);
556 ret
= WriteFile(stream
->file
, buffA
, len
, &written
, NULL
);
557 hr
= (ret
&& written
== len
) ? S_OK
: create_error(GetLastError());
563 static HRESULT WINAPI
textstream_Write(ITextStream
*iface
, BSTR text
)
565 struct textstream
*This
= impl_from_ITextStream(iface
);
567 TRACE("(%p)->(%s)\n", This
, debugstr_w(text
));
569 if (textstream_check_iomode(This
, IOWrite
))
570 return CTL_E_BADFILEMODE
;
572 return textstream_writestr(This
, text
);
575 static HRESULT
textstream_writecrlf(struct textstream
*stream
)
577 static const WCHAR crlfW
[] = {'\r','\n'};
578 static const char crlfA
[] = {'\r','\n'};
579 DWORD written
= 0, len
;
583 if (stream
->unicode
) {
592 ret
= WriteFile(stream
->file
, ptr
, len
, &written
, NULL
);
593 return (ret
&& written
== len
) ? S_OK
: create_error(GetLastError());
596 static HRESULT WINAPI
textstream_WriteLine(ITextStream
*iface
, BSTR text
)
598 struct textstream
*This
= impl_from_ITextStream(iface
);
601 TRACE("(%p)->(%s)\n", This
, debugstr_w(text
));
603 if (textstream_check_iomode(This
, IOWrite
))
604 return CTL_E_BADFILEMODE
;
606 hr
= textstream_writestr(This
, text
);
608 hr
= textstream_writecrlf(This
);
612 static HRESULT WINAPI
textstream_WriteBlankLines(ITextStream
*iface
, LONG lines
)
614 struct textstream
*This
= impl_from_ITextStream(iface
);
615 FIXME("(%p)->(%d): stub\n", This
, lines
);
619 static HRESULT WINAPI
textstream_Skip(ITextStream
*iface
, LONG count
)
621 struct textstream
*This
= impl_from_ITextStream(iface
);
622 FIXME("(%p)->(%d): stub\n", This
, count
);
626 static HRESULT WINAPI
textstream_SkipLine(ITextStream
*iface
)
628 struct textstream
*This
= impl_from_ITextStream(iface
);
629 FIXME("(%p): stub\n", This
);
633 static HRESULT WINAPI
textstream_Close(ITextStream
*iface
)
635 struct textstream
*This
= impl_from_ITextStream(iface
);
636 FIXME("(%p): stub\n", This
);
640 static const ITextStreamVtbl textstreamvtbl
= {
641 textstream_QueryInterface
,
644 textstream_GetTypeInfoCount
,
645 textstream_GetTypeInfo
,
646 textstream_GetIDsOfNames
,
649 textstream_get_Column
,
650 textstream_get_AtEndOfStream
,
651 textstream_get_AtEndOfLine
,
656 textstream_WriteLine
,
657 textstream_WriteBlankLines
,
663 static HRESULT
create_textstream(const WCHAR
*filename
, DWORD disposition
, IOMode mode
, BOOL unicode
, ITextStream
**ret
)
665 struct textstream
*stream
;
668 /* map access mode */
672 access
= GENERIC_READ
;
675 access
= GENERIC_WRITE
;
678 access
= FILE_APPEND_DATA
;
684 stream
= heap_alloc(sizeof(struct textstream
));
685 if (!stream
) return E_OUTOFMEMORY
;
687 stream
->ITextStream_iface
.lpVtbl
= &textstreamvtbl
;
690 stream
->unicode
= unicode
;
691 stream
->first_read
= TRUE
;
693 stream
->file
= CreateFileW(filename
, access
, 0, NULL
, disposition
, FILE_ATTRIBUTE_NORMAL
, NULL
);
694 if (stream
->file
== INVALID_HANDLE_VALUE
)
696 HRESULT hr
= create_error(GetLastError());
701 if (mode
== ForReading
)
702 GetFileSizeEx(stream
->file
, &stream
->size
);
704 stream
->size
.QuadPart
= 0;
706 /* Write Unicode BOM */
707 if (unicode
&& mode
== ForWriting
&& (disposition
== CREATE_ALWAYS
|| disposition
== CREATE_NEW
)) {
709 BOOL ret
= WriteFile(stream
->file
, &utf16bom
, sizeof(utf16bom
), &written
, NULL
);
710 if (!ret
|| written
!= sizeof(utf16bom
)) {
711 ITextStream_Release(&stream
->ITextStream_iface
);
712 return create_error(GetLastError());
716 *ret
= &stream
->ITextStream_iface
;
720 static HRESULT WINAPI
drive_QueryInterface(IDrive
*iface
, REFIID riid
, void **obj
)
722 struct drive
*This
= impl_from_IDrive(iface
);
724 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), obj
);
728 if (IsEqualIID( riid
, &IID_IDrive
) ||
729 IsEqualIID( riid
, &IID_IDispatch
) ||
730 IsEqualIID( riid
, &IID_IUnknown
))
733 IDrive_AddRef(iface
);
736 return E_NOINTERFACE
;
741 static ULONG WINAPI
drive_AddRef(IDrive
*iface
)
743 struct drive
*This
= impl_from_IDrive(iface
);
744 ULONG ref
= InterlockedIncrement(&This
->ref
);
745 TRACE("(%p)->(%d)\n", This
, ref
);
749 static ULONG WINAPI
drive_Release(IDrive
*iface
)
751 struct drive
*This
= impl_from_IDrive(iface
);
752 ULONG ref
= InterlockedDecrement(&This
->ref
);
753 TRACE("(%p)->(%d)\n", This
, ref
);
757 SysFreeString(This
->root
);
764 static HRESULT WINAPI
drive_GetTypeInfoCount(IDrive
*iface
, UINT
*pctinfo
)
766 struct drive
*This
= impl_from_IDrive(iface
);
767 TRACE("(%p)->(%p)\n", This
, pctinfo
);
772 static HRESULT WINAPI
drive_GetTypeInfo(IDrive
*iface
, UINT iTInfo
,
773 LCID lcid
, ITypeInfo
**ppTInfo
)
775 struct drive
*This
= impl_from_IDrive(iface
);
776 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
777 return get_typeinfo(IDrive_tid
, ppTInfo
);
780 static HRESULT WINAPI
drive_GetIDsOfNames(IDrive
*iface
, REFIID riid
,
781 LPOLESTR
*rgszNames
, UINT cNames
,
782 LCID lcid
, DISPID
*rgDispId
)
784 struct drive
*This
= impl_from_IDrive(iface
);
788 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
, lcid
, rgDispId
);
790 hr
= get_typeinfo(IDrive_tid
, &typeinfo
);
793 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
794 ITypeInfo_Release(typeinfo
);
800 static HRESULT WINAPI
drive_Invoke(IDrive
*iface
, DISPID dispIdMember
,
801 REFIID riid
, LCID lcid
, WORD wFlags
,
802 DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
,
803 EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
805 struct drive
*This
= impl_from_IDrive(iface
);
809 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
810 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
812 hr
= get_typeinfo(IDrive_tid
, &typeinfo
);
815 hr
= ITypeInfo_Invoke(typeinfo
, iface
, dispIdMember
, wFlags
,
816 pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
817 ITypeInfo_Release(typeinfo
);
823 static HRESULT WINAPI
drive_get_Path(IDrive
*iface
, BSTR
*path
)
825 struct drive
*This
= impl_from_IDrive(iface
);
826 FIXME("(%p)->(%p): stub\n", This
, path
);
830 static HRESULT WINAPI
drive_get_DriveLetter(IDrive
*iface
, BSTR
*letter
)
832 struct drive
*This
= impl_from_IDrive(iface
);
834 TRACE("(%p)->(%p)\n", This
, letter
);
839 *letter
= SysAllocStringLen(This
->root
, 1);
841 return E_OUTOFMEMORY
;
846 static HRESULT WINAPI
drive_get_ShareName(IDrive
*iface
, BSTR
*share_name
)
848 struct drive
*This
= impl_from_IDrive(iface
);
849 FIXME("(%p)->(%p): stub\n", This
, share_name
);
853 static HRESULT WINAPI
drive_get_DriveType(IDrive
*iface
, DriveTypeConst
*type
)
855 struct drive
*This
= impl_from_IDrive(iface
);
857 TRACE("(%p)->(%p)\n", This
, type
);
859 switch (GetDriveTypeW(This
->root
))
861 case DRIVE_REMOVABLE
:
884 static HRESULT WINAPI
drive_get_RootFolder(IDrive
*iface
, IFolder
**folder
)
886 struct drive
*This
= impl_from_IDrive(iface
);
887 FIXME("(%p)->(%p): stub\n", This
, folder
);
891 static HRESULT
variant_from_largeint(const ULARGE_INTEGER
*src
, VARIANT
*v
)
895 if (src
->u
.HighPart
|| src
->u
.LowPart
> INT_MAX
)
898 hr
= VarR8FromUI8(src
->QuadPart
, &V_R8(v
));
903 V_I4(v
) = src
->u
.LowPart
;
909 static HRESULT WINAPI
drive_get_AvailableSpace(IDrive
*iface
, VARIANT
*v
)
911 struct drive
*This
= impl_from_IDrive(iface
);
912 ULARGE_INTEGER avail
;
914 TRACE("(%p)->(%p)\n", This
, v
);
919 if (!GetDiskFreeSpaceExW(This
->root
, &avail
, NULL
, NULL
))
922 return variant_from_largeint(&avail
, v
);
925 static HRESULT WINAPI
drive_get_FreeSpace(IDrive
*iface
, VARIANT
*v
)
927 struct drive
*This
= impl_from_IDrive(iface
);
928 ULARGE_INTEGER freespace
;
930 TRACE("(%p)->(%p)\n", This
, v
);
935 if (!GetDiskFreeSpaceExW(This
->root
, &freespace
, NULL
, NULL
))
938 return variant_from_largeint(&freespace
, v
);
941 static HRESULT WINAPI
drive_get_TotalSize(IDrive
*iface
, VARIANT
*v
)
943 struct drive
*This
= impl_from_IDrive(iface
);
944 ULARGE_INTEGER total
;
946 TRACE("(%p)->(%p)\n", This
, v
);
951 if (!GetDiskFreeSpaceExW(This
->root
, NULL
, &total
, NULL
))
954 return variant_from_largeint(&total
, v
);
957 static HRESULT WINAPI
drive_get_VolumeName(IDrive
*iface
, BSTR
*name
)
959 struct drive
*This
= impl_from_IDrive(iface
);
960 WCHAR nameW
[MAX_PATH
+1];
963 TRACE("(%p)->(%p)\n", This
, name
);
969 ret
= GetVolumeInformationW(This
->root
, nameW
, sizeof(nameW
)/sizeof(WCHAR
), NULL
, NULL
, NULL
, NULL
, 0);
971 *name
= SysAllocString(nameW
);
972 return ret
? S_OK
: E_FAIL
;
975 static HRESULT WINAPI
drive_put_VolumeName(IDrive
*iface
, BSTR name
)
977 struct drive
*This
= impl_from_IDrive(iface
);
978 FIXME("(%p)->(%s): stub\n", This
, debugstr_w(name
));
982 static HRESULT WINAPI
drive_get_FileSystem(IDrive
*iface
, BSTR
*fs
)
984 struct drive
*This
= impl_from_IDrive(iface
);
985 WCHAR nameW
[MAX_PATH
+1];
988 TRACE("(%p)->(%p)\n", This
, fs
);
994 ret
= GetVolumeInformationW(This
->root
, NULL
, 0, NULL
, NULL
, NULL
, nameW
, sizeof(nameW
)/sizeof(WCHAR
));
996 *fs
= SysAllocString(nameW
);
997 return ret
? S_OK
: E_FAIL
;
1000 static HRESULT WINAPI
drive_get_SerialNumber(IDrive
*iface
, LONG
*serial
)
1002 struct drive
*This
= impl_from_IDrive(iface
);
1005 TRACE("(%p)->(%p)\n", This
, serial
);
1010 ret
= GetVolumeInformationW(This
->root
, NULL
, 0, (DWORD
*)serial
, NULL
, NULL
, NULL
, 0);
1011 return ret
? S_OK
: E_FAIL
;
1014 static HRESULT WINAPI
drive_get_IsReady(IDrive
*iface
, VARIANT_BOOL
*ready
)
1016 struct drive
*This
= impl_from_IDrive(iface
);
1017 ULARGE_INTEGER freespace
;
1020 TRACE("(%p)->(%p)\n", This
, ready
);
1025 ret
= GetDiskFreeSpaceExW(This
->root
, &freespace
, NULL
, NULL
);
1026 *ready
= ret
? VARIANT_TRUE
: VARIANT_FALSE
;
1030 static const IDriveVtbl drivevtbl
= {
1031 drive_QueryInterface
,
1034 drive_GetTypeInfoCount
,
1036 drive_GetIDsOfNames
,
1039 drive_get_DriveLetter
,
1040 drive_get_ShareName
,
1041 drive_get_DriveType
,
1042 drive_get_RootFolder
,
1043 drive_get_AvailableSpace
,
1044 drive_get_FreeSpace
,
1045 drive_get_TotalSize
,
1046 drive_get_VolumeName
,
1047 drive_put_VolumeName
,
1048 drive_get_FileSystem
,
1049 drive_get_SerialNumber
,
1053 static HRESULT
create_drive(WCHAR letter
, IDrive
**drive
)
1059 This
= heap_alloc(sizeof(*This
));
1060 if (!This
) return E_OUTOFMEMORY
;
1062 This
->IDrive_iface
.lpVtbl
= &drivevtbl
;
1064 This
->root
= SysAllocStringLen(NULL
, 3);
1068 return E_OUTOFMEMORY
;
1070 This
->root
[0] = letter
;
1071 This
->root
[1] = ':';
1072 This
->root
[2] = '\\';
1075 *drive
= &This
->IDrive_iface
;
1079 static HRESULT WINAPI
enumvariant_QueryInterface(IEnumVARIANT
*iface
, REFIID riid
, void **obj
)
1081 struct enumvariant
*This
= impl_from_IEnumVARIANT(iface
);
1083 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), obj
);
1087 if (IsEqualIID( riid
, &IID_IEnumVARIANT
) ||
1088 IsEqualIID( riid
, &IID_IUnknown
))
1091 IEnumVARIANT_AddRef(iface
);
1094 return E_NOINTERFACE
;
1099 static ULONG WINAPI
enumvariant_AddRef(IEnumVARIANT
*iface
)
1101 struct enumvariant
*This
= impl_from_IEnumVARIANT(iface
);
1102 ULONG ref
= InterlockedIncrement(&This
->ref
);
1103 TRACE("(%p)->(%d)\n", This
, ref
);
1107 static ULONG WINAPI
foldercoll_enumvariant_Release(IEnumVARIANT
*iface
)
1109 struct enumvariant
*This
= impl_from_IEnumVARIANT(iface
);
1110 ULONG ref
= InterlockedDecrement(&This
->ref
);
1112 TRACE("(%p)->(%d)\n", This
, ref
);
1116 IFolderCollection_Release(&This
->data
.u
.foldercoll
.coll
->IFolderCollection_iface
);
1117 FindClose(This
->data
.u
.foldercoll
.find
);
1124 static HANDLE
start_enumeration(const WCHAR
*path
, WIN32_FIND_DATAW
*data
, BOOL file
)
1126 static const WCHAR allW
[] = {'*',0};
1127 WCHAR pathW
[MAX_PATH
];
1131 strcpyW(pathW
, path
);
1132 len
= strlenW(pathW
);
1133 if (len
&& pathW
[len
-1] != '\\')
1134 strcatW(pathW
, bsW
);
1135 strcatW(pathW
, allW
);
1136 handle
= FindFirstFileW(pathW
, data
);
1137 if (handle
== INVALID_HANDLE_VALUE
) return 0;
1139 /* find first dir/file */
1142 if (file
? is_file_data(data
) : is_dir_data(data
))
1145 if (!FindNextFileW(handle
, data
))
1154 static HRESULT WINAPI
foldercoll_enumvariant_Next(IEnumVARIANT
*iface
, ULONG celt
, VARIANT
*var
, ULONG
*fetched
)
1156 struct enumvariant
*This
= impl_from_IEnumVARIANT(iface
);
1157 HANDLE handle
= This
->data
.u
.foldercoll
.find
;
1158 WIN32_FIND_DATAW data
;
1161 TRACE("(%p)->(%d %p %p)\n", This
, celt
, var
, fetched
);
1166 if (!celt
) return S_OK
;
1170 handle
= start_enumeration(This
->data
.u
.foldercoll
.coll
->path
, &data
, FALSE
);
1171 if (!handle
) return S_FALSE
;
1173 This
->data
.u
.foldercoll
.find
= handle
;
1177 if (!FindNextFileW(handle
, &data
))
1183 if (is_dir_data(&data
))
1189 str
= get_full_path(This
->data
.u
.foldercoll
.coll
->path
, &data
);
1190 hr
= create_folder(str
, &folder
);
1192 if (FAILED(hr
)) return hr
;
1194 V_VT(&var
[count
]) = VT_DISPATCH
;
1195 V_DISPATCH(&var
[count
]) = (IDispatch
*)folder
;
1198 if (count
>= celt
) break;
1200 } while (FindNextFileW(handle
, &data
));
1205 return (count
< celt
) ? S_FALSE
: S_OK
;
1208 static HRESULT WINAPI
foldercoll_enumvariant_Skip(IEnumVARIANT
*iface
, ULONG celt
)
1210 struct enumvariant
*This
= impl_from_IEnumVARIANT(iface
);
1211 HANDLE handle
= This
->data
.u
.foldercoll
.find
;
1212 WIN32_FIND_DATAW data
;
1214 TRACE("(%p)->(%d)\n", This
, celt
);
1216 if (!celt
) return S_OK
;
1220 handle
= start_enumeration(This
->data
.u
.foldercoll
.coll
->path
, &data
, FALSE
);
1221 if (!handle
) return S_FALSE
;
1223 This
->data
.u
.foldercoll
.find
= handle
;
1227 if (!FindNextFileW(handle
, &data
))
1233 if (is_dir_data(&data
))
1237 } while (FindNextFileW(handle
, &data
));
1239 return celt
? S_FALSE
: S_OK
;
1242 static HRESULT WINAPI
foldercoll_enumvariant_Reset(IEnumVARIANT
*iface
)
1244 struct enumvariant
*This
= impl_from_IEnumVARIANT(iface
);
1246 TRACE("(%p)\n", This
);
1248 FindClose(This
->data
.u
.foldercoll
.find
);
1249 This
->data
.u
.foldercoll
.find
= NULL
;
1254 static HRESULT WINAPI
foldercoll_enumvariant_Clone(IEnumVARIANT
*iface
, IEnumVARIANT
**pclone
)
1256 struct enumvariant
*This
= impl_from_IEnumVARIANT(iface
);
1257 TRACE("(%p)->(%p)\n", This
, pclone
);
1258 return create_foldercoll_enum(This
->data
.u
.foldercoll
.coll
, (IUnknown
**)pclone
);
1261 static const IEnumVARIANTVtbl foldercollenumvariantvtbl
= {
1262 enumvariant_QueryInterface
,
1264 foldercoll_enumvariant_Release
,
1265 foldercoll_enumvariant_Next
,
1266 foldercoll_enumvariant_Skip
,
1267 foldercoll_enumvariant_Reset
,
1268 foldercoll_enumvariant_Clone
1271 static HRESULT
create_foldercoll_enum(struct foldercollection
*collection
, IUnknown
**newenum
)
1273 struct enumvariant
*This
;
1277 This
= heap_alloc(sizeof(*This
));
1278 if (!This
) return E_OUTOFMEMORY
;
1280 This
->IEnumVARIANT_iface
.lpVtbl
= &foldercollenumvariantvtbl
;
1282 This
->data
.u
.foldercoll
.find
= NULL
;
1283 This
->data
.u
.foldercoll
.coll
= collection
;
1284 IFolderCollection_AddRef(&collection
->IFolderCollection_iface
);
1286 *newenum
= (IUnknown
*)&This
->IEnumVARIANT_iface
;
1291 static ULONG WINAPI
filecoll_enumvariant_Release(IEnumVARIANT
*iface
)
1293 struct enumvariant
*This
= impl_from_IEnumVARIANT(iface
);
1294 ULONG ref
= InterlockedDecrement(&This
->ref
);
1296 TRACE("(%p)->(%d)\n", This
, ref
);
1300 IFileCollection_Release(&This
->data
.u
.filecoll
.coll
->IFileCollection_iface
);
1301 FindClose(This
->data
.u
.filecoll
.find
);
1308 static HRESULT WINAPI
filecoll_enumvariant_Next(IEnumVARIANT
*iface
, ULONG celt
, VARIANT
*var
, ULONG
*fetched
)
1310 struct enumvariant
*This
= impl_from_IEnumVARIANT(iface
);
1311 HANDLE handle
= This
->data
.u
.filecoll
.find
;
1312 WIN32_FIND_DATAW data
;
1315 TRACE("(%p)->(%d %p %p)\n", This
, celt
, var
, fetched
);
1320 if (!celt
) return S_OK
;
1324 handle
= start_enumeration(This
->data
.u
.filecoll
.coll
->path
, &data
, TRUE
);
1325 if (!handle
) return S_FALSE
;
1326 This
->data
.u
.filecoll
.find
= handle
;
1328 else if (!FindNextFileW(handle
, &data
))
1333 if (is_file_data(&data
))
1339 str
= get_full_path(This
->data
.u
.filecoll
.coll
->path
, &data
);
1340 hr
= create_file(str
, &file
);
1342 if (FAILED(hr
)) return hr
;
1344 V_VT(&var
[count
]) = VT_DISPATCH
;
1345 V_DISPATCH(&var
[count
]) = (IDispatch
*)file
;
1346 if (++count
>= celt
) break;
1348 } while (FindNextFileW(handle
, &data
));
1353 return (count
< celt
) ? S_FALSE
: S_OK
;
1356 static HRESULT WINAPI
filecoll_enumvariant_Skip(IEnumVARIANT
*iface
, ULONG celt
)
1358 struct enumvariant
*This
= impl_from_IEnumVARIANT(iface
);
1359 HANDLE handle
= This
->data
.u
.filecoll
.find
;
1360 WIN32_FIND_DATAW data
;
1362 TRACE("(%p)->(%d)\n", This
, celt
);
1364 if (!celt
) return S_OK
;
1368 handle
= start_enumeration(This
->data
.u
.filecoll
.coll
->path
, &data
, TRUE
);
1369 if (!handle
) return S_FALSE
;
1370 This
->data
.u
.filecoll
.find
= handle
;
1372 else if (!FindNextFileW(handle
, &data
))
1377 if (is_file_data(&data
))
1379 } while (celt
&& FindNextFileW(handle
, &data
));
1381 return celt
? S_FALSE
: S_OK
;
1384 static HRESULT WINAPI
filecoll_enumvariant_Reset(IEnumVARIANT
*iface
)
1386 struct enumvariant
*This
= impl_from_IEnumVARIANT(iface
);
1388 TRACE("(%p)\n", This
);
1390 FindClose(This
->data
.u
.filecoll
.find
);
1391 This
->data
.u
.filecoll
.find
= NULL
;
1396 static HRESULT WINAPI
filecoll_enumvariant_Clone(IEnumVARIANT
*iface
, IEnumVARIANT
**pclone
)
1398 struct enumvariant
*This
= impl_from_IEnumVARIANT(iface
);
1399 TRACE("(%p)->(%p)\n", This
, pclone
);
1400 return create_filecoll_enum(This
->data
.u
.filecoll
.coll
, (IUnknown
**)pclone
);
1403 static const IEnumVARIANTVtbl filecollenumvariantvtbl
= {
1404 enumvariant_QueryInterface
,
1406 filecoll_enumvariant_Release
,
1407 filecoll_enumvariant_Next
,
1408 filecoll_enumvariant_Skip
,
1409 filecoll_enumvariant_Reset
,
1410 filecoll_enumvariant_Clone
1413 static HRESULT
create_filecoll_enum(struct filecollection
*collection
, IUnknown
**newenum
)
1415 struct enumvariant
*This
;
1419 This
= heap_alloc(sizeof(*This
));
1420 if (!This
) return E_OUTOFMEMORY
;
1422 This
->IEnumVARIANT_iface
.lpVtbl
= &filecollenumvariantvtbl
;
1424 This
->data
.u
.filecoll
.find
= NULL
;
1425 This
->data
.u
.filecoll
.coll
= collection
;
1426 IFileCollection_AddRef(&collection
->IFileCollection_iface
);
1428 *newenum
= (IUnknown
*)&This
->IEnumVARIANT_iface
;
1433 static ULONG WINAPI
drivecoll_enumvariant_Release(IEnumVARIANT
*iface
)
1435 struct enumvariant
*This
= impl_from_IEnumVARIANT(iface
);
1436 ULONG ref
= InterlockedDecrement(&This
->ref
);
1438 TRACE("(%p)->(%d)\n", This
, ref
);
1442 IDriveCollection_Release(&This
->data
.u
.drivecoll
.coll
->IDriveCollection_iface
);
1449 static HRESULT
find_next_drive(struct enumvariant
*penum
)
1451 int i
= penum
->data
.u
.drivecoll
.cur
== -1 ? 0 : penum
->data
.u
.drivecoll
.cur
+ 1;
1454 if (penum
->data
.u
.drivecoll
.coll
->drives
& (1 << i
))
1456 penum
->data
.u
.drivecoll
.cur
= i
;
1463 static HRESULT WINAPI
drivecoll_enumvariant_Next(IEnumVARIANT
*iface
, ULONG celt
, VARIANT
*var
, ULONG
*fetched
)
1465 struct enumvariant
*This
= impl_from_IEnumVARIANT(iface
);
1468 TRACE("(%p)->(%d %p %p)\n", This
, celt
, var
, fetched
);
1473 if (!celt
) return S_OK
;
1475 while (find_next_drive(This
) == S_OK
)
1480 hr
= create_drive('A' + This
->data
.u
.drivecoll
.cur
, &drive
);
1481 if (FAILED(hr
)) return hr
;
1483 V_VT(&var
[count
]) = VT_DISPATCH
;
1484 V_DISPATCH(&var
[count
]) = (IDispatch
*)drive
;
1486 if (++count
>= celt
) break;
1492 return (count
< celt
) ? S_FALSE
: S_OK
;
1495 static HRESULT WINAPI
drivecoll_enumvariant_Skip(IEnumVARIANT
*iface
, ULONG celt
)
1497 struct enumvariant
*This
= impl_from_IEnumVARIANT(iface
);
1499 TRACE("(%p)->(%d)\n", This
, celt
);
1501 if (!celt
) return S_OK
;
1503 while (celt
&& find_next_drive(This
) == S_OK
)
1506 return celt
? S_FALSE
: S_OK
;
1509 static HRESULT WINAPI
drivecoll_enumvariant_Reset(IEnumVARIANT
*iface
)
1511 struct enumvariant
*This
= impl_from_IEnumVARIANT(iface
);
1513 TRACE("(%p)\n", This
);
1515 This
->data
.u
.drivecoll
.cur
= -1;
1519 static HRESULT WINAPI
drivecoll_enumvariant_Clone(IEnumVARIANT
*iface
, IEnumVARIANT
**pclone
)
1521 struct enumvariant
*This
= impl_from_IEnumVARIANT(iface
);
1522 FIXME("(%p)->(%p): stub\n", This
, pclone
);
1526 static const IEnumVARIANTVtbl drivecollenumvariantvtbl
= {
1527 enumvariant_QueryInterface
,
1529 drivecoll_enumvariant_Release
,
1530 drivecoll_enumvariant_Next
,
1531 drivecoll_enumvariant_Skip
,
1532 drivecoll_enumvariant_Reset
,
1533 drivecoll_enumvariant_Clone
1536 static HRESULT
create_drivecoll_enum(struct drivecollection
*collection
, IUnknown
**newenum
)
1538 struct enumvariant
*This
;
1542 This
= heap_alloc(sizeof(*This
));
1543 if (!This
) return E_OUTOFMEMORY
;
1545 This
->IEnumVARIANT_iface
.lpVtbl
= &drivecollenumvariantvtbl
;
1547 This
->data
.u
.drivecoll
.coll
= collection
;
1548 This
->data
.u
.drivecoll
.cur
= -1;
1549 IDriveCollection_AddRef(&collection
->IDriveCollection_iface
);
1551 *newenum
= (IUnknown
*)&This
->IEnumVARIANT_iface
;
1556 static HRESULT WINAPI
foldercoll_QueryInterface(IFolderCollection
*iface
, REFIID riid
, void **obj
)
1558 struct foldercollection
*This
= impl_from_IFolderCollection(iface
);
1560 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), obj
);
1564 if (IsEqualIID( riid
, &IID_IFolderCollection
) ||
1565 IsEqualIID( riid
, &IID_IDispatch
) ||
1566 IsEqualIID( riid
, &IID_IUnknown
))
1569 IFolderCollection_AddRef(iface
);
1572 return E_NOINTERFACE
;
1577 static ULONG WINAPI
foldercoll_AddRef(IFolderCollection
*iface
)
1579 struct foldercollection
*This
= impl_from_IFolderCollection(iface
);
1580 ULONG ref
= InterlockedIncrement(&This
->ref
);
1581 TRACE("(%p)->(%d)\n", This
, ref
);
1585 static ULONG WINAPI
foldercoll_Release(IFolderCollection
*iface
)
1587 struct foldercollection
*This
= impl_from_IFolderCollection(iface
);
1588 ULONG ref
= InterlockedDecrement(&This
->ref
);
1589 TRACE("(%p)->(%d)\n", This
, ref
);
1593 SysFreeString(This
->path
);
1600 static HRESULT WINAPI
foldercoll_GetTypeInfoCount(IFolderCollection
*iface
, UINT
*pctinfo
)
1602 struct foldercollection
*This
= impl_from_IFolderCollection(iface
);
1603 TRACE("(%p)->(%p)\n", This
, pctinfo
);
1608 static HRESULT WINAPI
foldercoll_GetTypeInfo(IFolderCollection
*iface
, UINT iTInfo
,
1609 LCID lcid
, ITypeInfo
**ppTInfo
)
1611 struct foldercollection
*This
= impl_from_IFolderCollection(iface
);
1612 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
1613 return get_typeinfo(IFolderCollection_tid
, ppTInfo
);
1616 static HRESULT WINAPI
foldercoll_GetIDsOfNames(IFolderCollection
*iface
, REFIID riid
,
1617 LPOLESTR
*rgszNames
, UINT cNames
,
1618 LCID lcid
, DISPID
*rgDispId
)
1620 struct foldercollection
*This
= impl_from_IFolderCollection(iface
);
1621 ITypeInfo
*typeinfo
;
1624 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
, lcid
, rgDispId
);
1626 hr
= get_typeinfo(IFolderCollection_tid
, &typeinfo
);
1629 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
1630 ITypeInfo_Release(typeinfo
);
1636 static HRESULT WINAPI
foldercoll_Invoke(IFolderCollection
*iface
, DISPID dispIdMember
,
1637 REFIID riid
, LCID lcid
, WORD wFlags
,
1638 DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
,
1639 EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
1641 struct foldercollection
*This
= impl_from_IFolderCollection(iface
);
1642 ITypeInfo
*typeinfo
;
1645 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
1646 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1648 hr
= get_typeinfo(IFolderCollection_tid
, &typeinfo
);
1651 hr
= ITypeInfo_Invoke(typeinfo
, iface
, dispIdMember
, wFlags
,
1652 pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1653 ITypeInfo_Release(typeinfo
);
1659 static HRESULT WINAPI
foldercoll_Add(IFolderCollection
*iface
, BSTR name
, IFolder
**folder
)
1661 struct foldercollection
*This
= impl_from_IFolderCollection(iface
);
1662 FIXME("(%p)->(%s %p): stub\n", This
, debugstr_w(name
), folder
);
1666 static HRESULT WINAPI
foldercoll_get_Item(IFolderCollection
*iface
, VARIANT key
, IFolder
**folder
)
1668 struct foldercollection
*This
= impl_from_IFolderCollection(iface
);
1669 FIXME("(%p)->(%p): stub\n", This
, folder
);
1673 static HRESULT WINAPI
foldercoll_get__NewEnum(IFolderCollection
*iface
, IUnknown
**newenum
)
1675 struct foldercollection
*This
= impl_from_IFolderCollection(iface
);
1677 TRACE("(%p)->(%p)\n", This
, newenum
);
1682 return create_foldercoll_enum(This
, newenum
);
1685 static HRESULT WINAPI
foldercoll_get_Count(IFolderCollection
*iface
, LONG
*count
)
1687 struct foldercollection
*This
= impl_from_IFolderCollection(iface
);
1688 static const WCHAR allW
[] = {'\\','*',0};
1689 WIN32_FIND_DATAW data
;
1690 WCHAR pathW
[MAX_PATH
];
1693 TRACE("(%p)->(%p)\n", This
, count
);
1700 strcpyW(pathW
, This
->path
);
1701 strcatW(pathW
, allW
);
1702 handle
= FindFirstFileW(pathW
, &data
);
1703 if (handle
== INVALID_HANDLE_VALUE
)
1704 return HRESULT_FROM_WIN32(GetLastError());
1708 if (is_dir_data(&data
))
1710 } while (FindNextFileW(handle
, &data
));
1716 static const IFolderCollectionVtbl foldercollvtbl
= {
1717 foldercoll_QueryInterface
,
1720 foldercoll_GetTypeInfoCount
,
1721 foldercoll_GetTypeInfo
,
1722 foldercoll_GetIDsOfNames
,
1725 foldercoll_get_Item
,
1726 foldercoll_get__NewEnum
,
1727 foldercoll_get_Count
1730 static HRESULT
create_foldercoll(BSTR path
, IFolderCollection
**folders
)
1732 struct foldercollection
*This
;
1736 This
= heap_alloc(sizeof(struct foldercollection
));
1737 if (!This
) return E_OUTOFMEMORY
;
1739 This
->IFolderCollection_iface
.lpVtbl
= &foldercollvtbl
;
1741 This
->path
= SysAllocString(path
);
1745 return E_OUTOFMEMORY
;
1748 *folders
= &This
->IFolderCollection_iface
;
1753 static HRESULT WINAPI
filecoll_QueryInterface(IFileCollection
*iface
, REFIID riid
, void **obj
)
1755 struct filecollection
*This
= impl_from_IFileCollection(iface
);
1757 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), obj
);
1761 if (IsEqualIID( riid
, &IID_IFileCollection
) ||
1762 IsEqualIID( riid
, &IID_IDispatch
) ||
1763 IsEqualIID( riid
, &IID_IUnknown
))
1766 IFileCollection_AddRef(iface
);
1769 return E_NOINTERFACE
;
1774 static ULONG WINAPI
filecoll_AddRef(IFileCollection
*iface
)
1776 struct filecollection
*This
= impl_from_IFileCollection(iface
);
1777 ULONG ref
= InterlockedIncrement(&This
->ref
);
1778 TRACE("(%p)->(%d)\n", This
, ref
);
1782 static ULONG WINAPI
filecoll_Release(IFileCollection
*iface
)
1784 struct filecollection
*This
= impl_from_IFileCollection(iface
);
1785 ULONG ref
= InterlockedDecrement(&This
->ref
);
1786 TRACE("(%p)->(%d)\n", This
, ref
);
1790 SysFreeString(This
->path
);
1797 static HRESULT WINAPI
filecoll_GetTypeInfoCount(IFileCollection
*iface
, UINT
*pctinfo
)
1799 struct filecollection
*This
= impl_from_IFileCollection(iface
);
1800 TRACE("(%p)->(%p)\n", This
, pctinfo
);
1805 static HRESULT WINAPI
filecoll_GetTypeInfo(IFileCollection
*iface
, UINT iTInfo
,
1806 LCID lcid
, ITypeInfo
**ppTInfo
)
1808 struct filecollection
*This
= impl_from_IFileCollection(iface
);
1809 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
1810 return get_typeinfo(IFileCollection_tid
, ppTInfo
);
1813 static HRESULT WINAPI
filecoll_GetIDsOfNames(IFileCollection
*iface
, REFIID riid
,
1814 LPOLESTR
*rgszNames
, UINT cNames
,
1815 LCID lcid
, DISPID
*rgDispId
)
1817 struct filecollection
*This
= impl_from_IFileCollection(iface
);
1818 ITypeInfo
*typeinfo
;
1821 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
, lcid
, rgDispId
);
1823 hr
= get_typeinfo(IFileCollection_tid
, &typeinfo
);
1826 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
1827 ITypeInfo_Release(typeinfo
);
1833 static HRESULT WINAPI
filecoll_Invoke(IFileCollection
*iface
, DISPID dispIdMember
,
1834 REFIID riid
, LCID lcid
, WORD wFlags
,
1835 DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
,
1836 EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
1838 struct filecollection
*This
= impl_from_IFileCollection(iface
);
1839 ITypeInfo
*typeinfo
;
1842 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
1843 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1845 hr
= get_typeinfo(IFileCollection_tid
, &typeinfo
);
1848 hr
= ITypeInfo_Invoke(typeinfo
, iface
, dispIdMember
, wFlags
,
1849 pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1850 ITypeInfo_Release(typeinfo
);
1856 static HRESULT WINAPI
filecoll_get_Item(IFileCollection
*iface
, VARIANT Key
, IFile
**file
)
1858 struct filecollection
*This
= impl_from_IFileCollection(iface
);
1859 FIXME("(%p)->(%p)\n", This
, file
);
1863 static HRESULT WINAPI
filecoll_get__NewEnum(IFileCollection
*iface
, IUnknown
**ppenum
)
1865 struct filecollection
*This
= impl_from_IFileCollection(iface
);
1867 TRACE("(%p)->(%p)\n", This
, ppenum
);
1872 return create_filecoll_enum(This
, ppenum
);
1875 static HRESULT WINAPI
filecoll_get_Count(IFileCollection
*iface
, LONG
*count
)
1877 struct filecollection
*This
= impl_from_IFileCollection(iface
);
1878 static const WCHAR allW
[] = {'\\','*',0};
1879 WIN32_FIND_DATAW data
;
1880 WCHAR pathW
[MAX_PATH
];
1883 TRACE("(%p)->(%p)\n", This
, count
);
1890 strcpyW(pathW
, This
->path
);
1891 strcatW(pathW
, allW
);
1892 handle
= FindFirstFileW(pathW
, &data
);
1893 if (handle
== INVALID_HANDLE_VALUE
)
1894 return HRESULT_FROM_WIN32(GetLastError());
1898 if (is_file_data(&data
))
1900 } while (FindNextFileW(handle
, &data
));
1906 static const IFileCollectionVtbl filecollectionvtbl
= {
1907 filecoll_QueryInterface
,
1910 filecoll_GetTypeInfoCount
,
1911 filecoll_GetTypeInfo
,
1912 filecoll_GetIDsOfNames
,
1915 filecoll_get__NewEnum
,
1919 static HRESULT
create_filecoll(BSTR path
, IFileCollection
**files
)
1921 struct filecollection
*This
;
1925 This
= heap_alloc(sizeof(*This
));
1926 if (!This
) return E_OUTOFMEMORY
;
1928 This
->IFileCollection_iface
.lpVtbl
= &filecollectionvtbl
;
1930 This
->path
= SysAllocString(path
);
1934 return E_OUTOFMEMORY
;
1937 *files
= &This
->IFileCollection_iface
;
1941 static HRESULT WINAPI
drivecoll_QueryInterface(IDriveCollection
*iface
, REFIID riid
, void **obj
)
1943 struct drivecollection
*This
= impl_from_IDriveCollection(iface
);
1945 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), obj
);
1949 if (IsEqualIID( riid
, &IID_IDriveCollection
) ||
1950 IsEqualIID( riid
, &IID_IDispatch
) ||
1951 IsEqualIID( riid
, &IID_IUnknown
))
1954 IDriveCollection_AddRef(iface
);
1957 return E_NOINTERFACE
;
1962 static ULONG WINAPI
drivecoll_AddRef(IDriveCollection
*iface
)
1964 struct drivecollection
*This
= impl_from_IDriveCollection(iface
);
1965 ULONG ref
= InterlockedIncrement(&This
->ref
);
1966 TRACE("(%p)->(%d)\n", This
, ref
);
1970 static ULONG WINAPI
drivecoll_Release(IDriveCollection
*iface
)
1972 struct drivecollection
*This
= impl_from_IDriveCollection(iface
);
1973 ULONG ref
= InterlockedDecrement(&This
->ref
);
1974 TRACE("(%p)->(%d)\n", This
, ref
);
1982 static HRESULT WINAPI
drivecoll_GetTypeInfoCount(IDriveCollection
*iface
, UINT
*pctinfo
)
1984 struct drivecollection
*This
= impl_from_IDriveCollection(iface
);
1985 TRACE("(%p)->(%p)\n", This
, pctinfo
);
1990 static HRESULT WINAPI
drivecoll_GetTypeInfo(IDriveCollection
*iface
, UINT iTInfo
,
1991 LCID lcid
, ITypeInfo
**ppTInfo
)
1993 struct drivecollection
*This
= impl_from_IDriveCollection(iface
);
1994 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
1995 return get_typeinfo(IDriveCollection_tid
, ppTInfo
);
1998 static HRESULT WINAPI
drivecoll_GetIDsOfNames(IDriveCollection
*iface
, REFIID riid
,
1999 LPOLESTR
*rgszNames
, UINT cNames
,
2000 LCID lcid
, DISPID
*rgDispId
)
2002 struct drivecollection
*This
= impl_from_IDriveCollection(iface
);
2003 ITypeInfo
*typeinfo
;
2006 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
, lcid
, rgDispId
);
2008 hr
= get_typeinfo(IDriveCollection_tid
, &typeinfo
);
2011 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
2012 ITypeInfo_Release(typeinfo
);
2018 static HRESULT WINAPI
drivecoll_Invoke(IDriveCollection
*iface
, DISPID dispIdMember
,
2019 REFIID riid
, LCID lcid
, WORD wFlags
,
2020 DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
,
2021 EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
2023 struct drivecollection
*This
= impl_from_IDriveCollection(iface
);
2024 ITypeInfo
*typeinfo
;
2027 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
2028 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
2030 hr
= get_typeinfo(IDriveCollection_tid
, &typeinfo
);
2033 hr
= ITypeInfo_Invoke(typeinfo
, iface
, dispIdMember
, wFlags
,
2034 pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
2035 ITypeInfo_Release(typeinfo
);
2041 static HRESULT WINAPI
drivecoll_get_Item(IDriveCollection
*iface
, VARIANT key
, IDrive
**drive
)
2043 struct drivecollection
*This
= impl_from_IDriveCollection(iface
);
2044 FIXME("(%p)->(%p): stub\n", This
, drive
);
2048 static HRESULT WINAPI
drivecoll_get__NewEnum(IDriveCollection
*iface
, IUnknown
**ppenum
)
2050 struct drivecollection
*This
= impl_from_IDriveCollection(iface
);
2052 TRACE("(%p)->(%p)\n", This
, ppenum
);
2057 return create_drivecoll_enum(This
, ppenum
);
2060 static HRESULT WINAPI
drivecoll_get_Count(IDriveCollection
*iface
, LONG
*count
)
2062 struct drivecollection
*This
= impl_from_IDriveCollection(iface
);
2064 TRACE("(%p)->(%p)\n", This
, count
);
2066 if (!count
) return E_POINTER
;
2068 *count
= This
->count
;
2072 static const IDriveCollectionVtbl drivecollectionvtbl
= {
2073 drivecoll_QueryInterface
,
2076 drivecoll_GetTypeInfoCount
,
2077 drivecoll_GetTypeInfo
,
2078 drivecoll_GetIDsOfNames
,
2081 drivecoll_get__NewEnum
,
2085 static HRESULT
create_drivecoll(IDriveCollection
**drives
)
2087 struct drivecollection
*This
;
2092 This
= heap_alloc(sizeof(*This
));
2093 if (!This
) return E_OUTOFMEMORY
;
2095 This
->IDriveCollection_iface
.lpVtbl
= &drivecollectionvtbl
;
2097 This
->drives
= mask
= GetLogicalDrives();
2098 /* count set bits */
2099 for (This
->count
= 0; mask
; This
->count
++)
2102 *drives
= &This
->IDriveCollection_iface
;
2106 static HRESULT WINAPI
folder_QueryInterface(IFolder
*iface
, REFIID riid
, void **obj
)
2108 struct folder
*This
= impl_from_IFolder(iface
);
2110 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), obj
);
2114 if (IsEqualIID( riid
, &IID_IFolder
) ||
2115 IsEqualIID( riid
, &IID_IDispatch
) ||
2116 IsEqualIID( riid
, &IID_IUnknown
))
2119 IFolder_AddRef(iface
);
2122 return E_NOINTERFACE
;
2127 static ULONG WINAPI
folder_AddRef(IFolder
*iface
)
2129 struct folder
*This
= impl_from_IFolder(iface
);
2130 ULONG ref
= InterlockedIncrement(&This
->ref
);
2131 TRACE("(%p)->(%d)\n", This
, ref
);
2135 static ULONG WINAPI
folder_Release(IFolder
*iface
)
2137 struct folder
*This
= impl_from_IFolder(iface
);
2138 ULONG ref
= InterlockedDecrement(&This
->ref
);
2139 TRACE("(%p)->(%d)\n", This
, ref
);
2143 SysFreeString(This
->path
);
2150 static HRESULT WINAPI
folder_GetTypeInfoCount(IFolder
*iface
, UINT
*pctinfo
)
2152 struct folder
*This
= impl_from_IFolder(iface
);
2153 TRACE("(%p)->(%p)\n", This
, pctinfo
);
2158 static HRESULT WINAPI
folder_GetTypeInfo(IFolder
*iface
, UINT iTInfo
,
2159 LCID lcid
, ITypeInfo
**ppTInfo
)
2161 struct folder
*This
= impl_from_IFolder(iface
);
2162 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
2163 return get_typeinfo(IFolder_tid
, ppTInfo
);
2166 static HRESULT WINAPI
folder_GetIDsOfNames(IFolder
*iface
, REFIID riid
,
2167 LPOLESTR
*rgszNames
, UINT cNames
,
2168 LCID lcid
, DISPID
*rgDispId
)
2170 struct folder
*This
= impl_from_IFolder(iface
);
2171 ITypeInfo
*typeinfo
;
2174 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
, lcid
, rgDispId
);
2176 hr
= get_typeinfo(IFolder_tid
, &typeinfo
);
2179 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
2180 ITypeInfo_Release(typeinfo
);
2186 static HRESULT WINAPI
folder_Invoke(IFolder
*iface
, DISPID dispIdMember
,
2187 REFIID riid
, LCID lcid
, WORD wFlags
,
2188 DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
,
2189 EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
2191 struct folder
*This
= impl_from_IFolder(iface
);
2192 ITypeInfo
*typeinfo
;
2195 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
2196 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
2198 hr
= get_typeinfo(IFolder_tid
, &typeinfo
);
2201 hr
= ITypeInfo_Invoke(typeinfo
, iface
, dispIdMember
, wFlags
,
2202 pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
2203 ITypeInfo_Release(typeinfo
);
2209 static HRESULT WINAPI
folder_get_Path(IFolder
*iface
, BSTR
*path
)
2211 struct folder
*This
= impl_from_IFolder(iface
);
2213 TRACE("(%p)->(%p)\n", This
, path
);
2218 *path
= SysAllocString(This
->path
);
2219 return *path
? S_OK
: E_OUTOFMEMORY
;
2222 static HRESULT WINAPI
folder_get_Name(IFolder
*iface
, BSTR
*name
)
2224 struct folder
*This
= impl_from_IFolder(iface
);
2227 TRACE("(%p)->(%p)\n", This
, name
);
2234 ptr
= strrchrW(This
->path
, '\\');
2237 *name
= SysAllocString(ptr
+1);
2238 TRACE("%s\n", debugstr_w(*name
));
2239 if (!*name
) return E_OUTOFMEMORY
;
2247 static HRESULT WINAPI
folder_put_Name(IFolder
*iface
, BSTR name
)
2249 struct folder
*This
= impl_from_IFolder(iface
);
2250 FIXME("(%p)->(%s): stub\n", This
, debugstr_w(name
));
2254 static HRESULT WINAPI
folder_get_ShortPath(IFolder
*iface
, BSTR
*path
)
2256 struct folder
*This
= impl_from_IFolder(iface
);
2257 FIXME("(%p)->(%p): stub\n", This
, path
);
2261 static HRESULT WINAPI
folder_get_ShortName(IFolder
*iface
, BSTR
*name
)
2263 struct folder
*This
= impl_from_IFolder(iface
);
2264 FIXME("(%p)->(%p): stub\n", This
, name
);
2268 static HRESULT WINAPI
folder_get_Drive(IFolder
*iface
, IDrive
**drive
)
2270 struct folder
*This
= impl_from_IFolder(iface
);
2271 FIXME("(%p)->(%p): stub\n", This
, drive
);
2275 static HRESULT WINAPI
folder_get_ParentFolder(IFolder
*iface
, IFolder
**parent
)
2277 struct folder
*This
= impl_from_IFolder(iface
);
2278 FIXME("(%p)->(%p): stub\n", This
, parent
);
2282 static HRESULT WINAPI
folder_get_Attributes(IFolder
*iface
, FileAttribute
*attr
)
2284 struct folder
*This
= impl_from_IFolder(iface
);
2285 FIXME("(%p)->(%p): stub\n", This
, attr
);
2289 static HRESULT WINAPI
folder_put_Attributes(IFolder
*iface
, FileAttribute attr
)
2291 struct folder
*This
= impl_from_IFolder(iface
);
2292 FIXME("(%p)->(0x%x): stub\n", This
, attr
);
2296 static HRESULT WINAPI
folder_get_DateCreated(IFolder
*iface
, DATE
*date
)
2298 struct folder
*This
= impl_from_IFolder(iface
);
2299 FIXME("(%p)->(%p): stub\n", This
, date
);
2303 static HRESULT WINAPI
folder_get_DateLastModified(IFolder
*iface
, DATE
*date
)
2305 struct folder
*This
= impl_from_IFolder(iface
);
2306 FIXME("(%p)->(%p): stub\n", This
, date
);
2310 static HRESULT WINAPI
folder_get_DateLastAccessed(IFolder
*iface
, DATE
*date
)
2312 struct folder
*This
= impl_from_IFolder(iface
);
2313 FIXME("(%p)->(%p): stub\n", This
, date
);
2317 static HRESULT WINAPI
folder_get_Type(IFolder
*iface
, BSTR
*type
)
2319 struct folder
*This
= impl_from_IFolder(iface
);
2320 FIXME("(%p)->(%p): stub\n", This
, type
);
2324 static HRESULT WINAPI
folder_Delete(IFolder
*iface
, VARIANT_BOOL force
)
2326 struct folder
*This
= impl_from_IFolder(iface
);
2327 FIXME("(%p)->(%x): stub\n", This
, force
);
2331 static HRESULT WINAPI
folder_Copy(IFolder
*iface
, BSTR dest
, VARIANT_BOOL overwrite
)
2333 struct folder
*This
= impl_from_IFolder(iface
);
2334 FIXME("(%p)->(%s %x): stub\n", This
, debugstr_w(dest
), overwrite
);
2338 static HRESULT WINAPI
folder_Move(IFolder
*iface
, BSTR dest
)
2340 struct folder
*This
= impl_from_IFolder(iface
);
2341 FIXME("(%p)->(%s): stub\n", This
, debugstr_w(dest
));
2345 static HRESULT WINAPI
folder_get_IsRootFolder(IFolder
*iface
, VARIANT_BOOL
*isroot
)
2347 struct folder
*This
= impl_from_IFolder(iface
);
2348 FIXME("(%p)->(%p): stub\n", This
, isroot
);
2352 static HRESULT WINAPI
folder_get_Size(IFolder
*iface
, VARIANT
*size
)
2354 struct folder
*This
= impl_from_IFolder(iface
);
2355 FIXME("(%p)->(%p): stub\n", This
, size
);
2359 static HRESULT WINAPI
folder_get_SubFolders(IFolder
*iface
, IFolderCollection
**folders
)
2361 struct folder
*This
= impl_from_IFolder(iface
);
2363 TRACE("(%p)->(%p)\n", This
, folders
);
2368 return create_foldercoll(This
->path
, folders
);
2371 static HRESULT WINAPI
folder_get_Files(IFolder
*iface
, IFileCollection
**files
)
2373 struct folder
*This
= impl_from_IFolder(iface
);
2375 TRACE("(%p)->(%p)\n", This
, files
);
2380 return create_filecoll(This
->path
, files
);
2383 static HRESULT WINAPI
folder_CreateTextFile(IFolder
*iface
, BSTR filename
, VARIANT_BOOL overwrite
,
2384 VARIANT_BOOL unicode
, ITextStream
**stream
)
2386 struct folder
*This
= impl_from_IFolder(iface
);
2387 FIXME("(%p)->(%s %x %x %p): stub\n", This
, debugstr_w(filename
), overwrite
, unicode
, stream
);
2391 static const IFolderVtbl foldervtbl
= {
2392 folder_QueryInterface
,
2395 folder_GetTypeInfoCount
,
2397 folder_GetIDsOfNames
,
2402 folder_get_ShortPath
,
2403 folder_get_ShortName
,
2405 folder_get_ParentFolder
,
2406 folder_get_Attributes
,
2407 folder_put_Attributes
,
2408 folder_get_DateCreated
,
2409 folder_get_DateLastModified
,
2410 folder_get_DateLastAccessed
,
2415 folder_get_IsRootFolder
,
2417 folder_get_SubFolders
,
2419 folder_CreateTextFile
2422 HRESULT
create_folder(const WCHAR
*path
, IFolder
**folder
)
2424 struct folder
*This
;
2428 TRACE("%s\n", debugstr_w(path
));
2430 This
= heap_alloc(sizeof(struct folder
));
2431 if (!This
) return E_OUTOFMEMORY
;
2433 This
->IFolder_iface
.lpVtbl
= &foldervtbl
;
2435 This
->path
= SysAllocString(path
);
2439 return E_OUTOFMEMORY
;
2442 *folder
= &This
->IFolder_iface
;
2447 static HRESULT WINAPI
file_QueryInterface(IFile
*iface
, REFIID riid
, void **obj
)
2449 struct file
*This
= impl_from_IFile(iface
);
2451 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), obj
);
2453 if (IsEqualIID(riid
, &IID_IFile
) ||
2454 IsEqualIID(riid
, &IID_IDispatch
) ||
2455 IsEqualIID(riid
, &IID_IUnknown
))
2458 IFile_AddRef(iface
);
2463 return E_NOINTERFACE
;
2466 static ULONG WINAPI
file_AddRef(IFile
*iface
)
2468 struct file
*This
= impl_from_IFile(iface
);
2469 LONG ref
= InterlockedIncrement(&This
->ref
);
2471 TRACE("(%p) ref=%d\n", This
, ref
);
2476 static ULONG WINAPI
file_Release(IFile
*iface
)
2478 struct file
*This
= impl_from_IFile(iface
);
2479 LONG ref
= InterlockedDecrement(&This
->ref
);
2481 TRACE("(%p) ref=%d\n", This
, ref
);
2485 heap_free(This
->path
);
2492 static HRESULT WINAPI
file_GetTypeInfoCount(IFile
*iface
, UINT
*pctinfo
)
2494 struct file
*This
= impl_from_IFile(iface
);
2496 TRACE("(%p)->(%p)\n", This
, pctinfo
);
2502 static HRESULT WINAPI
file_GetTypeInfo(IFile
*iface
,
2503 UINT iTInfo
, LCID lcid
, ITypeInfo
**ppTInfo
)
2505 struct file
*This
= impl_from_IFile(iface
);
2507 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
2509 return get_typeinfo(IFile_tid
, ppTInfo
);
2512 static HRESULT WINAPI
file_GetIDsOfNames(IFile
*iface
, REFIID riid
,
2513 LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
2515 struct file
*This
= impl_from_IFile(iface
);
2516 ITypeInfo
*typeinfo
;
2519 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
),
2520 rgszNames
, cNames
, lcid
, rgDispId
);
2522 hr
= get_typeinfo(IFile_tid
, &typeinfo
);
2524 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
2525 ITypeInfo_Release(typeinfo
);
2530 static HRESULT WINAPI
file_Invoke(IFile
*iface
, DISPID dispIdMember
, REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
2532 struct file
*This
= impl_from_IFile(iface
);
2533 ITypeInfo
*typeinfo
;
2536 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
2537 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
2539 hr
= get_typeinfo(IFile_tid
, &typeinfo
);
2542 hr
= ITypeInfo_Invoke(typeinfo
, iface
, dispIdMember
, wFlags
,
2543 pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
2544 ITypeInfo_Release(typeinfo
);
2549 static HRESULT WINAPI
file_get_Path(IFile
*iface
, BSTR
*pbstrPath
)
2551 struct file
*This
= impl_from_IFile(iface
);
2552 FIXME("(%p)->(%p)\n", This
, pbstrPath
);
2556 static HRESULT WINAPI
file_get_Name(IFile
*iface
, BSTR
*name
)
2558 struct file
*This
= impl_from_IFile(iface
);
2561 TRACE("(%p)->(%p)\n", This
, name
);
2568 ptr
= strrchrW(This
->path
, '\\');
2571 *name
= SysAllocString(ptr
+1);
2572 TRACE("%s\n", debugstr_w(*name
));
2573 if (!*name
) return E_OUTOFMEMORY
;
2581 static HRESULT WINAPI
file_put_Name(IFile
*iface
, BSTR pbstrName
)
2583 struct file
*This
= impl_from_IFile(iface
);
2584 FIXME("(%p)->(%s)\n", This
, debugstr_w(pbstrName
));
2588 static HRESULT WINAPI
file_get_ShortPath(IFile
*iface
, BSTR
*pbstrPath
)
2590 struct file
*This
= impl_from_IFile(iface
);
2591 FIXME("(%p)->(%p)\n", This
, pbstrPath
);
2595 static HRESULT WINAPI
file_get_ShortName(IFile
*iface
, BSTR
*pbstrName
)
2597 struct file
*This
= impl_from_IFile(iface
);
2598 FIXME("(%p)->(%p)\n", This
, pbstrName
);
2602 static HRESULT WINAPI
file_get_Drive(IFile
*iface
, IDrive
**ppdrive
)
2604 struct file
*This
= impl_from_IFile(iface
);
2605 FIXME("(%p)->(%p)\n", This
, ppdrive
);
2609 static HRESULT WINAPI
file_get_ParentFolder(IFile
*iface
, IFolder
**ppfolder
)
2611 struct file
*This
= impl_from_IFile(iface
);
2612 FIXME("(%p)->(%p)\n", This
, ppfolder
);
2616 static HRESULT WINAPI
file_get_Attributes(IFile
*iface
, FileAttribute
*pfa
)
2618 struct file
*This
= impl_from_IFile(iface
);
2621 TRACE("(%p)->(%p)\n", This
, pfa
);
2626 fa
= GetFileAttributesW(This
->path
);
2627 if(fa
== INVALID_FILE_ATTRIBUTES
)
2628 return create_error(GetLastError());
2630 *pfa
= fa
& (FILE_ATTRIBUTE_READONLY
| FILE_ATTRIBUTE_HIDDEN
|
2631 FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_DIRECTORY
| FILE_ATTRIBUTE_ARCHIVE
|
2632 FILE_ATTRIBUTE_REPARSE_POINT
| FILE_ATTRIBUTE_COMPRESSED
);
2636 static HRESULT WINAPI
file_put_Attributes(IFile
*iface
, FileAttribute pfa
)
2638 struct file
*This
= impl_from_IFile(iface
);
2639 FIXME("(%p)->(%x)\n", This
, pfa
);
2643 static HRESULT WINAPI
file_get_DateCreated(IFile
*iface
, DATE
*pdate
)
2645 struct file
*This
= impl_from_IFile(iface
);
2646 FIXME("(%p)->(%p)\n", This
, pdate
);
2650 static HRESULT WINAPI
file_get_DateLastModified(IFile
*iface
, DATE
*pdate
)
2652 struct file
*This
= impl_from_IFile(iface
);
2653 FIXME("(%p)->(%p)\n", This
, pdate
);
2657 static HRESULT WINAPI
file_get_DateLastAccessed(IFile
*iface
, DATE
*pdate
)
2659 struct file
*This
= impl_from_IFile(iface
);
2660 FIXME("(%p)->(%p)\n", This
, pdate
);
2664 static HRESULT WINAPI
file_get_Size(IFile
*iface
, VARIANT
*pvarSize
)
2666 struct file
*This
= impl_from_IFile(iface
);
2667 ULARGE_INTEGER size
;
2668 WIN32_FIND_DATAW fd
;
2671 TRACE("(%p)->(%p)\n", This
, pvarSize
);
2676 f
= FindFirstFileW(This
->path
, &fd
);
2677 if(f
== INVALID_HANDLE_VALUE
)
2678 return create_error(GetLastError());
2681 size
.u
.LowPart
= fd
.nFileSizeLow
;
2682 size
.u
.HighPart
= fd
.nFileSizeHigh
;
2684 return variant_from_largeint(&size
, pvarSize
);
2687 static HRESULT WINAPI
file_get_Type(IFile
*iface
, BSTR
*pbstrType
)
2689 struct file
*This
= impl_from_IFile(iface
);
2690 FIXME("(%p)->(%p)\n", This
, pbstrType
);
2694 static HRESULT WINAPI
file_Delete(IFile
*iface
, VARIANT_BOOL Force
)
2696 struct file
*This
= impl_from_IFile(iface
);
2697 FIXME("(%p)->(%x)\n", This
, Force
);
2701 static HRESULT WINAPI
file_Copy(IFile
*iface
, BSTR Destination
, VARIANT_BOOL OverWriteFiles
)
2703 struct file
*This
= impl_from_IFile(iface
);
2704 FIXME("(%p)->(%s %x)\n", This
, debugstr_w(Destination
), OverWriteFiles
);
2708 static HRESULT WINAPI
file_Move(IFile
*iface
, BSTR Destination
)
2710 struct file
*This
= impl_from_IFile(iface
);
2711 FIXME("(%p)->(%s)\n", This
, debugstr_w(Destination
));
2715 static HRESULT WINAPI
file_OpenAsTextStream(IFile
*iface
, IOMode mode
, Tristate format
, ITextStream
**stream
)
2717 struct file
*This
= impl_from_IFile(iface
);
2719 TRACE("(%p)->(%d %d %p)\n", This
, mode
, format
, stream
);
2721 if (format
== TristateUseDefault
) {
2722 FIXME("default format not handled, defaulting to unicode\n");
2723 format
= TristateTrue
;
2726 return create_textstream(This
->path
, OPEN_EXISTING
, mode
, format
== TristateTrue
, stream
);
2729 static const IFileVtbl file_vtbl
= {
2730 file_QueryInterface
,
2733 file_GetTypeInfoCount
,
2743 file_get_ParentFolder
,
2744 file_get_Attributes
,
2745 file_put_Attributes
,
2746 file_get_DateCreated
,
2747 file_get_DateLastModified
,
2748 file_get_DateLastAccessed
,
2754 file_OpenAsTextStream
2757 static HRESULT
create_file(BSTR path
, IFile
**file
)
2764 f
= heap_alloc(sizeof(struct file
));
2766 return E_OUTOFMEMORY
;
2768 f
->IFile_iface
.lpVtbl
= &file_vtbl
;
2771 len
= GetFullPathNameW(path
, 0, NULL
, NULL
);
2777 f
->path
= heap_alloc(len
*sizeof(WCHAR
));
2780 return E_OUTOFMEMORY
;
2783 if(!GetFullPathNameW(path
, len
, f
->path
, NULL
)) {
2789 attrs
= GetFileAttributesW(f
->path
);
2790 if(attrs
==INVALID_FILE_ATTRIBUTES
||
2791 (attrs
&(FILE_ATTRIBUTE_DIRECTORY
|FILE_ATTRIBUTE_DEVICE
))) {
2794 return create_error(GetLastError());
2797 *file
= &f
->IFile_iface
;
2801 static HRESULT WINAPI
filesys_QueryInterface(IFileSystem3
*iface
, REFIID riid
, void **ppvObject
)
2803 TRACE("%p %s %p\n", iface
, debugstr_guid(riid
), ppvObject
);
2805 if ( IsEqualGUID( riid
, &IID_IFileSystem3
) ||
2806 IsEqualGUID( riid
, &IID_IFileSystem
) ||
2807 IsEqualGUID( riid
, &IID_IDispatch
) ||
2808 IsEqualGUID( riid
, &IID_IUnknown
) )
2812 else if ( IsEqualGUID( riid
, &IID_IDispatchEx
))
2814 TRACE("Interface IDispatchEx not supported - returning NULL\n");
2816 return E_NOINTERFACE
;
2818 else if ( IsEqualGUID( riid
, &IID_IObjectWithSite
))
2820 TRACE("Interface IObjectWithSite not supported - returning NULL\n");
2822 return E_NOINTERFACE
;
2826 FIXME("Unsupported interface %s\n", debugstr_guid(riid
));
2827 return E_NOINTERFACE
;
2830 IFileSystem3_AddRef(iface
);
2835 static ULONG WINAPI
filesys_AddRef(IFileSystem3
*iface
)
2837 TRACE("%p\n", iface
);
2842 static ULONG WINAPI
filesys_Release(IFileSystem3
*iface
)
2844 TRACE("%p\n", iface
);
2849 static HRESULT WINAPI
filesys_GetTypeInfoCount(IFileSystem3
*iface
, UINT
*pctinfo
)
2851 TRACE("(%p)->(%p)\n", iface
, pctinfo
);
2857 static HRESULT WINAPI
filesys_GetTypeInfo(IFileSystem3
*iface
, UINT iTInfo
,
2858 LCID lcid
, ITypeInfo
**ppTInfo
)
2860 TRACE("(%p)->(%u %u %p)\n", iface
, iTInfo
, lcid
, ppTInfo
);
2861 return get_typeinfo(IFileSystem3_tid
, ppTInfo
);
2864 static HRESULT WINAPI
filesys_GetIDsOfNames(IFileSystem3
*iface
, REFIID riid
,
2865 LPOLESTR
*rgszNames
, UINT cNames
,
2866 LCID lcid
, DISPID
*rgDispId
)
2868 ITypeInfo
*typeinfo
;
2871 TRACE("(%p)->(%s %p %u %u %p)\n", iface
, debugstr_guid(riid
), rgszNames
, cNames
, lcid
, rgDispId
);
2873 hr
= get_typeinfo(IFileSystem3_tid
, &typeinfo
);
2876 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
2877 ITypeInfo_Release(typeinfo
);
2883 static HRESULT WINAPI
filesys_Invoke(IFileSystem3
*iface
, DISPID dispIdMember
,
2884 REFIID riid
, LCID lcid
, WORD wFlags
,
2885 DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
,
2886 EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
2888 ITypeInfo
*typeinfo
;
2891 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", iface
, dispIdMember
, debugstr_guid(riid
),
2892 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
2894 hr
= get_typeinfo(IFileSystem3_tid
, &typeinfo
);
2897 hr
= ITypeInfo_Invoke(typeinfo
, iface
, dispIdMember
, wFlags
,
2898 pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
2899 ITypeInfo_Release(typeinfo
);
2905 static HRESULT WINAPI
filesys_get_Drives(IFileSystem3
*iface
, IDriveCollection
**ppdrives
)
2907 TRACE("%p %p\n", iface
, ppdrives
);
2908 return create_drivecoll(ppdrives
);
2911 static HRESULT WINAPI
filesys_BuildPath(IFileSystem3
*iface
, BSTR Path
,
2912 BSTR Name
, BSTR
*Result
)
2916 TRACE("%p %s %s %p\n", iface
, debugstr_w(Path
), debugstr_w(Name
), Result
);
2918 if (!Result
) return E_POINTER
;
2922 int path_len
= SysStringLen(Path
), name_len
= SysStringLen(Name
);
2924 /* if both parts have backslashes strip one from Path */
2925 if (Path
[path_len
-1] == '\\' && Name
[0] == '\\')
2929 ret
= SysAllocStringLen(NULL
, path_len
+ name_len
);
2937 else if (Path
[path_len
-1] != '\\' && Name
[0] != '\\')
2939 ret
= SysAllocStringLen(NULL
, path_len
+ name_len
+ 1);
2943 if (Path
[path_len
-1] != ':')
2950 ret
= SysAllocStringLen(NULL
, path_len
+ name_len
);
2958 else if (Path
|| Name
)
2959 ret
= SysAllocString(Path
? Path
: Name
);
2961 ret
= SysAllocStringLen(NULL
, 0);
2963 if (!ret
) return E_OUTOFMEMORY
;
2969 static HRESULT WINAPI
filesys_GetDriveName(IFileSystem3
*iface
, BSTR path
, BSTR
*drive
)
2971 TRACE("(%p)->(%s %p)\n", iface
, debugstr_w(path
), drive
);
2978 if (path
&& strlenW(path
) > 1 && path
[1] == ':')
2979 *drive
= SysAllocStringLen(path
, 2);
2984 static inline DWORD
get_parent_folder_name(const WCHAR
*path
, DWORD len
)
2991 for(i
=len
-1; i
>=0; i
--)
2992 if(path
[i
]!='/' && path
[i
]!='\\')
2996 if(path
[i
]=='/' || path
[i
]=='\\')
3000 if(path
[i
]!='/' && path
[i
]!='\\')
3006 if(path
[i
]==':' && i
==1)
3011 static HRESULT WINAPI
filesys_GetParentFolderName(IFileSystem3
*iface
, BSTR Path
,
3016 TRACE("%p %s %p\n", iface
, debugstr_w(Path
), pbstrResult
);
3021 len
= get_parent_folder_name(Path
, SysStringLen(Path
));
3023 *pbstrResult
= NULL
;
3027 *pbstrResult
= SysAllocStringLen(Path
, len
);
3029 return E_OUTOFMEMORY
;
3033 static HRESULT WINAPI
filesys_GetFileName(IFileSystem3
*iface
, BSTR Path
,
3038 TRACE("%p %s %p\n", iface
, debugstr_w(Path
), pbstrResult
);
3044 *pbstrResult
= NULL
;
3048 for(end
=strlenW(Path
)-1; end
>=0; end
--)
3049 if(Path
[end
]!='/' && Path
[end
]!='\\')
3052 for(i
=end
; i
>=0; i
--)
3053 if(Path
[i
]=='/' || Path
[i
]=='\\')
3057 if(i
>end
|| (i
==0 && end
==1 && Path
[1]==':')) {
3058 *pbstrResult
= NULL
;
3062 *pbstrResult
= SysAllocStringLen(Path
+i
, end
-i
+1);
3064 return E_OUTOFMEMORY
;
3068 static HRESULT WINAPI
filesys_GetBaseName(IFileSystem3
*iface
, BSTR Path
,
3073 TRACE("%p %s %p\n", iface
, debugstr_w(Path
), pbstrResult
);
3079 *pbstrResult
= NULL
;
3083 for(end
=strlenW(Path
)-1; end
>=0; end
--)
3084 if(Path
[end
]!='/' && Path
[end
]!='\\')
3087 for(i
=end
; i
>=0; i
--) {
3088 if(Path
[i
]=='.' && Path
[end
+1]!='.')
3090 if(Path
[i
]=='/' || Path
[i
]=='\\')
3095 if((i
>end
&& Path
[end
+1]!='.') || (i
==0 && end
==1 && Path
[1]==':')) {
3096 *pbstrResult
= NULL
;
3100 *pbstrResult
= SysAllocStringLen(Path
+i
, end
-i
+1);
3102 return E_OUTOFMEMORY
;
3106 static HRESULT WINAPI
filesys_GetExtensionName(IFileSystem3
*iface
, BSTR Path
,
3109 FIXME("%p %s %p\n", iface
, debugstr_w(Path
), pbstrResult
);
3114 static HRESULT WINAPI
filesys_GetAbsolutePathName(IFileSystem3
*iface
, BSTR Path
,
3117 static const WCHAR cur_path
[] = {'.',0};
3119 WCHAR buf
[MAX_PATH
], ch
;
3121 DWORD i
, beg
, len
, exp_len
;
3122 WIN32_FIND_DATAW fdata
;
3125 TRACE("%p %s %p\n", iface
, debugstr_w(Path
), pbstrResult
);
3135 len
= GetFullPathNameW(path
, MAX_PATH
, buf
, NULL
);
3139 buf
[0] = toupperW(buf
[0]);
3140 if(len
>3 && buf
[len
-1] == '\\')
3143 for(beg
=3, i
=3; i
<=len
; i
++) {
3144 if(buf
[i
]!='\\' && buf
[i
])
3149 fh
= FindFirstFileW(buf
, &fdata
);
3150 if(fh
== INVALID_HANDLE_VALUE
)
3153 exp_len
= strlenW(fdata
.cFileName
);
3154 if(exp_len
== i
-beg
)
3155 memcpy(buf
+beg
, fdata
.cFileName
, exp_len
*sizeof(WCHAR
));
3161 *pbstrResult
= SysAllocString(buf
);
3163 return E_OUTOFMEMORY
;
3167 static HRESULT WINAPI
filesys_GetTempName(IFileSystem3
*iface
, BSTR
*pbstrResult
)
3169 static const WCHAR fmt
[] = {'r','a','d','%','0','5','X','.','t','x','t',0};
3173 TRACE("%p %p\n", iface
, pbstrResult
);
3178 *pbstrResult
= SysAllocStringLen(NULL
, 12);
3180 return E_OUTOFMEMORY
;
3182 if(!RtlGenRandom(&random
, sizeof(random
)))
3184 sprintfW(*pbstrResult
, fmt
, random
& 0xfffff);
3188 static HRESULT WINAPI
filesys_DriveExists(IFileSystem3
*iface
, BSTR DriveSpec
,
3189 VARIANT_BOOL
*pfExists
)
3191 FIXME("%p %s %p\n", iface
, debugstr_w(DriveSpec
), pfExists
);
3196 static HRESULT WINAPI
filesys_FileExists(IFileSystem3
*iface
, BSTR path
, VARIANT_BOOL
*ret
)
3199 TRACE("%p %s %p\n", iface
, debugstr_w(path
), ret
);
3201 if (!ret
) return E_POINTER
;
3203 attrs
= GetFileAttributesW(path
);
3204 *ret
= attrs
!= INVALID_FILE_ATTRIBUTES
&& !(attrs
& FILE_ATTRIBUTE_DIRECTORY
) ? VARIANT_TRUE
: VARIANT_FALSE
;
3208 static HRESULT WINAPI
filesys_FolderExists(IFileSystem3
*iface
, BSTR path
, VARIANT_BOOL
*ret
)
3211 TRACE("%p %s %p\n", iface
, debugstr_w(path
), ret
);
3213 if (!ret
) return E_POINTER
;
3215 attrs
= GetFileAttributesW(path
);
3216 *ret
= attrs
!= INVALID_FILE_ATTRIBUTES
&& (attrs
& FILE_ATTRIBUTE_DIRECTORY
) ? VARIANT_TRUE
: VARIANT_FALSE
;
3221 static HRESULT WINAPI
filesys_GetDrive(IFileSystem3
*iface
, BSTR DriveSpec
,
3224 FIXME("%p %s %p\n", iface
, debugstr_w(DriveSpec
), ppdrive
);
3229 static HRESULT WINAPI
filesys_GetFile(IFileSystem3
*iface
, BSTR FilePath
,
3232 TRACE("%p %s %p\n", iface
, debugstr_w(FilePath
), ppfile
);
3237 return E_INVALIDARG
;
3239 return create_file(FilePath
, ppfile
);
3242 static HRESULT WINAPI
filesys_GetFolder(IFileSystem3
*iface
, BSTR FolderPath
,
3247 TRACE("%p %s %p\n", iface
, debugstr_w(FolderPath
), folder
);
3254 return E_INVALIDARG
;
3256 attrs
= GetFileAttributesW(FolderPath
);
3257 if((attrs
== INVALID_FILE_ATTRIBUTES
) || !(attrs
& FILE_ATTRIBUTE_DIRECTORY
))
3258 return CTL_E_PATHNOTFOUND
;
3260 return create_folder(FolderPath
, folder
);
3263 static HRESULT WINAPI
filesys_GetSpecialFolder(IFileSystem3
*iface
,
3264 SpecialFolderConst SpecialFolder
,
3267 FIXME("%p %d %p\n", iface
, SpecialFolder
, ppfolder
);
3272 static inline HRESULT
delete_file(const WCHAR
*file
, DWORD file_len
, VARIANT_BOOL force
)
3274 WCHAR path
[MAX_PATH
];
3275 DWORD len
, name_len
;
3276 WIN32_FIND_DATAW ffd
;
3279 f
= FindFirstFileW(file
, &ffd
);
3280 if(f
== INVALID_HANDLE_VALUE
)
3281 return create_error(GetLastError());
3283 len
= get_parent_folder_name(file
, file_len
);
3284 if(len
+1 >= MAX_PATH
) {
3289 memcpy(path
, file
, len
*sizeof(WCHAR
));
3294 if(ffd
.dwFileAttributes
& (FILE_ATTRIBUTE_DIRECTORY
|FILE_ATTRIBUTE_DEVICE
))
3297 name_len
= strlenW(ffd
.cFileName
);
3298 if(len
+name_len
+1 >= MAX_PATH
) {
3302 memcpy(path
+len
, ffd
.cFileName
, (name_len
+1)*sizeof(WCHAR
));
3304 TRACE("deleting %s\n", debugstr_w(path
));
3306 if(!DeleteFileW(path
)) {
3307 if(!force
|| !SetFileAttributesW(path
, FILE_ATTRIBUTE_NORMAL
)
3308 || !DeleteFileW(path
)) {
3310 return create_error(GetLastError());
3313 } while(FindNextFileW(f
, &ffd
));
3319 static HRESULT WINAPI
filesys_DeleteFile(IFileSystem3
*iface
, BSTR FileSpec
,
3322 TRACE("%p %s %d\n", iface
, debugstr_w(FileSpec
), Force
);
3327 return delete_file(FileSpec
, SysStringLen(FileSpec
), Force
);
3330 static HRESULT
delete_folder(const WCHAR
*folder
, DWORD folder_len
, VARIANT_BOOL force
)
3332 WCHAR path
[MAX_PATH
];
3333 DWORD len
, name_len
;
3334 WIN32_FIND_DATAW ffd
;
3338 f
= FindFirstFileW(folder
, &ffd
);
3339 if(f
== INVALID_HANDLE_VALUE
)
3340 return create_error(GetLastError());
3342 len
= get_parent_folder_name(folder
, folder_len
);
3343 if(len
+1 >= MAX_PATH
) {
3348 memcpy(path
, folder
, len
*sizeof(WCHAR
));
3353 if(!(ffd
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
))
3355 if(ffd
.cFileName
[0]=='.' && (ffd
.cFileName
[1]==0 ||
3356 (ffd
.cFileName
[1]=='.' && ffd
.cFileName
[2]==0)))
3359 name_len
= strlenW(ffd
.cFileName
);
3360 if(len
+name_len
+3 >= MAX_PATH
) {
3364 memcpy(path
+len
, ffd
.cFileName
, name_len
*sizeof(WCHAR
));
3365 path
[len
+name_len
] = '\\';
3366 path
[len
+name_len
+1] = '*';
3367 path
[len
+name_len
+2] = 0;
3369 hr
= delete_file(path
, len
+name_len
+2, force
);
3375 hr
= delete_folder(path
, len
+name_len
+2, force
);
3381 path
[len
+name_len
] = 0;
3382 TRACE("deleting %s\n", debugstr_w(path
));
3384 if(!RemoveDirectoryW(path
)) {
3386 return create_error(GetLastError());
3388 } while(FindNextFileW(f
, &ffd
));
3394 static HRESULT WINAPI
filesys_DeleteFolder(IFileSystem3
*iface
, BSTR FolderSpec
,
3397 TRACE("%p %s %d\n", iface
, debugstr_w(FolderSpec
), Force
);
3402 return delete_folder(FolderSpec
, SysStringLen(FolderSpec
), Force
);
3405 static HRESULT WINAPI
filesys_MoveFile(IFileSystem3
*iface
, BSTR Source
,
3408 FIXME("%p %s %s\n", iface
, debugstr_w(Source
), debugstr_w(Destination
));
3413 static HRESULT WINAPI
filesys_MoveFolder(IFileSystem3
*iface
,BSTR Source
,
3416 FIXME("%p %s %s\n", iface
, debugstr_w(Source
), debugstr_w(Destination
));
3421 static inline HRESULT
copy_file(const WCHAR
*source
, DWORD source_len
,
3422 const WCHAR
*destination
, DWORD destination_len
, VARIANT_BOOL overwrite
)
3425 WCHAR src_path
[MAX_PATH
], dst_path
[MAX_PATH
];
3426 DWORD src_len
, dst_len
, name_len
;
3427 WIN32_FIND_DATAW ffd
;
3431 if(!source
[0] || !destination
[0])
3432 return E_INVALIDARG
;
3434 attrs
= GetFileAttributesW(destination
);
3435 if(attrs
==INVALID_FILE_ATTRIBUTES
|| !(attrs
& FILE_ATTRIBUTE_DIRECTORY
)) {
3436 attrs
= GetFileAttributesW(source
);
3437 if(attrs
== INVALID_FILE_ATTRIBUTES
)
3438 return create_error(GetLastError());
3439 else if(attrs
& FILE_ATTRIBUTE_DIRECTORY
)
3440 return CTL_E_FILENOTFOUND
;
3442 if(!CopyFileW(source
, destination
, !overwrite
))
3443 return create_error(GetLastError());
3447 f
= FindFirstFileW(source
, &ffd
);
3448 if(f
== INVALID_HANDLE_VALUE
)
3449 return CTL_E_FILENOTFOUND
;
3451 src_len
= get_parent_folder_name(source
, source_len
);
3452 if(src_len
+1 >= MAX_PATH
) {
3457 memcpy(src_path
, source
, src_len
*sizeof(WCHAR
));
3458 src_path
[src_len
++] = '\\';
3461 dst_len
= destination_len
;
3462 if(dst_len
+1 >= MAX_PATH
) {
3466 memcpy(dst_path
, destination
, dst_len
*sizeof(WCHAR
));
3467 if(dst_path
[dst_len
-1]!= '\\' && dst_path
[dst_len
-1]!='/')
3468 dst_path
[dst_len
++] = '\\';
3470 hr
= CTL_E_FILENOTFOUND
;
3472 if(ffd
.dwFileAttributes
& (FILE_ATTRIBUTE_DIRECTORY
|FILE_ATTRIBUTE_DEVICE
))
3475 name_len
= strlenW(ffd
.cFileName
);
3476 if(src_len
+name_len
+1>=MAX_PATH
|| dst_len
+name_len
+1>=MAX_PATH
) {
3480 memcpy(src_path
+src_len
, ffd
.cFileName
, (name_len
+1)*sizeof(WCHAR
));
3481 memcpy(dst_path
+dst_len
, ffd
.cFileName
, (name_len
+1)*sizeof(WCHAR
));
3483 TRACE("copying %s to %s\n", debugstr_w(src_path
), debugstr_w(dst_path
));
3485 if(!CopyFileW(src_path
, dst_path
, !overwrite
)) {
3487 return create_error(GetLastError());
3491 } while(FindNextFileW(f
, &ffd
));
3497 static HRESULT WINAPI
filesys_CopyFile(IFileSystem3
*iface
, BSTR Source
,
3498 BSTR Destination
, VARIANT_BOOL OverWriteFiles
)
3500 TRACE("%p %s %s %d\n", iface
, debugstr_w(Source
), debugstr_w(Destination
), OverWriteFiles
);
3502 if(!Source
|| !Destination
)
3505 return copy_file(Source
, SysStringLen(Source
), Destination
,
3506 SysStringLen(Destination
), OverWriteFiles
);
3509 static HRESULT
copy_folder(const WCHAR
*source
, DWORD source_len
, const WCHAR
*destination
,
3510 DWORD destination_len
, VARIANT_BOOL overwrite
)
3512 DWORD tmp
, src_len
, dst_len
, name_len
;
3513 WCHAR src
[MAX_PATH
], dst
[MAX_PATH
];
3514 WIN32_FIND_DATAW ffd
;
3517 BOOL copied
= FALSE
;
3519 if(!source
[0] || !destination
[0])
3520 return E_INVALIDARG
;
3522 dst_len
= destination_len
;
3523 if(dst_len
+1 >= MAX_PATH
)
3525 memcpy(dst
, destination
, (dst_len
+1)*sizeof(WCHAR
));
3527 if(dst
[dst_len
-1]!='\\' && dst
[dst_len
-1]!='/' &&
3528 (tmp
= GetFileAttributesW(source
))!=INVALID_FILE_ATTRIBUTES
&&
3529 tmp
&FILE_ATTRIBUTE_DIRECTORY
) {
3530 if(!CreateDirectoryW(dst
, NULL
)) {
3531 if(overwrite
&& GetLastError()==ERROR_ALREADY_EXISTS
) {
3532 tmp
= GetFileAttributesW(dst
);
3533 if(tmp
==INVALID_FILE_ATTRIBUTES
|| !(tmp
&FILE_ATTRIBUTE_DIRECTORY
))
3534 return CTL_E_FILEALREADYEXISTS
;
3536 return create_error(GetLastError());
3541 src_len
= source_len
;
3542 if(src_len
+2 >= MAX_PATH
)
3544 memcpy(src
, source
, src_len
*sizeof(WCHAR
));
3545 src
[src_len
++] = '\\';
3549 hr
= copy_file(src
, src_len
+1, dst
, dst_len
, overwrite
);
3550 if(FAILED(hr
) && hr
!=CTL_E_FILENOTFOUND
)
3551 return create_error(GetLastError());
3553 f
= FindFirstFileW(src
, &ffd
);
3555 src_len
= get_parent_folder_name(source
, source_len
);
3556 if(src_len
+2 >= MAX_PATH
)
3558 memcpy(src
, source
, src_len
*sizeof(WCHAR
));
3560 src
[src_len
++] = '\\';
3562 f
= FindFirstFileW(source
, &ffd
);
3564 if(f
== INVALID_HANDLE_VALUE
)
3565 return CTL_E_PATHNOTFOUND
;
3567 dst
[dst_len
++] = '\\';
3571 if(!(ffd
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
))
3573 if(ffd
.cFileName
[0]=='.' && (ffd
.cFileName
[1]==0 ||
3574 (ffd
.cFileName
[1]=='.' && ffd
.cFileName
[2]==0)))
3577 name_len
= strlenW(ffd
.cFileName
);
3578 if(dst_len
+name_len
>=MAX_PATH
|| src_len
+name_len
+2>=MAX_PATH
) {
3582 memcpy(dst
+dst_len
, ffd
.cFileName
, name_len
*sizeof(WCHAR
));
3583 dst
[dst_len
+name_len
] = 0;
3584 memcpy(src
+src_len
, ffd
.cFileName
, name_len
*sizeof(WCHAR
));
3585 src
[src_len
+name_len
] = '\\';
3586 src
[src_len
+name_len
+1] = '*';
3587 src
[src_len
+name_len
+2] = 0;
3589 TRACE("copying %s to %s\n", debugstr_w(src
), debugstr_w(dst
));
3591 if(!CreateDirectoryW(dst
, NULL
)) {
3592 if(overwrite
&& GetLastError()==ERROR_ALREADY_EXISTS
) {
3593 tmp
= GetFileAttributesW(dst
);
3594 if(tmp
==INVALID_FILE_ATTRIBUTES
|| !(tmp
&FILE_ATTRIBUTE_DIRECTORY
)) {
3596 return CTL_E_FILEALREADYEXISTS
;
3601 return create_error(GetLastError());
3605 hr
= copy_file(src
, src_len
+name_len
+2, dst
, dst_len
+name_len
, overwrite
);
3606 if(FAILED(hr
) && hr
!=CTL_E_FILENOTFOUND
) {
3611 hr
= copy_folder(src
, src_len
+name_len
+2, dst
, dst_len
+name_len
, overwrite
);
3612 if(FAILED(hr
) && hr
!=CTL_E_PATHNOTFOUND
) {
3616 } while(FindNextFileW(f
, &ffd
));
3619 return copied
? S_OK
: CTL_E_PATHNOTFOUND
;
3622 static HRESULT WINAPI
filesys_CopyFolder(IFileSystem3
*iface
, BSTR Source
,
3623 BSTR Destination
, VARIANT_BOOL OverWriteFiles
)
3625 TRACE("%p %s %s %d\n", iface
, debugstr_w(Source
), debugstr_w(Destination
), OverWriteFiles
);
3627 if(!Source
|| !Destination
)
3630 return copy_folder(Source
, SysStringLen(Source
), Destination
,
3631 SysStringLen(Destination
), OverWriteFiles
);
3634 static HRESULT WINAPI
filesys_CreateFolder(IFileSystem3
*iface
, BSTR path
,
3639 TRACE("(%p)->(%s %p)\n", iface
, debugstr_w(path
), folder
);
3641 ret
= CreateDirectoryW(path
, NULL
);
3645 if (GetLastError() == ERROR_ALREADY_EXISTS
) return CTL_E_FILEALREADYEXISTS
;
3646 return HRESULT_FROM_WIN32(GetLastError());
3649 return create_folder(path
, folder
);
3652 static HRESULT WINAPI
filesys_CreateTextFile(IFileSystem3
*iface
, BSTR filename
,
3653 VARIANT_BOOL overwrite
, VARIANT_BOOL unicode
,
3654 ITextStream
**stream
)
3658 TRACE("%p %s %d %d %p\n", iface
, debugstr_w(filename
), overwrite
, unicode
, stream
);
3660 disposition
= overwrite
== VARIANT_TRUE
? CREATE_ALWAYS
: CREATE_NEW
;
3661 return create_textstream(filename
, disposition
, ForWriting
, !!unicode
, stream
);
3664 static HRESULT WINAPI
filesys_OpenTextFile(IFileSystem3
*iface
, BSTR filename
,
3665 IOMode mode
, VARIANT_BOOL create
,
3666 Tristate format
, ITextStream
**stream
)
3670 TRACE("(%p)->(%s %d %d %d %p)\n", iface
, debugstr_w(filename
), mode
, create
, format
, stream
);
3671 disposition
= create
== VARIANT_TRUE
? OPEN_ALWAYS
: OPEN_EXISTING
;
3673 if (format
== TristateUseDefault
) {
3674 FIXME("default format not handled, defaulting to unicode\n");
3675 format
= TristateTrue
;
3678 return create_textstream(filename
, disposition
, mode
, format
== TristateTrue
, stream
);
3681 static HRESULT WINAPI
filesys_GetStandardStream(IFileSystem3
*iface
,
3682 StandardStreamTypes StandardStreamType
,
3683 VARIANT_BOOL Unicode
,
3686 FIXME("%p %d %d %p\n", iface
, StandardStreamType
, Unicode
, ppts
);
3691 static void get_versionstring(VS_FIXEDFILEINFO
*info
, WCHAR
*ver
)
3693 static const WCHAR fmtW
[] = {'%','d','.','%','d','.','%','d','.','%','d',0};
3697 version
= (((DWORDLONG
)info
->dwFileVersionMS
) << 32) + info
->dwFileVersionLS
;
3698 a
= (WORD
)( version
>> 48);
3699 b
= (WORD
)((version
>> 32) & 0xffff);
3700 c
= (WORD
)((version
>> 16) & 0xffff);
3701 d
= (WORD
)( version
& 0xffff);
3703 sprintfW(ver
, fmtW
, a
, b
, c
, d
);
3706 static HRESULT WINAPI
filesys_GetFileVersion(IFileSystem3
*iface
, BSTR name
, BSTR
*version
)
3708 static const WCHAR rootW
[] = {'\\',0};
3709 VS_FIXEDFILEINFO
*info
;
3715 TRACE("%p %s %p\n", iface
, debugstr_w(name
), version
);
3717 len
= GetFileVersionInfoSizeW(name
, NULL
);
3719 return HRESULT_FROM_WIN32(GetLastError());
3721 ptr
= heap_alloc(len
);
3722 if (!GetFileVersionInfoW(name
, 0, len
, ptr
))
3725 return HRESULT_FROM_WIN32(GetLastError());
3728 ret
= VerQueryValueW(ptr
, rootW
, (void**)&info
, &len
);
3732 return HRESULT_FROM_WIN32(GetLastError());
3735 get_versionstring(info
, ver
);
3738 *version
= SysAllocString(ver
);
3739 TRACE("version=%s\n", debugstr_w(ver
));
3744 static const struct IFileSystem3Vtbl filesys_vtbl
=
3746 filesys_QueryInterface
,
3749 filesys_GetTypeInfoCount
,
3750 filesys_GetTypeInfo
,
3751 filesys_GetIDsOfNames
,
3755 filesys_GetDriveName
,
3756 filesys_GetParentFolderName
,
3757 filesys_GetFileName
,
3758 filesys_GetBaseName
,
3759 filesys_GetExtensionName
,
3760 filesys_GetAbsolutePathName
,
3761 filesys_GetTempName
,
3762 filesys_DriveExists
,
3764 filesys_FolderExists
,
3768 filesys_GetSpecialFolder
,
3770 filesys_DeleteFolder
,
3775 filesys_CreateFolder
,
3776 filesys_CreateTextFile
,
3777 filesys_OpenTextFile
,
3778 filesys_GetStandardStream
,
3779 filesys_GetFileVersion
3782 static IFileSystem3 filesystem
= { &filesys_vtbl
};
3784 HRESULT WINAPI
FileSystem_CreateInstance(IClassFactory
*iface
, IUnknown
*outer
, REFIID riid
, void **ppv
)
3786 TRACE("(%p %s %p)\n", outer
, debugstr_guid(riid
), ppv
);
3788 return IFileSystem3_QueryInterface(&filesystem
, riid
, ppv
);