diff options
Diffstat (limited to 'examples/network/torrent/filemanager.cpp')
-rw-r--r-- | examples/network/torrent/filemanager.cpp | 73 |
1 files changed, 13 insertions, 60 deletions
diff --git a/examples/network/torrent/filemanager.cpp b/examples/network/torrent/filemanager.cpp index 69345442c7..054bb1d41c 100644 --- a/examples/network/torrent/filemanager.cpp +++ b/examples/network/torrent/filemanager.cpp @@ -1,52 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause #include "filemanager.h" #include "metainfo.h" @@ -77,13 +30,13 @@ FileManager::~FileManager() cond.wakeOne(); wait(); - for (QFile *file : qAsConst(files)) { + for (QFile *file : std::as_const(files)) { file->close(); delete file; } } -int FileManager::read(int pieceIndex, int offset, int length) +qint32 FileManager::read(qint32 pieceIndex, qint32 offset, qint32 length) { ReadRequest request; request.pieceIndex = pieceIndex; @@ -102,7 +55,7 @@ int FileManager::read(int pieceIndex, int offset, int length) return request.id; } -void FileManager::write(int pieceIndex, int offset, const QByteArray &data) +void FileManager::write(qint32 pieceIndex, qint32 offset, const QByteArray &data) { WriteRequest request; request.pieceIndex = pieceIndex; @@ -118,7 +71,7 @@ void FileManager::write(int pieceIndex, int offset, const QByteArray &data) } } -void FileManager::verifyPiece(int pieceIndex) +void FileManager::verifyPiece(qint32 pieceIndex) { QMutexLocker locker(&mutex); pendingVerificationRequests << pieceIndex; @@ -130,7 +83,7 @@ void FileManager::verifyPiece(int pieceIndex) } } -int FileManager::pieceLengthAt(int pieceIndex) const +qint32 FileManager::pieceLengthAt(qint32 pieceIndex) const { QMutexLocker locker(&mutex); return (sha1s.size() == pieceIndex + 1) @@ -329,7 +282,7 @@ bool FileManager::generateFiles() return true; } -QByteArray FileManager::readBlock(int pieceIndex, int offset, int length) +QByteArray FileManager::readBlock(qint32 pieceIndex, qint32 offset, qint32 length) { QByteArray block; qint64 startReadIndex = (quint64(pieceIndex) * pieceLength) + offset; @@ -367,7 +320,7 @@ QByteArray FileManager::readBlock(int pieceIndex, int offset, int length) return block; } -bool FileManager::writeBlock(int pieceIndex, int offset, const QByteArray &data) +bool FileManager::writeBlock(qint32 pieceIndex, qint32 offset, const QByteArray &data) { qint64 startWriteIndex = (qint64(pieceIndex) * pieceLength) + offset; qint64 currentIndex = 0; @@ -420,9 +373,9 @@ void FileManager::verifyFileContents() int oldPercent = 0; if (!newFile) { - int numPieces = sha1s.size(); + qint32 numPieces = sha1s.size(); - for (int index = 0; index < numPieces; ++index) { + for (qint32 index = 0; index < numPieces; ++index) { verifySinglePiece(index); int percent = ((index + 1) * 100) / numPieces; @@ -438,11 +391,11 @@ void FileManager::verifyFileContents() } // Verify all pending pieces - for (int index : qAsConst(newPendingVerificationRequests)) + for (int index : std::as_const(newPendingVerificationRequests)) emit pieceVerified(index, verifySinglePiece(index)); } -bool FileManager::verifySinglePiece(int pieceIndex) +bool FileManager::verifySinglePiece(qint32 pieceIndex) { QByteArray block = readBlock(pieceIndex, 0, pieceLength); QByteArray sha1Sum = QCryptographicHash::hash(block, QCryptographicHash::Sha1); |