xref: /haiku/src/apps/installer/UnzipEngine.h (revision 72586154d7f505bd5f15377db729b515d40dee40)
1 /*
2  * Copyright 2009, Stephan Aßmus <superstippi@gmx.de>
3  *  All rights reserved. Distributed under the terms of the MIT License.
4  */
5 #ifndef UNZIP_ENGINE_H
6 #define UNZIP_ENGINE_H
7 
8 
9 #include <stdio.h>
10 
11 #include <Messenger.h>
12 #include <String.h>
13 
14 #include "CommandPipe.h"
15 #include "HashMap.h"
16 #include "HashString.h"
17 
18 class ProgressReporter;
19 
20 
21 class UnzipEngine : private BCommandPipe::LineReader {
22 public:
23 								UnzipEngine(ProgressReporter* reporter,
24 									sem_id cancelSemaphore = -1);
25 	virtual						~UnzipEngine();
26 
27 			status_t			SetTo(const char* pathToPackage,
28 									const char* destinationFolder);
29 
BytesToUncompress()30 	inline	off_t				BytesToUncompress() const
31 									{ return fBytesToUncompress; }
ItemsToUncompress()32 	inline	uint64				ItemsToUncompress() const
33 									{ return fItemsToUncompress; }
34 
35 			status_t			UnzipPackage();
36 
37 private:
38 	// BCommandPipe::LineReader
39 			friend class BCommandPipe;
40 
41 	virtual	bool				IsCanceled();
42 	virtual	status_t			ReadLine(const BString& line);
43 
44 			status_t			_ReadLineListing(const BString& line);
45 			status_t			_ReadLineExtract(const BString& line);
46 
47 			void				_UpdateProgress(const char* item,
48 									const char* targetFolder);
49 
50 private:
51 			BString				fPackage;
52 			BString				fDestinationFolder;
53 			bool				fRetrievingListing;
54 
55 			typedef HashMap<HashString, off_t> EntrySizeMap;
56 			EntrySizeMap		fEntrySizeMap;
57 
58 			off_t				fBytesToUncompress;
59 			off_t				fBytesUncompressed;
60 			off_t				fLastBytesUncompressed;
61 			uint64				fItemsToUncompress;
62 			uint64				fItemsUncompressed;
63 			uint64				fLastItemsUncompressed;
64 
65 			ProgressReporter*	fProgressReporter;
66 			sem_id				fCancelSemaphore;
67 };
68 
69 
70 #endif // UNZIP_ENGINE_H
71