Recent

Author Topic: [SOLVED] Zipper Progress  (Read 3935 times)

wp

  • Hero Member
  • *****
  • Posts: 12773
Re: Zipper Progress
« Reply #15 on: December 13, 2020, 07:44:51 pm »
You could use two ProgressBars: the first one for the progress in the loop of unzippers, and the second one for the progress within each unzipper (like in my code).

The simplest way the design the first progress bar would be to simply count the zip files, set the count to ProgressBar.Max, and increment ProgressBar.Position with each zip file handled. This disadvantage is that there is no difference in progress between small and huge zips. Alternatively you could consider the file size of the zipped files: Add the file sizes of all zip files, set the total to Progressbar.Max and increment the Progressbar.Position with each processed zip file by the size of the zip file.

Study the code of OnlinePackageManager, it uses two progress bars for unzipping several zip files.

Handoko

  • Hero Member
  • *****
  • Posts: 5416
  • My goal: build my own game engine using Lazarus
Re: Zipper Progress
« Reply #16 on: December 13, 2020, 07:59:20 pm »
You're still too shy to provide the whole source code. But that's okay. I managed to rebuild the whole project laboriously and tested on Ubuntu Mate 20.04 Lazarus 2.0.10 GTK2. It works correctly on my test if I change this:

  MyUnzip.UnZip(MyFileList[iTEMP]);

to

  MyUnzip.UnZipAllFiles;

and add this line after the changing the progress bar's position:

  Application.ProcessMessages;

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: Zipper Progress
« Reply #17 on: December 13, 2020, 08:15:18 pm »
@Handoko - There is no more code. So far I have this

Code: Pascal  [Select][+][-]
  1. procedure TForm1.ProgressHandler(Sender : TObject; Const ATotPos, ATotSize: Int64);
  2. begin
  3.   Progressbar1.Position := Round(ATotPos/ATotSize*100.0);
  4.   sleep(100);  // Added this seems to help but not very elegant
  5.   ProgressBar1.Update;
  6. end;
  7.  
  8. procedure TForm1.UNZIP_FILES;
  9. var
  10.   MyUnzip : TUnZipper;
  11.   MyFileList : TStrings;
  12.   iTEMP : integer;
  13.   sTEMP : string;
  14. begin
  15.   ProgressBar1.Max := 100;
  16.  
  17.   MyFileList := TStringList.Create;
  18.  
  19.   FindAllFiles(MyFileList, '.\files\', '*.zip', true);
  20.  
  21.   for iTEMP := 0 to MyFileList.Count - 1 do
  22.     begin
  23.       MyUnzip := TUnZipper.Create;
  24.       MyUnzip.OnProgressEx := @ProgressHandler;
  25.       StatusBar1.SimpleText := 'Unzipping - ' + MyFileList[iTEMP];
  26.       Application.ProcessMessages;
  27.       MyUnzip.FileName := MyFileList[iTEMP];
  28.       sTEMP := Copy(MyFileList[iTEMP], 1, pos('_', MyFileList[iTEMP]) - 1);
  29.       Delete(sTEMP, 1, pos('\', sTEMP));
  30.       MyUnzip.OutputPath := 'd:\Media\Pictures\' + sTEMP + '\';
  31.  
  32.       try
  33.         MyUnzip.UnZipAllFiles;
  34.       except
  35.         ShowMessage('Corrupt zip file');
  36.       end;
  37.  
  38.       //DeleteFile(MyFileList[iTEMP]);
  39.  
  40.       MyUnzip.Free;
  41.     end;
  42.  
  43.     MyFileList.Free;
  44. end;
  45.  

@Handoko - Does it work correctly with more than one zip file? It also works for me when I process one file.

@wp - I really don't understand why it doesn't work with more than one file. I'm not good enough to delve into the OPM code.
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

Handoko

  • Hero Member
  • *****
  • Posts: 5416
  • My goal: build my own game engine using Lazarus
Re: Zipper Progress
« Reply #18 on: December 13, 2020, 08:21:50 pm »
@Handoko - There is no more code. So far I have this

It's not about I want to look into your code. It's about saving my time to rebuild the project so I can compile, test and debug. I had to manually design the UI and rebuild the project to be able to solve the problem and it took me about half an hour. If you provide the compile-able source at the beginning I may able to solve it in minutes.

@Handoko - Does it work correctly with more than one zip file? It also works for me when I process one file.

Yes I tested with a folder that contains 3 zip files and I saw the progress bar increasing and then reset from the beginning when starting the new file.

Do as what already said in post #16. It works on Linux. If it does not work on Windows then we need to inspect further. Unfortunately I now don't have any Windows machine for testing.
« Last Edit: December 13, 2020, 08:29:25 pm by Handoko »

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: Zipper Progress
« Reply #19 on: December 13, 2020, 08:28:31 pm »
So it would seem that its a Windows problem???
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

Handoko

  • Hero Member
  • *****
  • Posts: 5416
  • My goal: build my own game engine using Lazarus
Re: Zipper Progress
« Reply #20 on: December 13, 2020, 08:30:58 pm »
Not fully.

Before I done those things I mentioned, as you said, the onprogress event does not fire.

wp

  • Hero Member
  • *****
  • Posts: 12773
Re: Zipper Progress
« Reply #21 on: December 14, 2020, 12:27:44 am »
Here is another demo for unzipping several files. At first I wanted to implement the idea with the two progressbars, but then I had the idea that it should be possible to merge both progressbars into one if some data about the overall progress are available. This can be handled at the form level, but results in some ugly code. Therefore I decided to write a TDirUnzipper class which inherits from TUnzipper, reads the names of the zip files in the input directory and then unzips them one by one, as in your example code, but since it stores also the sizes of the zip files it can combine them with the OnProgressEx event so that a progress bar for the total progress can be controlled.

After finishing I noticed that it might be better to provide a stringlist containing the names of the zip files instead of scanning a directory. But maybe this is an exercise for somebody else.

Just look at the attached project.

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: Zipper Progress
« Reply #22 on: December 14, 2020, 01:49:39 am »
@wp - looks good. im sure i can modify to my needs.
Thank you so much for time and effort. That would of been above my head.
Thanks.
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

Handoko

  • Hero Member
  • *****
  • Posts: 5416
  • My goal: build my own game engine using Lazarus
Re: [SOLVED] Zipper Progress
« Reply #23 on: December 14, 2020, 03:56:28 am »
Good morning all.

I just tried the solution I suggested on a Win7 machine. It works but not exactly the same as running it on Linux.

On Windows TUnzipper will raise an exception if the target file already exists. On Linux it will automatically replace the old files without showing any exception.

 

TinyPortal © 2005-2018