VError VFolder::Delete( bool inRemoveContent ) const
{
	VError err;
	bool needThrow;
	if (IsEmpty())
	{
		err = fFolder.Delete();
		needThrow = IS_NATIVE_VERROR( err);
	}
	else
	{
		if ( inRemoveContent )
		{
			err = DeleteContents( true );
			if ( err == VE_OK )
				err = fFolder.Delete();
			needThrow = IS_NATIVE_VERROR( err);
		}
		else
		{
			err = VE_FOLDER_NOT_EMPTY;
			needThrow = true;
		}
	}

	xbox_assert( (err != VE_OK) || !fFolder.Exists( true));

	if (needThrow)
	{
		StThrowFileError errThrow( this, VE_FOLDER_CANNOT_DELETE, err);
		err = errThrow.GetError();
	}

	return err;
}
VError	VFolder::GetVolumeCapacity(sLONG8* outTotalBytes)const
{
#if !VERSION_LINUX

	VError err = fFolder.GetVolumeCapacity( outTotalBytes );

	if (IS_NATIVE_VERROR( err))
	{
		StThrowFileError errThrow( this, VE_FOLDER_CANNOT_GET_ATTRIBUTES, err);
		err = errThrow.GetError();
	}
	
	return err;

#else
    
    //jmo - Build fix rapide pour un truc qui n'est utilise que dans 4D.
    if(outTotalBytes!=NULL)
        *outTotalBytes=0;

    xbox_assert(false);
    return VE_UNIMPLEMENTED;

#endif
}
/*
	static
*/
VError VFolder::ResolveAliasFolder( VFolder **ioFolder, bool inDeleteInvalidAlias)
{
	VError err = VE_OK;
	if ( (*ioFolder != NULL) && (*ioFolder)->fPath.IsFolder() && !(*ioFolder)->fFolder.Exists( false /* doesn't check alias */) )
	{
		// the folder doesn't exists
		// maybe is it an alias file?
		VString path = (*ioFolder)->fPath.GetPath();
		if (testAssert( path[path.GetLength()-1] == FOLDER_SEPARATOR))
		{
			path.Truncate( path.GetLength()-1);
			#if VERSIONWIN
			path += ".lnk";
			#endif
			VFile file( path);
			if (file.IsAliasFile() && file.Exists())
			{
				VFilePath resolvedPath;
				err = file.GetImpl()->ResolveAlias( resolvedPath);	// nothrow
				if (err == VE_OK)
				{
					if (resolvedPath.IsFolder())
					{
						(*ioFolder)->Release();
						*ioFolder = new VFolder( resolvedPath);
					}
					else if (inDeleteInvalidAlias)
					{
						err = file.Delete();
					}
					else
					{
						StThrowFileError errThrow( *ioFolder, VE_FILE_CANNOT_RESOLVE_ALIAS_TO_FOLDER);
						err = errThrow.GetError();
					}
				}
				else if (inDeleteInvalidAlias)
				{
					err = file.Delete();
				}
				else
				{
					if (IS_NATIVE_VERROR( err))
					{
						StThrowFileError errThrow( &file, VE_FILE_CANNOT_RESOLVE_ALIAS, err);
						err = errThrow.GetError();
					}
				}
			}
		}
	}
	return err;
}
VError VFolder::MAC_GetPermissions( uWORD *outMode )
{
	VError err = fFolder.GetPermissions(outMode);
	
	if (IS_NATIVE_VERROR( err))
	{
		StThrowFileError errThrow( this, VE_FOLDER_CANNOT_GET_ATTRIBUTES, err);
		err = errThrow.GetError();
	}
	
	return err;
}
VError VFolder::WIN_SetAttributes( DWORD inAttrb) const
{
	VError err = fFolder.SetAttributes( inAttrb);

	if (IS_NATIVE_VERROR( err))
	{
		StThrowFileError errThrow( this, VE_FOLDER_CANNOT_SET_ATTRIBUTES, err);
		err = errThrow.GetError();
	}
	
	return err;
}
VError VFolder::MakeWritableByAll()
{
	VError err = fFolder.MakeWritableByAll();
	
	if (IS_NATIVE_VERROR( err))
	{
		StThrowFileError errThrow( this, VE_FOLDER_CANNOT_SET_ATTRIBUTES, err);
		err = errThrow.GetError();
	}
	
	return err;
}
VError VFolder::GetVolumeFreeSpace(sLONG8 *outFreeBytes, bool inWithQuotas ) const
{
	VError err = fFolder.GetVolumeFreeSpace( outFreeBytes, inWithQuotas );

	if (IS_NATIVE_VERROR( err))
	{
		StThrowFileError errThrow( this, VE_FOLDER_CANNOT_GET_ATTRIBUTES, err);
		err = errThrow.GetError();
	}
	
	return err;
}
VError VFolder::GetTimeAttributes( VTime* outLastModification, VTime* outCreationTime, VTime* outLastAccess ) const
{
	VError err = fFolder.GetTimeAttributes( outLastModification, outCreationTime, outLastAccess );

	if (IS_NATIVE_VERROR( err))
	{
		StThrowFileError errThrow( this, VE_FOLDER_CANNOT_GET_ATTRIBUTES, err);
		err = errThrow.GetError();
	}
	
	return err;
}
VError VFolder::SetTimeAttributes( const VTime *inLastModification, const VTime *inCreationTime, const VTime *inLastAccess ) const
{
	VError err = fFolder.SetTimeAttributes( inLastModification, inCreationTime, inLastAccess );

	if (IS_NATIVE_VERROR( err))
	{
		StThrowFileError errThrow( this, VE_FILE_CANNOT_GET_ATTRIBUTES, err);
		err = errThrow.GetError();
	}

	return err;
}
VError VFolder::Move( const VFolder& inNewParent, VFolder** outFolder ) const
{
	VError err = fFolder.Move( inNewParent, outFolder );

	if (IS_NATIVE_VERROR( err))
	{
		StThrowFileError errThrow( this, VE_FOLDER_CANNOT_RENAME, err);
		//errThrow->SetString( "newname", inName);
		err = errThrow.GetError();
	}

	return err;
}
VError VFolder::Rename( const VString& inName, VFolder** outFile ) const
{
	VError err = fFolder.Rename( inName, outFile );

	if (IS_NATIVE_VERROR( err))
	{
		StThrowFileError errThrow( this, VE_FOLDER_CANNOT_RENAME, err);
		errThrow->SetString( "newname", inName);
		err = errThrow.GetError();
	}

	return err;
}
VError VFolder::Create() const
{
	VError	err = VE_OK;
	
	// this is not an error if the folder already exists
	if (!fFolder.Exists( true))
	{
		err = fFolder.Create();
		xbox_assert( (err != VE_OK) || fFolder.Exists( true));

		if (IS_NATIVE_VERROR( err))
		{
			StThrowFileError errThrow( this, VE_FOLDER_CANNOT_CREATE, err);
			err = errThrow.GetError();
		}
	}
	return err;
}
VError VFolder::MoveToTrash() const
{
	VError	err = VE_OK;
	
	// this is not an error if the folder already exists
	if (fFolder.Exists( true))
	{
		err = fFolder.MoveToTrash();
		xbox_assert( (err != VE_OK) || !fFolder.Exists( true));
        
		if (IS_NATIVE_VERROR( err))
		{
			StThrowFileError errThrow( this, VE_CANNOT_MOVE_TO_TRASH, err);
			err = errThrow.GetError();
		}
	}
	return err;
}
Beispiel #14
0
VError XLinuxFile::Move(const VFilePath& inDestinationPath, VFileSystem *inDestinationFileSystem, VFile** outFile, FileCopyOptions /*inOptions*/) const
{
	VFilePath dstPath(inDestinationPath);

	if (dstPath.IsFolder())
	{
		VStr255 name;					//jmo - todo : NAME_MAX ?
		fOwner->GetName(name);
		dstPath.SetFileName(name);
	}

	PathBuffer pathBuffer;
	pathBuffer.Init(dstPath);

	//First we try to rename the file...
	VError verr;
	{
		RenameHelper rnmHlp;
		verr=rnmHlp.Rename(fPath, pathBuffer);
	}

	//If Rename() fails because src and dst are not on the same fs, we try a Copy()
	if(verr!=VE_OK && IS_NATIVE_VERROR(verr) && NATIVE_ERRCODE_FROM_VERROR(verr)==EXDEV)
	{
		CopyHelper cpHlp;
		verr = cpHlp.Copy(fPath, pathBuffer);

		// it's a move not a copy, so one must delete the source after a sucessful copy
		if (verr == VE_OK)
		{
			int res=unlink(fPath.GetPath());
			verr = (res==0) ? VE_OK :  MAKE_NATIVE_VERROR(errno);
		}
	}

	if (outFile != NULL)
	{
		*outFile = (verr == VE_OK) ? new VFile( dstPath, inDestinationFileSystem) : NULL;
	}

	return verr;
}
VError XLinuxFile::Move(const VFilePath& inDestinationPath, VFile** outFile, FileCopyOptions inOptions) const
{
	VFilePath dstPath(inDestinationPath);
	
	if (dstPath.IsFolder())
	{
		VStr255 name;					//jmo - todo : NAME_MAX ?
		fOwner->GetName(name);
		dstPath.SetFileName(name);
	}

	//First we try to rename the file...
	VError verr=Rename(dstPath.GetPath(), outFile);

	//If Rename() fails beacause src and dst are not on the same fs, we try a Copy()
	if(verr!=VE_OK && IS_NATIVE_VERROR(verr) && NATIVE_ERRCODE_FROM_VERROR(verr)==EXDEV)
		verr=Copy(inDestinationPath, outFile, inOptions);
	
	return verr;
}
bool VFolder::RevealInFinder( bool inInside) const
{
	bool done = false;
	if (inInside)
	{
		VFileIterator iter( this);
		VFile *firstFile = iter.First();
		if (firstFile != NULL)
			done = firstFile->RevealInFinder();
	}
	if (!done)
	{
		VError err = fFolder.RevealInFinder();

		if (IS_NATIVE_VERROR( err))
		{
			StThrowFileError errThrow( this, VE_FOLDER_CANNOT_REVEAL, err);
			err = errThrow.GetError();
		}
		done = err == VE_OK;
	}

	return done;
}