bool deleteProject ( const string& user, const string& project )
{
	bool calProject = project.rfind ( ".cal." ) != string::npos;

	if ( MySQLPPSDDBase::instance ().projectHasQueuedOrRunningJobs ( user, project ) ) {
		return false;
	}
	StringVector resultsList = MySQLPPSDDBase::instance ().getResultsList ( user, project );	// Delete all the results
	for ( StringVectorSizeType i = 0 ; i < resultsList.size () ; i++ ) {
		deleteResults ( user, project, resultsList [i] );
	}

	ProjectInfo* pi = MySQLPPSDDBase::instance ().getProjectInfo ( user, project );

	string projectPath = pi->getProjectFullPath ();
	if ( genFileExists ( projectPath + ".7z" ) ) {		// Check that the project isn't compressed
		gen7zaUncompress ( projectPath + ".7z" );
	}
	if ( !calProject ) {
		ProjectFile pf ( projectPath );
		if ( pf.isUploadProject () ) {
			string dataPath = pf.getUploadDirectory ();
			if ( genFileExists ( dataPath ) ) genUnlinkDirectory ( dataPath );				// Delete the data
			genRmdir ( genDirectoryFromPath ( dataPath ) );	// Try to delete the data date directory. This will fail if the directory isn't empty.
		}
	}
	genUnlink ( projectPath );													// Delete the project file.

	if ( !calProject ) {
		FileList f1 ( pi->getProjectDirectory (), pi->getProjectName () + ".exp.", "", false );	// Delete the .exp files.
		f1.unlink ();
	}

	MySQLPPSDDBase::instance ().deleteProjectID ( pi->getProjectID () );						// Delete the database entry.

	if ( !calProject ) {																		// Delete the calibrated projects.
		StringVector sv = MySQLPPSDDBase::instance ().getProjectList ( user, true );
		for ( StringVectorSizeType j = 0 ; j < sv.size () ; j++ ) {
			if ( isPrefix ( sv [j], project + ".cal." ) ) {
				deleteProject ( user, sv [j] );
			}
		}
	}
	genRmdir ( genDirectoryFromPath ( projectPath ) );	// Try to delete the project date directory. This will fail if the directory isn't empty.
	delete pi;
	return true;
}