15 #include "withOutputFile.h"
16 #include "executionEnvironment.h"
27 WithOutputFile(
bool allow_last_param,
bool allow_stdout,
29 _allow_last_param = allow_last_param;
30 _allow_stdout = allow_stdout;
31 _binary_output = binary_output;
32 _got_output_filename =
false;
33 _output_ptr = (ostream *)NULL;
34 _owns_output_ptr =
false;
44 if (_owns_output_ptr) {
46 _owns_output_ptr =
false;
59 if (_output_ptr == (ostream *)NULL) {
60 if (!_got_output_filename) {
63 nout <<
"No output filename specified.\n";
67 _owns_output_ptr =
false;
71 unlink(_output_filename.c_str());
83 if (_binary_output || pz_file) {
89 _output_stream.clear();
90 if (!_output_filename.
open_write(_output_stream)) {
91 nout <<
"Unable to write to " << _output_filename <<
"\n";
94 nout <<
"Writing " << _output_filename <<
"\n";
95 _output_ptr = &_output_stream;
96 _owns_output_ptr =
false;
100 _output_ptr =
new OCompressStream(_output_ptr, _owns_output_ptr);
101 _owns_output_ptr =
true;
118 if (_owns_output_ptr) {
120 _owns_output_ptr =
false;
123 _output_stream.close();
137 return _got_output_filename;
149 if (_got_output_filename) {
150 return _output_filename;
168 bool WithOutputFile::
170 if (_allow_last_param && !_got_output_filename &&
171 (
int)args.size() > minimum_args) {
174 if (!_preferred_extension.empty() &&
177 if (!_allow_stdout) {
178 nout <<
"Output filename " << filename
179 <<
" does not end in " << _preferred_extension
180 <<
". If this is really what you intended, "
181 "use the -o output_file syntax.\n";
187 _got_output_filename =
true;
188 _output_filename = filename;
191 if (!verify_output_file_safe()) {
214 bool WithOutputFile::
215 verify_output_file_safe()
const {
216 nassertr(_got_output_filename,
false);
218 if (_output_filename.
exists()) {
219 nout <<
"The output filename " << _output_filename <<
" already exists. "
220 "If you wish to overwrite it, you must use the -o option to specify "
221 "the output filename, instead of simply specifying it as the last "
bool make_dir() const
Creates all the directories in the path to the file specified in the filename, except for the basenam...
void set_binary()
Indicates that the filename represents a binary file.
void set_text()
Indicates that the filename represents a text file.
void close_output()
Closes the output stream previously opened by get_output().
Filename get_output_filename() const
If has_output_filename() returns true, this is the filename that the user specified.
bool has_output_filename() const
Returns true if the user specified an output filename, false otherwise (e.g.
The name of a file, such as a texture file or an Egg file.
bool exists() const
Returns true if the filename exists on the disk, false otherwise.
ostream & get_output()
Returns an output stream that corresponds to the user's intended egg file output–either stdout...
bool open_write(ofstream &stream, bool truncate=true) const
Opens the indicated ifstream for writing the file, if possible.
string get_extension() const
Returns the file extension.
static Filename from_os_specific(const string &os_specific, Type type=T_general)
This named constructor returns a Panda-style filename (that is, using forward slashes, and no drive letter) based on the supplied filename string that describes a filename in the local system conventions (for instance, on Windows, it may use backslashes or begin with a drive letter and a colon).