Skip to content

Commit

Permalink
fix percent fileWorkTickSignal
Browse files Browse the repository at this point in the history
  • Loading branch information
noisecode3 committed Jul 5, 2024
1 parent 0872923 commit 91fb563
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 45 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
CMakeLists.txt
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
Expand All @@ -9,6 +10,3 @@ Makefile
build-Debug
build
.cache
libs/quazip/quazip/QuaZip-Qt5Config.cmake
libs/quazip/quazip/QuaZip-Qt5ConfigVersion.cmake
libs/quazip/quazip/quazip1-qt5.pc
55 changes: 13 additions & 42 deletions src/FileManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,11 @@ bool FileManager::extractZip(const QString& zipFilename, const QString& outputFo

// Extract each file in the zip archive
mz_uint numFiles = mz_zip_reader_get_num_files(&zip);
qDebug() << "Zip file contains" << numFiles << "files";

unsigned int gotoPercent = 50; // Percentage of total work
unsigned int scale = 1000; // Resolution scale

unsigned int progress = 0; // Current progress
unsigned int lastPrintedPercent = 0; // Last printed percentage

// Calculate progress increment per iteration
unsigned int progressIncrement = scale / numFiles;

// Calculate remainder
unsigned int remainder = scale % numFiles;

qDebug() << "Zip file contains" << numFiles << "files";
for (uint i = 0; i < numFiles; i++)
{
mz_zip_archive_file_stat file_stat;
Expand All @@ -102,23 +93,9 @@ bool FileManager::extractZip(const QString& zipFilename, const QString& outputFo
QString filename = QString::fromUtf8(file_stat.m_filename);
if (filename.endsWith('/'))
{
progress += progressIncrement;
if (remainder > 0)
{
++progress;
--remainder;
}
unsigned int scaledProgress = progress * gotoPercent / scale;
if (scaledProgress != lastPrintedPercent)
{
for(int j=0; j<scaledProgress; j++)
{
emit this->fileWorkTickSignal();
}
lastPrintedPercent = scaledProgress;
}
continue;
continue; // Skip directories
}

QString outFile = outputPath + "/" + filename;
qDebug() << "Extracting" << filename;

Expand All @@ -136,31 +113,24 @@ bool FileManager::extractZip(const QString& zipFilename, const QString& outputFo
return false;
}

progress += progressIncrement;
if (remainder > 0)
{
++progress;
--remainder;
}
unsigned int currentPercent = ((i + 1) * gotoPercent) / numFiles;

unsigned int scaledProgress = progress * gotoPercent / scale;
if (scaledProgress != lastPrintedPercent)
if (currentPercent != lastPrintedPercent)
{
for(int j=0; j<scaledProgress; j++)
for (unsigned int j = lastPrintedPercent + 1; j <= currentPercent; j++)
{
emit this->fileWorkTickSignal();
}
lastPrintedPercent = scaledProgress;
lastPrintedPercent = currentPercent;
}
}
if(lastPrintedPercent <= gotoPercent)

// Ensure any remaining progress is emitted
for (unsigned int j = lastPrintedPercent + 1; j <= gotoPercent; j++)
{
unsigned int left = gotoPercent - lastPrintedPercent;
for(int j=0; j< left; j++)
{
emit this->fileWorkTickSignal();
}
emit this->fileWorkTickSignal();
}

// Clean up
mz_zip_reader_end(&zip);
qDebug() << "Unzip complete";
Expand Down Expand Up @@ -406,6 +376,7 @@ int FileManager::copyFile(const QString &gameFile, const QString &levelFile, boo
}
}
}

int FileManager::cleanWorkingDir(const QString &levelDir)
{
const QString& directoryPath = levelDir_m.absolutePath() + QDir::separator() + levelDir;
Expand Down

0 comments on commit 91fb563

Please sign in to comment.