Recent

Author Topic: Use a ProgressBar with Zipper (zip job)  (Read 1817 times)

cris75

  • Jr. Member
  • **
  • Posts: 59
Use a ProgressBar with Zipper (zip job)
« on: November 27, 2019, 05:46:18 pm »
While in the official wiki page for Zipper at "https://wiki.freepascal.org/paszlib" there are a lot of useful informations and examples, there are no informations about the use of OnProgress, OnPercent (etc..) properties;
my goal is to implement a progressbar when I create an archive using ZipFiles method by passing to it a list of entries (TZipFileEntries);
in the wiki i found this thread https://forum.lazarus.freepascal.org/index.php?topic=41372.0 but it didn't help me much and also searched the wiki and googled for some example without luck  :(
so after looking at the zipper unit source code and try to figure out how implement the progressbar I did my own attempts, no need to say I failed miserably..  :'(
so before I give up (sigh!) is there someone kind enought that has a bit of free time that could post an example?
It would be really appreciated, tank you.
Lazarus: 3.0 / FPC: 3.2.2
[x86_64-win64-win32/win64]
OS IDE: Win10 64bit

valdir.marcos

  • Hero Member
  • *****
  • Posts: 1106
Re: Use a ProgressBar with Zipper (zip job)
« Reply #1 on: November 27, 2019, 07:09:20 pm »
While in the official wiki page for Zipper at "https://wiki.freepascal.org/paszlib" there are a lot of useful informations and examples, there are no informations about the use of OnProgress, OnPercent (etc..) properties;
my goal is to implement a progressbar when I create an archive using ZipFiles method by passing to it a list of entries (TZipFileEntries);
in the wiki i found this thread https://forum.lazarus.freepascal.org/index.php?topic=41372.0 but it didn't help me much and also searched the wiki and googled for some example without luck  :(
so after looking at the zipper unit source code and try to figure out how implement the progressbar I did my own attempts, no need to say I failed miserably..  :'(
so before I give up (sigh!) is there someone kind enought that has a bit of free time that could post an example?
It would be really appreciated, tank you.
These links might be helpful:

Progress bar for zipper - how to do it?
https://forum.lazarus.freepascal.org/index.php/topic,41372.0.html

Updating ProgressBar from threads
https://forum.lazarus.freepascal.org/index.php/topic,25248.0.html

How to get the files/folders inside a ZIP file
http://lazplanet.blogspot.com/2013/05/how-to-get-filesfolders-inside-zip-file.html

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: Use a ProgressBar with Zipper (zip job)
« Reply #2 on: November 27, 2019, 11:11:57 pm »
TZipper has several events which fire during the process:
- OnStartFile
- OnProgress
- OnEndFile

Before compiling the attached demo project adapt the path in FindAllFile of TForm1.Button1Click (line 92) such that it points to a folder with several exe files.

cris75

  • Jr. Member
  • **
  • Posts: 59
Re: Use a ProgressBar with Zipper (zip job)
« Reply #3 on: November 28, 2019, 03:36:59 pm »
Thank you very much, your demo is simple and self explaining, I also tested it with an TUbuntuProgress and it works great even if compared to the TProgressBar the movement slightly different, I'll also try to adapt it to work in a threaded application.
I thought to create the zip in a thread and show a specific form with the progressbar(s) when the job start and hide it just before the thread is terminated, just to avoid the mainform to seem non-responsive and let the user move it or minimize it
Lazarus: 3.0 / FPC: 3.2.2
[x86_64-win64-win32/win64]
OS IDE: Win10 64bit

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: Use a ProgressBar with Zipper (zip job)
« Reply #4 on: November 28, 2019, 04:49:59 pm »
You could study the code in unit components/onlinepackagemanager/opkman_zipper.pp. It is used by the OnlinePackageManager and zips/unzips with threads.

cris75

  • Jr. Member
  • **
  • Posts: 59
Re: Use a ProgressBar with Zipper (zip job)
« Reply #5 on: December 04, 2019, 06:57:07 pm »
I wrote a simple Threaded application that create a zip file with "zipper" (it uses events), but It has some problems;
It is meant to run only on Windows;
It just create a zip from a source directory (all the files in it), in the Main form there is a progressbar, a pair of labels and a ListBox;
it works, has not leaks, but sometime the progressbar or the other GUI elements in the Main form "freeze", but the thread itself is completed correctly and the zip created.
Attached there is a project based on my application in which I "stripped" the unnecessary elements, and this one seems to run correctly without GUI freezes, to reproduce what I mean it's sufficent to comment line 119 and un-comment line 120 in the Unit1 (line 120 is obviously incorrect, but it is useful to reproduce the issue), the output zip is in the project source dir, named "test.zip";
I hope someone has a bit of free time and can give a look, any help is really appreciated, thank you

Windows 7 64bit / Lazarus 1.8.4 / FPC 3.0.4
Lazarus: 3.0 / FPC: 3.2.2
[x86_64-win64-win32/win64]
OS IDE: Win10 64bit

 

TinyPortal © 2005-2018