2 // This file is part of the aMule Project.
4 // Copyright (c) 2008 Dévai Tamás ( gonosztopi@amule.org )
5 // Copyright (c) 2008 aMule Team ( admin@amule.org / http://www.amule.org )
7 // Any parts of this program derived from the xMule, lMule or eMule project,
8 // or contributed by third-party developers are copyrighted by their
11 // This program is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation; either version 2 of the License, or
14 // (at your option) any later version.
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include <wx/cmdline.h>
31 #include "../../CFile.h"
33 #define VERSION_MAJOR 0
34 #define VERSION_MINOR 1
35 #define VERSION_MICRO 0
37 class CFileView
: public wxApp
42 virtual void OnInitCmdLine(wxCmdLineParser
& parser
);
43 virtual bool OnCmdLineParsed(wxCmdLineParser
& parser
);
45 std::list
<wxString
> m_files
;
48 DECLARE_APP(CFileView
);
50 // Logging facility from aMule
55 bool IsEnabled(DebugType
)
60 void AddLogLine(const wxString
& /*file*/, int /*line*/, bool /*critical*/, const wxString
& str
)
62 DoPrint(wxT("Log: ") + str
+ wxT("\n"));
65 void AddLogLine(const wxString
& /*file*/, int /*line*/, bool /*critical*/, DebugType
/*type*/, const wxString
& str
)
67 DoPrint(wxT("DebugLog: ") + str
+ wxT("\n"));
73 IMPLEMENT_APP(CFileView
);
75 void CFileView::OnInitCmdLine(wxCmdLineParser
& parser
)
77 parser
.AddSwitch(wxT("h"), wxT("help"), wxT("Show help"), wxCMD_LINE_OPTION_HELP
);
78 parser
.AddSwitch(wxT("v"), wxT("version"), wxT("Show program version"), wxCMD_LINE_PARAM_OPTIONAL
);
79 parser
.AddParam(wxT("input file"), wxCMD_LINE_VAL_STRING
, wxCMD_LINE_PARAM_OPTIONAL
| wxCMD_LINE_PARAM_MULTIPLE
);
82 bool CFileView::OnCmdLineParsed(wxCmdLineParser
& parser
)
84 if (parser
.Found(wxT("version"))) {
85 DoPrint(wxString::Format(wxT("MuleFileView version %u.%u.%u\nCopyright (c) 2008 aMule Team\n"), VERSION_MAJOR
, VERSION_MINOR
, VERSION_MICRO
));
88 for (size_t n
= 0; n
< parser
.GetParamCount(); n
++) {
89 m_files
.push_back(parser
.GetParam(n
));
91 if (m_files
.size() == 0) {
100 int CFileView::OnRun()
102 for (std::list
<wxString
>::const_iterator it
= m_files
.begin(); it
!= m_files
.end(); ++it
) {
103 wxString basename
= (*it
).AfterLast(wxFileName::GetPathSeparator()).AfterLast(wxT('/'));
106 if (file
.IsOpened()) {
107 if (it
!= m_files
.begin()) {
110 DoPrint(wxT("Decoding file: ") + (*it
) + wxT("\n"));
111 if (basename
== wxT("preferencesKad.dat")) {
112 DecodePreferencesKadDat(file
);
113 } else if (basename
== wxT("load_index.dat")) {
114 DecodeLoadIndexDat(file
);
115 } else if (basename
== wxT("key_index.dat")) {
116 DecodeKeyIndexDat(file
);
117 } else if (basename
== wxT("src_index.dat")) {
118 DecodeSourceIndexDat(file
);
119 } else if (basename
== wxT("nodes.dat")) {
120 DecodeNodesDat(file
);
122 DoPrint(wxT("ERROR: Don't know how to decode ") + (*it
) + wxT("\n"));
125 } catch (const CEOFException
& e
) {
126 DoPrint(wxT("ERROR: A CEOFException has been raised while decoding ") + (*it
) + wxT(": ") + e
.what() + wxT("\n"));
128 } catch (const CIOFailureException
& e
) {
129 DoPrint(wxT("ERROR: A CIOFailureException has been raised while decoding ") + (*it
) + wxT(": ") + e
.what() + wxT("\n"));
131 } catch (const CSafeIOException
& e
) {
132 DoPrint(wxT("ERROR: A CSafeIOException has been raised while decoding ") + (*it
) + wxT(": ") + e
.what() + wxT("\n"));
134 } catch (const CMuleException
& e
) {
135 DoPrint(wxT("ERROR: A CMuleException has been raised while decoding ") + (*it
) + wxT(": ") + e
.what() + wxT("\n"));
137 } catch (const wxString
& e
) {
138 DoPrint(wxT("ERROR: An exception of type wxString has been raised while decoding ") + (*it
) + wxT(": ") + e
+ wxT("\n"));