3 /// Reads an boost serialization file and dumps to stdout.
7 Copyright (C) 2008-2009, 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>
36 using namespace Barry
;
41 const char *Version
= Barry::Version(major
, minor
);
44 << "bs11nread - Reads a boost serialization file (from btool)\n"
45 << " and dumps data to stdout\n"
46 << " Copyright 2008-2009, Net Direct Inc. (http://www.netdirect.ca/)\n"
47 << " Using: " << Version
<< "\n"
49 << " -f file Filename to save or load handheld data to/from\n"
51 << " -S Show list of supported database parsers\n"
55 template <class Record
>
56 bool Dump(const std::string
&dbName
, ifstream
&ifs
)
58 if( dbName
!= Record::GetDBName() )
61 std::vector
<Record
> records
;
62 boost::archive::text_iarchive
ia(ifs
);
64 cout
<< records
.size()
65 << " records loaded" << endl
;
66 sort(records
.begin(), records
.end());
68 typename
std::vector
<Record
>::const_iterator
69 beg
= records
.begin(), end
= records
.end();
70 for( ; beg
!= end
; beg
++ ) {
71 cout
<< (*beg
) << endl
;
77 void DumpDB(const string
&filename
)
79 // filename is available, attempt to load
80 ifstream
ifs(filename
.c_str());
84 // check for recognized database names
85 Dump
<Contact
> (dbName
, ifs
) ||
86 Dump
<Message
> (dbName
, ifs
) ||
87 Dump
<Calendar
> (dbName
, ifs
) ||
88 Dump
<ServiceBook
> (dbName
, ifs
) ||
89 Dump
<Memo
> (dbName
, ifs
) ||
90 Dump
<Task
> (dbName
, ifs
) ||
91 Dump
<PINMessage
> (dbName
, ifs
) ||
92 Dump
<SavedMessage
> (dbName
, ifs
) ||
93 Dump
<Folder
> (dbName
, ifs
) ||
94 Dump
<Timezone
> (dbName
, ifs
) ||
95 cerr
<< "Unknown database name: " << dbName
<< endl
;
100 cout
<< "Supported Database parsers:\n"
108 << " Saved Email Messages\n"
114 int main(int argc
, char *argv
[])
121 // process command line options
123 int cmd
= getopt(argc
, argv
, "f:hS");
129 case 'f': // filename
133 case 'S': // show supported databases
144 // Initialize the barry library. Must be called before
148 if( !filename
.size() ) {
149 cerr
<< "Filename must be specified" << endl
;
156 catch( boost::archive::archive_exception
&ae
) {
157 cerr
<< "Archive exception: "
158 << ae
.what() << endl
;
161 catch( Usb::Error
&ue
) {
162 std::cerr
<< "Usb::Error caught: " << ue
.what() << endl
;
165 catch( Barry::Error
&se
) {
166 std::cerr
<< "Barry::Error caught: " << se
.what() << endl
;
169 catch( std::exception
&e
) {
170 std::cerr
<< "std::exception caught: " << e
.what() << endl
;