Exemplo n.º 1
0
UBDocumentProxy* UBImportDocument::importFile(const QFile& pFile, const QString& pGroup)
{
    Q_UNUSED(pGroup); // group is defined in the imported file

    QFileInfo fi(pFile);
    UBApplication::showMessage(tr("Importing file %1...").arg(fi.baseName()), true);

    // first unzip the file to the correct place
    QString path = UBSettings::userDocumentDirectory();

    QString documentRootFolder;
    
	if(!extractFileToDir(pFile, path, documentRootFolder)){
		UBApplication::showMessage(tr("Import of file %1 failed.").arg(fi.baseName()));
		return NULL;
	}

    bool addTitlePage = false;
    if(UBSettings::settings()->teacherGuidePageZeroActivated->get().toBool() && !QFile(documentRootFolder+"/page000.svg").exists())
        addTitlePage=true;

    UBDocumentProxy* newDocument = UBPersistenceManager::persistenceManager()->createDocumentFromDir(documentRootFolder, pGroup, "", false, addTitlePage);
	UBApplication::showMessage(tr("Import successful."));
	return newDocument;
}
Exemplo n.º 2
0
bool UBImportDocument::addFileToDocument(UBDocumentProxy* pDocument, const QFile& pFile)
{
    QFileInfo fi(pFile);
    UBApplication::showMessage(tr("Importing file %1...").arg(fi.baseName()), true);

    QString path = UBFileSystemUtils::createTempDir();

    QString documentRootFolder;
    if (!extractFileToDir(pFile, path, documentRootFolder))
    {
        UBApplication::showMessage(tr("Import of file %1 failed.").arg(fi.baseName()));
        return false;
    }
        
    if (!UBPersistenceManager::persistenceManager()->addDirectoryContentToDocument(documentRootFolder, pDocument))
    {
        UBApplication::showMessage(tr("Import of file %1 failed.").arg(fi.baseName()));
        return false;
    }

    UBFileSystemUtils::deleteDir(path);

    UBApplication::showMessage(tr("Import successful."));

    return true;
}
Exemplo n.º 3
0
void extractLauncherResource(LauncherProperties * props, LauncherResource ** file, char * name) {
    char * typeStr = appendString(appendString(NULL, name), " type");
    * file = newLauncherResource();
    
    readNumberWithDebug( props, & ((*file)->type) , typeStr);
    
    if(isOK(props)) {
        FREE(typeStr);
        
        if((*file)->type==0) { //bundled
            writeMessageA(props, OUTPUT_LEVEL_DEBUG, 1,  "... file is bundled", 1);
            extractFileToDir(props, & ((*file)->path));
            if(!isOK(props)) {
                writeMessageA(props, OUTPUT_LEVEL_DEBUG, 1,  "Error extracting file!", 1);
                return;
            } else {
                (*file)->resolved = appendStringW(NULL, (*file)->path);
                writeMessageA(props, OUTPUT_LEVEL_DEBUG, 0, "file was succesfully extracted to ", 0);
                writeMessageW(props, OUTPUT_LEVEL_DEBUG, 0,  (*file)->path, 1);
            }
        } else {
            writeMessageA(props, OUTPUT_LEVEL_DEBUG, 1,  "... file is external", 1);
            readStringWithDebugW(props, & ((*file)->path), name);
            if(!isOK(props)) {
                writeMessageA(props, OUTPUT_LEVEL_DEBUG, 1, "Error reading ", 1);
                writeMessageA(props, OUTPUT_LEVEL_DEBUG, 1, name, 1);
            }
        }
    }  else {
        writeMessageA(props, OUTPUT_LEVEL_DEBUG, 1, "Error reading ", 0);
        writeMessageA(props, OUTPUT_LEVEL_DEBUG, 1, typeStr, 0);
        FREE(typeStr);
    }
}