@@ -784,7 +784,7 @@ void Downloader::download()
784784 if (!dlQueue.empty ())
785785 {
786786 unsigned long long totalSizeBytes = iTotalRemainingBytes.load ();
787- std::cout << " Total size: " << Util::makeSizeString (totalSizeBytes) << std::endl;
787+ std::cout << " Total size: " << Util::makeSizeString (totalSizeBytes, Globals::globalConfig. iUnitFormat ) << std::endl;
788788
789789 if (Globals::globalConfig.dlConf .bFreeSpaceCheck )
790790 {
@@ -801,7 +801,7 @@ void Downloader::download()
801801 if (space.available < totalSizeBytes)
802802 {
803803 std::cerr << " Not enough free space in " << boost::filesystem::canonical (path) << " ("
804- << Util::makeSizeString (space.available ) << " )" << std::endl;
804+ << Util::makeSizeString (space.available , Globals::globalConfig. iUnitFormat ) << " )" << std::endl;
805805 exit (1 );
806806 }
807807 }
@@ -1561,18 +1561,23 @@ int Downloader::progressCallback(void *clientp, curl_off_t dltotal, curl_off_t d
15611561 std::cout << Util::formattedString (" \033 [0K\r %3.0f%% " , fraction * 100 );
15621562
15631563 // Download rate unit conversion
1564- std::string rate_unit;
1565- if (rate > 1048576 ) // 1 MB
1564+ std::string unit;
1565+ int divisor_M;
1566+
1567+ if (Globals::globalConfig.iUnitFormat == GlobalConstants::UNIT_FORMAT_IEC )
15661568 {
1567- rate /= 1048576 ;
1568- rate_unit = " MB/s " ;
1569+ divisor_M = GlobalConstants:: UNIT_DIVISOR_M_IEC ;
1570+ unit = GlobalConstants:: UNIT_STRING_M_IEC ;
15691571 }
15701572 else
15711573 {
1572- rate /= 1024 ;
1573- rate_unit = " kB/s " ;
1574+ divisor_M = GlobalConstants:: UNIT_DIVISOR_M_SI ;
1575+ unit = GlobalConstants:: UNIT_STRING_M_SI ;
15741576 }
1575- std::string status_text = Util::formattedString (" %0.2f/%0.2fMB @ %0.2f%s ETA: %s\r " , static_cast <double >(dlnow)/1024 /1024 , static_cast <double >(dltotal)/1024 /1024 , rate, rate_unit.c_str (), etastring.c_str ());
1577+
1578+ std::string rate_string = Util::makeRateString (rate, Globals::globalConfig.iUnitFormat );
1579+
1580+ std::string status_text = Util::formattedString (" %0.2f/%0.2f%s @ %s ETA: %s\r " , static_cast <double >(dlnow)/divisor_M, static_cast <double >(dltotal)/divisor_M, unit.c_str (), rate_string.c_str (), etastring.c_str ());
15761581 int status_text_length = status_text.length () + 6 ;
15771582
15781583 if ((status_text_length + bar_length) > iTermWidth)
@@ -2898,22 +2903,10 @@ void Downloader::processCloudSaveDownloadQueue(Config conf, const unsigned int&
28982903 }
28992904
29002905 // Average download speed
2901- std::ostringstream dlrate_avg;
2902- std::string rate_unit;
29032906 progressInfo progress_info = vDownloadInfo[tid].getProgressInfo ();
2904- if (progress_info.rate_avg > 1048576 ) // 1 MB
2905- {
2906- progress_info.rate_avg /= 1048576 ;
2907- rate_unit = " MB/s" ;
2908- }
2909- else
2910- {
2911- progress_info.rate_avg /= 1024 ;
2912- rate_unit = " kB/s" ;
2913- }
2914- dlrate_avg << std::setprecision (2 ) << std::fixed << progress_info.rate_avg << rate_unit;
2907+ std::string rate_string = Util::makeRateString (progress_info.rate_avg , Globals::globalConfig.iUnitFormat );
29152908
2916- msgQueue.push (Message (" Download complete: " + csf.path + " (@ " + dlrate_avg. str () + " )" , MSGTYPE_SUCCESS , msg_prefix, MSGLEVEL_DEFAULT ));
2909+ msgQueue.push (Message (" Download complete: " + csf.path + " (@ " + rate_string + " )" , MSGTYPE_SUCCESS , msg_prefix, MSGLEVEL_DEFAULT ));
29172910 }
29182911 else
29192912 {
@@ -3408,22 +3401,10 @@ void Downloader::processDownloadQueue(Config conf, const unsigned int& tid)
34083401 }
34093402
34103403 // Average download speed
3411- std::ostringstream dlrate_avg;
3412- std::string rate_unit;
34133404 progressInfo progress_info = vDownloadInfo[tid].getProgressInfo ();
3414- if (progress_info.rate_avg > 1048576 ) // 1 MB
3415- {
3416- progress_info.rate_avg /= 1048576 ;
3417- rate_unit = " MB/s" ;
3418- }
3419- else
3420- {
3421- progress_info.rate_avg /= 1024 ;
3422- rate_unit = " kB/s" ;
3423- }
3424- dlrate_avg << std::setprecision (2 ) << std::fixed << progress_info.rate_avg << rate_unit;
3405+ std::string rate_string = Util::makeRateString (progress_info.rate_avg , Globals::globalConfig.iUnitFormat );
34253406
3426- msgQueue.push (Message (" Download complete: " + filepath.filename ().string () + " (@ " + dlrate_avg. str () + " )" , MSGTYPE_SUCCESS , msg_prefix, MSGLEVEL_DEFAULT ));
3407+ msgQueue.push (Message (" Download complete: " + filepath.filename ().string () + " (@ " + rate_string + " )" , MSGTYPE_SUCCESS , msg_prefix, MSGLEVEL_DEFAULT ));
34273408 }
34283409 else
34293410 {
@@ -3527,6 +3508,14 @@ int Downloader::progressCallbackForThread(void *clientp, curl_off_t dltotal, cur
35273508
35283509template <typename T> void Downloader::printProgress (const ThreadSafeQueue<T>& download_queue)
35293510{
3511+ int divisor_M = GlobalConstants::UNIT_DIVISOR_M_IEC ;
3512+ std::string unit_M = GlobalConstants::UNIT_STRING_M_IEC ;
3513+ if (Globals::globalConfig.iUnitFormat == GlobalConstants::UNIT_FORMAT_SI )
3514+ {
3515+ divisor_M = GlobalConstants::UNIT_DIVISOR_M_SI ;
3516+ unit_M = GlobalConstants::UNIT_STRING_M_SI ;
3517+ }
3518+
35303519 // Print progress information until all threads have finished their tasks
35313520 ProgressBar bar (Globals::globalConfig.bUnicode , Globals::globalConfig.bColor );
35323521 unsigned int dl_status = DLSTATUS_NOTSTARTED ;
@@ -3586,19 +3575,10 @@ template <typename T> void Downloader::printProgress(const ThreadSafeQueue<T>& d
35863575 eta_total_seconds += eta;
35873576 std::string etastring = Util::makeEtaString (eta);
35883577
3589- std::string rate_unit;
3590- if (progress_info.rate > 1048576 ) // 1 MB
3591- {
3592- progress_info.rate /= 1048576 ;
3593- rate_unit = " MB/s" ;
3594- }
3595- else
3596- {
3597- progress_info.rate /= 1024 ;
3598- rate_unit = " kB/s" ;
3599- }
3578+ std::string unit = unit_M;
3579+ std::string rate_string = Util::makeRateString (progress_info.rate_avg , Globals::globalConfig.iUnitFormat );
36003580
3601- std::string progress_status_text = Util::formattedString (" %0.2f/%0.2fMB @ %0.2f% s ETA: %s" , static_cast <double >(progress_info.dlnow )/1024 / 1024 , static_cast <double >(progress_info.dltotal )/1024 / 1024 , progress_info. rate , rate_unit .c_str (), etastring.c_str ());
3581+ std::string progress_status_text = Util::formattedString (" %0.2f/%0.2f%s @ %s ETA: %s" , static_cast <double >(progress_info.dlnow )/divisor_M , static_cast <double >(progress_info.dltotal )/divisor_M, unit. c_str (), rate_string .c_str (), etastring.c_str ());
36023582 int status_text_length = progress_status_text.length () + 1 ;
36033583
36043584 if ((status_text_length + progress_percentage_text_length + bar_length) > iTermWidth)
@@ -3627,41 +3607,16 @@ template <typename T> void Downloader::printProgress(const ThreadSafeQueue<T>& d
36273607 bptime::time_duration eta (bptime::seconds ((long )(total_remaining / total_rate)));
36283608 eta += eta_total_seconds;
36293609 std::string eta_str = Util::makeEtaString (eta);
3610+ std::string total_remaining_string = Util::makeSizeString (total_remaining, Globals::globalConfig.iUnitFormat );
36303611
3631- double total_remaining_double = static_cast <double >(total_remaining)/1048576 ;
3632- std::string total_remaining_unit = " MB" ;
3633- std::vector<std::string> units = { " GB" , " TB" , " PB" };
3634-
3635- if (total_remaining_double > 1024 )
3636- {
3637- for (const auto & unit : units)
3638- {
3639- total_remaining_double /= 1024 ;
3640- total_remaining_unit = unit;
3641-
3642- if (total_remaining_double < 1024 )
3643- break ;
3644- }
3645- }
3646-
3647- total_eta_str = Util::formattedString (" (%0.2f%s) ETA: %s" , total_remaining_double, total_remaining_unit.c_str (), eta_str.c_str ());
3612+ total_eta_str = Util::formattedString (" (%s) ETA: %s" , total_remaining_string.c_str (), eta_str.c_str ());
36483613 }
36493614
36503615 std::ostringstream ss;
36513616 if (Globals::globalConfig.iThreads > 1 )
36523617 {
3653- std::string rate_unit;
3654- if (total_rate > 1048576 ) // 1 MB
3655- {
3656- total_rate /= 1048576 ;
3657- rate_unit = " MB/s" ;
3658- }
3659- else
3660- {
3661- total_rate /= 1024 ;
3662- rate_unit = " kB/s" ;
3663- }
3664- ss << " Total: " << std::setprecision (2 ) << std::fixed << total_rate << rate_unit << " | " ;
3618+ std::string total_rate_string = Util::makeRateString (total_rate, Globals::globalConfig.iUnitFormat );
3619+ ss << " Total: " << total_rate_string << " | " ;
36653620 }
36663621 ss << " Remaining: " << download_queue.size ();
36673622
@@ -4256,7 +4211,7 @@ void Downloader::galaxyInstallGameById(const std::string& product_id, const std:
42564211
42574212 std::cout << game_title << std::endl;
42584213 std::cout << " Files: " << items.size () << std::endl;
4259- std::cout << " Total size installed: " << Util::makeSizeString (totalSize) << std::endl;
4214+ std::cout << " Total size installed: " << Util::makeSizeString (totalSize, Globals::globalConfig. iUnitFormat ) << std::endl;
42604215
42614216 if (Globals::globalConfig.dlConf .bFreeSpaceCheck )
42624217 {
@@ -4273,7 +4228,7 @@ void Downloader::galaxyInstallGameById(const std::string& product_id, const std:
42734228 if (space.available < totalSize)
42744229 {
42754230 std::cerr << " Not enough free space in " << boost::filesystem::canonical (path) << " ("
4276- << Util::makeSizeString (space.available ) << " )" << std::endl;
4231+ << Util::makeSizeString (space.available , Globals::globalConfig. iUnitFormat ) << " )" << std::endl;
42774232 exit (1 );
42784233 }
42794234 }
@@ -5815,7 +5770,7 @@ void Downloader::galaxyInstallGame_MojoSetupHack(const std::string& product_id)
58155770
58165771 std::cout << game.title << std::endl;
58175772 std::cout << " Files: " << dlQueueGalaxy_MojoSetupHack.size () << std::endl;
5818- std::cout << " Total size installed: " << Util::makeSizeString (totalSize) << std::endl;
5773+ std::cout << " Total size installed: " << Util::makeSizeString (totalSize, Globals::globalConfig. iUnitFormat ) << std::endl;
58195774
58205775 if (Globals::globalConfig.dlConf .bFreeSpaceCheck )
58215776 {
@@ -5832,7 +5787,7 @@ void Downloader::galaxyInstallGame_MojoSetupHack(const std::string& product_id)
58325787 if (space.available < totalSize)
58335788 {
58345789 std::cerr << " Not enough free space in " << boost::filesystem::canonical (path) << " ("
5835- << Util::makeSizeString (space.available ) << " )" << std::endl;
5790+ << Util::makeSizeString (space.available , Globals::globalConfig. iUnitFormat ) << " )" << std::endl;
58365791 exit (1 );
58375792 }
58385793 }
@@ -6226,7 +6181,7 @@ void Downloader::processGalaxyDownloadQueue_MojoSetupHack(Config conf, const uns
62266181 // Download file
62276182 CURLcode result = CURLE_RECV_ERROR ;
62286183
6229- off_t max_size_memory = 5 << 20 ; // 5MB
6184+ off_t max_size_memory = 5 << 20 ; // 5MiB
62306185 if (zfe.comp_size < max_size_memory) // Handle small files in memory
62316186 {
62326187 std::ofstream ofs (path.string (), std::ofstream::out | std::ofstream::binary);
@@ -6549,8 +6504,8 @@ int Downloader::mojoSetupGetFileVector(const gameFile& gf, std::vector<zipFileEn
65496504 return 1 ;
65506505 }
65516506
6552- off_t head_size = 100 << 10 ; // 100 kB
6553- off_t tail_size = 200 << 10 ; // 200 kB
6507+ off_t head_size = 100 << 10 ; // 100 KiB
6508+ off_t tail_size = 200 << 10 ; // 200 KiB
65546509 std::string head_range = " 0-" + std::to_string (head_size);
65556510 std::string tail_range = std::to_string (file_size - tail_size) + " -" + std::to_string (file_size);
65566511
0 commit comments