![]() |
Disk ARchive
2.5.2
Full featured and portable backup and archiving tool
|
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 : http://dar.linux.free.fr/email.html 00020 /*********************************************************************/ 00021 00033 00035 // IMPORTANT : THIS FILE MUST ALWAYS BE INCLUDE AFTER infinint.hpp // 00036 // (and infinint.hpp must be included too, always) // 00038 #include "infinint.hpp" 00040 00041 00042 00043 #ifndef USER_INTERACTION_HPP 00044 #define USER_INTERACTION_HPP 00045 00046 #include "../my_config.h" 00047 00048 #include <string> 00049 #include "erreurs.hpp" 00050 #include "integers.hpp" 00051 #include "secu_string.hpp" 00052 #include "on_pool.hpp" 00053 00054 namespace libdar 00055 { 00056 00059 00060 00061 00063 00098 class user_interaction : public on_pool 00099 { 00100 public: 00101 00103 user_interaction(); 00104 virtual ~user_interaction() {}; 00105 00107 00111 virtual void pause(const std::string & message) 00112 { 00113 if(!pause2(message)) 00114 throw Euser_abort(message); 00115 }; 00116 00118 00125 virtual bool pause2(const std::string & message) 00126 { throw Elibcall("user_interaction::pause2", "user_interaction::pause() or pause2() must be overwritten !"); }; 00127 00128 00134 void warning(const std::string & message); 00135 00137 00141 virtual std::string get_string(const std::string & message, bool echo) = 0; 00142 00144 00148 virtual secu_string get_secu_string(const std::string & message, bool echo) = 0; 00149 00150 00157 00169 virtual void listing(const std::string & flag, 00170 const std::string & perm, 00171 const std::string & uid, 00172 const std::string & gid, 00173 const std::string & size, 00174 const std::string & date, 00175 const std::string & filename, 00176 bool is_dir, 00177 bool has_children); 00178 00179 00180 00187 00192 virtual void dar_manager_show_files(const std::string & filename, 00193 bool data_change, 00194 bool ea_change); 00195 00196 00203 00208 virtual void dar_manager_contents(U_I number, 00209 const std::string & chemin, 00210 const std::string & archive_name); 00211 00218 00225 virtual void dar_manager_statistics(U_I number, 00226 const infinint & data_count, 00227 const infinint & total_data, 00228 const infinint & ea_count, 00229 const infinint & total_ea); 00230 00237 00244 virtual void dar_manager_show_version(U_I number, 00245 const std::string & data_date, 00246 const std::string & data_presence, 00247 const std::string & ea_date, 00248 const std::string & ea_presence); 00249 00251 00259 void printf(const char *format, ...); 00260 00264 00266 bool get_use_listing() const { return use_listing; }; 00268 bool get_use_dar_manager_show_files() const { return use_dar_manager_show_files; }; 00270 bool get_use_dar_manager_contents() const { return use_dar_manager_contents; }; 00272 bool get_use_dar_manager_statistics() const { return use_dar_manager_statistics; }; 00274 bool get_use_dar_manager_show_version() const { return use_dar_manager_show_version; }; 00275 00276 00278 00284 virtual user_interaction *clone() const = 0; 00285 00287 00292 void warning_with_more(U_I num) { at_once = num; count = 0; }; 00293 00294 protected: 00295 00297 00302 void set_use_listing(bool val) { use_listing = val; }; 00303 00305 void set_use_dar_manager_show_files(bool val) { use_dar_manager_show_files = val; }; 00306 00308 void set_use_dar_manager_contents(bool val) { use_dar_manager_contents = val; }; 00309 00311 void set_use_dar_manager_statistics(bool val) { use_dar_manager_statistics = val; }; 00312 00314 void set_use_dar_manager_show_version(bool val) { use_dar_manager_show_version = val; }; 00315 00317 00320 virtual void inherited_warning(const std::string & message) = 0; 00321 00322 private: 00323 bool use_listing; 00324 bool use_dar_manager_show_files; 00325 bool use_dar_manager_contents; 00326 bool use_dar_manager_statistics; 00327 bool use_dar_manager_show_version; 00328 U_I at_once, count; 00329 00330 }; 00331 00332 00334 00338 class user_interaction_callback : public user_interaction 00339 { 00340 public: 00341 00343 00354 user_interaction_callback(void (*x_warning_callback)(const std::string &x, void *context), 00355 bool (*x_answer_callback)(const std::string &x, void *context), 00356 std::string (*x_string_callback)(const std::string &x, bool echo, void *context), 00357 secu_string (*x_secu_string_callback)(const std::string &x, bool echo, void *context), 00358 void *context_value); 00359 00361 void pause(const std::string & message); 00363 std::string get_string(const std::string & message, bool echo); 00365 secu_string get_secu_string(const std::string & message, bool echo); 00367 void listing(const std::string & flag, 00368 const std::string & perm, 00369 const std::string & uid, 00370 const std::string & gid, 00371 const std::string & size, 00372 const std::string & date, 00373 const std::string & filename, 00374 bool is_dir, 00375 bool has_children); 00376 00378 void dar_manager_show_files(const std::string & filename, 00379 bool available_data, 00380 bool available_ea); 00381 00383 void dar_manager_contents(U_I number, 00384 const std::string & chemin, 00385 const std::string & archive_name); 00386 00388 void dar_manager_statistics(U_I number, 00389 const infinint & data_count, 00390 const infinint & total_data, 00391 const infinint & ea_count, 00392 const infinint & total_ea); 00393 00395 void dar_manager_show_version(U_I number, 00396 const std::string & data_date, 00397 const std::string & data_presence, 00398 const std::string & ea_date, 00399 const std::string & ea_presence); 00400 00402 00406 void set_listing_callback(void (*callback)(const std::string & flag, 00407 const std::string & perm, 00408 const std::string & uid, 00409 const std::string & gid, 00410 const std::string & size, 00411 const std::string & date, 00412 const std::string & filename, 00413 bool is_dir, 00414 bool has_children, 00415 void *context)) 00416 { 00417 tar_listing_callback = callback; 00418 set_use_listing(true); // this is to inform libdar to use listing() 00419 }; 00420 00421 // You can set a dar_manager_show_files callback thanks to this method 00422 00423 void set_dar_manager_show_files_callback(void (*callback)(const std::string & filename, 00424 bool available_data, 00425 bool available_ea, 00426 void *context)) 00427 { 00428 dar_manager_show_files_callback = callback; 00429 set_use_dar_manager_show_files(true); // this is to inform libdar to use the dar_manager_show_files() method 00430 }; 00431 00432 void set_dar_manager_contents_callback(void (*callback)(U_I number, 00433 const std::string & chemin, 00434 const std::string & archive_name, 00435 void *context)) 00436 { 00437 dar_manager_contents_callback = callback; 00438 set_use_dar_manager_contents(true); // this is to inform libdar to use the dar_manager_contents() method 00439 }; 00440 00441 void set_dar_manager_statistics_callback(void (*callback)(U_I number, 00442 const infinint & data_count, 00443 const infinint & total_data, 00444 const infinint & ea_count, 00445 const infinint & total_ea, 00446 void *context)) 00447 { 00448 dar_manager_statistics_callback = callback; 00449 set_use_dar_manager_statistics(true); // this is to inform libdar to use the dar_manager_statistics() method 00450 }; 00451 00452 void set_dar_manager_show_version_callback(void (*callback)(U_I number, 00453 const std::string & data_date, 00454 const std::string & data_presence, 00455 const std::string & ea_date, 00456 const std::string & ea_presence, 00457 void *context)) 00458 { 00459 dar_manager_show_version_callback = callback; 00460 set_use_dar_manager_show_version(true); // this is to inform libdar to use the dar_manager_show_version() method 00461 }; 00462 00463 00465 virtual user_interaction *clone() const; 00466 00467 protected: 00469 void change_context_value(void *new_value) { context_val = new_value; }; 00470 00472 void inherited_warning(const std::string & message); 00473 00474 private: 00475 void (*warning_callback)(const std::string & x, void *context); // pointer to function 00476 bool (*answer_callback)(const std::string & x, void *context); // pointer to function 00477 std::string (*string_callback)(const std::string & x, bool echo, void *context); // pointer to function 00478 secu_string (*secu_string_callback)(const std::string & x, bool echo, void *context); // pointer to function 00479 void (*tar_listing_callback)(const std::string & flags, 00480 const std::string & perm, 00481 const std::string & uid, 00482 const std::string & gid, 00483 const std::string & size, 00484 const std::string & date, 00485 const std::string & filename, 00486 bool is_dir, 00487 bool has_children, 00488 void *context); 00489 void (*dar_manager_show_files_callback)(const std::string & filename, 00490 bool available_data, 00491 bool available_ea, 00492 void *context); 00493 void (*dar_manager_contents_callback)(U_I number, 00494 const std::string & chemin, 00495 const std::string & archive_name, 00496 void *context); 00497 void (*dar_manager_statistics_callback)(U_I number, 00498 const infinint & data_count, 00499 const infinint & total_data, 00500 const infinint & ea_count, 00501 const infinint & total_ea, 00502 void *context); 00503 void (*dar_manager_show_version_callback)(U_I number, 00504 const std::string & data_date, 00505 const std::string & data_presence, 00506 const std::string & ea_date, 00507 const std::string & ea_presence, 00508 void *context); 00509 00510 void *context_val; 00511 }; 00512 00513 00515 00516 class user_interaction_blind : public user_interaction 00517 { 00518 public: 00519 bool pause2(const std::string & message) { return false; }; 00520 00521 std::string get_string(const std::string & message, bool echo) { return "user_interaction_blind, is blindly answering no"; }; 00522 secu_string get_secu_string(const std::string & message, bool echo) { return secu_string(); }; 00523 00524 user_interaction *clone() const { user_interaction *ret = new (get_pool()) user_interaction_blind(); if(ret == nullptr) throw Ememory("user_interaction_blind::clone"); return ret; }; 00525 00526 protected: 00527 void inherited_warning(const std::string & message) {}; // do not display any warning, this is "bind user_interaction" ! 00528 00529 }; 00530 00532 00533 } // end of namespace 00534 00535 #endif