QT_BEGIN_NAMESPACE /* This function looks at two file names and returns the name of the infile with a path relative to outfile. Examples: /tmp/abc, /tmp/bcd -> abc xyz/a/bc, xyz/b/ac -> ../a/bc /tmp/abc, xyz/klm -> /tmp/abc */ static QByteArray combinePath(const QString &infile, const QString &outfile) { QFileInfo inFileInfo(QDir::current(), infile); QFileInfo outFileInfo(QDir::current(), outfile); const QByteArray relativePath = QFile::encodeName(outFileInfo.dir().relativeFilePath(inFileInfo.filePath())); #ifdef Q_OS_WIN // It's a system limitation. // It depends on the Win API function which is used by the program to open files. // cl apparently uses the functions that have the MAX_PATH limitation. if (outFileInfo.dir().absolutePath().length() + relativePath.length() + 1 >= 260) return QFile::encodeName(inFileInfo.absoluteFilePath()); #endif return relativePath; }
QByteArray combinePath(const char *infile, const char *outfile) { QFileInfo inFileInfo(QDir::current(), QFile::decodeName(infile)); QFileInfo outFileInfo(QDir::current(), QFile::decodeName(outfile)); int numCommonComponents = 0; QStringList inSplitted = inFileInfo.dir().canonicalPath().split(QLatin1Char('/')); QStringList outSplitted = outFileInfo.dir().canonicalPath().split(QLatin1Char('/')); while (!inSplitted.isEmpty() && !outSplitted.isEmpty() && inSplitted.first() == outSplitted.first()) { inSplitted.erase(inSplitted.begin()); outSplitted.erase(outSplitted.begin()); numCommonComponents++; } if (numCommonComponents < 2) { /* The paths don't have the same drive, or they don't have the same root directory. Use an absolute path. */ return QFile::encodeName(inFileInfo.absoluteFilePath()); } else { /* The paths have something in common. Use a path relative to the output file. */ while (!outSplitted.isEmpty()) { outSplitted.erase(outSplitted.begin()); inSplitted.prepend(QLatin1String("..")); } inSplitted.append(inFileInfo.fileName()); return QFile::encodeName(inSplitted.join(QLatin1String("/"))); } }
QT_BEGIN_NAMESPACE /* This function looks at two file names and returns the name of the infile with a path relative to outfile. Examples: /tmp/abc, /tmp/bcd -> abc xyz/a/bc, xyz/b/ac -> ../a/bc /tmp/abc, xyz/klm -> /tmp/abc */ static QByteArray combinePath(const char *infile, const char *outfile) { QFileInfo inFileInfo(QDir::current(), QFile::decodeName(infile)); QFileInfo outFileInfo(QDir::current(), QFile::decodeName(outfile)); int numCommonComponents = 0; QStringList inSplitted = inFileInfo.dir().canonicalPath().split(QLatin1Char('/')); QStringList outSplitted = outFileInfo.dir().canonicalPath().split(QLatin1Char('/')); while (!inSplitted.isEmpty() && !outSplitted.isEmpty() && inSplitted.first() == outSplitted.first()) { inSplitted.removeFirst(); outSplitted.removeFirst(); numCommonComponents++; } if (numCommonComponents < 2) /* The paths don't have the same drive, or they don't have the same root directory. Use an absolute path. */ return QFile::encodeName(inFileInfo.absoluteFilePath()); /* The paths have something in common. Use a path relative to the output file. */ while (!outSplitted.isEmpty()) { outSplitted.removeFirst(); inSplitted.prepend(QLatin1String("..")); } inSplitted.append(inFileInfo.fileName()); return QFile::encodeName(inSplitted.join(QLatin1String("/"))); }
QT_BEGIN_NAMESPACE /* This function looks at two file names and returns the name of the infile with a path relative to outfile. Examples: /tmp/abc, /tmp/bcd -> abc xyz/a/bc, xyz/b/ac -> ../a/bc /tmp/abc, xyz/klm -> /tmp/abc */ static QByteArray combinePath(const char *infile, const char *outfile) { QFileInfo inFileInfo(QDir::current(), QFile::decodeName(infile)); QFileInfo outFileInfo(QDir::current(), QFile::decodeName(outfile)); return QFile::encodeName(outFileInfo.dir().relativeFilePath(inFileInfo.filePath())); }
void NewDatabaseDlg::buildButtonPressed() { QDir rootDir(ui->directoryEdit->text()); QFileInfo outFileInfo(ui->nameEdit->text()); if ("" == ui->nameEdit->text() || outFileInfo.isDir()) { QMessageBox::warning(this, tr("Error"), tr("You have to specify a file for the new database."), QMessageBox::Ok); return; } else if (!rootDir.exists()) { QMessageBox::warning(this, tr("Error"), tr("You have to specify a valid directory."), QMessageBox::Ok); return; } if (outFileInfo.exists()) { if (QMessageBox::question(this, tr("The database file exists already"), tr("The chosen database file already exists. Do you want to override it?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::No) { return; } } QFile outFile(ui->nameEdit->text()); if (!outFile.open(QIODevice::WriteOnly)) { QMessageBox::warning(this, tr("Error"), tr("The database file you specified can not be written. Specify another one."), QMessageBox::Ok); return; } outFile.close(); outFile.remove(); m_canceled = false; this->m_directory = ui->directoryEdit->text(); this->m_name = ui->nameEdit->text(); this->m_includeSubdirs = ui->includeSubdirectories->isChecked(); this->writeSettings(); close(); }
bool OtamaConverter::convert(const QString &filePath, int trimMode) const { QFile htmlFile(filePath); QFile otmFile(ViewConverter::changeFileExtension(filePath, logicFileSuffix())); QString className = ViewConverter::getViewClassName(filePath); QFile outFile(erbConverter.outputDir().filePath(className + ".cpp")); // Checks file's timestamp QFileInfo htmlFileInfo(htmlFile); QFileInfo otmFileInfo(otmFile); QFileInfo outFileInfo(outFile); if (htmlFileInfo.exists() && outFileInfo.exists()) { if (outFileInfo.lastModified() > htmlFileInfo.lastModified() && (!otmFileInfo.exists() || outFileInfo.lastModified() > otmFileInfo.lastModified())) { //printf("done %s\n", qPrintable(outFile.fileName())); return true; } else { if (outFile.remove()) { printf(" removed %s\n", qPrintable(outFile.fileName())); } } } if (!htmlFile.open(QIODevice::ReadOnly)) { qCritical("failed to read phtm file : %s", qPrintable(htmlFile.fileName())); return false; } // Otama logic reading QString otm; if (otmFile.open(QIODevice::ReadOnly)) { otm = QTextStream(&otmFile).readAll(); } QString erb = OtamaConverter::convertToErb(QTextStream(&htmlFile).readAll(), otm, trimMode); return erbConverter.convert(className, erb, trimMode); }