1
//--------------------------------------------------------------------------------------
2
// LenMus project: free software for music theory and language
3
// Copyright (c) 2002-2009 Cecilio Salmeron
5
// This program is free software; you can redistribute it and/or modify it under the
6
// terms of the GNU General Public License as published by the Free Software Foundation;
7
// either version 3 of the License, or (at your option) any later version.
9
// This program is distributed in the hope that it will be useful, but WITHOUT ANY
10
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
11
// PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
// You should have received a copy of the GNU General Public License along with this
14
// program. If not, see <http://www.gnu.org/licenses/>.
17
// For any comment, suggestion or feature request, please contact the manager of
18
// the project at cecilios@users.sourceforge.net
20
//-------------------------------------------------------------------------------------
22
#pragma implementation "ebook_processor.h"
25
// for (compilers that support precompilation, includes "wx/wx.h".
26
#include "wx/wxprec.h"
36
#include "wx/filename.h"
37
#include "wx/txtstrm.h"
38
#include "wx/zipstrm.h"
39
#include "wx/textfile.h"
40
#include "wx/arrstr.h"
43
#include "help_processor.h"
44
#include "wx/xml2.h" // include libxml2 wrapper definitions
45
#include "wx/dtd.h" // include libxml2 wrapper definitions
49
ltHelpProcessor::ltHelpProcessor(int nDbgOptions, wxTextCtrl* pUserLog)
54
ltHelpProcessor::~ltHelpProcessor()
58
bool ltHelpProcessor::GenerateHelpFile(wxString sSrcPath, wxString sLangCode,
59
wxString sCharCode, int nOptions)
61
// returns true if success
62
// PO and lang.cpp are created in sDestName (langtool\locale\)
63
// help.xxx files are created in sTempFolder (lenmus\locale\xx\books\)
64
// help.htb is created in sDestName (lenmus\locale\xx\)
67
wxString sTempFolder = g_pPaths->GetTempPath();
70
wxFileName oFDest( g_pPaths->GetBooksRootPath() );
71
oFDest.AppendDir(sLangCode);
72
wxString sDestFolder = oFDest.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);
75
oFDest.SetName(_T("help"));
76
oFDest.SetExt(_T("htb"));
77
m_pZipOutFile = new wxFFileOutputStream( oFDest.GetFullPath() );
78
m_pZipFile = new wxZipOutputStream(*m_pZipOutFile);
81
bool fSuccess = PackHelpFile(sSrcPath, sTempFolder, sDestFolder);
88
bool ltHelpProcessor::CreateHelpPoFile(wxString sFilename, wxString& sCharSet,
89
wxString& sLangName, wxString& sLangCode,
92
// returns true if success
94
//wxFile oFile(sFilename, wxFile::write);
95
//if (!m_pLangFile->IsOpened())
97
// wxLogMessage(_T("Error: File %s can not be created"), sFilename);
98
// m_pLangFile = (wxFile*)NULL;
99
// return false; //error
102
////Generate Po header
103
//wxString sNil = _T("");
104
//wxString sHeader = sNil +
105
// _T("msgid \"\"\n")
106
// _T("msgstr \"\"\n")
107
// _T("\"Project-Id-Version: LenMus 3.4\\n\"\n")
108
// _T("\"POT-Creation-Date: \\n\"\n")
109
// _T("\"PO-Revision-Date: 2006-08-25 12:19+0100\\n\"\n")
110
// _T("\"Last-Translator: \\n\"\n")
111
// _T("\"Language-Team: <cecilios@gmail.com>\\n\"\n")
112
// _T("\"MIME-Version: 1.0\\n\"\n")
113
// _T("\"Content-Type: text/plain; charset=utf-8\\n\"\n")
114
// _T("\"Content-Transfer-Encoding: 8bit\\n\"\n")
115
// _T("\"X-Poedit-Language: ") + sLangName + _T("\\n\"\n")
116
// _T("\"X-Poedit-SourceCharset: utf-8\\n\"\n")
117
// _T("\"X-Poedit-Basepath: c:\\usr\\desarrollo_wx\\lenmus\\langtool\\locale\\src\\n\"\n")
118
// _T("\"X-Poedit-SearchPath-0: ") + sFolder + _T("\\n\"\n\n");
121
//oFile.Write(sHeader);
126
bool ltHelpProcessor::PackHelpFile(wxString& sSrcFolder, wxString& sTempFolder,
127
wxString& sDestFolder)
129
//return true if success
130
//- copy all files in sTempFolder, zip them as help.htb and places this
131
// resulting file in sDestFolder.
132
//- Doesn't delete temp files
134
bool fSuccess = true;
137
wxFileName oFN1(sSrcFolder, _T("help.hhc"), wxPATH_NATIVE);
138
fSuccess &= CopyFileToHelp( oFN1.GetFullPath() );
139
wxFileName oFN2(sSrcFolder, _T("help.hhk"), wxPATH_NATIVE);
140
fSuccess &= CopyFileToHelp( oFN2.GetFullPath() );
141
wxFileName oFN3(sSrcFolder, _T("help.hhp"), wxPATH_NATIVE);
142
fSuccess &= CopyFileToHelp( oFN3.GetFullPath() );
146
fSuccess &= CopyAllFilesToHelp(sSrcFolder, _T(""), _T("*.htm"));
149
wxFileName oFNImg(sSrcFolder);
150
oFNImg.AppendDir(_T("img"));
151
wxString sImgFolder = oFNImg.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);
152
fSuccess &= CopyAllFilesToHelp(sImgFolder, _T("img\\"), _T("*.*"));
153
//wxDir oDirImg(sImgFolder);
154
//if ( !oDirImg.IsOpened() )
156
// wxLogMessage(_T("Error: Folder %s can not be opened"), sImgFolder);
159
//bool fFound = oDirImg.GetFirst(&sFilename, _T("*.*"), wxDIR_FILES);
162
// wxFileName oFN(sImgFolder, sFilename, wxPATH_NATIVE);
163
// fSuccess &= CopyFileToHelp( oFN.GetFullPath() );
164
// fFound = oDirImg.GetNext(&sFilename);
170
//print final message
172
LogMsg( _T("Help file created successfuly") );
174
LogMsg( _T("Errors while creating help file") );
175
LogMsg( _T("===========================================\n") );
181
bool ltHelpProcessor::CopyFileToHelp(const wxString& sFilename, const wxString& sZipFolder)
183
//return true if success
184
//sZipFolder is a string with the folder prefix to add to filename when creating
185
//the entry in the zip file. For example, if zip file should contain a folder
186
//in which to add the files sZipFolder should contain "the-folder"
188
wxFFileInputStream inFile( sFilename, _T("rb") );
189
if (!inFile.IsOk()) {
190
wxLogMessage(_T("*** Error: File %s can not be included in help"), sFilename.c_str());
193
wxFileName oFN(sFilename);
194
wxString sEntryName = sZipFolder + oFN.GetFullName();
195
m_pZipFile->PutNextEntry( sEntryName );
196
m_pZipFile->Write( inFile );
197
m_pZipFile->CloseEntry();
201
bool ltHelpProcessor::CopyAllFilesToHelp(const wxString& sSrcFolder,
202
const wxString& sZipFolder,
203
const wxString& sFilter)
205
//return true if success
207
bool fSuccess = true;
208
wxDir oDir(sSrcFolder);
209
if ( !oDir.IsOpened() )
211
wxLogMessage(_T("*** Error: Folder %s can not be opened"), sSrcFolder.c_str());
215
bool fFound = oDir.GetFirst(&sFilename, sFilter, wxDIR_FILES);
218
wxFileName oFN(sSrcFolder, sFilename, wxPATH_NATIVE);
219
fSuccess &= CopyFileToHelp(oFN.GetFullPath(), sZipFolder);
220
fFound = oDir.GetNext(&sFilename);
226
void ltHelpProcessor::LogMsg(const wxChar* szFormat, ...)
231
va_start(argptr, szFormat);
232
wxString sMsg = wxString::FormatV(szFormat, argptr) + _T("\n");
233
m_pLog->AppendText(sMsg);