11#include " FileSystemService.h"
2+ #define WIN32_LEAN_AND_MEAN
3+ #include < windows.h>
24#include < shlobj.h>
35#include < shlwapi.h>
46#include < winnetwk.h>
@@ -100,74 +102,75 @@ std::vector<FileSystemEntry> FileSystemService::GetDirectoryEntries(const std::w
100102 }
101103
102104 unsigned __int64 fileSize = (static_cast <unsigned __int64>(findData.nFileSizeHigh ) << 32 ) + findData.nFileSizeLow ;
103- entries.emplace_back (findData.cFileName , findData.dwFileAttributes , fileSize, findData.ftLastWriteTime , isParent);
105+ unsigned __int64 lastWriteTime = (static_cast <unsigned __int64>(findData.ftLastWriteTime .dwHighDateTime ) << 32 ) + findData.ftLastWriteTime .dwLowDateTime ;
106+ entries.emplace_back (findData.cFileName , static_cast <unsigned int >(findData.dwFileAttributes ), fileSize, lastWriteTime, isParent);
104107 } while (::FindNextFile (hFind, &findData));
105108 ::FindClose (hFind);
106109 }
107110 return entries;
108111}
109112
110- HRESULT FileSystemService::CreateNewFile (const std::wstring& filePath)
113+ bool FileSystemService::CreateNewFile (const std::wstring& filePath)
111114{
112115 HANDLE hFile = ::CreateFile (filePath.c_str (), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr , OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr );
113116 if (hFile == INVALID_HANDLE_VALUE) {
114- return HRESULT_FROM_WIN32 (:: GetLastError ()) ;
117+ return false ;
115118 }
116119 ::CloseHandle (hFile);
117- return S_OK ;
120+ return true ;
118121}
119122
120123bool FileSystemService::CreateNewDirectory (const std::wstring& directoryPath)
121124{
122125 return ::CreateDirectory (directoryPath.c_str (), nullptr ) != FALSE ;
123126}
124127
125- int FileSystemService::DeleteFiles (HWND hWnd, const std::vector<std::wstring>& paths, bool immediate)
128+ bool FileSystemService::DeleteFiles (void * hWnd, const std::vector<std::wstring>& paths, bool immediate)
126129{
127130 std::wstring from = ToDoubleNullTerminatedString (paths);
128131 SHFILEOPSTRUCT fileOp = {
129- .hwnd = hWnd,
132+ .hwnd = static_cast <HWND>( hWnd) ,
130133 .wFunc = FO_DELETE,
131134 .pFrom = from.c_str (),
132135 .pTo = nullptr ,
133136 .fFlags = static_cast <FILEOP_FLAGS>(immediate ? 0 : FOF_ALLOWUNDO),
134137 };
135- return ::SHFileOperation (&fileOp);
138+ return ::SHFileOperation (&fileOp) == 0 ;
136139}
137140
138- int FileSystemService::CopyFiles (HWND hWnd, const std::vector<std::wstring>& fromPaths, const std::wstring& toPath)
141+ bool FileSystemService::CopyFiles (void * hWnd, const std::vector<std::wstring>& fromPaths, const std::wstring& toPath)
139142{
140143 std::wstring from = ToDoubleNullTerminatedString (fromPaths);
141144 std::wstring to = toPath;
142145 to.push_back (L' \0 ' ); // double null termination for SHFileOperation
143146
144147 SHFILEOPSTRUCT fileOp = {
145- .hwnd = hWnd,
148+ .hwnd = static_cast <HWND>( hWnd) ,
146149 .wFunc = FO_COPY,
147150 .pFrom = from.c_str (),
148151 .pTo = to.c_str (),
149152 .fFlags = FOF_RENAMEONCOLLISION,
150153 };
151- return ::SHFileOperation (&fileOp);
154+ return ::SHFileOperation (&fileOp) == 0 ;
152155}
153156
154- int FileSystemService::MoveFiles (HWND hWnd, const std::vector<std::wstring>& fromPaths, const std::wstring& toPath)
157+ bool FileSystemService::MoveFiles (void * hWnd, const std::vector<std::wstring>& fromPaths, const std::wstring& toPath)
155158{
156159 std::wstring from = ToDoubleNullTerminatedString (fromPaths);
157160 std::wstring to = toPath;
158161 to.push_back (L' \0 ' ); // double null termination for SHFileOperation
159162
160163 SHFILEOPSTRUCT fileOp = {
161- .hwnd = hWnd,
164+ .hwnd = static_cast <HWND>( hWnd) ,
162165 .wFunc = FO_MOVE,
163166 .pFrom = from.c_str (),
164167 .pTo = to.c_str (),
165168 .fFlags = FOF_RENAMEONCOLLISION,
166169 };
167- return ::SHFileOperation (&fileOp);
170+ return ::SHFileOperation (&fileOp) == 0 ;
168171}
169172
170- BOOL FileSystemService::ConvertNetPathName (const std::wstring& pathName, std::wstring& remotePath)
173+ bool FileSystemService::ConvertNetPathName (const std::wstring& pathName, std::wstring& remotePath)
171174{
172175 DWORD driveList = ::GetLogicalDrives ();
173176 WCHAR volumeName[3 ] = L" :" ;
@@ -194,32 +197,32 @@ BOOL FileSystemService::ConvertNetPathName(const std::wstring& pathName, std::ws
194197 return FALSE ;
195198}
196199
197- HRESULT FileSystemService::ResolveShortCut (const std::wstring& shortcutPath, std::wstring& resolvedPath)
200+ bool FileSystemService::ResolveShortCut (const std::wstring& shortcutPath, std::wstring& resolvedPath)
198201{
199202 Microsoft::WRL::ComPtr<IShellLink> shellLink;
200203 HRESULT hr = CoCreateInstance (CLSID_ShellLink, nullptr , CLSCTX_INPROC_SERVER, IID_PPV_ARGS (&shellLink));
201- if (FAILED (hr)) return hr ;
204+ if (FAILED (hr)) return false ;
202205
203206 Microsoft::WRL::ComPtr<IPersistFile> persistFile;
204207 hr = shellLink.As (&persistFile);
205- if (FAILED (hr)) return hr ;
208+ if (FAILED (hr)) return false ;
206209
207210 hr = persistFile->Load (shortcutPath.c_str (), STGM_READ);
208- if (FAILED (hr)) return hr ;
211+ if (FAILED (hr)) return false ;
209212
210213 hr = shellLink->Resolve (nullptr , SLR_UPDATE);
211- if (FAILED (hr)) return hr ;
214+ if (FAILED (hr)) return false ;
212215
213216 WCHAR szResolvedPath[MAX_PATH];
214217 hr = shellLink->GetPath (szResolvedPath, MAX_PATH, nullptr , SLGP_RAWPATH);
215- if (FAILED (hr)) return hr ;
218+ if (FAILED (hr)) return false ;
216219
217220 resolvedPath = szResolvedPath;
218221 if (::PathIsDirectory (szResolvedPath) && resolvedPath.back () != L' \\ ' ) {
219222 resolvedPath.push_back (L' \\ ' );
220223 }
221224
222- return S_OK ;
225+ return true ;
223226}
224227
225228std::wstring FileSystemService::ToDoubleNullTerminatedString (const std::vector<std::wstring>& paths)
0 commit comments