3 /// Reads an boost serialization file and dumps to stdout.
7 Copyright (C) 2008, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #define __BARRY_BOOST_MODE__ // this program always requires BOOST
23 #include <barry/barry.h>
35 using namespace Barry
;
40 const char *Version
= Barry::Version(major
, minor
);
43 << "bs11nread - Reads a boost serialization file (from btool)\n"
44 << " and dumps data to stdout\n"
45 << " Copyright 2008, Net Direct Inc. (http://www.netdirect.ca/)\n"
46 << " Using: " << Version
<< "\n"
48 << " -f file Filename to save or load handheld data to/from\n"
50 << " -S Show list of supported database parsers\n"
54 template <class Record
>
55 bool Dump(const std::string
&dbName
, ifstream
&ifs
)
57 if( dbName
!= Record::GetDBName() )
60 std::vector
<Record
> records
;
61 boost::archive::text_iarchive
ia(ifs
);
63 cout
<< records
.size()
64 << " records loaded" << endl
;
65 sort(records
.begin(), records
.end());
67 typename
std::vector
<Record
>::const_iterator
68 beg
= records
.begin(), end
= records
.end();
69 for( ; beg
!= end
; beg
++ ) {
70 cout
<< (*beg
) << endl
;
76 void DumpDB(const string
&filename
)
78 // filename is available, attempt to load
79 ifstream
ifs(filename
.c_str());
83 // check for recognized database names
84 Dump
<Contact
> (dbName
, ifs
) ||
85 Dump
<Message
> (dbName
, ifs
) ||
86 Dump
<Calendar
> (dbName
, ifs
) ||
87 Dump
<ServiceBook
> (dbName
, ifs
) ||
88 Dump
<Memo
> (dbName
, ifs
) ||
89 Dump
<Task
> (dbName
, ifs
) ||
90 Dump
<PINMessage
> (dbName
, ifs
) ||
91 Dump
<SavedMessage
> (dbName
, ifs
) ||
92 Dump
<Folder
> (dbName
, ifs
) ||
93 Dump
<Timezone
> (dbName
, ifs
) ||
94 cerr
<< "Unknown database name: " << dbName
<< endl
;
99 cout
<< "Supported Database parsers:\n"
107 << " Saved Email Messages\n"
113 int main(int argc
, char *argv
[])
118 // process command line options
120 int cmd
= getopt(argc
, argv
, "f:hS");
126 case 'f': // filename
130 case 'S': // show supported databases
141 // Initialize the barry library. Must be called before
145 if( !filename
.size() ) {
146 cerr
<< "Filename must be specified" << endl
;
153 catch( boost::archive::archive_exception
&ae
) {
154 cerr
<< "Archive exception: "
155 << ae
.what() << endl
;
158 catch( Usb::Error
&ue
) {
159 std::cerr
<< "Usb::Error caught: " << ue
.what() << endl
;
162 catch( Barry::Error
&se
) {
163 std::cerr
<< "Barry::Error caught: " << se
.what() << endl
;
166 catch( std::exception
&e
) {
167 std::cerr
<< "std::exception caught: " << e
.what() << endl
;