|
9 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | 11 | * GNU General Public License for more details. |
12 | | -
|
13 | | - * You should have received a copy of the GNU General Public License |
14 | | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | 12 | */ |
16 | 13 |
|
17 | | -#include "FileManager.h" |
| 14 | +#include "FileManager.hpp" |
18 | 15 | #include <QFile> |
19 | 16 | #include <QIODevice> |
20 | 17 | #include <QDir> |
|
23 | 20 | #include <QtCore> |
24 | 21 | #include <QByteArray> |
25 | 22 | #include <QDataStream> |
26 | | -#include "gameTree.h" |
| 23 | +#include "gameTree.hpp" |
27 | 24 |
|
28 | 25 | bool FileManager::setUpCamp(const QString& levelDir, const QString& gameDir) { |
29 | 26 | QDir levelDirPath(levelDir); |
@@ -52,19 +49,26 @@ const QString FileManager::calculateMD5(const QString& file, bool lookGameDir) { |
52 | 49 | gameDir_m.absolutePath() + QDir::separator()+file : |
53 | 50 | levelDir_m.absolutePath() + QDir::separator()+file; |
54 | 51 |
|
| 52 | + QFileInfo fileInfo(path); |
| 53 | + |
| 54 | + if (fileInfo.exists() && !fileInfo.isFile()) { |
| 55 | + qDebug() << "Error: The path is not a regular file." << path; |
| 56 | + return""; |
| 57 | + } |
| 58 | + |
55 | 59 | QFile f(path); |
56 | | - if (!f.open(QIODevice::ReadOnly)) { |
| 60 | + if (!f.open(QIODevice::ReadOnly)) { // flawfinder: ignore |
57 | 61 | qDebug() << "Error opening file for reading: " << f.errorString(); |
58 | 62 | return ""; |
59 | 63 | } |
60 | 64 |
|
61 | 65 | QCryptographicHash md5(QCryptographicHash::Md5); |
62 | 66 |
|
63 | | - char buffer[1024]; |
| 67 | + std::array<char, 1024> buffer; |
64 | 68 | qint64 bytesRead; |
65 | 69 |
|
66 | | - while ((bytesRead = f.read(buffer, sizeof(buffer))) > 0) { |
67 | | - md5.addData(buffer, static_cast<int>(bytesRead)); |
| 70 | + while ((bytesRead = f.read(buffer.data(), buffer.size())) > 0) { |
| 71 | + md5.addData(buffer.data(), static_cast<int>(bytesRead)); |
68 | 72 | } |
69 | 73 |
|
70 | 74 | f.close(); |
|
0 commit comments