00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
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
00061 bool skip(const infinint &pos);
00062 bool skip_to_eof();
00063 bool skip_relative(S_I x);
00064 infinint get_position();
00065
00066
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
00073 void set_info_status(const std::string & s) { status = s; };
00074 std::string get_info_status() const { return status; };
00075
00076
00077 void disable_natural_destruction() { natural_destruction = false; };
00078
00079
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(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
00099
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
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(char *fic, const infinint &num);
00121 void open_writeonly(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
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);
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(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 }
00157
00158 #endif