// ---------------------------------------------------------------------------
// CMmMtpDpMetadataAccessWrapper::RenameObjectL
// Renames the file part of a record in the collection database
// ---------------------------------------------------------------------------
//
EXPORT_C void CMmMtpDpMetadataAccessWrapper::RenameObjectL( const CMTPObjectMetaData& aOldObject,
    const TDesC& aNewFileName )
    {
    TPtrC oldFileName( aOldObject.DesC( CMTPObjectMetaData::ESuid ) );
    PRINT2( _L( "MM MTP => CMmMtpDpMetadataAccessWrapper::RenameObjectL old = %S, new = %S" ),
        &oldFileName,
        &aNewFileName );

    TMPXGeneralCategory category = Category( aOldObject );
    switch ( category )
        {
        case EMPXSong:
        case EMPXAbstractAlbum:
        case EMPXPlaylist:
            {
            iMmMtpDpMetadataMpxAccess->RenameObjectL( oldFileName,
                aNewFileName,
                category );
            }
            break;
        case EMPXVideo:
            iMmMtpDpMetadataVideoAccess->RenameRecordL( oldFileName, aNewFileName );
            break;
        default:
            break;
        }


    PRINT( _L( "MM MTP <= CMmMtpDpMetadataAccessWrapper::RenameObjectL" ) );
    }
