Esempio n. 1
0
static void convertMDY(Gob::GameDir &gameDir) {
	const std::list<std::string> &mdy = gameDir.getMDY();
	for (std::list<std::string>::const_iterator f = mdy.begin(); f != mdy.end(); ++f) {
		std::string tbr = changeExtension(*f, "tbr");

		try {
			convertMDY(gameDir, *f, tbr);
		} catch (Common::Exception &e) {
			Common::printException(e, "WARNING: ");
		}
	}
}
Esempio n. 2
0
void DataManagerImpl::deleteFiles(DataPtr data, QString basePath)
{
	if (!data)
		return;
	ImagePtr image = boost::dynamic_pointer_cast<Image>(data);
	QStringList files;
	if (!data->getFilename().isEmpty())
	{
		files << QDir(basePath).absoluteFilePath(data->getFilename());
		if (image)
			files <<  changeExtension(files[0], "raw");
	}

	for (int i=0; i<files.size(); ++i)
	{
		if (!QFileInfo(files[i]).exists())
			continue;
		report(QString("Removing %1 from disk").arg(files[i]));
		QFile(files[i]).remove();
	}
}
Esempio n. 3
0
FileSystem::FileSystem(const char *hashFilename) {

	for (int i = 0; i < 10; i++) {
		_hagEntries[i].filename[0] = '\0';
		_hagEntries[i].fileIndex = 0; // Was -1
		_hagEntries[i].hagFile = 0;
	}

	Common::File hashFile;
	uint32 hashSize;

	hashFile.open(hashFilename);

	if (!hashFile.isOpen()) {
		debugCN(kDebugCore, "FileSystem::FileSystem: error opening hash %s\n", hashFilename);
	}

	hashSize = hashFile.readUint32LE();

	//debugCN(kDebugCore, "FileSystem::FileSystem: hashSize = %d\n", hashSize);

	/* load file records and add them to the hash list */
	for (uint i = 0; i < hashSize; i++) {
		HashFileEntry entry;
		hashFile.read(entry.filename, kM4MaxFilenameSize);
		str_lower(entry.filename);
		entry.hagfile = hashFile.readByte();
		hashFile.readByte();
		entry.offset = hashFile.readUint32LE();
		entry.size = hashFile.readUint32LE();
		hashFile.readUint32LE();

		if (entry.filename[0]) {
			/*
			debugCN(kDebugCore, "  filename: %s\n", entry.filename);
			debugCN(kDebugCore, "  hagfile: %d\n", entry.hagfile);
			debugCN(kDebugCore, "  disks: %d\n", entry.disks);
			debugCN(kDebugCore, "  offset: %08X\n", entry.offset);
			debugCN(kDebugCore, "  size: %d\n", entry.size);
			debugCN(kDebugCore, "  next: %08X\n", entry.next);
			*/
			_fileEntries[entry.filename] = entry;
		}

	}

	/* load hagfile records and update the list */
	while (!hashFile.eos()) {
		HashHagEntry entry;
		hashFile.read(entry.filename, kM4MaxFilenameSize);
		entry.fileIndex = hashFile.readByte();
		if (hashFile.eos())
			break;

		changeExtension(_hagEntries[entry.fileIndex].filename, entry.filename, "HAG");
		_hagEntries[entry.fileIndex].fileIndex = entry.fileIndex;

		_hagEntries[entry.fileIndex].hagFile = new Common::File();
		_hagEntries[entry.fileIndex].hagFile->open(_hagEntries[entry.fileIndex].filename);

		if (!_hagEntries[entry.fileIndex].hagFile->isOpen()) {
			debugCN(kDebugCore, "FileSystem::FileSystem: error opening hag %s\n", _hagEntries[entry.fileIndex].filename);
		}

	}

	hashFile.close();

}
Esempio n. 4
0
void case4(char *nf) {
  char 
    *pres=changeExtension(nf, abr),
    *pfig=changeExtension(pres, fig);
  execlp("./bin/creerA", "creerA", nf, pres, pfig, NULL);
}
Esempio n. 5
0
void case3(char *nf) {
  char 
    *pres=changeExtension(nf, hach),
    *pfig=changeExtension(pres, fig);
  execlp("./bin/creerH", "creerH", nf, pres, pfig, NULL);
}
Esempio n. 6
0
void case2(char *nf) {
  char 
    *pres=changeExtension(nf, res),
    *pfig=changeExtension(nf, fig);
  execlp("./bin/creerR", "creerR", nf, pres, pfig, NULL);
}
Esempio n. 7
0
void case1(char *nf) {
  char *pfig=changeExtension(nf, fig);
  execlp("./bin/creerL", "creerL", nf, pfig, NULL);
  printf("Fichier rendu : %s\n", pfig);
}
Esempio n. 8
0
string const doSubstitution(InsetExternalParams const & params,
			    Buffer const & buffer, string const & s,
			    bool use_latex_path,
			    bool external_in_tmpdir,
			    Substitute what)
{
	Buffer const * masterBuffer = buffer.masterBuffer();
	string const parentpath = external_in_tmpdir ?
		masterBuffer->temppath() :
		buffer.filePath();
	string const filename = external_in_tmpdir ?
		params.filename.mangledFileName() :
		params.filename.outputFileName(parentpath);
	string const basename = changeExtension(
			onlyFileName(filename), string());
	string const absname = makeAbsPath(filename, parentpath).absFileName();

	string result = s;
	if (what != ALL_BUT_PATHS) {
		string const filepath = onlyPath(filename);
		string const abspath = onlyPath(absname);
		string const masterpath = external_in_tmpdir ?
			masterBuffer->temppath() :
			masterBuffer->filePath();
		// FIXME UNICODE
		string relToMasterPath = onlyPath(
				to_utf8(makeRelPath(from_utf8(absname),
							     from_utf8(masterpath))));
		if (relToMasterPath == "./")
			relToMasterPath.clear();
		// FIXME UNICODE
		string relToParentPath = onlyPath(
				to_utf8(makeRelPath(from_utf8(absname),
							     from_utf8(parentpath))));
		if (relToParentPath == "./")
			relToParentPath.clear();

		result = subst_path(result, "$$FPath", filepath,
				    use_latex_path,
				    PROTECT_EXTENSION,
				    ESCAPE_DOTS);
		result = subst_path(result, "$$AbsPath", abspath,
				    use_latex_path,
				    PROTECT_EXTENSION,
				    ESCAPE_DOTS);
		result = subst_path(result, "$$RelPathMaster",
				    relToMasterPath, use_latex_path,
				    PROTECT_EXTENSION,
				    ESCAPE_DOTS);
		result = subst_path(result, "$$RelPathParent",
				    relToParentPath, use_latex_path,
				    PROTECT_EXTENSION,
				    ESCAPE_DOTS);
		if (FileName::isAbsolute(filename)) {
			result = subst_path(result, "$$AbsOrRelPathMaster",
					    abspath, use_latex_path,
					    PROTECT_EXTENSION,
					    ESCAPE_DOTS);
			result = subst_path(result, "$$AbsOrRelPathParent",
					    abspath, use_latex_path,
					    PROTECT_EXTENSION,
					    ESCAPE_DOTS);
		} else {
			result = subst_path(result, "$$AbsOrRelPathMaster",
					    relToMasterPath, use_latex_path,
					    PROTECT_EXTENSION,
					    ESCAPE_DOTS);
			result = subst_path(result, "$$AbsOrRelPathParent",
					    relToParentPath, use_latex_path,
					    PROTECT_EXTENSION,
					    ESCAPE_DOTS);
		}
	}

	if (what == PATHS)
		return result;

	result = subst_path(result, "$$FName", filename, use_latex_path,
			    EXCLUDE_EXTENSION);
	result = subst_path(result, "$$Basename", basename, use_latex_path,
			    PROTECT_EXTENSION, ESCAPE_DOTS);
	result = subst_path(result, "$$Extension",
			'.' + getExtension(filename), use_latex_path);
	result = subst_path(result, "$$Tempname", params.tempname().absFileName(), use_latex_path);
	result = subst_path(result, "$$Sysdir",
				package().system_support().absFileName(), use_latex_path);

	// Handle the $$Contents(filename) syntax
	if (contains(result, "$$Contents(\"")) {
		// Since use_latex_path may be true we must extract the file
		// name from s instead of result and do the substitutions
		// again, this time with use_latex_path false.
		size_t const spos = s.find("$$Contents(\"");
		size_t const send = s.find("\")", spos);
		string const file_template = s.substr(spos + 12, send - (spos + 12));
		string const file = doSubstitution(params, buffer,
						   file_template, false,
						   external_in_tmpdir, what);
		string contents;

		FileName const absfile(
			makeAbsPath(file, masterBuffer->temppath()));
		if (absfile.isReadableFile())
			// FIXME UNICODE
			contents = to_utf8(absfile.fileContents("UTF-8"));

		size_t const pos = result.find("$$Contents(\"");
		size_t const end = result.find("\")", pos);
		result.replace(pos, end + 2, contents);
	}

	return result;
}
KUrl OutputDirectory::calcPath( FileListItem *fileListItem, Config *config, const QStringList& usedOutputNames )
{
    ConversionOptions *options = config->conversionOptionsManager()->getConversionOptions(fileListItem->conversionOptionsId);
    if( !options )
        return KUrl();

    QString path;
    KUrl url;

    QString extension;
    if( config->pluginLoader()->codecExtensions(options->codecName).count() > 0 )
        extension = config->pluginLoader()->codecExtensions(options->codecName).first();

    if( extension.isEmpty() )
        extension = options->codecName;

    QString fileName;
    if( fileListItem->track == -1 )
        fileName = fileListItem->url.fileName();
    else
        fileName =  QString().sprintf("%02i",fileListItem->tags->track) + " - " + fileListItem->tags->artist + " - " + fileListItem->tags->title + "." + extension;

    if( options->outputDirectoryMode == Specify )
    {
        path = options->outputDirectory+"/"+fileName;

        if( config->data.general.useVFATNames || options->outputFilesystem == "vfat" )
            path = vfatPath( path );

        if( options->outputFilesystem == "ntfs" )
            path = ntfsPath( path );

        url = changeExtension( KUrl(path), extension );

        if( config->data.general.conflictHandling == Config::Data::General::NewFileName )
            url = uniqueFileName( url, usedOutputNames );

        return url;
    }
    else if( options->outputDirectoryMode == MetaData )
    {
        path = options->outputDirectory;

        // TODO a little bit redundant, adding %f if file name wasn't set properly
        // TODO these restrictions could be a little bit over the top
        if( path.right(1) == "/" )
            path += "%f";
        else if( path.lastIndexOf(QRegExp("%[abcdfgnpty]")) < path.lastIndexOf("/") )
            path += "/%f";

        const int fileNameBegin = path.lastIndexOf("/");
        if( fileListItem->tags == 0 ||
            ( path.mid(fileNameBegin).contains("%n") && fileListItem->tags->track == 0 ) ||
            ( path.mid(fileNameBegin).contains("%t") && fileListItem->tags->title.isEmpty() )
          )
        {
            path = path.left( fileNameBegin ) + "/%f";
        }

        path.replace( "\\[", "$quared_bracket_open$" );
        path.replace( "\\]", "$quared_bracket_close$" );

        QRegExp reg( "\\[(.*)%([abcdfgnpty])(.*)\\]" );
        reg.setMinimal( true );
        while( path.indexOf(reg) != -1 )
        {
            if( fileListItem->tags &&
                (
                  ( reg.cap(2) == "a" && !fileListItem->tags->artist.isEmpty() ) ||
                  ( reg.cap(2) == "b" && !fileListItem->tags->album.isEmpty() ) ||
                  ( reg.cap(2) == "c" && !fileListItem->tags->comment.isEmpty() ) ||
                  ( reg.cap(2) == "d" && fileListItem->tags->disc != 0 ) ||
                  ( reg.cap(2) == "g" && !fileListItem->tags->genre.isEmpty() ) ||
                  ( reg.cap(2) == "n" && fileListItem->tags->track != 0 ) ||
                  ( reg.cap(2) == "p" && !fileListItem->tags->composer.isEmpty() ) ||
                  ( reg.cap(2) == "t" && !fileListItem->tags->title.isEmpty() ) ||
                  ( reg.cap(2) == "y" && fileListItem->tags->year != 0 )
                )
              )
            {
                path.replace( reg, "\\1%\\2\\3" );
            }
            else
            {
                path.replace( reg, "" );
            }
        }

        path.replace( "$quared_bracket_open$", "[" );
        path.replace( "$quared_bracket_close$", "]" );

        while( path.contains("//") )
            path.replace( "//", "/" );

        path.replace( "%a", "$replace_by_artist$" );
        path.replace( "%b", "$replace_by_album$" );
        path.replace( "%c", "$replace_by_comment$" );
        path.replace( "%d", "$replace_by_disc$" );
        path.replace( "%g", "$replace_by_genre$" );
        path.replace( "%n", "$replace_by_track$" );
        path.replace( "%p", "$replace_by_composer$" );
        path.replace( "%t", "$replace_by_title$" );
        path.replace( "%y", "$replace_by_year$" );
        path.replace( "%f", "$replace_by_filename$" );

        QString artist = ( fileListItem->tags == 0 || fileListItem->tags->artist.isEmpty() ) ? i18n("Unknown Artist") : fileListItem->tags->artist;
        artist.replace("/",",");
        path.replace( "$replace_by_artist$", artist );

        QString album = ( fileListItem->tags == 0 || fileListItem->tags->album.isEmpty() ) ? i18n("Unknown Album") : fileListItem->tags->album;
        album.replace("/",",");
        path.replace( "$replace_by_album$", album );

        QString comment = ( fileListItem->tags == 0 || fileListItem->tags->comment.isEmpty() ) ? i18n("No Comment") : fileListItem->tags->comment;
        comment.replace("/",",");
        path.replace( "$replace_by_comment$", comment );

        QString disc = ( fileListItem->tags == 0 ) ? "0" : QString().sprintf("%i",fileListItem->tags->disc);
        path.replace( "$replace_by_disc$", disc );

        QString genre = ( fileListItem->tags == 0 || fileListItem->tags->genre.isEmpty() ) ? i18n("Unknown Genre") : fileListItem->tags->genre;
        genre.replace("/",",");
        path.replace( "$replace_by_genre$", genre );

        QString track = ( fileListItem->tags == 0 ) ? "00" : QString().sprintf("%02i",fileListItem->tags->track);
        path.replace( "$replace_by_track$", track );

        QString composer = ( fileListItem->tags == 0 || fileListItem->tags->composer.isEmpty() ) ? i18n("Unknown Composer") : fileListItem->tags->composer;
        composer.replace("/",",");
        path.replace( "$replace_by_composer$", composer );

        QString title = ( fileListItem->tags == 0 || fileListItem->tags->title.isEmpty() ) ? i18n("Unknown Title") : fileListItem->tags->title;
        title.replace("/",",");
        path.replace( "$replace_by_title$", title );

        QString year = ( fileListItem->tags == 0 ) ? "0000" : QString().sprintf("%04i",fileListItem->tags->year);
        path.replace( "$replace_by_year$", year );

        QString filename = fileName.left( fileName.lastIndexOf(".") );
        filename.replace("/",",");
        path.replace( "$replace_by_filename$", filename );

        if( config->data.general.useVFATNames || options->outputFilesystem == "vfat" )
            path = vfatPath( path );

        if( options->outputFilesystem == "ntfs" )
            path = ntfsPath( path );

        url = KUrl( path + "." + extension );

        if( config->data.general.conflictHandling == Config::Data::General::NewFileName )
            url = uniqueFileName( url, usedOutputNames );

        return url;
    }
    else if( options->outputDirectoryMode == CopyStructure )
    {
        QString basePath = options->outputDirectory;
        QString originalPath = fileListItem->url.pathOrUrl();
        int cutpos = basePath.length();
        while( basePath.left(cutpos) != originalPath.left(cutpos) )
        {
            cutpos = basePath.lastIndexOf( '/', cutpos - 1 );
        }
        // At this point, basePath and originalPath overlap on the left for cutpos characters (which might be 0).
        path = basePath+originalPath.mid(cutpos);

        if( config->data.general.useVFATNames || options->outputFilesystem == "vfat" )
            path = vfatPath( path );

        if( options->outputFilesystem == "ntfs" )
            path = ntfsPath( path );

        url = changeExtension( KUrl(path), extension );

        if( config->data.general.conflictHandling == Config::Data::General::NewFileName )
            url = uniqueFileName( url, usedOutputNames );

        return url;
    }
    else // SourceDirectory
    {
        path = fileListItem->url.toLocalFile();

        url = changeExtension( KUrl(path), extension );

        if( config->data.general.conflictHandling == Config::Data::General::NewFileName )
            url = uniqueFileName( url, usedOutputNames );

        return url;
    }
}