mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-02 09:52:27 -04:00
prompt user on error
This commit is contained in:
parent
df79a1d629
commit
17e060966e
@ -32,6 +32,7 @@ CVSCopy() {
|
||||
_model_dirname = ".";
|
||||
_key_filename = "Sources.pp";
|
||||
_cvs_binary = "cvs";
|
||||
_user_aborted = false;
|
||||
_model_dir = (CVSSourceDirectory *)NULL;
|
||||
_map_dir = (CVSSourceDirectory *)NULL;
|
||||
|
||||
@ -146,16 +147,52 @@ import(const Filename &source, void *extra_data,
|
||||
nout << "Copying " << basename << " to " << dir->get_path() << "\n";
|
||||
|
||||
if (!copy_file(source, dest, dir, extra_data, new_file)) {
|
||||
return (CVSSourceDirectory *)NULL;
|
||||
}
|
||||
if (new_file) {
|
||||
cvs_add(dest);
|
||||
if (!continue_after_error()) {
|
||||
return (CVSSourceDirectory *)NULL;
|
||||
}
|
||||
} else {
|
||||
if (new_file) {
|
||||
cvs_add(dest);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return dir;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CVSCopy::continue_after_error
|
||||
// Access: Public
|
||||
// Description: Prompts the user (unless -f was specified) if he
|
||||
// wants to continue the copy operation after some error
|
||||
// has occurred. Returns true to continue, false
|
||||
// otherwise.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool CVSCopy::
|
||||
continue_after_error() {
|
||||
if (_force) {
|
||||
return true;
|
||||
}
|
||||
if (_user_aborted) {
|
||||
return false;
|
||||
}
|
||||
|
||||
while (true) {
|
||||
string result = prompt("Error occurred during copy! Continue (y/n)? ");
|
||||
nassertr(!result.empty(), false);
|
||||
if (result.size() == 1) {
|
||||
if (tolower(result[0]) == 'y') {
|
||||
return true;
|
||||
} else if (tolower(result[0]) == 'n') {
|
||||
_user_aborted = true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
nout << "*** Invalid response: " << result << "\n\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CVSCopy::handle_args
|
||||
@ -467,3 +504,35 @@ scan_for_root(const string &dirname) {
|
||||
|
||||
return scan_for_root(dirname + "/..");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CVSCopy::prompt
|
||||
// Access: Private
|
||||
// Description: Issues a prompt to the user and waits for a typed
|
||||
// response. Returns the response (which will not be
|
||||
// empty).
|
||||
////////////////////////////////////////////////////////////////////
|
||||
string CVSCopy::
|
||||
prompt(const string &message) {
|
||||
nout << flush;
|
||||
while (true) {
|
||||
cerr << message << flush;
|
||||
string response;
|
||||
getline(cin, response);
|
||||
|
||||
// Remove leading and trailing whitespace.
|
||||
size_t p = 0;
|
||||
while (p < response.length() && isspace(response[p])) {
|
||||
p++;
|
||||
}
|
||||
|
||||
size_t q = response.length();
|
||||
while (q > p && isspace(response[q - 1])) {
|
||||
q--;
|
||||
}
|
||||
|
||||
if (q > p) {
|
||||
return response.substr(p, q - p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,12 +19,12 @@
|
||||
#ifndef CVSCOPY_H
|
||||
#define CVSCOPY_H
|
||||
|
||||
#include <pandatoolbase.h>
|
||||
#include "pandatoolbase.h"
|
||||
|
||||
#include "cvsSourceTree.h"
|
||||
|
||||
#include <programBase.h>
|
||||
#include <filename.h>
|
||||
#include "programBase.h"
|
||||
#include "filename.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : CVSCopy
|
||||
@ -41,6 +41,8 @@ public:
|
||||
import(const Filename &source, void *extra_data,
|
||||
CVSSourceDirectory *suggested_dir);
|
||||
|
||||
bool continue_after_error();
|
||||
|
||||
protected:
|
||||
virtual bool handle_args(Args &args);
|
||||
virtual bool post_command_line();
|
||||
@ -63,6 +65,7 @@ protected:
|
||||
private:
|
||||
bool scan_hierarchy();
|
||||
bool scan_for_root(const string &dirname);
|
||||
string prompt(const string &message);
|
||||
|
||||
protected:
|
||||
bool _force;
|
||||
@ -76,6 +79,7 @@ protected:
|
||||
Filename _key_filename;
|
||||
bool _no_cvs;
|
||||
string _cvs_binary;
|
||||
bool _user_aborted;
|
||||
|
||||
typedef vector_string SourceFiles;
|
||||
SourceFiles _source_files;
|
||||
|
Loading…
x
Reference in New Issue
Block a user