bs11nread.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #define __BARRY_BOOST_MODE__ // this program always requires BOOST
00023 #include <barry/barry.h>
00024 #include <iomanip>
00025 #include <iostream>
00026 #include <fstream>
00027 #include <sstream>
00028 #include <vector>
00029 #include <string>
00030 #include <algorithm>
00031 #include <getopt.h>
00032 #include "i18n.h"
00033
00034
00035 using namespace std;
00036 using namespace Barry;
00037
00038 void Usage()
00039 {
00040 int major, minor;
00041 const char *Version = Barry::Version(major, minor);
00042
00043 cerr
00044 << "bs11nread - Reads a boost serialization file (from btool)\n"
00045 << " and dumps data to stdout\n"
00046 << " Copyright 2008-2010, Net Direct Inc. (http://www.netdirect.ca/)\n"
00047 << " Using: " << Version << "\n"
00048 << "\n"
00049 << " -f file Filename to save or load handheld data to/from\n"
00050 << " -h This help\n"
00051 << " -S Show list of supported database parsers\n"
00052 << endl;
00053 }
00054
00055 template <class Record>
00056 bool Dump(const std::string &dbName, ifstream &ifs)
00057 {
00058 if( dbName != Record::GetDBName() )
00059 return false;
00060
00061 std::vector<Record> records;
00062 boost::archive::text_iarchive ia(ifs);
00063 ia >> records;
00064 cout << records.size()
00065 << " records loaded" << endl;
00066 sort(records.begin(), records.end());
00067
00068 typename std::vector<Record>::const_iterator
00069 beg = records.begin(), end = records.end();
00070 for( ; beg != end; beg++ ) {
00071 cout << (*beg) << endl;
00072 }
00073
00074 return true;
00075 }
00076
00077 void DumpDB(const string &filename)
00078 {
00079
00080 ifstream ifs(filename.c_str());
00081 std::string dbName;
00082 getline(ifs, dbName);
00083
00084
00085 Dump<Contact> (dbName, ifs) ||
00086 Dump<Message> (dbName, ifs) ||
00087 Dump<Calendar> (dbName, ifs) ||
00088 Dump<ServiceBook> (dbName, ifs) ||
00089 Dump<Memo> (dbName, ifs) ||
00090 Dump<Task> (dbName, ifs) ||
00091 Dump<PINMessage> (dbName, ifs) ||
00092 Dump<SavedMessage> (dbName, ifs) ||
00093 Dump<Folder> (dbName, ifs) ||
00094 Dump<Timezone> (dbName, ifs) ||
00095 cerr << "Unknown database name: " << dbName << endl;
00096 }
00097
00098 void ShowParsers()
00099 {
00100 cout << "Supported Database parsers:\n"
00101 << " Address Book\n"
00102 << " Messages\n"
00103 << " Calendar\n"
00104 << " Service Book\n"
00105 << " Memos\n"
00106 << " Tasks\n"
00107 << " PIN Messages\n"
00108 << " Saved Email Messages\n"
00109 << " Folders\n"
00110 << " Time Zones\n"
00111 << endl;
00112 }
00113
00114 int main(int argc, char *argv[])
00115 {
00116 INIT_I18N(PACKAGE);
00117
00118 try {
00119 string filename;
00120
00121
00122 for(;;) {
00123 int cmd = getopt(argc, argv, "f:hS");
00124 if( cmd == -1 )
00125 break;
00126
00127 switch( cmd )
00128 {
00129 case 'f':
00130 filename = optarg;
00131 break;
00132
00133 case 'S':
00134 ShowParsers();
00135 return 0;
00136
00137 case 'h':
00138 default:
00139 Usage();
00140 return 0;
00141 }
00142 }
00143
00144
00145
00146 Barry::Init();
00147
00148 if( !filename.size() ) {
00149 cerr << "Filename must be specified" << endl;
00150 return 1;
00151 }
00152
00153 DumpDB(filename);
00154
00155 }
00156 catch( boost::archive::archive_exception &ae ) {
00157 cerr << "Archive exception: "
00158 << ae.what() << endl;
00159 return 1;
00160 }
00161 catch( Usb::Error &ue) {
00162 std::cerr << "Usb::Error caught: " << ue.what() << endl;
00163 return 1;
00164 }
00165 catch( Barry::Error &se ) {
00166 std::cerr << "Barry::Error caught: " << se.what() << endl;
00167 return 1;
00168 }
00169 catch( std::exception &e ) {
00170 std::cerr << "std::exception caught: " << e.what() << endl;
00171 return 1;
00172 }
00173
00174 return 0;
00175 }
00176