void TopedApp::FinishSessionLog() { LogFile.close(); wxString fullName; fullName << tpdLogDir << wxT("/tpd_previous.log"); wxFileName* lFN = new wxFileName(fullName.c_str()); lFN->Normalize(); assert(lFN->IsOk()); wxRenameFile(logFileName.c_str(), lFN->GetFullPath()); delete lFN; }
bool RenameFile(const wxString& src, const wxString& dst) { wxFileName fname1(Manager::Get()->GetMacrosManager()->ReplaceMacros(src)); wxFileName fname2(Manager::Get()->GetMacrosManager()->ReplaceMacros(dst)); NormalizePath(fname1, wxEmptyString); NormalizePath(fname2, wxEmptyString); if (!SecurityAllows(_T("RenameFile"), wxString::Format(_T("%s -> %s"), fname1.GetFullPath().c_str(), fname2.GetFullPath().c_str()))) return false; if (!wxFileExists(fname1.GetFullPath())) return false; return wxRenameFile(fname1.GetFullPath(), fname2.GetFullPath()); }
// move file from source to dst, dst will be deleted if exists, dirs aren't created! bool MoveFile(const wxString& src, const wxString& dst) { //delete destination file if (wxFileExists(dst)) { wxRemoveFile(dst); } //rename file if (wxRenameFile(src, dst)) { return true; } // rename failed, try to copy + delete return wxCopyFile(src, dst) && wxRemoveFile(src); }
CLogManager::CLogManager() : wxLogStderr() { m_pLock = new wxCriticalSection(); wxASSERT(m_pLock); if (wxFileExists(wxT("BOINC-Sentinels-Valkyrie.log"))) { wxRenameFile(wxT("BOINC-Sentinels-Valkyrie.log"), wxT("BOINC-Sentinels-Valkyrie.bak"), true); } m_pFile = new wxFFile(wxT("BOINC-Sentinels-Valkyrie.log"), wxT("a")); m_fp = m_pFile->fp(); }
void TopedApp::SaveIgnoredCrashLog() { time_t timeNow = time(NULL); tm* broken_time = localtime(&timeNow); char* btm = DEBUG_NEW char[256]; strftime(btm, 256, "_%y%m%d_%H%M%S", broken_time); wxString fullName; fullName << tpdLogDir + wxT("/crash") + wxString(btm, wxConvUTF8) + wxT(".log"); wxFileName* lFN = DEBUG_NEW wxFileName(fullName.c_str()); delete [] btm; lFN->Normalize(); assert(lFN->IsOk()); wxRenameFile(logFileName.c_str(), lFN->GetFullPath()); delete lFN; }
int cellFsRename(u32 from_addr, u32 to_addr) { const wxString& ps3_from = Memory.ReadString(from_addr); const wxString& ps3_to = Memory.ReadString(to_addr); wxString from; wxString to; Emu.GetVFS().GetDevice(ps3_from, from); Emu.GetVFS().GetDevice(ps3_to, to); sys_fs.Log("cellFsRename(from: %s, to: %s)", from.mb_str(), to.mb_str()); if(!wxFileExists(from)) return CELL_ENOENT; if(wxFileExists(to)) return CELL_EEXIST; if(!wxRenameFile(from, to)) return CELL_EBUSY; // (TODO: RenameFile(a,b) = CopyFile(a,b) + RemoveFile(a), therefore file "a" will not be removed if it is opened) return CELL_OK; }
bool wxTempFile::Commit() { m_file.Close(); if ( wxFile::Exists(m_strName) && wxRemove(m_strName) != 0 ) { wxLogSysError(_("can't remove file '%s'"), m_strName.c_str()); return false; } if ( !wxRenameFile(m_strTemp, m_strName) ) { wxLogSysError(_("can't commit changes to file '%s'"), m_strName.c_str()); return false; } return true; }
bool RenameFile() { CPPUNIT_ASSERT(m_file.FileExists()); wxLogDebug("Renaming %s=>%s", m_file.GetFullPath(), m_new.GetFullPath()); bool ret = wxRenameFile(m_file.GetFullPath(), m_new.GetFullPath()); if (ret) { m_old = m_file; m_file = m_new; m_new = RandomName(); } return ret; }
bool mmAttachmentManage::RelocateAllAttachments(const wxString& RefType, int OldRefId, int NewRefId) { auto attachments = Model_Attachment::instance().find(Model_Attachment::DB_Table_ATTACHMENT_V1::REFTYPE(RefType), Model_Attachment::REFID(OldRefId)); wxString AttachmentsFolder = mmex::getPathAttachment(mmAttachmentManage::InfotablePathSetting()) + m_PathSep + RefType + m_PathSep; for (auto &entry : attachments) { wxString NewFileName = entry.FILENAME; NewFileName.Replace(entry.REFTYPE + "_" + wxString::Format("%i", entry.REFID), entry.REFTYPE + "_" + wxString::Format("%i", NewRefId)); wxRenameFile(AttachmentsFolder + entry.FILENAME, AttachmentsFolder + NewFileName); entry.REFID = NewRefId; entry.FILENAME = NewFileName; Model_Attachment::instance().save(attachments); } return true; }
void CIP2Country::DownloadFinished(uint32 result) { if (result == HTTP_Success) { Disable(); // download succeeded. Switch over to new database. wxString newDat = m_DataBasePath + wxT(".download"); // Try to unpack the file, might be an archive wxWCharBuffer dataBaseName = m_DataBaseName.wc_str(); const wxChar* geoip_files[] = { dataBaseName, NULL }; if (UnpackArchive(CPath(newDat), geoip_files).second == EFT_Error) { AddLogLineC(_("Download of GeoIP.dat file failed, aborting update.")); return; } if (wxFileExists(m_DataBasePath)) { if (!wxRemoveFile(m_DataBasePath)) { AddLogLineC(CFormat(_("Failed to remove %s file, aborting update.")) % m_DataBaseName); return; } } if (!wxRenameFile(newDat, m_DataBasePath)) { AddLogLineC(CFormat(_("Failed to rename %s file, aborting update.")) % m_DataBaseName); return; } Enable(); if (m_geoip) { AddLogLineN(CFormat(_("Successfully updated %s")) % m_DataBaseName); } else { AddLogLineC(_("Error updating GeoIP.dat")); } } else if (result == HTTP_Skipped) { AddLogLineN(CFormat(_("Skipped download of %s, because requested file is not newer.")) % m_DataBaseName); } else { AddLogLineC(CFormat(_("Failed to download %s from %s")) % m_DataBaseName % thePrefs::GetGeoIPUpdateUrl()); // if it failed and there is no database, turn it off if (!wxFileExists(m_DataBasePath)) { thePrefs::SetGeoIPEnabled(false); } } }
void wxFileCtrl::OnListEndLabelEdit( wxListEvent &event ) { wxFileData *fd = (wxFileData*)event.m_item.m_data; wxASSERT( fd ); if ((event.GetLabel().empty()) || (event.GetLabel() == _(".")) || (event.GetLabel() == _("..")) || (event.GetLabel().First( wxFILE_SEP_PATH ) != wxNOT_FOUND)) { wxMessageDialog dialog(this, _("Illegal directory name."), _("Error"), wxOK | wxICON_ERROR ); dialog.ShowModal(); event.Veto(); return; } wxString new_name( wxPathOnly( fd->GetFilePath() ) ); new_name += wxFILE_SEP_PATH; new_name += event.GetLabel(); wxLogNull log; if (wxFileExists(new_name)) { wxMessageDialog dialog(this, _("File name exists already."), _("Error"), wxOK | wxICON_ERROR ); dialog.ShowModal(); event.Veto(); } if (wxRenameFile(fd->GetFilePath(),new_name)) { fd->SetNewName( new_name, event.GetLabel() ); ignoreChanges = true; SetItemState( event.GetItem(), wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED ); ignoreChanges = false; UpdateItem( event.GetItem() ); EnsureVisible( event.GetItem() ); } else { wxMessageDialog dialog(this, _("Operation not permitted."), _("Error"), wxOK | wxICON_ERROR ); dialog.ShowModal(); event.Veto(); } }
bool TREEPROJECT_ITEM::Rename( const wxString& name, bool check ) { // this is broken & unsafe to use on linux. if( m_Type == TREE_DIRECTORY ) return false; if( name.IsEmpty() ) return false; const wxString sep = wxFileName().GetPathSeparator(); wxString newFile; wxString dirs = GetDir(); if( !dirs.IsEmpty() && GetType() != TREE_DIRECTORY ) newFile = dirs + sep + name; else newFile = name; if( newFile == GetFileName() ) return false; wxString ext = TREE_PROJECT_FRAME::GetFileExt( GetType() ); wxRegEx reg( wxT( "^.*\\" ) + ext + wxT( "$" ), wxRE_ICASE ); if( check && !ext.IsEmpty() && !reg.Matches( newFile ) ) { wxMessageDialog dialog( m_parent, _( "Changing file extension will change file type.\n Do you want to continue ?" ), _( "Rename File" ), wxYES_NO | wxICON_QUESTION ); if( wxID_YES != dialog.ShowModal() ) return false; } if( !wxRenameFile( GetFileName(), newFile, false ) ) { wxMessageDialog( m_parent, _( "Unable to rename file ... " ), _( "Permission error ?" ), wxICON_ERROR | wxOK ); return false; } SetFileName( newFile ); return true; }
void t4p::ExplorerModifyActionClass::BackgroundWork() { wxFileName parentDir; wxString name; bool totalSuccess = true; std::vector<wxFileName> dirsDeleted; std::vector<wxFileName> dirsNotDeleted; std::vector<wxFileName> filesDeleted; std::vector<wxFileName> filesNotDeleted; if (t4p::ExplorerModifyActionClass::DELETE_FILES_DIRS == Action) { std::vector<wxFileName>::iterator d; for (d = Dirs.begin(); d != Dirs.end(); ++d) { bool success = t4p::RecursiveRmDir(d->GetPath()); if (success) { wxFileName wxFileName; wxFileName.AssignDir(d->GetPath()); dirsDeleted.push_back(wxFileName); } else { wxFileName wxFileName; wxFileName.AssignDir(d->GetPath()); dirsNotDeleted.push_back(wxFileName); } totalSuccess &= success; } std::vector<wxFileName>::iterator f; for (f = Files.begin(); f != Files.end(); ++f) { bool success = wxRemoveFile(f->GetFullPath()); if (success) { wxFileName deletedFile(f->GetFullPath()); filesDeleted.push_back(deletedFile); } else { wxFileName deletedFile(f->GetFullPath()); filesNotDeleted.push_back(deletedFile); } totalSuccess &= success; } t4p::ExplorerModifyEventClass modEvent(GetEventId(), dirsDeleted, filesDeleted, dirsNotDeleted, filesNotDeleted, totalSuccess); PostEvent(modEvent); } else if (t4p::ExplorerModifyActionClass::RENAME_FILE == Action) { wxFileName destFile(OldFile.GetPath(), NewName); bool success = wxRenameFile(OldFile.GetFullPath(), destFile.GetFullPath(), false); t4p::ExplorerModifyEventClass modEvent(GetEventId(), OldFile, NewName, success); PostEvent(modEvent); } }
bool CXmlFile::SaveXmlFile() { bool exists = false; bool isLink = false; int flags = 0; wxString redirectedName = GetRedirectedName(); if (CLocalFileSystem::GetFileInfo(redirectedName, isLink, 0, 0, &flags) == CLocalFileSystem::file) { #ifdef __WXMSW__ if (flags & FILE_ATTRIBUTE_HIDDEN) SetFileAttributes(redirectedName, flags & ~FILE_ATTRIBUTE_HIDDEN); #endif exists = true; bool res; { wxLogNull null; res = wxCopyFile(redirectedName, redirectedName + _T("~")); } if (!res) { m_error = _("Failed to create backup copy of xml file"); return false; } } bool success = false; { wxFFile f(redirectedName, _T("w")); success = f.IsOpened() && m_pDocument->SaveFile(f.fp()); } if (!success) { wxRemoveFile(redirectedName); if (exists) { wxLogNull null; wxRenameFile(redirectedName + _T("~"), redirectedName); } m_error = _("Failed to write xml file"); return false; } if (exists) wxRemoveFile(redirectedName + _T("~")); return true; }
void wxGenericDirCtrl::OnEndEditItem(wxTreeEvent &event) { if (event.IsEditCancelled()) return; if ((event.GetLabel().empty()) || (event.GetLabel() == wxT(".")) || (event.GetLabel() == wxT("..")) || (event.GetLabel().Find(wxT('/')) != wxNOT_FOUND) || (event.GetLabel().Find(wxT('\\')) != wxNOT_FOUND) || (event.GetLabel().Find(wxT('|')) != wxNOT_FOUND)) { wxMessageDialog dialog(this, _("Illegal directory name."), _("Error"), wxOK | wxICON_ERROR ); dialog.ShowModal(); event.Veto(); return; } wxTreeItemId treeid = event.GetItem(); wxDirItemData *data = (wxDirItemData*)m_treeCtrl->GetItemData( treeid ); wxASSERT( data ); wxString new_name( wxPathOnly( data->m_path ) ); new_name += wxString(wxFILE_SEP_PATH); new_name += event.GetLabel(); wxLogNull log; if (wxFileExists(new_name)) { wxMessageDialog dialog(this, _("File name exists already."), _("Error"), wxOK | wxICON_ERROR ); dialog.ShowModal(); event.Veto(); } if (wxRenameFile(data->m_path,new_name)) { data->SetNewDirName( new_name ); } else { wxMessageDialog dialog(this, _("Operation not permitted."), _("Error"), wxOK | wxICON_ERROR ); dialog.ShowModal(); event.Veto(); } }
void BaseCompressThread::ExecuteTaskInThread() { // TODO : Add an API to PersistentThread for this! :) --air //SetThreadPriority( THREAD_PRIORITY_BELOW_NORMAL ); // Notes: // * Safeguard against corruption by writing to a temp file, and then copying the final // result over the original. if( !m_src_list ) return; SetPendingSave(); Yield( 3 ); uint listlen = m_src_list->GetLength(); for( uint i=0; i<listlen; ++i ) { const ArchiveEntry& entry = (*m_src_list)[i]; if (!entry.GetDataSize()) continue; wxArchiveOutputStream& woot = *(wxArchiveOutputStream*)m_gzfp->GetWxStreamBase(); woot.PutNextEntry( entry.GetFilename() ); static const uint BlockSize = 0x64000; uint curidx = 0; do { uint thisBlockSize = std::min( BlockSize, entry.GetDataSize() - curidx ); m_gzfp->Write(m_src_list->GetPtr( entry.GetDataIndex() + curidx ), thisBlockSize); curidx += thisBlockSize; Yield( 2 ); } while( curidx < entry.GetDataSize() ); woot.CloseEntry(); } m_gzfp->Close(); if( !wxRenameFile( m_gzfp->GetStreamName(), m_final_filename, true ) ) throw Exception::BadStream( m_final_filename ) .SetDiagMsg(L"Failed to move or copy the temporary archive to the destination filename.") .SetUserMsg(_("The savestate was not properly saved. The temporary file was created successfully but could not be moved to its final resting place.")); Console.WriteLn( "(gzipThread) Data saved to disk without error." ); }
void CSourcesListBox::EndEditLabel( wxListEvent& event ) { #if wxVERSION_NUMBER >= 2500 if(event.IsEditCancelled()) return; #endif wxString sCheck = event.GetText(); sCheck.Replace( wxT( " " ), wxT( "" ), TRUE ); if ( sCheck.IsEmpty() ) return; // do not want to rename to an empty string ( or one that only consists of spaces EMUSIK_SOURCES_TYPE nType = GetType( event.GetIndex() ); wxString sType; if(!GetTypeAsString(nType,sType)) { wxASSERT(FALSE); return; } //--- Musik Library entry edited ---// if ( nType == MUSIK_SOURCES_LIBRARY ) { } //--- Now Playing entry edited ---// else if ( nType == MUSIK_SOURCES_NOW_PLAYING ) { } //--- "playlist with data in a file" renamed ---// else { //--- rename file ---// wxString sOldFile = OnGetItemText(event.GetIndex(),0); wxString sNewFile = event.GetText(); SourcesToFilename( &sOldFile, nType ); SourcesToFilename( &sNewFile, nType ); wxRenameFile( sOldFile, sNewFile ); } //--- rename in musiksources.dat ---// m_SourcesList.Item( event.GetIndex() ) = sType + event.GetText(); }
bool CXmlFile::SaveXmlFile() { bool exists = false; bool isLink = false; int flags = 0; wxString redirectedName = GetRedirectedName(); if (fz::local_filesys::get_file_info(fz::to_native(redirectedName), isLink, 0, 0, &flags) == fz::local_filesys::file) { #ifdef __WXMSW__ if (flags & FILE_ATTRIBUTE_HIDDEN) SetFileAttributes(redirectedName.c_str(), flags & ~FILE_ATTRIBUTE_HIDDEN); #endif exists = true; bool res; { wxLogNull null; res = wxCopyFile(redirectedName, redirectedName + _T("~")); } if (!res) { m_error = _("Failed to create backup copy of xml file").ToStdWstring(); return false; } } bool success = m_document.save_file(static_cast<wchar_t const*>(redirectedName.c_str())); if (!success) { wxRemoveFile(redirectedName); if (exists) { wxLogNull null; wxRenameFile(redirectedName + _T("~"), redirectedName); } m_error = _("Failed to write xml file").ToStdWstring(); return false; } if (exists) wxRemoveFile(redirectedName + _T("~")); return true; }
bool SaveXmlFile(const wxFileName& file, TiXmlNode* node, wxString* error /*=0*/) { if (!node) return true; const wxString& fullPath = file.GetFullPath(); TiXmlDocument* pDocument = node->GetDocument(); bool exists = false; if (wxFileExists(fullPath)) { exists = true; if (!wxCopyFile(fullPath, fullPath + _T("~"))) { const wxString msg = _("Failed to create backup copy of xml file"); if (error) *error = msg; else wxMessageBox(msg); return false; } } if (!pDocument->SaveFile(fullPath.mb_str())) { wxRemoveFile(fullPath); if (exists) wxRenameFile(fullPath + _T("~"), fullPath); const wxString msg = _("Failed to write xml file"); if (error) *error = msg; else wxMessageBox(msg); return false; } if (exists) wxRemoveFile(fullPath + _T("~")); return true; }
bool DirManager::MoveToNewProjectDirectory(BlockFile *f) { wxString newFullPath = projFull + pathChar + f->mName; if (newFullPath != f->mFullPath) { bool ok = wxRenameFile(f->mFullPath, newFullPath); if (ok) f->mFullPath = newFullPath; else { ok = wxCopyFile(f->mFullPath, newFullPath); if (ok) { wxRemoveFile(f->mFullPath); f->mFullPath = newFullPath; } else return false; } } return true; }
void mmg_app::prepare_mmg_data_folder() { // The 'jobs' folder is part of the application data // folder. Therefore both directories will be creatd. // 'prepare_path' treats the last part of the path as a file name; // therefore append a dummy file name so that all directory parts // will be created. mm_file_io_c::prepare_path(wxMB(get_jobs_folder() + wxT("/dummy"))); #if !defined(SYS_WINDOWS) // Migrate the config file from its old location ~/.mkvmergeGUI to // the new location ~/.mkvtoolnix/config wxString old_config_name; wxGetEnv(wxT("HOME"), &old_config_name); old_config_name += wxT("/.mkvmergeGUI"); if (wxFileExists(old_config_name)) wxRenameFile(old_config_name, get_config_file_name()); #endif }
//--------------------------------------------------------------------------- bool File::Move(const Ztring &Source, const Ztring &Destination, bool OverWrite) { if (OverWrite && Exists(Source)) Delete(Destination); #ifdef ZENLIB_USEWX if (OverWrite && Exists(Destination)) wxRemoveFile(Destination.c_str()); return wxRenameFile(Source.c_str(), Destination.c_str()); #else //ZENLIB_USEWX #ifdef ZENLIB_STANDARD return !std::rename(Source.To_Local().c_str(), Destination.To_Local().c_str()); #elif defined WINDOWS #ifdef UNICODE return MoveFileW(Source.c_str(), Destination.c_str())!=0; #else return MoveFile(Source.c_str(), Destination.c_str())!=0; #endif //UNICODE #endif #endif //ZENLIB_USEWX }
void DirManager::MakePartOfProject(BlockFile *f) { wxString newFullPath = projFull + pathChar + f->name; if (newFullPath != f->fullPath) { bool ok = wxRenameFile(f->fullPath, newFullPath); if (ok) f->fullPath = newFullPath; else { ok = wxCopyFile(f->fullPath, newFullPath); if (ok) { wxRemoveFile(f->fullPath); f->fullPath = newFullPath; } else { wxString msg; msg.Printf("Could not rename %s to %s", (const char *)f->fullPath, (const char *)newFullPath); wxMessageBox(msg); } } } }
wxString weather_routing_pi::StandardPath() { wxStandardPathsBase& std_path = wxStandardPathsBase::Get(); wxString s = wxFileName::GetPathSeparator(); #ifdef __WXMSW__ wxString stdPath = std_path.GetConfigDir(); #endif #ifdef __WXGTK__ wxString stdPath = std_path.GetUserDataDir(); #endif #ifdef __WXOSX__ wxString stdPath = (std_path.GetUserConfigDir() + s + _T("opencpn")); // should be ~/Library/Preferences/opencpn #endif return stdPath + wxFileName::GetPathSeparator() + _T("plugins") + wxFileName::GetPathSeparator() + _T("weather_routing") + wxFileName::GetPathSeparator(); stdPath += s + _T("plugins"); if (!wxDirExists(stdPath)) wxMkdir(stdPath); stdPath += s + _T("weather_routing"); #ifdef __WXOSX__ // Compatibility with pre-OCPN-4.2; move config dir to // ~/Library/Preferences/opencpn if it exists wxString oldPath = (std_path.GetUserConfigDir() + s + _T("plugins") + s + _T("weather_routing")); if (wxDirExists(oldPath) && !wxDirExists(stdPath)) { wxLogMessage("weather_routing_pi: moving config dir %s to %s", oldPath, stdPath); wxRenameFile(oldPath, stdPath); } #endif if (!wxDirExists(stdPath)) wxMkdir(stdPath); stdPath += s; return stdPath; }
bool DirManager::MoveToNewProjectDirectory(BlockFile *f) { wxFileName newFileName(projFull, f->mFileName.GetFullName()); if ( !(newFileName == f->mFileName) ) { bool ok = wxRenameFile(f->mFileName.GetFullPath(), newFileName.GetFullPath()); if (ok) f->mFileName = newFileName; else { ok = wxCopyFile(f->mFileName.GetFullPath(), newFileName.GetFullPath()); if (ok) { wxRemoveFile(f->mFileName.GetFullPath()); f->mFileName = newFileName; } else return false; } } return true; }
bool mmAttachmentManage::DeleteAttachment(const wxString& FileToDelete) { if (wxFileExists(FileToDelete)) { if (Model_Infotable::instance().GetBoolInfo("ATTACHMENTSTRASH", false)) { wxString DeletedAttachmentFolder = mmex::getPathAttachment(mmAttachmentManage::InfotablePathSetting()) + m_PathSep + "Deleted"; if (!wxDirExists(DeletedAttachmentFolder)) { if (wxMkdir(DeletedAttachmentFolder)) mmAttachmentManage::CreateReadmeFile(DeletedAttachmentFolder); else return false; } wxString FileToTrash = DeletedAttachmentFolder + m_PathSep + wxDateTime::Now().FormatISODate() + "_" + wxFileNameFromPath(FileToDelete); if (!wxRenameFile(FileToDelete, FileToTrash)) return false; } else if (!wxRemoveFile(FileToDelete)) return false; } else { wxString msgStr = wxString() << _("Attachment not found:") << "\n" << "'" << FileToDelete << "'" << "\n" << "\n" << _("Do you want to continue and delete attachment on database?") << "\n"; int DeleteResponse = wxMessageBox(msgStr, _("Delete attachment failed"), wxYES_NO | wxNO_DEFAULT | wxICON_ERROR); if (DeleteResponse == wxYES) return true; else return false; } return true; }
//---------------------------------------- bool wxBratTools::RenameFile(const wxString& oldName, const wxString& newName) { bool bOk = true; bOk = wxFileExists(oldName); if (bOk == false) { return true; } try { bOk = wxRenameFile(oldName, newName); } catch (...) { //Nothing to do bOk = false; } return bOk; }
bool CodeLiteApp::IsSingleInstance(const wxCmdLineParser &parser, const wxString &curdir) { // check for single instance if ( clConfig::Get().Read("SingleInstance", false) ) { const wxString name = wxString::Format(wxT("CodeLite-%s"), wxGetUserId().c_str()); m_singleInstance = new wxSingleInstanceChecker(name); if (m_singleInstance->IsAnotherRunning()) { // prepare commands file for the running instance wxString files; for (size_t i=0; i< parser.GetParamCount(); i++) { wxString argument = parser.GetParam(i); //convert to full path and open it wxFileName fn(argument); fn.MakeAbsolute(curdir); files << fn.GetFullPath() << wxT("\n"); } if (files.IsEmpty() == false) { Mkdir(ManagerST::Get()->GetStarupDirectory() + wxT("/ipc")); wxString file_name, tmp_file; tmp_file << ManagerST::Get()->GetStarupDirectory() << wxT("/ipc/command.msg.tmp"); file_name << ManagerST::Get()->GetStarupDirectory() << wxT("/ipc/command.msg"); // write the content to a temporary file, once completed, // rename the file to the actual file name WriteFileUTF8(tmp_file, files); wxRenameFile(tmp_file, file_name); } return false; } } return true; }
void ModEditWindow::OnInstallForgeClicked(wxCommandEvent &event) { InstallForgeDialog installDlg (this, m_inst->GetMCVersion()); installDlg.CenterOnParent(); if (installDlg.ShowModal() == wxID_OK) { auto ver = installDlg.GetSelectedItem(); wxString forgePath = Path::Combine(m_inst->GetInstModsDir(), ver.Filename); auto dlTask = new FileDownloadTask(ver.Url, wxFileName("forge.zip")); TaskProgressDialog taskDlg(this); taskDlg.CenterOnParent(); if (taskDlg.ShowModal(dlTask)) { MinecraftForge forge(wxFileName("forge.zip")); forge.FixVersionIfNeeded(ver.ForgeVersion); wxRenameFile("forge.zip",forgePath, true); m_inst->GetModList()->InsertMod(0, forgePath); jarModList->UpdateItems(); } } }
bool PHPFolder::RenameFile(const wxString& old_filename, const wxString& new_filename) { wxFileName fnOld(old_filename); wxFileName fnNew(new_filename); fnNew.SetPath(fnOld.GetPath()); int where = m_files.Index(fnOld.GetFullName()); if(where == wxNOT_FOUND) { return false; } // a file with this name already exists if(fnNew.Exists()) { return false; } m_files.RemoveAt(where); m_files.Add(fnNew.GetFullName()); m_files.Sort(); // Step: 2 // Notify the plugins, maybe they want to override the // default behavior (e.g. Subversion plugin) wxArrayString f; f.Add(fnOld.GetFullPath()); f.Add(fnNew.GetFullPath()); if(!::SendCmdEvent(wxEVT_FILE_RENAMED, (void*)&f)) { // rename the file on filesystem wxRenameFile(fnOld.GetFullPath(), fnNew.GetFullPath()); } PHPEvent eventFileRenamed(wxEVT_PHP_FILE_RENAMED); eventFileRenamed.SetOldFilename(fnOld.GetFullPath()); eventFileRenamed.SetFileName(fnNew.GetFullPath()); EventNotifier::Get()->AddPendingEvent(eventFileRenamed); return true; }