本文整理汇总了C++中CopyFileW函数的典型用法代码示例。如果您正苦于以下问题:C++ CopyFileW函数的具体用法?C++ CopyFileW怎么用?C++ CopyFileW使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CopyFileW函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Sleep
/*!
* Copies file from source path to destination.
*
* @param sourceFilename Path to the file.
* @param destFilename Destination file path.
* @param doOverwrite Do overwrite destination file if it exists.
* @returns True if file was successfully moved.
*/
GDAPI bool FileUtilitiesWindows::FileCopy(WideString const& sourceFilename, WideString const& destFilename, bool const doOverwrite /*= false*/)
{
auto const sourceFilenameSystem = Paths::Platformize(sourceFilename);
auto const destFilenameSystem = Paths::Platformize(destFilename);
if (CopyFileW(sourceFilenameSystem.CStr(), destFilenameSystem.CStr(), !doOverwrite) == FALSE)
{
Sleep(0);
return CopyFileW(sourceFilenameSystem.CStr(), destFilenameSystem.CStr(), !doOverwrite) == TRUE;
}
return true;
}
示例2: FixAutoplay
void FixAutoplay( LPCWSTR wszApplicationName, LPCWSTR wszCommandLine, LPCWSTR wszCurrentDirectory )
{
LPCWSTR uppApplicationName = _wcsupr( _wcsdup( wszApplicationName ) );
// only UT2004
if( wcsstr(uppApplicationName,L"UT2004.EXE") == NULL )
return;
// read mod name from commandline, must be specified
LPCWSTR uppCommandLine = _wcsupr( _wcsdup( wszCommandLine ) );
LPWSTR pb = wcsstr(uppCommandLine,L"-MOD=");
if( pb == NULL )
return;
// mod name must be valid
LPWSTR ps = pb + wcslen(L"-MOD=");
LPWSTR token = wcstok( ps, L" " );
if( token == NULL )
return;
// mod directory must be valid
if( !SetCurrentDirectoryW(wszCurrentDirectory)
|| !SetCurrentDirectoryW(L"..")
|| !SetCurrentDirectoryW(token) )
return;
// copy Autoplay.ut2
if( !CopyFileW( L"..\\Maps\\Autoplay.ut2", L"Maps\\Autoplay.ut2", FALSE ) )
return;
//MessageBox( NULL, TEXT("Copy OK"), TEXT("SwAutoplayFix"), MB_OK );
}
示例3: CopyFolder
bool CopyFolder(std::wstring src, std::wstring dst)
{
if(!os_create_dir(dst))
return false;
std::vector<SFile> curr_files=getFiles(src);
for(size_t i=0;i<curr_files.size();++i)
{
if(curr_files[i].isdir)
{
bool b=CopyFolder(src+os_file_sep()+curr_files[i].name, dst+os_file_sep()+curr_files[i].name);
if(!b)
return false;
}
else
{
if(!os_create_hardlink(dst+os_file_sep()+curr_files[i].name, src+os_file_sep()+curr_files[i].name, false, NULL) )
{
BOOL b=CopyFileW( (src+os_file_sep()+curr_files[i].name).c_str(), (dst+os_file_sep()+curr_files[i].name).c_str(), FALSE);
if(!b)
{
return false;
}
}
}
}
return true;
}
示例4: BLI_copy
int BLI_copy(const char *file, const char *to)
{
int err;
/* windows doesn't support copying to a directory
* it has to be 'cp filename filename' and not
* 'cp filename destdir' */
BLI_strncpy(str, to, sizeof(str));
/* points 'to' to a directory ? */
if (BLI_last_slash(str) == (str + strlen(str) - 1)) {
if (BLI_last_slash(file) != NULL) {
strcat(str, BLI_last_slash(file) + 1);
}
}
UTF16_ENCODE(file);
UTF16_ENCODE(str);
err = !CopyFileW(file_16, str_16, false);
UTF16_UN_ENCODE(str);
UTF16_UN_ENCODE(file);
if (err) {
callLocalErrorCallBack("Unable to copy file!");
printf(" Copy from '%s' to '%s' failed\n", file, str);
}
return err;
}
示例5: copyFiles
size_t copyFiles(std::wstring sourcepath, std::wstring destpath, std::wstring mask, bool case_sensitive, bool rec, bool overwrite)
{
#if defined (_MSC_VER)
int copied = 0;
if ((sourcepath.length() != 0) && (sourcepath[sourcepath.length() - 1] != L'\\')) { sourcepath += L"\\"; }
if ((destpath.length() != 0) && (destpath[destpath.length() - 1] != L'\\')) { destpath += L"\\"; }
std::vector<std::wstring> tabsource;
if (getFileList(sourcepath, mask, case_sensitive, tabsource, rec, true, rec) == false) { return(-1); }
for (std::vector<std::wstring>::iterator it = tabsource.begin(); it != tabsource.end(); it++)
{
if ((it->length() != 0) && ((*it)[it->length() - 1] == L'\\'))
{
if (CreateDirectoryW((destpath + (*it)).c_str(), NULL) == 0) { if (GetLastError() != ERROR_ALREADY_EXISTS) { return -1; } }
}
else
{
bool fie = false; if (overwrite == false) { fie = true; }
if (CopyFileW((sourcepath + (*it)).c_str(), (destpath + (*it)).c_str(), fie) == 0) { return -1; }
}
copied++;
}
return copied;
#else
// TODO
#endif
return -1;
}
示例6: SetFileAttributesW
DWORD FFileManagerWindows::InternalCopy( const TCHAR* DestFile, const TCHAR* SrcFile, UBOOL ReplaceExisting, UBOOL EvenIfReadOnly, UBOOL Attributes, FCopyProgress* Progress )
{
if( EvenIfReadOnly )
{
SetFileAttributesW(DestFile, 0);
}
DWORD Result;
if( Progress )
{
Result = FFileManagerGeneric::Copy( DestFile, SrcFile, ReplaceExisting, EvenIfReadOnly, Attributes, Progress );
}
else
{
MakeDirectory(*FFilename(DestFile).GetPath(), TRUE);
if( CopyFileW(SrcFile, DestFile, !ReplaceExisting) != 0)
{
Result = COPY_OK;
}
else
{
Result = COPY_MiscFail;
}
}
if( Result==COPY_OK && !Attributes )
{
SetFileAttributesW(DestFile, 0);
}
return Result;
}
示例7: copy_file
static HRESULT copy_file( const WCHAR *src_dir, DWORD src_len, const WCHAR *dst_dir, DWORD dst_len,
const WCHAR *filename )
{
WCHAR *src_file, *dst_file;
DWORD len = strlenW( filename );
HRESULT hr = S_OK;
if (!(src_file = HeapAlloc( GetProcessHeap(), 0, (src_len + len + 1) * sizeof(WCHAR) )))
return E_OUTOFMEMORY;
memcpy( src_file, src_dir, src_len * sizeof(WCHAR) );
strcpyW( src_file + src_len, filename );
if (!(dst_file = HeapAlloc( GetProcessHeap(), 0, (dst_len + len + 1) * sizeof(WCHAR) )))
{
HeapFree( GetProcessHeap(), 0, src_file );
return E_OUTOFMEMORY;
}
memcpy( dst_file, dst_dir, dst_len * sizeof(WCHAR) );
strcpyW( dst_file + dst_len, filename );
if (!CopyFileW( src_file, dst_file, FALSE )) hr = HRESULT_FROM_WIN32( GetLastError() );
HeapFree( GetProcessHeap(), 0, src_file );
HeapFree( GetProcessHeap(), 0, dst_file );
return hr;
}
示例8: DownloadBSC_OnStopBinding
static HRESULT WINAPI DownloadBSC_OnStopBinding(IBindStatusCallback *iface,
HRESULT hresult, LPCWSTR szError)
{
DownloadBSC *This = impl_from_IBindStatusCallback(iface);
TRACE("(%p)->(%08x %s)\n", This, hresult, debugstr_w(szError));
if(This->file_name) {
if(This->cache_file) {
BOOL b;
b = CopyFileW(This->cache_file, This->file_name, FALSE);
if(!b)
FIXME("CopyFile failed: %u\n", GetLastError());
}else {
FIXME("No cache file\n");
}
}
if(This->callback)
IBindStatusCallback_OnStopBinding(This->callback, hresult, szError);
if(This->binding) {
IBinding_Release(This->binding);
This->binding = NULL;
}
return S_OK;
}
示例9: copy_user_manual
/* Copy manual from install dir to Seafile directory */
void
copy_user_manual ()
{
char *installdir; /* C:\Program Files\Seafile */
char *seafdir; /* C:\Seafile */
char *src_path; /* C:\Program Files\Seafile\help.txt */
char *dst_path; /* C:\Seafile\help.txt */
wchar_t *src_path_w, *dst_path_w;
installdir = g_path_get_dirname (seafile_bin_dir);
seafdir = g_path_get_dirname (applet->seafile_dir);
src_path = g_build_filename (installdir, _("Seafile help.txt"), NULL);
dst_path = g_build_filename (seafdir, _("Seafile help.txt"), NULL);
src_path_w = wchar_from_utf8 (src_path);
dst_path_w = wchar_from_utf8 (dst_path);
BOOL failIfExist = FALSE;
CopyFileW (src_path_w, dst_path_w, failIfExist);
g_free (installdir);
g_free (seafdir);
g_free (src_path);
g_free (dst_path);
g_free (src_path_w);
g_free (dst_path_w);
}
示例10: downloadcb_OnStopBinding
static HRESULT WINAPI downloadcb_OnStopBinding(IBindStatusCallback *iface, HRESULT hresult, LPCWSTR szError)
{
struct downloadcb *This = impl_from_IBindStatusCallback(iface);
TRACE("(%p)->(%08x %s)\n", This, hresult, debugstr_w(szError));
if (FAILED(hresult))
{
This->hr = hresult;
goto done;
}
if (!This->cache_file)
{
This->hr = E_FAIL;
goto done;
}
if (CopyFileW(This->cache_file, This->file_name, FALSE))
This->hr = S_OK;
else
{
ERR("CopyFile failed: %u\n", GetLastError());
This->hr = E_FAIL;
}
done:
SetEvent(This->event_done);
return S_OK;
}
示例11: SetupDecompressOrCopyFileW
/***********************************************************************
* SetupDecompressOrCopyFileW ([email protected])
*
* Copy a file and decompress it if needed.
*
* PARAMS
* source [I] File to copy.
* target [I] Filename of the copy.
* type [I] Compression type.
*
* RETURNS
* Success: ERROR_SUCCESS
* Failure: Win32 error code.
*/
DWORD WINAPI SetupDecompressOrCopyFileW( PCWSTR source, PCWSTR target, PUINT type )
{
UINT comp;
DWORD ret = ERROR_INVALID_PARAMETER;
if (!source || !target) return ERROR_INVALID_PARAMETER;
if (!type) comp = detect_compression_type( source );
else comp = *type;
switch (comp)
{
case FILE_COMPRESSION_NONE:
if (CopyFileW( source, target, FALSE )) ret = ERROR_SUCCESS;
else ret = GetLastError();
break;
case FILE_COMPRESSION_WINLZA:
ret = decompress_file_lz( source, target );
break;
case FILE_COMPRESSION_NTCAB:
case FILE_COMPRESSION_MSZIP:
ret = decompress_file_cab( source, target );
break;
default:
WARN("unknown compression type %d\n", comp);
break;
}
TRACE("%s -> %s %d\n", debugstr_w(source), debugstr_w(target), comp);
return ret;
}
示例12: newFileQ
void AnotherMainWindow::DoTask()
{
int t1s = QTime::currentTime().msec();
QList<QString>* fList = new QList<QString>();
DirWorker::FindFiles(_taskOptions->FromDir, "*.txt", fList);
int len = fList->length();
for(int i = 0; i < len; i++)
{
QString fName = fList->at(i);
std::wstring sst = fName.toStdWString();
LPCWSTR sourseFile = sst.c_str();
QString newFileQ(_taskOptions->ToDir + "\\" + QString::number(1) + '_' + QString::number(i) + ".html");
std::wstring nst = newFileQ.toStdWString();
LPCWSTR newFile = nst.c_str();
if(!CopyFileW(sourseFile, newFile, false))
{
QMessageBox::critical(0, "Ошибка", "Не удалось скопировать файл: " + fName);
return;
}
FileCreateParams* params = new FileCreateParams();
params->CreateOptions = OPEN_EXISTING;
params->DesiredAccess = GENERIC_READ;
params->DesiredAccess += GENERIC_WRITE;
params->FileName = newFileQ;
FileWorker::OpenCreateFile(params);
FileWorker::UpdateFile(params);
FileWorker::CloseOpenedFile(params);
delete params;
}
int t2s = QTime::currentTime().msec();
ui->DurationBox->setText(QString::number(t2s - t1s));
}
示例13: ServiceUpdate
bool ServiceUpdate(bool validService)
{
if (validService)
{
ServiceInstaller si;
if (si.run() != 0)
return false;
}
else
{
std::wstring appPath = UTIL::OS::getCommonProgramFilesPath();
if (!FolderExists(appPath.c_str()))
CreateDirectoryW(appPath.c_str(), NULL);
std::wstring newService = UTIL::OS::getCommonProgramFilesPath(L"desura_service.exe");
std::wstring curService = UTIL::OS::getCurrentDir(L"desura_service.exe");
char regname[255];
Safe::snprintf(regname, 255, "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\%s\\ImagePath", SERVICE_NAME);
CopyFileW(curService.c_str(), newService.c_str(), FALSE);
UTIL::WIN::setRegValue(regname, gcString(newService).c_str());
}
return true;
}
示例14: FSCopyFile
bool FSCopyFile(const unicode_t *srcFileName, const unicode_t *desFileName, bool bFailIfExists/* = true*/)
{
#if defined(_WIN32_WCE)
return CopyFile(srcFileName, desFileName, bFailIfExists) == TRUE;
#elif defined(WIN32)
return CopyFileW(srcFileName, desFileName, bFailIfExists) == TRUE;
#elif defined(__APPLE_CPP__) || defined(__APPLE_CC__)
FSString srcString(srcFileName);
FSString desString(desFileName);
if ( srcString == desString ) return false;
if ( bFailIfExists )
{
if ( _ExistFile(desString.GetString()) ) return false;
}
return _CopyFile(srcFileName, desFileName);
// return copyfile(srcString.GetString(), desString.GetString(), NULL, bFailIfExists ? COPYFILE_ALL | COPYFILE_EXCL : COPYFILE_ALL) == 0;
#else
FSString srcString(srcFileName);
FSString desString(desFileName);
if ( srcString == desString ) return false;
if ( bFailIfExists )
{
if ( _ExistFile(desString.GetString()) ) return false;
}
return copyfile(srcString.GetString(), desString.GetString(), NULL, bFailIfExists? COPYFILE_ALL | COPYFILE_EXCL : COPYFILE_ALL) == 0;
#endif
}
示例15: copyFile
bool Platform::copyFile(std::string from, std::string to)
{
boost::replace_all(from, "/", "\\");
boost::replace_all(to, "/", "\\");
if(CopyFileW(stdext::utf8_to_utf16(from).c_str(), stdext::utf8_to_utf16(to).c_str(), FALSE) == 0)
return false;
return true;
}