Ejemplo n.º 2
0
void MainDialog::OnButtonTargetFile(wxCommandEvent& WXUNUSED(event))
{
  // Get the path of any currently selected file
  wxString oldDirectory = "";

  // Get the current file (if any) and set as the default
  wxFileName oldFileName(targetFileTextCtrl->GetValue());
  if(oldFileName.FileExists())
  {
    oldDirectory = oldFileName.GetPath();
  }

  // Open the file dialog
  wxFileDialog fileDialog(this, _T("Select the target OpenGL application"), oldDirectory, _T(""), _T("Executables (*.exe)|*.exe|Any (*.*)|*.*"), wxOPEN | wxFILE_MUST_EXIST );
  if (fileDialog.ShowModal() != wxID_OK)
  {
    return;
  }

  // If the selected string is empty, or the file does not exist, abort.
  if (fileDialog.GetPath().IsEmpty() || 
      !wxFileExists(fileDialog.GetPath()))
  {
    return;
  }
  
  // Set the new text in the text edit control
  targetFileTextCtrl->SetValue(fileDialog.GetPath());
}
Ejemplo n.º 3
0
void cItem::safeoldsave()
{
	std::string oldFileName( SrvParms->savePath + SrvParms->itemWorldfile + SrvParms->worldfileExtension );
	std::string newFileName( SrvParms->savePath + SrvParms->itemWorldfile + SrvParms->worldfileExtension + "$" );
	remove( newFileName.c_str() );
	rename( oldFileName.c_str(), newFileName.c_str() );
}
Ejemplo n.º 4
0
void File::rename(const Str & name)
{
	if(0 <= file)
		close();

	String oldFileName(fileName);
//	char buf[PATH_MAX];
//	String cwd(char *getcwd(buf, PATH_MAX));
	fileName.assign(name);
	int fn = ::rename(oldFileName.c_str(), fileName.c_str());
	if(fn < 0){
		int errNo = errno;
		fileName = move_cast(oldFileName);
		throw FileError(errNo, "Could not rename file % to %.", fileName, name);
	}
}
Ejemplo n.º 5
0
bool Utils::cp(const QString &oldName, const QString &newName) {
    QString oldFileName(oldName.split("file://").last());
    return QFile::copy(oldFileName, newName) || QFile::exists(newName);
}
Ejemplo n.º 6
0
//---------------------------------------------------------
bool CWKSP_Project::_Save(const wxString &FileName, bool bSaveModified, bool bUpdateMenu)
{
	int							i, j;
	wxString					ProjectDir, oldFileName(m_File_Name);
	CSG_MetaData				Project, *pNode;
	CWKSP_Table_Manager			*pTables;
	CWKSP_Shapes_Manager		*pShapes;
	CWKSP_TIN_Manager			*pTINs;
	CWKSP_PointCloud_Manager	*pPointClouds;
	CWKSP_Grid_Manager			*pGrids;

	//-----------------------------------------------------
	m_File_Name	= FileName;

	if( bSaveModified && !g_pData->Save_Modified() )
	{
		m_File_Name	= oldFileName;

		return( false );
	}

	//-----------------------------------------------------
	ProjectDir	= SG_File_Get_Path(&FileName).w_str();

	Project.Set_Name    ("SAGA_PROJECT");
	Project.Add_Property("VERSION", SAGA_VERSION);

	//-----------------------------------------------------
	pNode		= Project.Add_Child("DATA");

	if( (pTables = g_pData->Get_Tables()) != NULL )
	{
		for(i=0; i<pTables->Get_Count(); i++)
		{
			_Save_Data(*pNode, ProjectDir,
				pTables->Get_Data(i)->Get_Object(),
				pTables->Get_Data(i)->Get_Parameters()
			);
		}
	}

	if( (pTINs = g_pData->Get_TINs()) != NULL )
	{
		for(i=0; i<pTINs->Get_Count(); i++)
		{
			_Save_Data(*pNode, ProjectDir,
				pTINs->Get_Data(i)->Get_Object(),
				pTINs->Get_Data(i)->Get_Parameters()
			);
		}
	}

	if( (pPointClouds = g_pData->Get_PointClouds()) != NULL )
	{
		for(i=0; i<pPointClouds->Get_Count(); i++)
		{
			_Save_Data(*pNode, ProjectDir,
				pPointClouds->Get_Data(i)->Get_Object(),
				pPointClouds->Get_Data(i)->Get_Parameters()
			);
		}
	}

	if( (pShapes = g_pData->Get_Shapes()) != NULL )
	{
		for(j=0; j<pShapes->Get_Count(); j++)
		{
			for(i=0; i<pShapes->Get_Shapes_Type(j)->Get_Count(); i++)
			{
				_Save_Data(*pNode, ProjectDir,
					pShapes->Get_Shapes_Type(j)->Get_Data(i)->Get_Object(),
					pShapes->Get_Shapes_Type(j)->Get_Data(i)->Get_Parameters()
				);
			}
		}
	}

	if( (pGrids = g_pData->Get_Grids()) != NULL )
	{
		for(j=0; j<pGrids->Get_Count(); j++)
		{
			for(i=0; i<pGrids->Get_System(j)->Get_Count(); i++)
			{
				_Save_Data(*pNode, ProjectDir,
					((CWKSP_Data_Item *)pGrids->Get_System(j)->Get_Item(i))->Get_Object(),
					((CWKSP_Data_Item *)pGrids->Get_System(j)->Get_Item(i))->Get_Parameters()
				);
			}
		}
	}

	//-----------------------------------------------------
	if( g_pMaps->Get_Count() > 0 )
	{
		pNode		= Project.Add_Child("MAPS");

		for(i=0; i<g_pMaps->Get_Count(); i++)
		{
			_Save_Map(*pNode, ProjectDir, g_pMaps->Get_Map(i));
		}
	}

	//-----------------------------------------------------
	if( Project.Save(&FileName) )
	{
		m_File_Name	= FileName;

		if( bUpdateMenu )
			g_pData->Get_Menu_Files()->Recent_Add(SG_DATAOBJECT_TYPE_Undefined, FileName);

		MSG_General_Add(_TL("Project has been saved."), true, true, SG_UI_MSG_STYLE_SUCCESS);

		_Set_Project_Name();

		PROGRESSBAR_Set_Position(0);

		return( true );
	}

	m_File_Name.Clear();

	if( bUpdateMenu )
		g_pData->Get_Menu_Files()->Recent_Del(SG_DATAOBJECT_TYPE_Undefined, FileName);

	MSG_General_Add(_TL("Could not save project."), true, true, SG_UI_MSG_STYLE_FAILURE);

	PROGRESSBAR_Set_Position(0);

	return( false );
}
Ejemplo n.º 7
0
bool ArticleWriter::MoveCompletedFiles(NzbInfo* nzbInfo, const char* oldDestDir)
{
	if (nzbInfo->GetCompletedFiles()->empty())
	{
		return true;
	}

	// Ensure the DstDir is created
	CString errmsg;
	if (!FileSystem::ForceDirectories(nzbInfo->GetDestDir(), errmsg))
	{
		nzbInfo->PrintMessage(Message::mkError, "Could not create directory %s: %s", nzbInfo->GetDestDir(), *errmsg);
		return false;
	}

	// move already downloaded files to new destination
	for (CompletedFile& completedFile : nzbInfo->GetCompletedFiles())
	{
		BString<1024> oldFileName("%s%c%s", oldDestDir, PATH_SEPARATOR, completedFile.GetFilename());
		BString<1024> newFileName("%s%c%s", nzbInfo->GetDestDir(), PATH_SEPARATOR, completedFile.GetFilename());

		// check if file was not moved already
		if (strcmp(oldFileName, newFileName))
		{
			// prevent overwriting of existing files
			newFileName = FileSystem::MakeUniqueFilename(nzbInfo->GetDestDir(), completedFile.GetFilename());

			detail("Moving file %s to %s", *oldFileName, *newFileName);
			if (!FileSystem::MoveFile(oldFileName, newFileName))
			{
				nzbInfo->PrintMessage(Message::mkError, "Could not move file %s to %s: %s",
					*oldFileName, *newFileName, *FileSystem::GetLastErrorMessage());
			}
		}
	}

	// delete old directory (if empty)
	if (FileSystem::DirEmpty(oldDestDir))
	{
		// check if there are pending writes into directory
		bool pendingWrites = false;
		for (FileInfo* fileInfo : nzbInfo->GetFileList())
		{
			if (!pendingWrites)
			{
				break;
			}

			if (fileInfo->GetActiveDownloads() > 0)
			{
				Guard guard = fileInfo->GuardOutputFile();
				pendingWrites = fileInfo->GetOutputInitialized() && !Util::EmptyStr(fileInfo->GetOutputFilename());
			}
			else
			{
				pendingWrites = fileInfo->GetOutputInitialized() && !Util::EmptyStr(fileInfo->GetOutputFilename());
			}
		}

		if (!pendingWrites)
		{
			FileSystem::RemoveDirectory(oldDestDir);
		}
	}

	return true;
}