24WithOutputFile(
bool allow_last_param,
bool allow_stdout,
26 _allow_last_param = allow_last_param;
27 _allow_stdout = allow_stdout;
28 _binary_output = binary_output;
29 _got_output_filename =
false;
30 _output_ptr =
nullptr;
31 _owns_output_ptr =
false;
39 if (_owns_output_ptr) {
41 _owns_output_ptr =
false;
51 if (_output_ptr ==
nullptr) {
52 if (!_got_output_filename) {
55 nout <<
"No output filename specified.\n";
58 _output_ptr = &std::cout;
59 _owns_output_ptr =
false;
63 unlink(_output_filename.c_str());
75 if (_binary_output || pz_file) {
81 _output_stream.clear();
82 if (!_output_filename.
open_write(_output_stream)) {
83 nout <<
"Unable to write to " << _output_filename <<
"\n";
86 nout <<
"Writing " << _output_filename <<
"\n";
87 _output_ptr = &_output_stream;
88 _owns_output_ptr =
false;
92 _output_ptr =
new OCompressStream(_output_ptr, _owns_output_ptr);
93 _owns_output_ptr =
true;
107 if (_owns_output_ptr) {
109 _owns_output_ptr =
false;
111 _output_ptr =
nullptr;
112 _output_stream.close();
123 return _got_output_filename;
132 if (_got_output_filename) {
133 return _output_filename;
149 if (_allow_last_param && !_got_output_filename &&
150 (
int)args.size() > minimum_args) {
151 Filename filename = Filename::from_os_specific(args.back());
153 if (!_preferred_extension.empty() &&
156 if (!_allow_stdout) {
157 nout <<
"Output filename " << filename
158 <<
" does not end in " << _preferred_extension
159 <<
". If this is really what you intended, "
160 "use the -o output_file syntax.\n";
166 _got_output_filename =
true;
167 _output_filename = filename;
170 if (!verify_output_file_safe()) {
189verify_output_file_safe()
const {
190 nassertr(_got_output_filename,
false);
192 if (_output_filename.
exists()) {
193 nout <<
"The output filename " << _output_filename <<
" already exists. "
194 "If you wish to overwrite it, you must use the -o option to specify "
195 "the output filename, instead of simply specifying it as the last "
The name of a file, such as a texture file or an Egg file.
void set_binary()
Indicates that the filename represents a binary file.
bool make_dir() const
Creates all the directories in the path to the file specified in the filename, except for the basenam...
void set_text()
Indicates that the filename represents a text file.
bool open_write(std::ofstream &stream, bool truncate=true) const
Opens the indicated ifstream for writing the file, if possible.
std::string get_extension() const
Returns the file extension.
bool exists() const
Returns true if the filename exists on the physical disk, false otherwise.
Filename get_output_filename() const
If has_output_filename() returns true, this is the filename that the user specified.
void close_output()
Closes the output stream previously opened by get_output().
bool has_output_filename() const
Returns true if the user specified an output filename, false otherwise (e.g.
std::ostream & get_output()
Returns an output stream that corresponds to the user's intended egg file output–either stdout,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.