packageutils.cpp

00001 
00002 // Name:        packageutils.cpp
00003 // Purpose:     wxPackageDataWithRef, wxPackageId, wxPackageIdArray,
00004 //              wxPackageCondition
00005 // Author:      Francesco Montorsi
00006 // Modified by:
00007 // Created:     2006-11-07
00008 // RCS-ID:      $Id: packageutils.cpp,v 1.5 2007/01/28 14:35:29 frm Exp $
00009 // Copyright:   (c) Francesco Montorsi
00010 // Licence:     wxWidgets licence
00012 
00013 
00014 // For compilers that support precompilation, includes "wx/wx.h".
00015 #include "wx/wxprec.h"
00016 
00017 #ifdef __BORLANDC__
00018 #pragma hdrstop
00019 #endif
00020 
00021 #ifndef WX_PRECOMP
00022     #include "wx/wx.h"
00023 #endif
00024 
00025 // includes
00026 #include <wx/fileconf.h>
00027 #include <wx/filename.h>
00028 #include <wx/zipstrm.h>
00029 #include <wx/wfstream.h>
00030 #include <wx/ptr_scpd.h>
00031 #include <wx/dir.h>
00032 
00033 #include "wxp/package.h"
00034 #include "wxp/wxp.h"
00035 #include "wxp/wxbuild.h"
00036 
00037 
00038 // wx array implementations
00039 #include <wx/arrimpl.cpp> // this is a magic incantation which must be done!
00040 WX_DEFINE_OBJARRAY(wxPackageDataWithRefArray);
00041 WX_DEFINE_OBJARRAY(wxPackageIdArrayHelper);
00042 
00043 // global objects
00044 wxPackageDataWithRef wxEmptyPackageDataWithRef;
00045 wxPackageId wxEmptyPackageId;
00046 wxPackageIdArray wxEmptyPackageIdArray;
00047 wxPackageCondition wxEmptyPackageCondition;
00048 wxPackageHTMLOutputFormat wxEmptyPackageHTMLOutputFormat;
00049 
00050 
00051 // ----------------------------------------------------------------------------
00052 // string2enum helpers
00053 // ----------------------------------------------------------------------------
00054 
00055 wxString wxPackageSubstituteInfoContextName[] =
00056 {
00057     _("wxhtml"),
00058     _("xhtml")
00059 };
00060 
00061 wxIMPLEMENT_STRING2ENUM(PackageSubstituteInfoContext, wxPSIC_MAX)
00062 
00063 
00064 // ----------------------------------------------------------------------------
00065 // wxPackageDataWithRef
00066 // ----------------------------------------------------------------------------
00067 
00068 void wxPackageDataWithRef::ExpandLocalRef(const wxString &path)
00069 {
00070     if (m_strLocalRef.IsEmpty())
00071         return;       // no reference to expand!
00072     wxFileName fn;
00073     if (m_strLocalRef.Contains(wxT('#')))
00074         fn = m_strLocalRef.AfterFirst(wxT('#')).AfterFirst(wxT(':'));
00075     else
00076         fn = wxFileSystem::URLToFileName(m_strLocalRef);
00077 
00078     fn.MakeAbsolute(path);
00079     SetLocalRef(fn.GetFullPath());
00080 }
00081 
00082 void wxPackageDataWithRef::ExpandLocalRefToWXZRef(const wxString &wxzpath)
00083 {
00084     if (m_strLocalRef.IsEmpty())
00085         return;       // no reference to expand!
00086 
00087     // the file: protocol is already added by this function!
00088     wxASSERT(!wxzpath.StartsWith(wxT("file:")));
00089 
00090     wxFileName fn(wxFileSystem::URLToFileName(m_strLocalRef));
00091     wxFileName wxz(wxzpath);
00092 
00093     // the path to the given WXZ should be an absolute path!
00094     wxASSERT(!wxz.IsDir() && wxz.IsAbsolute());
00095 
00096     // NB: after the "wxz:" protocol we still need forward slashes since
00097     //     we are building an URL !
00098     SetLocalRef(wxFileSystem::FileNameToURL(wxz) +
00099             wxT("#wxz:") + fn.GetFullPath(wxPATH_UNIX));
00100 }
00101 
00102 
00103 // ----------------------------------------------------------------------------
00104 // wxPackageCondition
00105 // ----------------------------------------------------------------------------
00106 
00107 bool wxPackageCondition::IsValidForPackage(const wxPackage &pkg) const
00108 {
00109     return IsValidForCurrentPlatform() &&
00110             IsValidForCompiler(pkg.GetCompilerSettings().GetSelFormat()) &&
00111             IsValidForBuildSys(pkg.GetBuildSystemType());
00112 }
00113 
00114 void wxPackageCondition::SetAlwaysTrue()
00115 {
00116     m_buildSys = wxGetFullPackageBuildSystemTypeList();
00117     m_format = wxGetFullPackageCompilerFormatList();
00118     m_platform = wxGetFullPortIdList();
00119     m_stages = wxGetFullPackageBuildSystemStageList();
00120 }
00121 
00122 bool wxPackageCondition::operator==(const wxPackageCondition &cond) const
00123 {
00124     return m_platform == cond.m_platform &&
00125             m_format == cond.m_format &&
00126             m_buildSys == cond.m_buildSys &&
00127             m_stages == cond.m_stages;
00128 }
00129 
00130 
00131 
00132 // ----------------------------------------------------------------------------
00133 // wxPackageHTMLOutputFormatXMLDescriptor: helper class for wxPackageHTMLOutputFormat
00134 // ----------------------------------------------------------------------------
00135 
00136 class wxPackageHTMLOutputFormatXMLDescriptor : public wxXmlDocument
00137 {
00138 public:
00139     wxPackageHTMLOutputFormatXMLDescriptor() {}
00140 
00141     bool Load(const wxString &file, wxPackageHTMLOutputFormat *out)
00142     {
00143         if (!wxXmlDocument::Load(file))
00144             return false;
00145 
00146         if (GetRoot()->GetName() != wxT("wxpackage-viewformat"))
00147             return false;
00148 
00149         wxXmlNode *child = GetRoot()->GetChildren();
00150         while (child)
00151         {
00152             if (child->GetName() == wxT("name"))
00153             {
00154                 out->m_strName = child->GetNodeContent();
00155             }
00156             else if (child->GetName() == wxT("description"))
00157             {
00158                 out->m_strDescription = child->GetNodeContent();
00159             }
00160             else if (child->GetName() == wxT("type"))
00161             {
00162                 out->m_ctx = wxString2PackageSubstituteInfoContext(child->GetNodeContent());
00163             }
00164 
00165             // proceed
00166             child = child->GetNext();
00167         }
00168 
00169         return true;
00170     }
00171 };
00172 
00173 
00174 // ----------------------------------------------------------------------------
00175 // wxPackageHTMLOutputFormat
00176 // ----------------------------------------------------------------------------
00177 
00178 bool wxPackageHTMLOutputFormat::Load(const wxString &dirname)
00179 {
00180     wxString summaryfile = dirname + wxFileName::GetPathSeparator() + wxT("summary.html");
00181     wxString detailsfile = dirname + wxFileName::GetPathSeparator() + wxT("details.html");
00182     wxString descfile = dirname + wxFileName::GetPathSeparator() + wxT("info.xml");
00183     wxFFile f;
00184 
00185     if (!wxFileExists(summaryfile) || !wxFileExists(detailsfile) || !wxFileExists(descfile))
00186     {
00187         // the given directory does not contain a valid view format
00188         wxLogWarning(_("The directory '%s' does not contain a valid view format."),
00189                      dirname.c_str());
00190         return false;
00191     }
00192 
00193     // summary
00194     if (!f.Open(summaryfile) || !f.ReadAll(&m_strSummary))
00195     {
00196         wxLogError(_("Could not load the '%s' file."), summaryfile.c_str());
00197         return false;
00198     }
00199     f.Close();
00200 
00201     // details
00202     if (!f.Open(detailsfile) || !f.ReadAll(&m_strDetails))
00203     {
00204         wxLogError(_("Could not load the '%s' file."), detailsfile.c_str());
00205         return false;
00206     }
00207     f.Close();
00208 
00209     // look at the XML specification file
00210     wxPackageHTMLOutputFormatXMLDescriptor desc;
00211     if (!desc.Load(descfile, this))
00212     {
00213         wxLogError(_("Could not load the '%s' file."), descfile.c_str());
00214         return false;
00215     }
00216 
00217     return true;
00218 }
00219 
00220 wxString wxPackageHTMLOutputFormat::GetSummaryFor(const wxPackageInfo &pkg) const
00221 {
00222     return pkg.SubstituteInfo(m_strSummary, m_ctx);
00223 }
00224 
00225 wxString wxPackageHTMLOutputFormat::GetDetailsFor(const wxPackageInfo &pkg) const
00226 {
00227     return pkg.SubstituteInfo(m_strDetails, m_ctx);
00228 }
00229 

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