00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012 #ifndef _PACKAGE_H_
00013 #define _PACKAGE_H_
00014
00015
00016 #include "wxp/packageinfo.h"
00017 #include "wx/md5.h"
00018
00019 class wxArchiveInputStream;
00020
00021 extern wxPackage wxEmptyPackage;
00022 extern wxPackageArray wxEmptyPackageArray;
00023
00024
00025
00026
00027
00028
00031 enum wxPackageStatus
00032 {
00033 wxPS_INVALID = -1,
00034
00036 wxPS_REMOTE,
00037
00040 wxPS_DOWNLOADED,
00041
00048 wxPS_DECOMPRESSED,
00049
00051 wxPS_BUILT,
00052
00054 wxPS_INSTALLED,
00055
00056
00057 wxPS_MAX
00058 };
00059
00060 wxDEFINE_STRING2ENUM(PackageStatus)
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070 class wxProgressHandler
00071 {
00072 public:
00073 wxProgressHandler(wxObject *owner = NULL) { m_owner=owner; }
00074 virtual ~wxProgressHandler() {}
00075
00076
00077
00078
00079
00080 virtual bool OnUpdate(unsigned long progress, const wxString &text) = 0;
00081
00082 wxObject *GetOwner() const
00083 { return m_owner; }
00084
00085 protected:
00086 wxObject *m_owner;
00087 };
00088
00089
00090
00091
00092
00093
00094
00102 class wxPackage : public wxPackageInfo
00103 {
00104
00105 friend class wxPackageDependency;
00106
00107 DECLARE_DYNAMIC_CLASS(wxPackage)
00108
00109 public:
00110
00111
00112
00113 wxPackage() : m_status(wxPS_INVALID) {}
00114 wxPackage(const wxPackageInfo &info, wxPackageStatus stat = wxPS_INVALID)
00115 : m_status(stat)
00116 { *this = info; }
00117 virtual ~wxPackage() {}
00118
00119
00120 wxPackage& operator= (const wxPackageInfo& info)
00121 { *((wxPackageInfo*)this) = info; return *this; }
00122
00123 public:
00124
00126 static wxArrayString s_arrLocalRepo;
00127
00129 static wxArrayString s_arrRemoteRepo;
00130
00131
00132
00134 static bool LoadGlobals(wxConfigBase *, const wxString &path);
00135
00137 static void SaveGlobals(wxConfigBase *, const wxString &path);
00138
00139 public:
00140
00141 wxPackageStatus GetStatus() const
00142 { return m_status; }
00143 wxString GetStatusStr() const
00144 { return wxPackageStatus2String(m_status); }
00145
00146 wxString GetDownloadPath() const
00147 { return m_strDownloadPath; }
00148 wxString GetDecompressionPath() const
00149 { return m_strDecompressionPath; }
00150 wxString GetInstallationPath() const
00151 { return m_strInstallationPath; }
00152
00153 wxCompilerSettings &GetCompilerSettings()
00154 { return m_compiler; }
00155 wxCompilerSettings GetCompilerSettings() const
00156 { return m_compiler; }
00157
00158 public:
00159
00160 wxString GetRelativeWXPPath() const
00161 { return m_strWXPPath; }
00162 wxString GetAbsWXPPath() const
00163 { return m_strDecompressionPath + wxFileName::GetPathSeparator() + m_strWXPPath; }
00164
00167 wxString GetWXPFileName() const
00168 { return wxFileName(m_strWXPPath).GetFullName(); }
00169
00171
00172
00173
00174
00175
00176
00177
00178
00181 wxULongLong GetDecompressedSize() const;
00182
00183 public:
00184
00185 void SetCompilerSettings(const wxCompilerSettings &sett)
00186 { m_compiler=sett; }
00187
00188 void SetDecompressionPath(const wxString &path)
00189 { m_strDecompressionPath=path; }
00190
00191 public:
00192
00193 bool IsOk() const;
00194
00196 wxWidgetsBuildArray GetSupportedWxBuilds(bool docompilercheck = true) const;
00197
00200 bool GetRecursiveDependencies(
00201 wxPackageDependencyArray *ret,
00202 const wxPackageArray &arr,
00203 wxPackageDependencyType type,
00204 wxPackageDependencyArray *notfound = NULL) const;
00205
00210 wxArrayString GetIncludedFiles(wxULongLong *totalsize = NULL) const;
00211
00214 bool LoadCompressedPackage(const wxString &wxzpath);
00215
00219 bool Decompress(const wxString &path, wxProgressHandler *handler = NULL);
00220
00228 bool Compress(const wxString &wxz = wxEmptyString, wxProgressHandler *handler = NULL);
00229
00233 bool UploadWithFTP(const wxString &user = wxEmptyString,
00234 const wxString &password = wxEmptyString,
00235 const wxString &server = wxEmptyString,
00236 const wxString &path = wxEmptyString);
00237
00238 public:
00239
00243 void SetRemoteStatus(const wxString &downloadpath = wxEmptyString);
00244
00246 void SetDownloadedStatus(const wxString &downloadpath);
00247
00249 void SetDecompressedStatus(const wxString &decompressionpath);
00250
00252 void SetBuiltStatus();
00253
00255 void SetInstalledStatus(const wxString &installpath);
00256
00259 void SetRelativeWXPPath(const wxString &path)
00260 { m_strWXPPath=path; }
00261
00265 void UpdatePackageInfo();
00266
00267 public:
00268
00269 bool LoadStatusInfo(wxConfigBase *cfg, const wxString &path);
00270 bool SaveStatusInfo(wxConfigBase *cfg, const wxString &path) const;
00271
00274 bool UpdateCompressedSize()
00275 {
00276 wxASSERT(m_status >= wxPS_DOWNLOADED);
00277
00278 if (m_strDownloadPath.IsEmpty())
00279 {
00280
00281
00282
00283 return false;
00284 }
00285
00286 m_nCompressedSize = wxFileName(m_strDownloadPath).GetSize();
00287 if (m_nCompressedSize == wxInvalidSize)
00288 return false;
00289 return true;
00290 }
00291
00294 bool UpdateMD5()
00295 {
00296 wxASSERT(m_status >= wxPS_DOWNLOADED);
00297
00298 if (m_strDownloadPath.IsEmpty())
00299 {
00300
00301
00302
00303 return false;
00304 }
00305
00306 m_strMD5 = wxMD5::GetFileMD5(m_strDownloadPath);
00307 return !m_strMD5.IsEmpty();
00308 }
00309
00310 protected:
00311
00312 virtual wxPackageCommand GetCmd(const wxPackageCommand &cmd,
00313 wxPackageBuildSystemStage stage,
00314 long flags,
00315 const wxPackageCondition &cond) const;
00316
00317 protected:
00318
00319 bool DoGetRecursiveDependencies(
00320 wxPackageDependencyArray *ret,
00321 const wxPackageArray &arr,
00322 wxPackageDependencyType type,
00323 wxPackageDependencyArray *notfound,
00324 wxPackageIdArray *alreadyprocessed) const;
00325
00327 wxArchiveInputStream *GetInputStream(const wxString &wxzpath) const;
00328
00331 virtual void DoUpdateSubstitutionHashMap(wxPackageSubstituteInfoContext ctx);
00332
00333
00334 protected:
00335
00337 wxPackageStatus m_status;
00338
00340 wxCompilerSettings m_compiler;
00341
00342 protected:
00343
00350 wxString m_strDownloadPath;
00351
00360 wxString m_strDecompressionPath;
00361
00368 wxString m_strWXPPath;
00369
00374 wxString m_strInstallationPath;
00375 };
00376
00377
00378 WX_DECLARE_OBJARRAY(wxPackage, wxPackageArrayHelper);
00379
00380
00381 WX_DEFINE_ARRAY(const wxPackage *, wxPackagePtrArray);
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391 class wxPackageArray : public wxPackageArrayHelper
00392 {
00393 public:
00394 wxPackageArray() {}
00395
00396 public:
00397
00398
00399
00400 WX_DECLARE_STD_OBJARRAY_HELPERS(wxPackage, wxEmptyPackage);
00401
00403 int IndexById(const wxPackageId &id) const
00404 {
00405 for (size_t i=0; i<GetCount(); i++)
00406 if ((const wxPackageId &)Item(i) == id)
00407 return i;
00408 return wxNOT_FOUND;
00409 }
00410
00411 wxPackage &ItemById(const wxPackageId &id)
00412 {
00413 int n = IndexById(id);
00414 if (n != wxNOT_FOUND)
00415 return wxPackageArrayHelper::Item(n);
00416 return wxEmptyPackage;
00417 }
00418
00419 public:
00420
00421
00422 size_t RemoveDuplicates();
00423
00427 bool UpdatePackage(const wxPackage &pkg);
00428
00432 bool GetRecursiveDependencies(
00433 wxPackageDependencyArray *ret,
00434 const wxPackageArray &arr,
00435 wxPackageDependencyType type,
00436 wxPackageDependencyArray *notfound = NULL) const;
00437
00439 wxPackageArray GetPackagesWhichBelongTo(wxPackageCategory cat) const;
00440
00442 void InvalidateCachedSubstHashMap(wxPackageSubstituteInfoContext ctx = wxPSIC_INVALID);
00443
00444 public:
00445
00448 bool LoadCompressedPackagesFrom(const wxString &path);
00449
00453 bool LoadCompressedPackagesFromLocalRepo();
00454
00455 public:
00456
00458 bool LoadPackagesStatusInfo(wxConfigBase *, const wxString &);
00459
00461 bool SavePackagesStatusInfo(wxConfigBase *, const wxString &) const;
00462 };
00463
00464 #endif // _PACKAGE_H_
00465