MCPcopy Create free account
hub / github.com/BlueMatthew/WechatExporter / copyFile

Function copyFile

WechatExporter/core/FileSystem.cpp:308–358  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

306}
307
308bool copyFile(const std::string& src, const std::string& dest, bool overwrite)
309{
310#ifdef _WIN32
311 CW2T pszSrc(CA2W(src.c_str(), CP_UTF8));
312 CW2T pszDest(CA2W(dest.c_str(), CP_UTF8));
313
314 BOOL bRet = FALSE;
315 if (::PathFileExists((LPCTSTR)pszSrc))
316 {
317 bRet = ::CopyFile((LPCTSTR)pszSrc, (LPCTSTR)pszDest, (overwrite ? FALSE : TRUE));
318#ifndef NDEBUG
319 DWORD err = ::GetLastError();
320 TCHAR buffer[256] = { 0 };
321 _itot((int)err, buffer, 10);
322 _tcscat(buffer, TEXT(" "));
323 _tcscat(buffer, pszDest);
324 assert(buffer);
325#endif
326 }
327 return (bRet == TRUE);
328#else
329 if (existsFile(dest) && !overwrite)
330 {
331 return false;
332 }
333
334 std::ifstream ss(src, std::ios::in | std::ios::binary);
335 if (!ss.is_open())
336 {
337#ifndef NDEBUG
338 // assert(false);
339#endif
340 return false;
341 }
342 std::ofstream ds(dest, std::ios::out | std::ios::binary | std::ios::trunc);
343 if (!ds.is_open())
344 {
345#ifndef NDEBUG
346 assert(false);
347#endif
348 ss.close();
349 return false;
350 }
351 ds << ss.rdbuf();
352
353 ss.close();
354 ds.close();
355
356 return true;
357#endif
358}
359
360bool moveFile(const std::string& src, const std::string& dest, bool overwrite/* = true*/)
361{

Callers 6

copyFileMethod · 0.85
runMethod · 0.85
copyFileMethod · 0.85
exportUserMethod · 0.85
runMethod · 0.85

Calls 1

existsFileFunction · 0.85

Tested by

no test coverage detected