3 /// Builder class for restoring from Barry Backup files
7 Copyright (C) 2010, 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 #ifndef __BARRYBACKUP_RESTORE_H__
23 #define __BARRYBACKUP_RESTORE_H__
27 #include "configfile.h"
32 // forward declarations
42 /// Barry Backup Restore builder class. This class is suitable
43 /// to be used as a builder object anywhere a builder object is
44 /// accepted. It reads from a Barry Backup tar.gz backup file,
45 /// and builds records in a staged manner.
47 /// If a backup file contains more than one database (for example
48 /// both Address Book and Calendar), then it will build one database
49 /// first, return false on Retrieve(), and then build the next.
50 /// If Retrieve() returns false, but EndOfFile() also returns false,
51 /// then more databases are available.
53 /// The idea is that you can call Desktop::SaveDatabase() multiple
54 /// times with this same Restore object, for all the databases in
57 /// It is safe to call Retrieve() multiple times, so when first
58 /// starting a restore, call the constructor, call AddDB() with
59 /// any filters, and then call Retrieve(), which will grab the
60 /// first record, and make GetDBName() valid.
62 class BXEXPORT Restore
: public Barry::Builder
65 typedef Barry::ConfigFile::DBListType DBListType
;
70 std::auto_ptr
<reuse::TarFile
> m_tar
;
72 bool m_default_all_db
;
74 bool m_tar_record_loaded
;
77 std::string m_current_dbname
;
78 std::string m_record_data
;
79 std::string m_tar_id_text
;
82 static bool SplitTarPath(const std::string
&tarpath
,
83 std::string
&dbname
, std::string
&dbid_text
,
84 uint8_t &dbrectype
, uint32_t &dbid
);
86 bool IsSelected(const std::string
&dbName
) const;
90 explicit Restore(const std::string
&tarpath
,
91 bool default_all_db
= true);
94 /// Add database names to the read filter.
96 /// If default_all_db is true and you don't call this function,
97 /// all databases are read.
98 /// If default_all_db is false and you don't call this function,
99 /// no databases are read.
100 /// Regardless of default_all_db, if you call this function one
101 /// or more times, only the specified databases are read.
102 void AddDB(const std::string
&dbName
);
104 // Skip the current DB, in case of error, or preference
105 void SkipCurrentDB();
107 /// Loads the given file, and counts all records according
108 /// to the current read filter. Does not use the main
109 /// Restore file, but opens the file separately.
110 /// It is safe to call this function as often as needed.
111 unsigned int GetRecordTotal(const std::string
&tarpath
) const;
113 // Barry::Builder overrides
114 virtual bool Retrieve();
115 virtual std::string
GetDBName() const; // only valid after a Retrieve()
116 virtual uint8_t GetRecType() const;
117 virtual uint32_t GetUniqueId() const;
118 virtual bool EndOfFile() const { return m_end_of_tar
; }
119 virtual void BuildHeader(Barry::Data
&data
, size_t &offset
);
120 virtual void BuildFields(Barry::Data
&data
, size_t &offset
, const Barry::IConverter
*ic
);