package.h

00001 
00002 // Name:        package.h
00003 // Purpose:     wxPackage, wxPackageArray
00004 // Author:      Julian Smart, Francesco Montorsi, Daniel J. Lauk
00005 // Modified by:
00006 // Created:     2004-11-07
00007 // RCS-ID:      $Id: package.h,v 1.13 2007/02/01 20:28:14 frm Exp $
00008 // Copyright:   (c) Julian Smart, Francesco Montorsi, Daniel J. Lauk
00009 // Licence:     wxWidgets licence
00011 
00012 #ifndef _PACKAGE_H_
00013 #define _PACKAGE_H_
00014 
00015 // Includes
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 // wxPackageStatus
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     // the number of possible package states
00057     wxPS_MAX
00058 };
00059 
00060 wxDEFINE_STRING2ENUM(PackageStatus)
00061 
00062 
00063 
00064 // ----------------------------------------------------------------------------
00065 // wxProgressHandler
00066 // ----------------------------------------------------------------------------
00067 
00068 // A small interface class which acts as a callback:
00069 // the OnUpdate() method is called when some progress is being done.
00070 class wxProgressHandler
00071 {
00072 public:
00073     wxProgressHandler(wxObject *owner = NULL) { m_owner=owner; }
00074     virtual ~wxProgressHandler() {}
00075 
00076     // NOTE: the "progress" value is a value always comprised between
00077     //       zero and the maximum 1000.
00078     //       It's not the progress "delta" but the value of the progress
00079     //       (i.e. don't sum it with previous progress values).
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 // wxPackage
00093 // ----------------------------------------------------------------------------
00094 
00102 class wxPackage : public wxPackageInfo
00103 {
00104     // required to get access to DoGetRecursiveDependency
00105     friend class wxPackageDependency;
00106 
00107     DECLARE_DYNAMIC_CLASS(wxPackage)
00108 
00109 public:
00110     /* 30/12/2006 WARNING: don't know if the following wxPS_REMOVE => wxPS_INVALID
00111                            change won't break wxPM !! */
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:     // static
00124 
00126     static wxArrayString s_arrLocalRepo;
00127 
00129     static wxArrayString s_arrRemoteRepo;
00130 
00131     // load/save
00132 
00134     static bool LoadGlobals(wxConfigBase *, const wxString &path);
00135 
00137     static void SaveGlobals(wxConfigBase *, const wxString &path);
00138 
00139 public:     // getters
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:     // WXP getters
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     wxString GetWXZFileName() const
00172     {
00173         if (m_status >= wxPS_DECOMPRESSED)
00174             // FIZME: this is very arbitrary: also the .tar.gz and .zip extensions could be used
00175             return wxFileName(m_strWXPPath).GetName() + wxT(".wxz");
00176         return wxFileSystem::URLToFileName(GetDownloadHref().Item(0)).GetFullName();
00177     }
00178 */
00181     wxULongLong GetDecompressedSize() const;
00182 
00183 public:     // setters
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:     // miscellaneous
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:     // status
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:     // load & save
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             // this happens when e.g. the package has the wxPS_DECOMPRESSED
00281             // status but it's a new package and thus the compressed package
00282             // does not exist (yet)!
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             // this happens when e.g. the package has the wxPS_DECOMPRESSED
00301             // status but it's a new package and thus the compressed package
00302             // does not exist (yet)!
00303             return false;
00304         }
00305 
00306         m_strMD5 = wxMD5::GetFileMD5(m_strDownloadPath);
00307         return !m_strMD5.IsEmpty();
00308     }
00309 
00310 protected:         // wxPackageInfo overloads
00311 
00312     virtual wxPackageCommand GetCmd(const wxPackageCommand &cmd, 
00313                                     wxPackageBuildSystemStage stage,
00314                                     long flags,
00315                                     const wxPackageCondition &cond) const;
00316 
00317 protected:      // internal utilities
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:          // miscellaneous
00335 
00337     wxPackageStatus m_status;
00338 
00340     wxCompilerSettings m_compiler;
00341 
00342 protected:          // paths
00343 
00350     wxString m_strDownloadPath;
00351 
00360     wxString m_strDecompressionPath;
00361 
00368     wxString m_strWXPPath;
00369 
00374     wxString m_strInstallationPath;
00375 };
00376 
00377 // the array
00378 WX_DECLARE_OBJARRAY(wxPackage, wxPackageArrayHelper);
00379 
00380 // a light array of wxPackages
00381 WX_DEFINE_ARRAY(const wxPackage *, wxPackagePtrArray);
00382 
00383 
00384 
00385 
00386 
00387 // ----------------------------------------------------------------------------
00388 // wxPackageArray
00389 // ----------------------------------------------------------------------------
00390 
00391 class wxPackageArray : public wxPackageArrayHelper
00392 {
00393 public:
00394     wxPackageArray() {}
00395 
00396 public:     // miscellaneous
00397 
00398     // define & implement IsOk(), IndexByName(), ItemByName(), Contains()
00399     // and ContainsItemNamed() functions
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:         // misc
00420 
00421     // Removes duplicate packages and returns the number of removed packages.
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:         // load functions
00445 
00448     bool LoadCompressedPackagesFrom(const wxString &path);
00449 
00453     bool LoadCompressedPackagesFromLocalRepo();
00454 
00455 public:     // status load & save
00456 
00458     bool LoadPackagesStatusInfo(wxConfigBase *, const wxString &);
00459 
00461     bool SavePackagesStatusInfo(wxConfigBase *, const wxString &) const;
00462 };
00463 
00464 #endif      // _PACKAGE_H_
00465 

Generated on Thu Feb 1 22:14:31 2007 for wxWidgets Package Manager by  doxygen 1.5.1-p1