diff --git a/nufxlib-0/Funnel.c b/nufxlib-0/Funnel.c index 6032fae..2319346 100644 --- a/nufxlib-0/Funnel.c +++ b/nufxlib-0/Funnel.c @@ -172,12 +172,36 @@ Nu_ProgressDataExpandPrep(NuArchive* pArchive, NuFunnel* pFunnel, return kNuErrNone; } +/* + * Compute a completion percentage. + */ +static int +Nu_ComputePercent(ulong total, ulong progress) +{ + ulong perc; + + if (!total) + return 0; + + if (total < 21474836) { + perc = (progress * 100 + 50) / total; + if (perc > 100) + perc = 100; + } else { + perc = progress / (total / 100); + if (perc > 100) + perc = 100; + } + + return (int) perc; +} + /* * Send the initial progress message, before the output file is opened * (when extracting) or the input file is opened (when adding). */ NuError -Nu_SendInitialProgress(NuArchive* pArchive, const NuProgressData* pProgress) +Nu_SendInitialProgress(NuArchive* pArchive, NuProgressData* pProgress) { NuResult result; @@ -187,6 +211,9 @@ Nu_SendInitialProgress(NuArchive* pArchive, const NuProgressData* pProgress) if (pProgress->progressFunc == nil) return kNuErrNone; + pProgress->percentComplete = Nu_ComputePercent( + pProgress->uncompressedLength, pProgress->uncompressedProgress); + result = (*pProgress->progressFunc)(pArchive, (NuProgressData*) pProgress); if (result == kNuSkip) @@ -703,7 +730,7 @@ Nu_StrawFree(NuArchive* pArchive, NuStraw* pStraw) /* - * Set the Funnel's progress state. + * Set the Straw's progress state. */ NuError Nu_StrawSetProgressState(NuStraw* pStraw, NuProgressState state) diff --git a/nufxlib-0/NufxLibPriv.h b/nufxlib-0/NufxLibPriv.h index 5125e60..a9bc467 100644 --- a/nufxlib-0/NufxLibPriv.h +++ b/nufxlib-0/NufxLibPriv.h @@ -615,8 +615,7 @@ NuError Nu_ProgressDataInit_Compress(NuArchive* pArchive, NuError Nu_ProgressDataInit_Expand(NuArchive* pArchive, NuProgressData* pProgressData, const NuRecord* pRecord, const char* newPathname, char newFssep, NuValue convertEOL); -NuError Nu_SendInitialProgress(NuArchive* pArchive, - const NuProgressData* pProgress); +NuError Nu_SendInitialProgress(NuArchive* pArchive, NuProgressData* pProgress); NuError Nu_FunnelNew(NuArchive* pArchive, NuDataSink* pDataSink, NuValue convertEOL, NuValue convertEOLTo, NuProgressData* pProgress,