+void XmlResApp::GenCPPHeader()
+{
+ wxString fileSpec = ((parOutput.BeforeLast('.')).AfterLast('/')).AfterLast('\\');
+ wxString heaFileName = fileSpec + _T(".h");
+
+ wxFFile file(heaFileName, wxT("wt"));
+ file.Write(
+"//\n"
+"// This file was automatically generated by wxrc, do not edit by hand.\n"
+"//\n\n"
+"#ifndef __" + fileSpec + "_h__\n"
+"#define __" + fileSpec + "_h__\n"
+);
+ for(size_t i=0;i<aXRCWndClassData.GetCount();++i){
+ aXRCWndClassData.Item(i).GenerateHeaderCode(file);
+ }
+ file.Write(
+ "\nvoid \n"
+ + parFuncname
+ + "();\n#endif\n");
+}
+
+static wxString FileToPythonArray(wxString filename, int num)
+{
+ wxString output;
+ wxString tmp;
+ wxString snum;
+ wxFFile file(filename, wxT("rb"));
+ wxFileOffset offset = file.Length();
+ wxASSERT_MSG( offset >= 0 , wxT("Invalid file length") );
+
+ const size_t lng = wx_truncate_cast(size_t, offset);
+ wxASSERT_MSG( wx_static_cast(wxFileOffset, lng) == offset,
+ wxT("Huge file not supported") );
+
+ snum.Printf(_T("%i"), num);
+ output = " xml_res_file_" + snum + " = '''\\\n";
+
+ unsigned char *buffer = new unsigned char[lng];
+ file.Read(buffer, lng);
+
+ for (size_t i = 0, linelng = 0; i < lng; i++)
+ {
+ unsigned char c = buffer[i];
+ if (c == '\n')
+ {
+ tmp = (wxChar)c;
+ linelng = 0;
+ }
+ else if (c < 32 || c > 127 || c == '\'')
+ tmp.Printf(_T("\\x%02x"), c);
+ else if (c == '\\')
+ tmp = _T("\\\\");
+ else
+ tmp = (wxChar)c;
+ if (linelng > 70)
+ {
+ linelng = 0;
+ output << _T("\\\n");
+ }
+ output << tmp;
+ linelng += tmp.Length();
+ }
+
+ delete[] buffer;
+
+ output += _T("'''\n\n");
+
+ return output;
+}
+
+
+void XmlResApp::MakePackagePython(const wxArrayString& flist)
+{
+ wxFFile file(parOutput, wxT("wt"));
+ size_t i;
+
+ if (flagVerbose)
+ wxPrintf(_T("creating Python source file ") + parOutput + _T("...\n"));
+
+ file.Write(
+ "#\n"
+ "# This file was automatically generated by wxrc, do not edit by hand.\n"
+ "#\n\n"
+ "import wx\n"
+ "import wx.xrc\n\n"
+ );
+
+
+ file.Write("def " + parFuncname + "():\n");
+
+ for (i = 0; i < flist.GetCount(); i++)
+ file.Write(
+ FileToPythonArray(parOutputPath + wxFILE_SEP_PATH + flist[i], i));
+
+ file.Write(
+ " # check if the memory filesystem handler has been loaded yet, and load it if not\n"
+ " wx.MemoryFSHandler.AddFile('XRC_resource/dummy_file', 'dummy value')\n"
+ " fsys = wx.FileSystem()\n"
+ " f = fsys.OpenFile('memory:XRC_resource/dummy_file')\n"
+ " wx.MemoryFSHandler.RemoveFile('XRC_resource/dummy_file')\n"
+ " if f is not None:\n"
+ " f.Destroy()\n"
+ " else:\n"
+ " wx.FileSystem.AddHandler(wx.MemoryFSHandler())\n"
+ "\n"
+ " # load all the strings as memory files and load into XmlRes\n"
+ );
+
+
+ for (i = 0; i < flist.GetCount(); i++)
+ {
+ wxString s;
+ s.Printf(" wx.MemoryFSHandler.AddFile('XRC_resource/" + flist[i] +
+ "', xml_res_file_%i)\n", i);
+ file.Write(s);
+ }
+ for (i = 0; i < parFiles.GetCount(); i++)
+ {
+ file.Write(" wx.xrc.XmlResource.Get().Load('memory:XRC_resource/" +
+ GetInternalFileName(parFiles[i], flist) + "')\n");
+ }
+
+ file.Write("\n");
+}
+