コード例 #1
0
ファイル: tGPXExportStrategy.cpp プロジェクト: dulton/53_hero
bool tGPXExportStrategy::ExportExtents(tOrientedRect extents)
{
    QFileInfo folderInfo;
    QModelIndex folderIndex; 
    QString filePath;
    bool isNew = true;
    bool success = false;

    if (SelectDestinationFolder(folderInfo, folderIndex, filePath, isNew) == false)
    {
        return false;
    }

    tGPXFileExport gpxExporter;

    m_pBusyIndicator->show();
    m_pBusyIndicator->repaint();
    qApp->processEvents();

    success = gpxExporter.ExportFile( filePath, true, extents);

    m_pBusyIndicator->close();

    tFile::syncdir( folderInfo.absoluteFilePath() );

    if ( success && isNew )
    {
        QFileInfo newFileInfo( filePath );
        m_pFilesTreeModel->AppendFileItem( newFileInfo, newFileInfo.fileName(), folderIndex );
    }

    return success;
}
コード例 #2
0
ファイル: Resource.cpp プロジェクト: CedarLogic/Sigil
void Resource::ResourceFileModified()
{
    QFileInfo newFileInfo(m_FullFilePath);
    const QDateTime lastModifiedDate = newFileInfo.lastModified();
    qint64 latestWrittenTo = lastModifiedDate.isValid() ? lastModifiedDate.toMSecsSinceEpoch() : 0;
    qint64 latestWrittenSize = newFileInfo.size();

    if (latestWrittenTo == m_LastSaved) {
        // The FileChangedOnDisk has triggered even though the data in the file has not changed.
        // This can happen if the FileWatcher is monitoring a file that Sigil has just performed
        // a disk operation with, such as Saving before a Merge. In this circumstance the data
        // loaded in memory by Sigil may be more up to date than that on disk (such as after the
        // merge but before user has chosen to Save) so we want to ignore the file change notification.
        return;
    }

    if ((latestWrittenTo != m_LastWrittenTo) || (latestWrittenSize != m_LastWrittenSize)) {
        // The file is still being written to.
        m_LastWrittenTo = latestWrittenTo;
        m_LastWrittenSize = latestWrittenSize;
        QTimer::singleShot(WAIT_FOR_WRITE_DELAY, this, SLOT(ResourceFileModified()));
    } else {
        if (LoadFromDisk()) {
            // will trigger marking the book as modified
            emit ResourceUpdatedFromDisk(this);
        }

        // will trigger updates in other resources that link to this resource
        emit ResourceUpdatedOnDisk();
    }
}
コード例 #3
0
ファイル: project.cpp プロジェクト: Malkavian/UMachVM
IUasmFile* Project::addFile(QString absoluteFilePath)
{

    //check if allready in list

    for (int i = 0; i < m_projectUasmFiles.size(); i++)
    {
        if (m_projectUasmFiles[i]->getRelativePath()
                == getProjectDir()->relativeFilePath(absoluteFilePath))
            return NULL;
    }

    setIsNotSaved();

    //file Info
    QFileInfo newFileInfo(absoluteFilePath);

    //create empty file if non exsist
    if (!newFileInfo.exists()) {
        QFile filePointer(absoluteFilePath);
        filePointer.open( QIODevice::ReadWrite );
        filePointer.flush();
        filePointer.close();
    }

    UAsmFile *file = new UAsmFile(this, absoluteFilePath);
    m_projectUasmFiles.push_back(file);
    return file;
}
コード例 #4
0
ファイル: modes.cpp プロジェクト: alinelena/aten
// Export all currently loaded models in the referenced format
void Aten::exportModels()
{
	Messenger::enter("Aten::exportModels");
	QFileInfo fileInfo;
	QString newFilename;

	// Loop over loaded models
	for (Model* m = models_.first(); m != NULL; m = m->next)
	{
		// Set current model
		setCurrentModel(m);

		// Generate new filename for model, with new suffix
		fileInfo.setFile(m->filename());
		newFilename = fileInfo.dir().absoluteFilePath(fileInfo.baseName() + "." + exportModelPlugin_->extensions().first());

		QFileInfo newFileInfo(newFilename);
		// Make sure that the new filename is not the same as the old filename
		if (fileInfo == newFileInfo)
		{
			Messenger::print("Exported file would overwrite the original (%s) - not converted.", qPrintable(m->filename()));
			continue;
		}

		if (exportModel(m, newFilename, exportModelPlugin_, FilePluginStandardImportOptions(), exportModelPluginOptions_)) Messenger::print("Model '%s' saved to file '%s' (%s)", qPrintable(m->name()), qPrintable(newFilename), qPrintable(exportModelPlugin_->name()));
		else Messenger::print("Failed to save model '%s'.", qPrintable(m->name()));
		m->enableUndoRedo();
	}
	Messenger::exit("Aten::exportModels");
}
コード例 #5
0
ファイル: trackinfoobject.cpp プロジェクト: HektikR/mixxx
void TrackInfoObject::setLocation(const QString& location) {
    QMutexLocker lock(&m_qMutex);
    QFileInfo newFileInfo(location);
    if (newFileInfo != m_fileInfo) {
        m_fileInfo = newFileInfo;
        m_bLocationChanged = true;
        setDirty(true);
    }
}
コード例 #6
0
ファイル: oswin9x.c プロジェクト: ajsteele/r-bioc-rtracklayer
struct fileInfo *listDirX(char *dir, char *pattern, boolean fullPath)
/* Return list of files matching wildcard pattern with
 * extra info. If full path is true then the path will be
 * included in the name of each file. */
{
  struct fileInfo *list = NULL, *el;
  long hFile;
  struct _finddata_t fileInfo;
  boolean otherDir = FALSE;
  char *currentDir;
  int dirNameSize = strlen(dir);
  int fileNameOffset = dirNameSize+1;
  char pathName[512];

  if (dir == NULL || sameString(".", dir) || sameString("", dir))
    dir = "";
  else
    {
      currentDir = getCurrentDir();
      setCurrentDir(dir);
      otherDir = TRUE;
    }

  if (pattern == NULL)
    pattern = "*";
  if( (hFile = _findfirst( pattern, &fileInfo)) == -1L )
    return NULL;

  memcpy(pathName, dir, dirNameSize);
  pathName[dirNameSize] = '/';

  do
    {
      if (!sameString(".", fileInfo.name) && !sameString("..", fileInfo.name))
        {
          char *fileName = fileInfo.name;
          strcpy(pathName+fileNameOffset, fileName);
          if (fullPath)
            fileName = pathName;
          el = newFileInfo(fileInfo.name, fileInfo.size,
                           fileInfo.attrib & _A_SUBDIR, 0,
                           fileInfo.time_access);
          slAddHead(&list, el);
        }
    }
  while( _findnext( hFile, &fileInfo) == 0 );
  _findclose( hFile );
  if (otherDir)
    setCurrentDir(currentDir);
  slSort(&list, cmpFileInfo);
  return list;
}
コード例 #7
0
ファイル: osunix.c プロジェクト: Bioinformaticsnl/SimSeq
struct fileInfo *listDirXExt(char *dir, char *pattern, boolean fullPath, boolean ignoreStatFailures)
/* Return list of files matching wildcard pattern with
 * extra info. If full path is true then the path will be
 * included in the name of each file. */
{
struct fileInfo *list = NULL, *el;
struct dirent *de;
DIR *d;
int dirNameSize = strlen(dir);
int fileNameOffset = dirNameSize+1;
char pathName[512];

if ((d = opendir(dir)) == NULL)
    return NULL;
memcpy(pathName, dir, dirNameSize);
pathName[dirNameSize] = '/';

while ((de = readdir(d)) != NULL)
    {
    char *fileName = de->d_name;
    if (differentString(fileName, ".") && differentString(fileName, ".."))
	{
	if (pattern == NULL || wildMatch(pattern, fileName))
	    {
	    struct stat st;
	    bool isDir = FALSE;
	    int statErrno = 0;
	    strcpy(pathName+fileNameOffset, fileName);
	    if (stat(pathName, &st) < 0)
		{
		if (ignoreStatFailures)
		    statErrno = errno;
		else
    		    errAbort("stat failed in listDirX");
		}
	    if (S_ISDIR(st.st_mode))
		isDir = TRUE;
	    if (fullPath)
		fileName = pathName;
	    el = newFileInfo(fileName, st.st_size, isDir, statErrno, st.st_atime);
	    slAddHead(&list, el);
	    }
	}
    }
closedir(d);
slSort(&list, cmpFileInfo);
return list;
}
コード例 #8
0
ファイル: DkProcess.cpp プロジェクト: a17r/nomacs
void DkBatchProcessing::init() {

    batchItems.clear();

    QStringList fileList = batchConfig.getFileList();

    for (int idx = 0; idx < fileList.size(); idx++) {

        QFileInfo cFileInfo = QFileInfo(fileList.at(idx));
        QString outDir = batchConfig.inputDirIsOutputDir() ? cFileInfo.absolutePath() : batchConfig.getOutputDirPath();

        DkFileNameConverter converter(cFileInfo.fileName(), batchConfig.getFileNamePattern(), idx);
        QFileInfo newFileInfo(outDir, converter.getConvertedFileName());

        DkBatchProcess cProcess(fileList.at(idx), newFileInfo.absoluteFilePath());
        cProcess.setMode(batchConfig.getMode());
        cProcess.setDeleteOriginal(batchConfig.getDeleteOriginal());
        cProcess.setProcessChain(batchConfig.getProcessFunctions());
        cProcess.setCompression(batchConfig.getCompression());

        batchItems.push_back(cProcess);
    }
}
コード例 #9
0
QString UBImportDocument::expandFileToDir(const QFile& pZipFile, const QString& pDir)
{

    QDir rootDir(pDir);
    QuaZip zip(pZipFile.fileName());

    if(!zip.open(QuaZip::mdUnzip))
    {
        qWarning() << "Import failed. Cause zip.open(): " << zip.getZipError();
        return "";
    }

    zip.setFileNameCodec("UTF-8");
    QuaZipFileInfo info;
    QuaZipFile file(&zip);

    // TODO UB 4.x  implement a mechanism that can replace an existing
    // document based on the UID of the document.
    bool createNewDocument = true;
    QString documentRootFolder;

    // first we search the metadata.rdf to check the document properties
    for(bool more = zip.goToFirstFile(); more; more = zip.goToNextFile())
    {
        if(!zip.getCurrentFileInfo(&info))
        {
            qWarning() << "Import failed. Cause: getCurrentFileInfo(): " << zip.getZipError();
            return "";
        }

        QFileInfo currentFileInfo(pDir + "/" + file.getActualFileName());
    }

    if (createNewDocument)
        documentRootFolder = UBPersistenceManager::persistenceManager()->generateUniqueDocumentPath();


    QFile out;
    char c;
    for(bool more=zip.goToFirstFile(); more; more=zip.goToNextFile())
    {
        if(!zip.getCurrentFileInfo(&info))
        {
            //TOD UB 4.3 O display error to user or use crash reporter
            qWarning() << "Import failed. Cause: getCurrentFileInfo(): " << zip.getZipError();
            return "";
        }

        if(!file.open(QIODevice::ReadOnly))
        {
            qWarning() << "Import failed. Cause: file.open(): " << zip.getZipError();
            return "";
        }

        if(file.getZipError()!= UNZ_OK)
        {
            qWarning() << "Import failed. Cause: file.getFileName(): " << zip.getZipError();
            return "";
        }

        QString newFileName = documentRootFolder + "/" + file.getActualFileName();
        QFileInfo newFileInfo(newFileName);
        rootDir.mkpath(newFileInfo.absolutePath());

        out.setFileName(newFileName);
        out.open(QIODevice::WriteOnly);

        // Slow like hell (on GNU/Linux at least), but it is not my fault.
        // Not ZIP/UNZIP package's fault either.
        // The slowest thing here is out.putChar(c).
        QByteArray outFileContent = file.readAll();
        if (out.write(outFileContent) == -1)
        {
            qWarning() << "Import failed. Cause: Unable to write file";
            out.close();
            return "";
        }

        while(file.getChar(&c))
            out.putChar(c);

        out.close();

        if(file.getZipError()!=UNZ_OK)
        {
            qWarning() << "Import failed. Cause: " << zip.getZipError();
            return "";
        }

        if(!file.atEnd())
        {
            qWarning() << "Import failed. Cause: read all but not EOF";
            return "";
        }

        file.close();

        if(file.getZipError()!=UNZ_OK)
        {
            qWarning() << "Import failed. Cause: file.close(): " <<  file.getZipError();
            return "";
        }

    }

    zip.close();

    if(zip.getZipError()!=UNZ_OK)
    {
      qWarning() << "Import failed. Cause: zip.close(): " << zip.getZipError();
      return "";
    }


    return documentRootFolder;
}
コード例 #10
0
QString UBImportCFF::expandFileToDir(const QFile& pZipFile, const QString& pDir)
{
    QuaZip zip(pZipFile.fileName());

    if(!zip.open(QuaZip::mdUnzip)) {
        qWarning() << "Import failed. Cause zip.open(): " << zip.getZipError();
        return "";
    }

    zip.setFileNameCodec("UTF-8");
    QuaZipFileInfo info;
    QuaZipFile file(&zip);

    //create unique cff document root fodler
    //use current date/time and temp number for folder name
    QString documentRootFolder;
    int tmpNumber = 0;
    QDir rootDir;
    while (true) {
        QString tempPath = QString("%1/sank%2.%3")
                .arg(pDir)
                .arg(QDateTime::currentDateTime().toString("dd_MM_yyyy_HH-mm"))
                .arg(tmpNumber);
        if (!rootDir.exists(tempPath)) {
            documentRootFolder = tempPath;
            break;
        }
        tmpNumber++;
        if (tmpNumber == 100000) {
            qWarning() << "Import failed. Failed to create temporary directory for iwb file";
            return "";
        }
    }
    if (!rootDir.mkdir(documentRootFolder)) {
        qWarning() << "Import failed. Couse: failed to create temp folder for cff package";
    }

    QFile out;
    char c;
    for(bool more=zip.goToFirstFile(); more; more=zip.goToNextFile()) {
        if(!zip.getCurrentFileInfo(&info)) {
            //TOD UB 4.3 O display error to user or use crash reporter
            qWarning() << "Import failed. Cause: getCurrentFileInfo(): " << zip.getZipError();
            return "";
        }
//        if(!file.open(QIODevice::ReadOnly)) {
//            qWarning() << "Import failed. Cause: file.open(): " << zip.getZipError();
//            return "";
//        }
        file.open(QIODevice::ReadOnly);
        if(file.getZipError()!= UNZ_OK) {
            qWarning() << "Import failed. Cause: file.getFileName(): " << zip.getZipError();
            return "";
        }

        QString newFileName = documentRootFolder + "/" + file.getActualFileName();

        QFileInfo newFileInfo(newFileName);
        rootDir.mkpath(newFileInfo.absolutePath());

        out.setFileName(newFileName);
        out.open(QIODevice::WriteOnly);

        while(file.getChar(&c))
            out.putChar(c);

        out.close();

        if(file.getZipError()!=UNZ_OK) {
            qWarning() << "Import failed. Cause: " << zip.getZipError();
            return "";
        }
        if(!file.atEnd()) {
            qWarning() << "Import failed. Cause: read all but not EOF";
            return "";
        }

        file.close();

        if(file.getZipError()!=UNZ_OK) {
            qWarning() << "Import failed. Cause: file.close(): " <<  file.getZipError();
            return "";
        }
    }

    zip.close();

    if(zip.getZipError()!=UNZ_OK) {
        qWarning() << "Import failed. Cause: zip.close(): " << zip.getZipError();
        return "";
    }

    return documentRootFolder;
}
コード例 #11
0
bool UBImportDocument::extractFileToDir(const QFile& pZipFile, const QString& pDir, QString& documentRoot)
{

    QDir rootDir(pDir);
    QuaZip zip(pZipFile.fileName());

    if(!zip.open(QuaZip::mdUnzip))
    {
        qWarning() << "Import failed. Cause zip.open(): " << zip.getZipError();
        return false;
    }

    zip.setFileNameCodec("UTF-8");
    QuaZipFileInfo info;
    QuaZipFile file(&zip);

    QFile out;
    char c;
    documentRoot = UBPersistenceManager::persistenceManager()->generateUniqueDocumentPath(pDir);
    for(bool more=zip.goToFirstFile(); more; more=zip.goToNextFile())
    {
        if(!zip.getCurrentFileInfo(&info))
        {
            //TOD UB 4.3 O display error to user or use crash reporter
            qWarning() << "Import failed. Cause: getCurrentFileInfo(): " << zip.getZipError();
            return false;
        }

        if(!file.open(QIODevice::ReadOnly))
        {
            qWarning() << "Import failed. Cause: file.open(): " << zip.getZipError();
            return false;
        }

        if(file.getZipError()!= UNZ_OK)
        {
            qWarning() << "Import failed. Cause: file.getFileName(): " << zip.getZipError();
            return false;
        }

        QString newFileName = documentRoot + "/" + file.getActualFileName();
        QFileInfo newFileInfo(newFileName);
        if (!rootDir.mkpath(newFileInfo.absolutePath()))
            return false;

        out.setFileName(newFileName);
        if (!out.open(QIODevice::WriteOnly))
            return false;

        // Slow like hell (on GNU/Linux at least), but it is not my fault.
        // Not ZIP/UNZIP package's fault either.
        // The slowest thing here is out.putChar(c).
        QByteArray outFileContent = file.readAll();
        if (out.write(outFileContent) == -1)
        {
            qWarning() << "Import failed. Cause: Unable to write file";
            out.close();
            return false;
        }

        while(file.getChar(&c))
            out.putChar(c);

        out.close();

        if(file.getZipError()!=UNZ_OK)
        {
            qWarning() << "Import failed. Cause: " << zip.getZipError();
            return false;
        }

        if(!file.atEnd())
        {
            qWarning() << "Import failed. Cause: read all but not EOF";
            return false;
        }

        file.close();

        if(file.getZipError()!=UNZ_OK)
        {
            qWarning() << "Import failed. Cause: file.close(): " <<  file.getZipError();
            return false;
        }

    }

    zip.close();

    if(zip.getZipError()!=UNZ_OK)
    {
      qWarning() << "Import failed. Cause: zip.close(): " << zip.getZipError();
      return false;
    }

    return true;
}
コード例 #12
0
void RecordingsModel::scanRecords(const QString &path)
{
    Q_ASSERT(mRecorder);

    // Current watching directories
    auto currentDirs = mWatcher->directories();

    // Is the recursive search enabled
    auto recursiveSearch = mRecorder->recursiveSearch();

    // Check if directory exists and add or remove it and
    // its subdirectories to the wathing list
    QDir dir(path);
    QStringList paths(path);
    if (dir.exists())
    {
        // Check for subdirectories that should be added
        if (recursiveSearch)
        {
            QDirIterator it(path, QDir::Dirs, QDirIterator::Subdirectories);
            while (it.hasNext())
            {
                paths << it.next();
            }
        }
        mWatcher->addPaths(paths);
    }
    else
    {
        // Check for subdirectories that should be removed
        for (auto d: currentDirs)
        {
            if (d.startsWith(path))
            {
                paths << d;
            }
        }
        mWatcher->removePaths(paths);
    }

    // Scan for updated and removed records
    for (int row = mData.size() - 1; row > -1; --row)
    {
        auto oldFileInfo = mData[row];
        // Process entries only of the changed path
        if (oldFileInfo.absolutePath() != path)
        {
            continue;
        }
        QFileInfo newFileInfo(oldFileInfo);
        newFileInfo.refresh();
        if (newFileInfo.exists())
        {
            if (newFileInfo.lastModified() != oldFileInfo.lastModified())
            {
                // The record was updated
                auto index = this->createIndex(row, 0);
                emit this->dataChanged(index, index, { Modified });
            }
        }
        else
        {
            // The record was removed
            this->beginRemoveRows(QModelIndex(), row, row);
            mData.removeAt(row);
            this->endRemoveRows();
        }
    }

    // Scan for new records
    auto flags = recursiveSearch ? QDirIterator::Subdirectories : QDirIterator::NoIteratorFlags;
    QDirIterator it(path, RecordingsModel::filters, QDir::Files, flags);
    QFileInfoList newRecords;
    while (it.hasNext())
    {
        // Add a new record
        QFileInfo fileInfo(it.next());
        if (!mData.contains(fileInfo))
        {
            newRecords << fileInfo;
        }
    }
    if (!newRecords.empty())
    {
        auto pos = mData.size();
        this->beginInsertRows(QModelIndex(), pos, pos + newRecords.size() - 1);
        mData.append(newRecords);
        this->endInsertRows();
    }
}