Results 1 to 4 of 4

Thread: Help Adding Progress Indicator

  1. #1
    Member
    Join Date
    May 2012
    Location
    United States
    Posts
    343
    Thanks
    200
    Thanked 58 Times in 42 Posts

    Help Adding Progress Indicator

    Hi everyone,

    Recently I've been attempting to learn about C++ source code compilation and modifications of existing sources. What I've learned so far is very, very basic.

    Some open-source compressors do their compression/decomression without any progress indicator which is rather annoying. By progress indicator, I mean a percentage display like in Nanozip, UDA, RAR, 7z, etc. Is there an easy way to add a progress indicator to display progress during the compression/decompression process?

    So, for example, I've been playing with TANGELO 1.0 by Jan Ondrus and CRUSH 1.0 by Ilia sources recently--They are somewhat understandable to me. Is there an easy way to add a progress indicator to be printed while doing compression and decompression? Both programmers chose not to put one in so perhaps it is not so simple of a task?

    Any help would be great.
    Thanks.
    Last edited by comp1; 7th May 2015 at 21:44.

  2. #2
    The Founder encode's Avatar
    Join Date
    May 2006
    Location
    Moscow, Russia
    Posts
    4,013
    Thanks
    406
    Thanked 403 Times in 153 Posts
    A quick example:

    _fseeki64(in, 0, SEEK_END);
    const __int64 filesize=_ftelli64(in);
    rewind(in);

    // ...

    while ((size=fread(buf, 1, BUF_SIZE, in)>0)
    {
    printf("%I64d%% complete\r", (_ftelli64(in)*100)/filesize);

    // ...
    }

    printf("\n");

  3. Thanks:

    jibz (9th May 2015)

  4. #3
    Member jibz's Avatar
    Join Date
    Jan 2015
    Location
    Denmark
    Posts
    124
    Thanks
    106
    Thanked 71 Times in 51 Posts
    For 64-bit values it is perhaps less of a problem (at least for now), but if you use shorter types, it is a good idea to check for over- and underflow. I've used something like:

    /*
    * Compute ratio between two numbers.
    */
    unsigned int ratio(unsigned long x, unsigned long y)
    {
    if (x <= ULONG_MAX / 100) {
    x *= 100;
    }
    else {
    y /= 100;
    }

    if (y == 0) {
    y = 1;
    }

    return (unsigned int) (x / y);
    }

  5. #4
    Member
    Join Date
    May 2012
    Location
    United States
    Posts
    343
    Thanks
    200
    Thanked 58 Times in 42 Posts
    Thanks for your help guys!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •