xref: /haiku/src/apps/packageinstaller/InstalledPackageInfo.h (revision 1e60bdeab63fa7a57bc9a55b032052e95a18bd2c)
1 /*
2  * Copyright (c) 2007, Haiku, Inc.
3  * Distributed under the terms of the MIT license.
4  *
5  * Author:
6  *		Łukasz 'Sil2100' Zemczak <sil2100@vexillium.org>
7  */
8 #ifndef INSTALLED_PACKAGE_INFO_H
9 #define INSTALLED_PACKAGE_INFO_H
10 
11 #include <File.h>
12 #include <String.h>
13 #include <List.h>
14 #include <Path.h>
15 
16 
17 #define P_BUSY_TRIES 10
18 
19 enum {
20 	P_PACKAGE_INFO = 'ppki'
21 };
22 
23 extern const char * kPackagesDir;
24 
25 
26 // Useful function for fetching the package name and version without parsing all
27 // other data
28 status_t info_get_package_name(const char* filename, BString& name);
29 status_t info_get_package_version(const char* filename, BString& name);
30 
31 
32 class InstalledPackageInfo {
33 public:
34 								InstalledPackageInfo();
35 								InstalledPackageInfo(const char* packageName,
36 									const char* version = NULL,
37 									bool create = false);
38 								~InstalledPackageInfo();
39 
40 			status_t			InitCheck();
41 			status_t			SetTo(const char* packageName,
42 									const char* version = NULL,
43 									bool create = false);
44 
45 			void				SetName(const char* name)
46 									{ fName = name; }
47 			const char*			Name()
48 									{ return fName.String(); }
49 			void				SetDescription(const char* description)
50 									{ fDescription = description; }
51 			const char*			Description()
52 									{ return fDescription.String(); }
53 			const char*			Version()
54 									{ return fVersion.String(); }
55 			void				SetSpaceNeeded(uint64 size)
56 									{ fSpaceNeeded = size; }
57 			uint64				SpaceNeeded()
58 									{ return fSpaceNeeded; }
59 
60 			status_t			AddItem(const char* itemName);
61 
62 			status_t			Uninstall();
63 			status_t			Save();
64 
65 private:
66 			void				_ClearItemList();
67 
68 private:
69 			status_t			fStatus;
70 			bool				fIsUpToDate;
71 			bool				fCreate;
72 
73 			BString				fName;
74 			BString				fDescription;
75 			BString				fVersion;
76 			uint64				fSpaceNeeded;
77 			BList				fInstalledItems;
78 
79 			BPath				fPathToInfo;
80 };
81 
82 
83 #endif // INSTALLED_PACKAGE_INFO_H
84 
85