Disk ARchive  2.3.11
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Defines
sar.hpp
00001 /*********************************************************************/
00002 // dar - disk archive - a backup/restoration program
00003 // Copyright (C) 2002-2052 Denis Corbin
00004 //
00005 // This program is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU General Public License
00007 // as published by the Free Software Foundation; either version 2
00008 // of the License, or (at your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 //
00019 // to contact the author : dar.linux@free.fr
00020 /*********************************************************************/
00021 // $Id: sar.hpp,v 1.16.2.2 2009/04/07 08:45:29 edrusb Rel $
00022 //
00023 /*********************************************************************/
00024 
00025 #ifndef SAR_HPP
00026 #define SAR_HPP
00027 
00028 #include "../my_config.h"
00029 
00030 #include <string>
00031 #include "infinint.hpp"
00032 #include "generic_file.hpp"
00033 #include "header.hpp"
00034 #include "path.hpp"
00035 #include "integers.hpp"
00036 
00037 namespace libdar
00038 {
00039         // contextual is defined in generic_file module
00040     class sar : public contextual
00041     {
00042     public:
00043         sar(user_interaction & dialog,
00044             const std::string & base_name,
00045             const std::string & extension,
00046             const path & dir,
00047             const std::string & execute = "");
00048         sar(user_interaction  & dialog,
00049             const std::string & base_name,
00050             const std::string & extension,
00051             const infinint & file_size,
00052             const infinint & first_file_size,
00053             bool x_warn_overwirte,
00054             bool x_allow_overwrite,
00055             const infinint & pause,
00056             const path & dir,
00057             const std::string & execute = "");
00058         ~sar();
00059 
00060             // inherited from generic_file
00061         bool skip(const infinint &pos);
00062         bool skip_to_eof();
00063         bool skip_relative(S_I x);
00064         infinint get_position();
00065 
00066             // informational routines
00067         infinint get_sub_file_size() const { return size; };
00068         infinint get_first_sub_file_size() const { return first_size; };
00069         bool get_total_file_number(infinint &num) const { num = of_last_file_num; return of_last_file_known; };
00070         bool get_last_file_size(infinint &num) const { num = of_last_file_size; return of_last_file_known; };
00071 
00072             // inherited methods from contextual
00073         void set_info_status(const std::string & s) { status = s; };
00074         std::string get_info_status() const { return status; };
00075 
00076             // disable execution of user command when destroying the current object
00077         void disable_natural_destruction() { natural_destruction = false; };
00078 
00079             // enable back execution of user command when destroying the current object
00080         void enable_natural_destruction() { natural_destruction = true; };
00081 
00082     protected :
00083         S_I inherited_read(char *a, size_t sz);
00084         S_I inherited_write(const char *a, size_t sz);
00085 
00086     private :
00087         path archive_dir;
00088         std::string base, ext;
00089         std::string hook;
00090         infinint size;
00091         infinint first_size;
00092         infinint first_file_offset;
00093         infinint file_offset;
00094         std::string status;
00095 
00096         bool natural_destruction;
00097 
00098             // these following variables are modified by open_file
00099             // else the are used only for reading
00100         infinint of_current;
00101         infinint of_max_seen;
00102         bool of_last_file_known;
00103         infinint of_last_file_num;
00104         infinint of_last_file_size;
00105         label of_internal_name;
00106         fichier *of_fd;
00107         char of_flag;
00108         bool initial;
00109 
00110             // these are the option flags
00111         bool opt_warn_overwrite;
00112         bool opt_allow_overwrite;
00113 
00114             //
00115         infinint pause;
00116 
00117         bool skip_forward(U_I x);
00118         bool skip_backward(U_I x);
00119         void close_file();
00120         void open_readonly(const char *fic, const infinint &num);
00121         void open_writeonly(const char *fic, const infinint &num);
00122         void open_file_init();
00123         void open_file(infinint num);
00124         void set_offset(infinint offset);
00125         void open_last_file();
00126         header make_write_header(const infinint &num, char flag);
00127 
00128             // hook to attach a command to execute after each slice
00129         std::string hook_substitute(const std::string & path, const std::string & basename, const std::string & num, const std::string & ext, const std::string & context);
00130         void hook_execute(const infinint &num);
00131     };
00132 
00133 
00134     class trivial_sar : public generic_file
00135     {
00136     public:
00137         trivial_sar(user_interaction & dialog, generic_file *ref); // trivial_sar own the argument
00138         ~trivial_sar() { if(reference != NULL) delete reference; };
00139 
00140         bool skip(const infinint & pos) { return reference->skip(pos + offset); };
00141         bool skip_to_eof() { return reference->skip_to_eof(); };
00142         bool skip_relative(S_I x);
00143         infinint get_position();
00144 
00145     protected:
00146         S_I inherited_read(char *a, size_t size) { return reference->read(a, size); };
00147         S_I inherited_write(const char *a, size_t size) { return reference->write(a, size); };
00148 
00149     private:
00150         generic_file *reference;
00151         infinint offset;
00152     };
00153 
00154     extern std::string sar_make_filename(std::string base_name, infinint num, std::string ext);
00155 
00156 } // end of namespace
00157 
00158 #endif
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Defines