예제 #1
0
파일: filesystem.cpp 프로젝트: Klius/client
bool FileSystem::rename(const QString &originFileName,
                        const QString &destinationFileName,
                        QString *errorString)
{
    bool success = false;
    QString error;
#ifdef Q_OS_WIN
    QString orig = longWinPath(originFileName);
    QString dest = longWinPath(destinationFileName);

    if (isLnkFile(originFileName) || isLnkFile(destinationFileName)) {
        success = MoveFileEx((wchar_t*)orig.utf16(),
                             (wchar_t*)dest.utf16(),
                             MOVEFILE_COPY_ALLOWED | MOVEFILE_WRITE_THROUGH);
        if (!success) {
            wchar_t *string = 0;
            FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
                          NULL, ::GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                          (LPWSTR)&string, 0, NULL);

            error = QString::fromWCharArray(string);
            LocalFree((HLOCAL)string);
        }
    } else
#endif
    {
        QFile orig(originFileName);
        success = orig.rename(destinationFileName);
        if (!success) {
            error = orig.errorString();
        }
    }

    if (!success) {
        qDebug() << "FAIL: renaming file" << originFileName
                 << "to" << destinationFileName
                 << "failed: " << error;
        if (errorString) {
            *errorString = error;
        }
    }
    return success;
}
예제 #2
0
파일: filesystem.cpp 프로젝트: Klius/client
qint64 FileSystem::getSize(const QString& filename)
{
#ifdef Q_OS_WIN
    if (isLnkFile(filename)) {
        // Use csync to get the file size. Qt seems unable to get at it.
        return getSizeWithCsync(filename);
    }
#endif
    return QFileInfo(filename).size();
}
예제 #3
0
파일: filesystem.cpp 프로젝트: Klius/client
bool FileSystem::fileExists(const QString& filename)
{
#ifdef Q_OS_WIN
    if (isLnkFile(filename)) {
        // Use a native check.
        return fileExistsWin(filename);
    }
#endif
    QFileInfo file(filename);
    return file.exists();
}
예제 #4
0
bool FileSystem::fileExists(const QString& filename, const QFileInfo& fileInfo)
{
#ifdef Q_OS_WIN
    if (isLnkFile(filename)) {
        // Use a native check.
        return fileExistsWin(filename);
    }
#endif
    bool re = fileInfo.exists();
    // if the filename is different from the filename in fileInfo, the fileInfo is
    // not valid. There needs to be one initialised here. Otherwise the incoming
    // fileInfo is re-used.
    if( fileInfo.filePath() != filename ) {
        QFileInfo myFI(filename);
        re = myFI.exists();
    }
    return re;
}