/*************************************** * Checks for .upd file for the updater ****************************************/ void CheckUpdaterFiles(QString UpdaterFilename) { QString OldFilename = QApplication::applicationDirPath() + QDir::separator() + UpdaterFilename; QString Filename = OldFilename + ".upd"; QFile RFile(Filename); if(!RFile.exists()) return; if(RFile.size() == 0) return; /* Check if file exists */ QFile OFile(OldFilename); if(OFile.exists()) { /* Rename it to [Filename].bak */ QString NewFilename = OldFilename + ".bak"; OFile.rename(OldFilename,NewFilename); } /* Now rename the actual file */ if(RFile.rename(Filename,OldFilename)) { /* Remove .bak file */ QString BakFile = OldFilename + ".bak"; QFile Bak(BakFile); Bak.remove(); } }
void jobSet(const QStringList &jobSetFiles, const QString &outFile) { qDebug() << __FUNCTION__ << jobSetFiles.at(0) << jobSetFiles.at(1) << jobSetFiles.at(2) << outFile; QFile Wfile(outFile); if (!Wfile.open(QIODevice::WriteOnly)) { qDebug() << "open " << outFile << "error."; return; } QDataStream iData(&Wfile); foreach(QString FilePath, jobSetFiles) { QFile RFile(FilePath); if (!RFile.open(QIODevice::ReadOnly | QIODevice::Text)) { qDebug() << "open " << FilePath << "error."; return; } QString strTmp; QStringList list; qint32 i; QVector<Info_jobAdd> vec; Info_jobAdd job; RFile.readLine(1000); //第一行是标题 while (!RFile.atEnd()) { i = 0; strTmp = RFile.readLine(1000); list = strTmp.split("\t"); job.level = list.at(i++).toInt(); job.exp = list.at(i++).toInt(); job.hp = list.at(i++).toInt(); job.mp = list.at(i++).toInt(); job.dc1 = list.at(i++).toInt(); job.dc2 = list.at(i++).toInt(); job.mc1 = list.at(i++).toInt(); job.mc2 = list.at(i++).toInt(); job.sc1 = list.at(i++).toInt(); job.sc2 = list.at(i++).toInt(); job.ac = list.at(i++).toInt(); job.mac = list.at(i++).toInt(); vec.append(job); } RFile.close(); iData << vec.size(); //单个职业设定文件长度。 for (qint32 i = 0; i < vec.size(); i++) { iData << vec[i].level << vec[i].exp << vec[i].hp << vec[i].mp << vec[i].dc1 << vec[i].dc2 << vec[i].mc1 << vec[i].mc2 << vec[i].sc1 << vec[i].sc2 << vec[i].ac << vec[i].mac; } }
/*! Opens the file descriptor specified by \a file in the mode given by \a openMode. Returns true on success; otherwise returns false. The \a handleFlags argument specifies whether the file handle will be closed by Qt. See the QFile::FileHandleFlags documentation for more information. */ bool QFSFileEngine::open(QIODevice::OpenMode openMode, const RFile &file, QFile::FileHandleFlags handleFlags) { Q_D(QFSFileEngine); // Append implies WriteOnly. if (openMode & QFile::Append) openMode |= QFile::WriteOnly; // WriteOnly implies Truncate if neither ReadOnly nor Append are sent. if ((openMode & QFile::WriteOnly) && !(openMode & (QFile::ReadOnly | QFile::Append))) openMode |= QFile::Truncate; d->openMode = openMode; d->lastFlushFailed = false; d->closeFileHandle = (handleFlags & QFile::AutoCloseHandle); d->fileEntry.clear(); d->fh = 0; d->fd = -1; d->tried_stat = 0; #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API //RFile64 adds only functions to RFile, no data members d->symbianFile = static_cast<const RFile64&>(file); #else d->symbianFile = file; #endif TInt ret; d->symbianFilePos = 0; if (openMode & QFile::Append) { // Seek to the end when in Append mode. ret = d->symbianFile.Size(d->symbianFilePos); } else { // Seek to current otherwise ret = d->symbianFile.Seek(ESeekCurrent, d->symbianFilePos); } if (ret != KErrNone) { setError(QFile::OpenError, QSystemError(ret, QSystemError::NativeError).toString()); d->openMode = QIODevice::NotOpen; #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API d->symbianFile = RFile64(); #else d->symbianFile = RFile(); #endif return false; } // Extract filename (best effort) TFileName fn; TInt err = d->symbianFile.FullName(fn); if (err == KErrNone) d->fileEntry = QFileSystemEntry(qt_TDesC2QString(fn), QFileSystemEntry::FromNativePath()); else d->fileEntry.clear(); return true; }