1999-01-12 18:10:02 -05:00
|
|
|
% automatically generated by HelpGen from tempfile.tex at 10/Jan/99 19:24:44
|
|
|
|
\section{\class{wxTempFile}}\label{wxtempfile}
|
|
|
|
|
|
|
|
wxTempFile provides a relatively safe way to replace the contents of the
|
|
|
|
existing file. The name is explained by the fact that it may be also used as
|
|
|
|
just a temporary file if you don't replace the old file contents.
|
|
|
|
|
|
|
|
Usually, when a program replaces the contents of some file it first opens it for
|
|
|
|
writing, thus losing all of the old data and then starts recreating it. This
|
|
|
|
approach is not very safe because during the regeneration of the file bad things
|
|
|
|
may happen: the program may find that there is an internal error preventing it
|
|
|
|
from completing file generation, the user may interrupt it (especially if file
|
|
|
|
generation takes long time) and, finally, any other external interrupts (power
|
|
|
|
supply failure or a disk error) will leave you without either the original file
|
|
|
|
or the new one.
|
|
|
|
|
|
|
|
wxTempFile addresses this problem by creating a temporary file which is meant to
|
|
|
|
replace the original file - but only after it is fully written. So, if the user
|
|
|
|
interrupts the program during the file generation, the old file won't be lost.
|
|
|
|
Also, if the program discovers itself that it doesn't want to replace the old
|
|
|
|
file there is no problem - in fact, wxTempFile will {\bf not} replace the old
|
|
|
|
file by default, you should explicitly call \helpref{Commit}{wxtempfilecommit}
|
|
|
|
to do it. Calling \helpref{Discard}{wxtempfilediscard} explicitly discards any
|
|
|
|
modifications: it closes and deletes the temporary file and leaves the original
|
|
|
|
file unchanged. If you don't call neither of Commit() and Discard(), the
|
|
|
|
destructor will call Discard() automatically.
|
|
|
|
|
|
|
|
To summarize: if you want to replace another file, create an instance of
|
|
|
|
wxTempFile passing the name of the file to be replaced to the constructor (you
|
|
|
|
may also use default constructor and pass the file name to
|
|
|
|
\helpref{Open}{wxtempfileopen}). Then you can \helpref{write}{wxtempfilewrite}
|
|
|
|
to wxTempFile using \helpref{wxFile}{wxfile}-like functions and later call
|
|
|
|
Commit() to replace the old file (and close this one) or call Discard() to cancel
|
|
|
|
the modifications.
|
|
|
|
|
|
|
|
\wxheading{Derived from}
|
|
|
|
|
|
|
|
No base class
|
|
|
|
|
1999-02-15 15:41:29 -05:00
|
|
|
\wxheading{Include files}
|
|
|
|
|
|
|
|
<wx/file.h>
|
|
|
|
|
1999-01-12 18:10:02 -05:00
|
|
|
\wxheading{See also:}
|
|
|
|
|
|
|
|
\helpref{wxFile}{wxfile}
|
|
|
|
|
|
|
|
\latexignore{\rtfignore{\wxheading{Members}}}
|
|
|
|
|
|
|
|
\membersection{wxTempFile::wxTempFile}\label{wxtempfilewxtempfilector}
|
2000-03-17 12:59:56 -05:00
|
|
|
|
1999-01-12 18:10:02 -05:00
|
|
|
\func{}{wxTempFile}{\void}
|
|
|
|
|
|
|
|
Default constructor - \helpref{Open}{wxtempfileopen} must be used to open the
|
|
|
|
file.
|
|
|
|
|
|
|
|
\membersection{wxTempFile::wxTempFile}\label{wxtempfilewxtempfile}
|
2000-03-17 12:59:56 -05:00
|
|
|
|
1999-01-12 18:10:02 -05:00
|
|
|
\func{}{wxTempFile}{\param{const wxString\& }{strName}}
|
|
|
|
|
2000-03-17 12:59:56 -05:00
|
|
|
Associates wxTempFile with the file to be replaced and opens it. You should use
|
1999-01-12 18:10:02 -05:00
|
|
|
\helpref{IsOpened}{wxtempfileisopened} to verify if the constructor succeeded.
|
|
|
|
|
|
|
|
\membersection{wxTempFile::Open}\label{wxtempfileopen}
|
2000-03-17 12:59:56 -05:00
|
|
|
|
1999-01-12 18:10:02 -05:00
|
|
|
\func{bool}{Open}{\param{const wxString\& }{strName}}
|
|
|
|
|
2003-01-17 19:16:34 -05:00
|
|
|
Open the temporary file, returns {\tt true} on success, {\tt false} if an error
|
2002-01-04 08:06:28 -05:00
|
|
|
occurred.
|
|
|
|
|
|
|
|
{\it strName} is the name of file to be replaced. The temporary file is always
|
|
|
|
created in the directory where {\it strName} is. In particular, if
|
|
|
|
{\it strName} doesn't include the path, it is created in the current directory
|
|
|
|
and the program should have write access to it for the function to succeed.
|
1999-01-12 18:10:02 -05:00
|
|
|
|
|
|
|
\membersection{wxTempFile::IsOpened}\label{wxtempfileisopened}
|
2002-01-04 08:06:28 -05:00
|
|
|
|
1999-01-12 18:10:02 -05:00
|
|
|
\constfunc{bool}{IsOpened}{\void}
|
|
|
|
|
2003-01-17 19:16:34 -05:00
|
|
|
Returns {\tt true} if the file was successfully opened.
|
1999-01-12 18:10:02 -05:00
|
|
|
|
|
|
|
\membersection{wxTempFile::Write}\label{wxtempfilewrite}
|
2000-03-17 12:59:56 -05:00
|
|
|
|
1999-01-12 18:10:02 -05:00
|
|
|
\func{bool}{Write}{\param{const void }{*p}, \param{size\_t }{n}}
|
|
|
|
|
2003-01-17 19:16:34 -05:00
|
|
|
Write to the file, return {\tt true} on success, {\tt false} on failure.
|
1999-01-12 18:10:02 -05:00
|
|
|
|
|
|
|
\membersection{wxTempFile::Write}\label{wxtempfilewrites}
|
2000-03-17 12:59:56 -05:00
|
|
|
|
2002-05-05 10:24:07 -04:00
|
|
|
\func{bool}{Write}{\param{const wxString\& }{str}, \param{wxMBConv\&}{ conv = wxConvLibc}}
|
1999-01-12 18:10:02 -05:00
|
|
|
|
2003-01-17 19:16:34 -05:00
|
|
|
Write to the file, return {\tt true} on success, {\tt false} on failure.
|
1999-01-12 18:10:02 -05:00
|
|
|
|
2001-08-08 19:18:24 -04:00
|
|
|
The second argument is only meaningful in Unicode build of wxWindows when
|
2001-08-06 18:40:09 -04:00
|
|
|
{\it conv} is used to convert {\it str} to multibyte representation.
|
|
|
|
|
1999-01-12 18:10:02 -05:00
|
|
|
\membersection{wxTempFile::Commit}\label{wxtempfilecommit}
|
2000-03-17 12:59:56 -05:00
|
|
|
|
1999-01-12 18:10:02 -05:00
|
|
|
\func{bool}{Commit}{\void}
|
|
|
|
|
|
|
|
Validate changes: deletes the old file of name m\_strName and renames the new
|
2003-01-17 19:16:34 -05:00
|
|
|
file to the old name. Returns {\tt true} if both actions succeeded. If {\tt false} is
|
1999-01-12 18:10:02 -05:00
|
|
|
returned it may unfortunately mean two quite different things: either that
|
|
|
|
either the old file couldn't be deleted or that the new file couldn't be renamed
|
|
|
|
to the old name.
|
|
|
|
|
|
|
|
\membersection{wxTempFile::Discard}\label{wxtempfilediscard}
|
2000-03-17 12:59:56 -05:00
|
|
|
|
1999-01-12 18:10:02 -05:00
|
|
|
\func{void}{Discard}{\void}
|
|
|
|
|
|
|
|
Discard changes: the old file contents is not changed, temporary file is
|
|
|
|
deleted.
|
|
|
|
|
|
|
|
\membersection{wxTempFile::\destruct{wxTempFile}}\label{wxtempfiledtor}
|
2000-03-17 12:59:56 -05:00
|
|
|
|
1999-01-12 18:10:02 -05:00
|
|
|
\func{}{\destruct{wxTempFile}}{\void}
|
|
|
|
|
|
|
|
Destructor calls \helpref{Discard()}{wxtempfilediscard} if temporary file
|
|
|
|
is still opened.
|
|
|
|
|