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>
29 #include "eD2kFiles.h"
32 #include "../../CFile.h"
34 #define VERSION_MAJOR 0
35 #define VERSION_MINOR 9
36 #define VERSION_MICRO 7
38 class CFileView
: public wxApp
43 virtual void OnInitCmdLine(wxCmdLineParser
& parser
);
44 virtual bool OnCmdLineParsed(wxCmdLineParser
& parser
);
46 std::list
<wxString
> m_files
;
49 DECLARE_APP(CFileView
);
51 // Logging facility from aMule
57 void AddLogLine(const wxString
& /*file*/, int /*line*/, bool /*critical*/, DebugType
/*type*/, const wxString
& str
, bool /*toStdout*/, bool /*toGUI*/);
60 void CLogger::AddLogLine(const wxString
& /*file*/, int /*line*/, bool /*critical*/, DebugType
/*type*/, const wxString
& str
, bool /*toStdout*/, bool /*toGUI*/)
62 cout
<< "DebugLog: " << str
<< "\n";
68 IMPLEMENT_APP(CFileView
);
70 void CFileView::OnInitCmdLine(wxCmdLineParser
& parser
)
72 parser
.AddSwitch(wxT("h"), wxT("help"), wxT("Show help"), wxCMD_LINE_OPTION_HELP
);
73 parser
.AddSwitch(wxT("v"), wxT("version"), wxT("Show program version"), wxCMD_LINE_PARAM_OPTIONAL
);
74 parser
.AddOption(wxT("s"), wxT("strings"), wxT("String decoding mode: display (default), safe, utf8, none"), wxCMD_LINE_VAL_STRING
, wxCMD_LINE_PARAM_OPTIONAL
);
75 parser
.AddParam(wxT("input file"), wxCMD_LINE_VAL_STRING
, wxCMD_LINE_PARAM_OPTIONAL
| wxCMD_LINE_PARAM_MULTIPLE
);
78 bool CFileView::OnCmdLineParsed(wxCmdLineParser
& parser
)
80 if (parser
.Found(wxT("version"))) {
81 cout
<< wxString::Format(wxT("MuleFileView version %u.%u.%u\nCopyright (c) 2008 aMule Team\n"), VERSION_MAJOR
, VERSION_MINOR
, VERSION_MICRO
);
85 if (parser
.Found(wxT("strings"), &strDecode
)) {
86 if (strDecode
== wxT("display")) {
87 SetStringsMode(SD_DISPLAY
);
88 } else if (strDecode
== wxT("safe")) {
89 SetStringsMode(SD_SAFE
);
90 } else if (strDecode
== wxT("utf8")) {
91 SetStringsMode(SD_UTF8
);
92 } else if (strDecode
== wxT("none")) {
93 SetStringsMode(SD_NONE
);
95 parser
.SetLogo(wxT("Error: Invalid argument to --strings option: \"") + strDecode
+ wxT("\""));
100 SetStringsMode(SD_DISPLAY
);
102 for (size_t n
= 0; n
< parser
.GetParamCount(); n
++) {
103 m_files
.push_back(parser
.GetParam(n
));
105 if (m_files
.size() == 0) {
114 int CFileView::OnRun()
116 for (std::list
<wxString
>::const_iterator it
= m_files
.begin(); it
!= m_files
.end(); ++it
) {
117 wxString basename
= (*it
).AfterLast(wxFileName::GetPathSeparator()).AfterLast(wxT('/'));
120 if (file
.IsOpened()) {
121 if (it
!= m_files
.begin()) {
124 cout
<< "Decoding file: " << *it
<< endl
;
125 if (basename
== wxT("preferencesKad.dat")) {
126 DecodePreferencesKadDat(file
);
127 } else if (basename
== wxT("load_index.dat")) {
128 DecodeLoadIndexDat(file
);
129 } else if (basename
== wxT("key_index.dat")) {
130 DecodeKeyIndexDat(file
);
131 } else if (basename
== wxT("src_index.dat")) {
132 DecodeSourceIndexDat(file
);
133 } else if (basename
== wxT("nodes.dat")) {
134 DecodeNodesDat(file
);
135 } else if (basename
== wxT("preferences.dat")) {
136 DecodePreferencesDat(file
);
137 } else if (basename
== wxT("emfriends.met")) {
138 DecodeFriendList(file
);
139 } else if (basename
== wxT("server.met")) {
140 DecodeServerMet(file
);
141 } else if (basename
== wxT("clients.met")) {
142 DecodeClientsMet(file
);
143 } else if (basename
== wxT("known.met")) {
144 DecodeKnownMet(file
);
145 } else if (basename
.Find(wxT(".part.met")) != wxNOT_FOUND
) {
146 DecodePartMetFile(file
);
148 cerr
<< "ERROR: Don't know how to decode " << *it
<< endl
;
151 } catch (const CEOFException
& e
) {
152 cerr
<< "ERROR: A CEOFException has been raised while decoding " << *it
<< ": " << e
.what() << endl
;
154 } catch (const CIOFailureException
& e
) {
155 cerr
<< "ERROR: A CIOFailureException has been raised while decoding " << *it
<< ": " << e
.what() << endl
;
157 } catch (const CSafeIOException
& e
) {
158 cerr
<< "ERROR: A CSafeIOException has been raised while decoding " << *it
<< ": " << e
.what() << endl
;
160 } catch (const CMuleException
& e
) {
161 cerr
<< "ERROR: A CMuleException has been raised while decoding " << *it
<< ": " << e
.what() << endl
;
163 } catch (const wxString
& e
) {
164 cerr
<< "ERROR: An exception of type wxString has been raised while decoding " << *it
<< ": " << e
<< endl
;