X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2b5f62a0b2db198609b45dec622a018dae37008e..1d14c0051c7530f303855d454e5601a596284a71:/contrib/utils/wxrc/wxrc.cpp
diff --git a/contrib/utils/wxrc/wxrc.cpp b/contrib/utils/wxrc/wxrc.cpp
index ff536b0ef8..8bf7f2ef0a 100644
--- a/contrib/utils/wxrc/wxrc.cpp
+++ b/contrib/utils/wxrc/wxrc.cpp
@@ -27,29 +27,19 @@
#endif
#include "wx/cmdline.h"
-#include "wx/xrc/xml.h"
+#include "wx/xml/xml.h"
#include "wx/ffile.h"
+#include "wx/filename.h"
#include "wx/wfstream.h"
-
-
-
-/*
-#if wxUSE_GUI
-#error "You must compile the resource compiler with wxBase!"
-#endif
-*/
-
-class XmlResApp : public wxApp
+class XmlResApp : public wxAppConsole
{
public:
+ // don't use builtin cmd line parsing:
+ virtual bool OnInit() { return true; }
-#if wxUSE_GUI
- bool OnInit();
-#else
virtual int OnRun();
-#endif
private:
@@ -76,11 +66,7 @@ private:
IMPLEMENT_APP(XmlResApp)
-#if wxUSE_GUI
-bool XmlResApp::OnInit()
-#else
int XmlResApp::OnRun()
-#endif
{
static const wxCmdLineEntryDesc cmdLineDesc[] =
{
@@ -117,19 +103,11 @@ int XmlResApp::OnRun()
OutputGettext();
else
CompileRes();
-#if wxUSE_GUI
- return FALSE;
-#else
return retCode;
-#endif
break;
default:
-#if wxUSE_GUI
- return FALSE;
-#else
return 1;
-#endif
break;
}
}
@@ -158,6 +136,9 @@ void XmlResApp::ParseParams(const wxCmdLineParser& cmdline)
parOutput = _T("resource.xrs");
}
}
+ wxFileName fn(parOutput);
+ fn.Normalize();
+ parOutput = fn.GetFullPath();
parOutputPath = wxPathOnly(parOutput);
if (!parOutputPath) parOutputPath = _T(".");
@@ -165,7 +146,18 @@ void XmlResApp::ParseParams(const wxCmdLineParser& cmdline)
parFuncname = _T("InitXmlResource");
for (size_t i = 0; i < cmdline.GetParamCount(); i++)
+ {
+#ifdef __WINDOWS__
+ wxString fn=wxFindFirstFile(cmdline.GetParam(i), wxFILE);
+ while (!fn.IsEmpty())
+ {
+ parFiles.Add(fn);
+ fn=wxFindNextFile();
+ }
+#else
parFiles.Add(cmdline.GetParam(i));
+#endif
+ }
}
@@ -239,7 +231,7 @@ wxArrayString XmlResApp::PrepareTempFiles()
wxString internalName = GetInternalFileName(parFiles[i], flist);
- doc.Save(parOutputPath + _T("/") + internalName);
+ doc.Save(parOutputPath + wxFILE_SEP_PATH + internalName);
flist.Add(internalName);
}
@@ -247,6 +239,36 @@ wxArrayString XmlResApp::PrepareTempFiles()
}
+// Does 'node' contain filename information at all?
+static bool NodeContainsFilename(wxXmlNode *node)
+{
+ // Any bitmaps:
+ if (node->GetName() == _T("bitmap"))
+ return TRUE;
+
+ // URLs in wxHtmlWindow:
+ if (node->GetName() == _T("url"))
+ return TRUE;
+
+ // wxBitmapButton:
+ wxXmlNode *parent = node->GetParent();
+ if (parent != NULL &&
+ parent->GetPropVal(_T("class"), _T("")) == _T("wxBitmapButton") &&
+ (node->GetName() == _T("focus") ||
+ node->GetName() == _T("disabled") ||
+ node->GetName() == _T("selected")))
+ return TRUE;
+
+ // wxBitmap or wxIcon toplevel resources:
+ if (node->GetName() == _T("object"))
+ {
+ wxString klass = node->GetPropVal(_T("class"), wxEmptyString);
+ if (klass == _T("wxBitmap") || klass == _T("wxIcon"))
+ return TRUE;
+ }
+
+ return FALSE;
+}
// find all files mentioned in structure, e.g. filename
void XmlResApp::FindFilesInXML(wxXmlNode *node, wxArrayString& flist, const wxString& inputPath)
@@ -255,19 +277,7 @@ void XmlResApp::FindFilesInXML(wxXmlNode *node, wxArrayString& flist, const wxSt
if (node == NULL) return;
if (node->GetType() != wxXML_ELEMENT_NODE) return;
- // Does 'node' contain filename information at all?
- bool containsFilename = (
- // Any bitmaps:
- (node->GetName() == _T("bitmap")) ||
- // URLs in wxHtmlWindow:
- (node->GetName() == _T("url")) ||
- // wxBitmapButton:
- (node->GetParent() != NULL &&
- node->GetParent()->GetPropVal(_T("class"), _T("")) == _T("wxBitmapButton") &&
- (node->GetName() == _T("focus") ||
- node->GetName() == _T("disabled") ||
- node->GetName() == _T("selected")))
- );
+ bool containsFilename = NodeContainsFilename(node);
wxXmlNode *n = node->GetChildren();
while (n)
@@ -280,7 +290,7 @@ void XmlResApp::FindFilesInXML(wxXmlNode *node, wxArrayString& flist, const wxSt
if (wxIsAbsolutePath(n->GetContent()) || inputPath.empty())
fullname = n->GetContent();
else
- fullname = inputPath + _T("/") + n->GetContent();
+ fullname = inputPath + wxFILE_SEP_PATH + n->GetContent();
if (flagVerbose)
wxPrintf(_T("adding ") + fullname + _T("...\n"));
@@ -292,7 +302,7 @@ void XmlResApp::FindFilesInXML(wxXmlNode *node, wxArrayString& flist, const wxSt
flist.Add(filename);
wxFileInputStream sin(fullname);
- wxFileOutputStream sout(parOutputPath + _T("/") + filename);
+ wxFileOutputStream sout(parOutputPath + wxFILE_SEP_PATH + filename);
sin.Read(sout); // copy the stream
}
@@ -309,7 +319,7 @@ void XmlResApp::FindFilesInXML(wxXmlNode *node, wxArrayString& flist, const wxSt
void XmlResApp::DeleteTempFiles(const wxArrayString& flist)
{
for (size_t i = 0; i < flist.Count(); i++)
- wxRemoveFile(parOutputPath + _T("/") + flist[i]);
+ wxRemoveFile(parOutputPath + wxFILE_SEP_PATH + flist[i]);
}
@@ -324,9 +334,14 @@ void XmlResApp::MakePackageZIP(const wxArrayString& flist)
if (flagVerbose)
wxPrintf(_T("compressing ") + parOutput + _T("...\n"));
-
- if (wxExecute(_T("zip -9 -j ") + wxString(flagVerbose ? _T("") : _T("-q ")) +
- parOutput + _T(" ") + files, TRUE) == -1)
+
+ wxString cwd = wxGetCwd();
+ wxSetWorkingDirectory(parOutputPath);
+ int execres = wxExecute(_T("zip -9 -j ") +
+ wxString(flagVerbose ? _T("") : _T("-q ")) +
+ parOutput + _T(" ") + files, TRUE);
+ wxSetWorkingDirectory(cwd);
+ if (execres == -1)
{
wxLogError(_T("Unable to execute zip program. Make sure it is in the path."));
wxLogError(_T("You can download it at http://www.cdrom.com/pub/infozip/"));
@@ -343,7 +358,7 @@ static wxString FileToCppArray(wxString filename, int num)
wxString output;
wxString tmp;
wxString snum;
- wxFFile file(filename, "rb");
+ wxFFile file(filename, wxT("rb"));
size_t lng = file.Length();
snum.Printf(_T("%i"), num);
@@ -378,7 +393,7 @@ static wxString FileToCppArray(wxString filename, int num)
void XmlResApp::MakePackageCPP(const wxArrayString& flist)
{
- wxFFile file(parOutput, "wt");
+ wxFFile file(parOutput, wxT("wt"));
size_t i;
if (flagVerbose)
@@ -405,18 +420,19 @@ _T("#include \n")
_T("\n"));
for (i = 0; i < flist.Count(); i++)
- file.Write(FileToCppArray(flist[i], i));
+ file.Write(
+ FileToCppArray(parOutputPath + wxFILE_SEP_PATH + flist[i], i));
file.Write(_T("")
-_T("void " + parFuncname + "()\n")
+_T("void ") + parFuncname + wxT("()\n")
_T("{\n")
_T("\n")
_T(" // Check for memory FS. If not present, load the handler:\n")
_T(" {\n")
-_T(" wxMemoryFSHandler::AddFile(\"XRC_resource/dummy_file\", \"dummy one\");\n")
+_T(" wxMemoryFSHandler::AddFile(wxT(\"XRC_resource/dummy_file\"), wxT(\"dummy one\"));\n")
_T(" wxFileSystem fsys;\n")
-_T(" wxFSFile *f = fsys.OpenFile(\"memory:XRC_resource/dummy_file\");\n")
-_T(" wxMemoryFSHandler::RemoveFile(\"XRC_resource/dummy_file\");\n")
+_T(" wxFSFile *f = fsys.OpenFile(wxT(\"memory:XRC_resource/dummy_file\"));\n")
+_T(" wxMemoryFSHandler::RemoveFile(wxT(\"XRC_resource/dummy_file\"));\n")
_T(" if (f) delete f;\n")
_T(" else wxFileSystem::AddHandler(new wxMemoryFSHandler);\n")
_T(" }\n")
@@ -425,15 +441,15 @@ _T("\n"));
for (i = 0; i < flist.Count(); i++)
{
wxString s;
- s.Printf(_T(" wxMemoryFSHandler::AddFile(\"XRC_resource/") + flist[i] +
- _T("\", xml_res_file_%i, xml_res_size_%i);\n"), i, i);
+ s.Printf(_T(" wxMemoryFSHandler::AddFile(wxT(\"XRC_resource/") + flist[i] +
+ _T("\"), xml_res_file_%i, xml_res_size_%i);\n"), i, i);
file.Write(s);
}
for (i = 0; i < parFiles.Count(); i++)
{
- file.Write(_T(" wxXmlResource::Get()->Load(\"memory:XRC_resource/") +
- GetInternalFileName(parFiles[i], flist) + _T("\");\n"));
+ file.Write(_T(" wxXmlResource::Get()->Load(wxT(\"memory:XRC_resource/") +
+ GetInternalFileName(parFiles[i], flist) + _T("\"));\n"));
}
file.Write(_T("}\n"));
@@ -446,7 +462,7 @@ static wxString FileToPythonArray(wxString filename, int num)
wxString output;
wxString tmp;
wxString snum;
- wxFFile file(filename, "rb");
+ wxFFile file(filename, wxT("rb"));
size_t lng = file.Length();
snum.Printf(_T("%i"), num);
@@ -488,7 +504,7 @@ static wxString FileToPythonArray(wxString filename, int num)
void XmlResApp::MakePackagePython(const wxArrayString& flist)
{
- wxFFile file(parOutput, "wt");
+ wxFFile file(parOutput, wxT("wt"));
size_t i;
if (flagVerbose)
@@ -506,7 +522,8 @@ void XmlResApp::MakePackagePython(const wxArrayString& flist)
file.Write(_T("def ") + parFuncname + _T("():\n"));
for (i = 0; i < flist.Count(); i++)
- file.Write(FileToPythonArray(flist[i], i));
+ file.Write(
+ FileToPythonArray(parOutputPath + wxFILE_SEP_PATH + flist[i], i));
for (i = 0; i < flist.Count(); i++)
{
@@ -524,7 +541,7 @@ void XmlResApp::OutputGettext()
wxFFile fout;
if (!parOutput) fout.Attach(stdout);
- else fout.Open(parOutput, "wt");
+ else fout.Open(parOutput, wxT("wt"));
for (size_t i = 0; i < str.GetCount(); i++)
fout.Write(_T("_(\"") + str[i] + _T("\");\n"));