From e8a053e248164d2bd134f9518de5b8d6886b07ae Mon Sep 17 00:00:00 2001 From: Noisyfox Date: Wed, 29 Nov 2023 22:43:37 +0800 Subject: [PATCH] Use windows API to copy files (#2923) --- src/libslic3r/utils.cpp | 52 +---------------------------------------- 1 file changed, 1 insertion(+), 51 deletions(-) diff --git a/src/libslic3r/utils.cpp b/src/libslic3r/utils.cpp index e31656cda9a..8b1f86a3ac7 100644 --- a/src/libslic3r/utils.cpp +++ b/src/libslic3r/utils.cpp @@ -852,50 +852,8 @@ CopyFileResult copy_file(const std::string &from, const std::string &to, std::st ::MultiByteToWideChar(CP_UTF8, NULL, dest_str, strlen(dest_str), dst_wstr, dst_wlen); dst_wstr[dst_wlen] = '\0'; - BOOL result; - char* buff = nullptr; - HANDLE handlesrc = nullptr; - HANDLE handledst = nullptr; CopyFileResult ret = SUCCESS; - - handlesrc = CreateFile(src_wstr, - GENERIC_READ, - FILE_SHARE_READ, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_TEMPORARY, - 0); - if(handlesrc==INVALID_HANDLE_VALUE){ - error_message = "Error: open src file"; - ret = FAIL_COPY_FILE; - goto __finished; - } - - handledst=CreateFile(dst_wstr, - GENERIC_WRITE, - FILE_SHARE_READ, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_TEMPORARY, - 0); - if(handledst==INVALID_HANDLE_VALUE){ - error_message = "Error: create dest file"; - ret = FAIL_COPY_FILE; - goto __finished; - } - - DWORD size=GetFileSize(handlesrc,NULL); - buff = new char[size+1]; - DWORD dwRead=0,dwWrite; - result = ReadFile(handlesrc, buff, size, &dwRead, NULL); - if (!result) { - DWORD errCode = GetLastError(); - error_message = "Error: " + errCode; - ret = FAIL_COPY_FILE; - goto __finished; - } - buff[size]=0; - result = WriteFile(handledst,buff,size,&dwWrite,NULL); + BOOL result = CopyFileW(src_wstr, dst_wstr, FALSE); if (!result) { DWORD errCode = GetLastError(); error_message = "Error: " + errCode; @@ -903,19 +861,11 @@ CopyFileResult copy_file(const std::string &from, const std::string &to, std::st goto __finished; } - FlushFileBuffers(handledst); - __finished: if (src_wstr) delete[] src_wstr; if (dst_wstr) delete[] dst_wstr; - if (handlesrc) - CloseHandle(handlesrc); - if (handledst) - CloseHandle(handledst); - if (buff) - delete[] buff; return ret; #else