1998-12-09 01:43:57 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
1998-12-09 01:43:57 +03:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
1998-12-09 01:43:57 +03:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1998-12-09 01:43:57 +03:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 06:43:54 +03:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1998-12-09 01:43:57 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
// First checked in on 98/12/08 by John R. McMullen.
|
|
|
|
// Since nsFileStream.h is entirely templates, common code (such as open())
|
1998-12-16 01:45:09 +03:00
|
|
|
// which does not actually depend on the charT, can be placed here.
|
|
|
|
|
1998-12-09 01:43:57 +03:00
|
|
|
#include "nsFileStream.h"
|
1999-05-26 05:38:36 +04:00
|
|
|
#include "nsFileSpec.h"
|
1999-06-15 02:04:27 +04:00
|
|
|
#include "nsIFileSpec.h"
|
1999-03-06 01:53:56 +03:00
|
|
|
#include "nsIStringStream.h"
|
1999-02-25 23:49:47 +03:00
|
|
|
|
1998-12-19 02:06:54 +03:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
1998-12-09 01:43:57 +03:00
|
|
|
|
1998-12-19 02:06:54 +03:00
|
|
|
//========================================================================================
|
1999-02-25 23:49:47 +03:00
|
|
|
// nsInputStream
|
1998-12-19 02:06:54 +03:00
|
|
|
//========================================================================================
|
|
|
|
|
1998-12-09 01:43:57 +03:00
|
|
|
//----------------------------------------------------------------------------------------
|
1999-02-25 23:49:47 +03:00
|
|
|
nsInputStream::~nsInputStream()
|
1998-12-09 01:43:57 +03:00
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
{
|
1998-12-19 02:06:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------
|
1999-02-25 23:49:47 +03:00
|
|
|
char nsInputStream::get()
|
1998-12-19 02:06:54 +03:00
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
{
|
1999-02-25 23:49:47 +03:00
|
|
|
char c;
|
1999-04-08 21:31:00 +04:00
|
|
|
if (read(&c, sizeof(c)) == sizeof(c))
|
|
|
|
return c;
|
|
|
|
return 0;
|
1998-12-19 02:06:54 +03:00
|
|
|
}
|
|
|
|
|
1999-03-06 01:53:56 +03:00
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
PRInt32 nsInputStream::read(void* s, PRInt32 n)
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
{
|
|
|
|
if (!mInputStream)
|
|
|
|
return 0;
|
|
|
|
PRInt32 result = 0;
|
|
|
|
mInputStream->Read((char*)s, n, (PRUint32*)&result);
|
2000-02-11 03:50:58 +03:00
|
|
|
if (result == 0)
|
1999-03-06 01:53:56 +03:00
|
|
|
set_at_eof(PR_TRUE);
|
|
|
|
return result;
|
|
|
|
} // nsInputStream::read
|
|
|
|
|
1998-12-19 02:06:54 +03:00
|
|
|
//----------------------------------------------------------------------------------------
|
1999-02-25 23:49:47 +03:00
|
|
|
static void TidyEndOfLine(char*& cp)
|
|
|
|
// Assumes that cp is pointing at \n or \r. Nulls out the character, checks for
|
|
|
|
// a second terminator (of the opposite persuasion), and returns cp pointing past the
|
|
|
|
// entire eol construct (one or two characters).
|
1998-12-19 02:06:54 +03:00
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
{
|
1999-02-25 23:49:47 +03:00
|
|
|
char ch = *cp;
|
|
|
|
*cp++ = '\0'; // terminate at the newline, then skip past it
|
|
|
|
if ((ch == '\n' && *cp == '\r') || (ch == '\r' && *cp == '\n'))
|
|
|
|
cp++; // possibly a pair.
|
1998-12-19 02:06:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------
|
1999-02-25 23:49:47 +03:00
|
|
|
nsInputStream& nsInputStream::operator >> (char& c)
|
1998-12-19 02:06:54 +03:00
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
{
|
1999-02-25 23:49:47 +03:00
|
|
|
c = get();
|
1998-12-19 02:06:54 +03:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
//========================================================================================
|
1999-02-25 23:49:47 +03:00
|
|
|
// nsOutputStream
|
1998-12-19 02:06:54 +03:00
|
|
|
//========================================================================================
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------
|
1999-02-25 23:49:47 +03:00
|
|
|
nsOutputStream::~nsOutputStream()
|
1998-12-19 02:06:54 +03:00
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------
|
1999-02-25 23:49:47 +03:00
|
|
|
void nsOutputStream::put(char c)
|
1998-12-19 02:06:54 +03:00
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
{
|
|
|
|
write(&c, sizeof(c));
|
|
|
|
}
|
|
|
|
|
1999-03-06 01:53:56 +03:00
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
PRInt32 nsOutputStream::write(const void* s, PRInt32 n)
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
{
|
|
|
|
if (!mOutputStream)
|
|
|
|
return 0;
|
|
|
|
PRInt32 result = 0;
|
|
|
|
mOutputStream->Write((char*)s, n, (PRUint32*)&result);
|
|
|
|
return result;
|
|
|
|
} // nsOutputStream::write
|
|
|
|
|
1998-12-19 02:06:54 +03:00
|
|
|
//----------------------------------------------------------------------------------------
|
2001-03-30 09:24:34 +04:00
|
|
|
nsresult nsOutputStream::flush()
|
1998-12-19 02:06:54 +03:00
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
{
|
2001-03-30 09:24:34 +04:00
|
|
|
return NS_OK;
|
1998-12-19 02:06:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------
|
1999-02-25 23:49:47 +03:00
|
|
|
nsOutputStream& nsOutputStream::operator << (char c)
|
1998-12-19 02:06:54 +03:00
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
{
|
|
|
|
put(c);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------
|
1999-02-25 23:49:47 +03:00
|
|
|
nsOutputStream& nsOutputStream::operator << (const char* s)
|
1998-12-19 02:06:54 +03:00
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
{
|
1999-06-10 06:24:21 +04:00
|
|
|
if (s)
|
|
|
|
write(s, strlen(s));
|
1998-12-19 02:06:54 +03:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------
|
1999-02-25 23:49:47 +03:00
|
|
|
nsOutputStream& nsOutputStream::operator << (short val)
|
1998-12-19 02:06:54 +03:00
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
{
|
|
|
|
char buf[30];
|
1999-03-10 23:56:38 +03:00
|
|
|
sprintf(buf, "%hd", val);
|
1999-02-25 23:49:47 +03:00
|
|
|
return (*this << buf);
|
1998-12-19 02:06:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------
|
1999-02-25 23:49:47 +03:00
|
|
|
nsOutputStream& nsOutputStream::operator << (unsigned short val)
|
1998-12-19 02:06:54 +03:00
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
{
|
|
|
|
char buf[30];
|
1999-03-10 23:56:38 +03:00
|
|
|
sprintf(buf, "%hu", val);
|
1999-02-25 23:49:47 +03:00
|
|
|
return (*this << buf);
|
1998-12-19 02:06:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------
|
1999-02-25 23:49:47 +03:00
|
|
|
nsOutputStream& nsOutputStream::operator << (long val)
|
1998-12-19 02:06:54 +03:00
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
{
|
|
|
|
char buf[30];
|
|
|
|
sprintf(buf, "%ld", val);
|
1999-02-25 23:49:47 +03:00
|
|
|
return (*this << buf);
|
1998-12-19 02:06:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------
|
1999-02-25 23:49:47 +03:00
|
|
|
nsOutputStream& nsOutputStream::operator << (unsigned long val)
|
1998-12-19 02:06:54 +03:00
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
{
|
|
|
|
char buf[30];
|
1999-03-10 23:56:38 +03:00
|
|
|
sprintf(buf, "%lu", val);
|
|
|
|
return (*this << buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
nsOutputStream& nsOutputStream::operator << (int val)
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
{
|
|
|
|
char buf[30];
|
|
|
|
sprintf(buf, "%d", val);
|
|
|
|
return (*this << buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
nsOutputStream& nsOutputStream::operator << (unsigned int val)
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
{
|
|
|
|
char buf[30];
|
|
|
|
sprintf(buf, "%u", val);
|
1999-02-25 23:49:47 +03:00
|
|
|
return (*this << buf);
|
1998-12-19 02:06:54 +03:00
|
|
|
}
|
|
|
|
|
1999-02-25 23:49:47 +03:00
|
|
|
//========================================================================================
|
1999-03-06 01:53:56 +03:00
|
|
|
// nsRandomAccessInputStream
|
1999-02-25 23:49:47 +03:00
|
|
|
//========================================================================================
|
|
|
|
|
1998-12-19 02:06:54 +03:00
|
|
|
//----------------------------------------------------------------------------------------
|
1999-03-06 01:53:56 +03:00
|
|
|
PRBool nsRandomAccessInputStream::readline(char* s, PRInt32 n)
|
1999-02-25 23:49:47 +03:00
|
|
|
// This will truncate if the buffer is too small. Result will always be null-terminated.
|
1998-12-19 02:06:54 +03:00
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
{
|
1999-02-25 23:49:47 +03:00
|
|
|
PRBool bufferLargeEnough = PR_TRUE; // result
|
|
|
|
if (!s || !n)
|
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
PRIntn position = tell();
|
|
|
|
if (position < 0)
|
|
|
|
return PR_FALSE;
|
|
|
|
PRInt32 bytesRead = read(s, n - 1);
|
|
|
|
if (failed())
|
|
|
|
return PR_FALSE;
|
|
|
|
s[bytesRead] = '\0'; // always terminate at the end of the buffer
|
|
|
|
char* tp = strpbrk(s, "\n\r");
|
|
|
|
if (tp)
|
1998-12-19 02:06:54 +03:00
|
|
|
{
|
1999-02-25 23:49:47 +03:00
|
|
|
TidyEndOfLine(tp);
|
|
|
|
bytesRead = (tp - s);
|
1998-12-19 02:06:54 +03:00
|
|
|
}
|
2000-10-13 15:14:48 +04:00
|
|
|
else if (!eof() && n-1 == bytesRead)
|
1999-02-25 23:49:47 +03:00
|
|
|
bufferLargeEnough = PR_FALSE;
|
|
|
|
position += bytesRead;
|
|
|
|
seek(position);
|
|
|
|
return bufferLargeEnough;
|
1999-03-06 01:53:56 +03:00
|
|
|
} // nsRandomAccessInputStream::readline
|
|
|
|
|
|
|
|
//========================================================================================
|
|
|
|
// nsInputStringStream
|
|
|
|
//========================================================================================
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
nsInputStringStream::nsInputStringStream(const char* stringToRead)
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
{
|
|
|
|
nsISupports* stream;
|
|
|
|
if (NS_FAILED(NS_NewCharInputStream(&stream, stringToRead)))
|
|
|
|
return;
|
1999-10-31 03:32:15 +03:00
|
|
|
mInputStream = do_QueryInterface(stream);
|
|
|
|
mStore = do_QueryInterface(stream);
|
1999-03-06 01:53:56 +03:00
|
|
|
NS_RELEASE(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
nsInputStringStream::nsInputStringStream(const nsString& stringToRead)
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
{
|
|
|
|
nsISupports* stream;
|
|
|
|
if (NS_FAILED(NS_NewStringInputStream(&stream, stringToRead)))
|
|
|
|
return;
|
1999-10-31 03:32:15 +03:00
|
|
|
mInputStream = do_QueryInterface(stream);
|
|
|
|
mStore = do_QueryInterface(stream);
|
1999-03-06 01:53:56 +03:00
|
|
|
NS_RELEASE(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
//========================================================================================
|
|
|
|
// nsOutputStringStream
|
|
|
|
//========================================================================================
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
nsOutputStringStream::nsOutputStringStream(char*& stringToChange)
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
{
|
|
|
|
nsISupports* stream;
|
|
|
|
if (NS_FAILED(NS_NewCharOutputStream(&stream, &stringToChange)))
|
|
|
|
return;
|
1999-10-31 03:32:15 +03:00
|
|
|
mOutputStream = do_QueryInterface(stream);
|
|
|
|
mStore = do_QueryInterface(stream);
|
1999-03-06 01:53:56 +03:00
|
|
|
NS_RELEASE(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
nsOutputStringStream::nsOutputStringStream(nsString& stringToChange)
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
{
|
|
|
|
nsISupports* stream;
|
|
|
|
if (NS_FAILED(NS_NewStringOutputStream(&stream, stringToChange)))
|
|
|
|
return;
|
1999-10-31 03:32:15 +03:00
|
|
|
mOutputStream = do_QueryInterface(stream);
|
|
|
|
mStore = do_QueryInterface(stream);
|
1999-03-06 01:53:56 +03:00
|
|
|
NS_RELEASE(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
//========================================================================================
|
|
|
|
// nsInputFileStream
|
|
|
|
//========================================================================================
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
nsInputFileStream::nsInputFileStream(
|
|
|
|
const nsFileSpec& inFile,
|
|
|
|
int nsprMode,
|
|
|
|
PRIntn accessMode)
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
{
|
|
|
|
nsISupports* stream;
|
|
|
|
if (NS_FAILED(NS_NewIOFileStream(&stream, inFile, nsprMode, accessMode)))
|
|
|
|
return;
|
1999-06-15 02:04:27 +04:00
|
|
|
AssignFrom(stream);
|
|
|
|
NS_RELEASE(stream);
|
|
|
|
} // nsInputFileStream::nsInputFileStream
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
nsInputFileStream::nsInputFileStream(nsIFileSpec* inSpec)
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
{
|
|
|
|
nsIInputStream* stream;
|
|
|
|
if (NS_FAILED(inSpec->GetInputStream(&stream)))
|
|
|
|
return;
|
|
|
|
AssignFrom(stream);
|
|
|
|
NS_RELEASE(stream);
|
|
|
|
} // nsInputFileStream::nsInputFileStream
|
|
|
|
|
2001-02-26 21:50:25 +03:00
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
nsInputFileStream::~nsInputFileStream()
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
{
|
2001-03-14 10:36:13 +03:00
|
|
|
// if (is_open())
|
|
|
|
// close();
|
2001-02-26 21:50:25 +03:00
|
|
|
}
|
|
|
|
|
1999-06-15 02:04:27 +04:00
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
void nsInputFileStream::AssignFrom(nsISupports* stream)
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
{
|
1999-10-31 03:32:15 +03:00
|
|
|
mFile = do_QueryInterface(stream);
|
|
|
|
mInputStream = do_QueryInterface(stream);
|
|
|
|
mStore = do_QueryInterface(stream);
|
|
|
|
mFileInputStream = do_QueryInterface(stream);
|
1999-06-15 02:04:27 +04:00
|
|
|
}
|
1999-01-27 02:49:33 +03:00
|
|
|
|
|
|
|
//========================================================================================
|
|
|
|
// nsOutputFileStream
|
|
|
|
//========================================================================================
|
|
|
|
|
1999-06-15 02:04:27 +04:00
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
nsOutputFileStream::nsOutputFileStream(nsIFileSpec* inSpec)
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
{
|
1999-06-15 13:31:49 +04:00
|
|
|
if (!inSpec)
|
|
|
|
return;
|
1999-06-15 02:04:27 +04:00
|
|
|
nsIOutputStream* stream;
|
|
|
|
if (NS_FAILED(inSpec->GetOutputStream(&stream)))
|
|
|
|
return;
|
|
|
|
AssignFrom(stream);
|
|
|
|
NS_RELEASE(stream);
|
|
|
|
}
|
|
|
|
|
2001-02-26 21:50:25 +03:00
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
nsOutputFileStream::~nsOutputFileStream()
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
{
|
2001-03-14 10:36:13 +03:00
|
|
|
// if (is_open())
|
|
|
|
// close();
|
2001-02-26 21:50:25 +03:00
|
|
|
}
|
1999-06-15 02:04:27 +04:00
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
void nsOutputFileStream::AssignFrom(nsISupports* stream)
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
{
|
1999-10-31 03:32:15 +03:00
|
|
|
mFile = do_QueryInterface(stream);
|
|
|
|
mOutputStream = do_QueryInterface(stream);
|
|
|
|
mStore = do_QueryInterface(stream);
|
|
|
|
mFileOutputStream = do_QueryInterface(stream);
|
1999-06-15 02:04:27 +04:00
|
|
|
}
|
|
|
|
|
1999-01-27 02:49:33 +03:00
|
|
|
//----------------------------------------------------------------------------------------
|
2001-03-30 09:24:34 +04:00
|
|
|
nsresult nsOutputFileStream::flush()
|
1999-01-27 02:49:33 +03:00
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
{
|
1999-02-25 23:49:47 +03:00
|
|
|
if (mFileOutputStream)
|
|
|
|
mFileOutputStream->Flush();
|
2001-03-30 09:24:34 +04:00
|
|
|
return error();
|
1999-01-27 02:49:33 +03:00
|
|
|
}
|
1998-12-19 02:06:54 +03:00
|
|
|
|
1999-05-26 05:38:36 +04:00
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
void nsOutputFileStream::abort()
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
{
|
|
|
|
mResult = NS_FILE_FAILURE;
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
|
|
|
//========================================================================================
|
|
|
|
// nsSaveViaTempStream
|
|
|
|
//========================================================================================
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
nsSaveViaTempStream::nsSaveViaTempStream(const nsFileSpec& inFileToSave)
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
: mFileToSave(inFileToSave)
|
|
|
|
, mTempFileSpec(new nsFileSpec(inFileToSave))
|
|
|
|
{
|
|
|
|
// Make sure the temp file's unique (in particular, different from the target file)
|
|
|
|
mTempFileSpec->MakeUnique();
|
2000-07-22 02:16:18 +04:00
|
|
|
open(*mTempFileSpec, (PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE), 0666);
|
1999-05-26 05:38:36 +04:00
|
|
|
} // nsSaveViaTempStream::nsSaveViaTempStream
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
void nsSaveViaTempStream::close()
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
{
|
|
|
|
if (!mTempFileSpec)
|
|
|
|
return;
|
|
|
|
nsresult currentResult = mResult;
|
|
|
|
Inherited::close();
|
|
|
|
mResult = currentResult;
|
|
|
|
if (error())
|
|
|
|
{
|
|
|
|
mTempFileSpec->Delete(PR_FALSE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nsFileSpec thirdSpec(mFileToSave);
|
|
|
|
thirdSpec.MakeUnique();
|
|
|
|
nsSimpleCharString originalName(mFileToSave.GetLeafName());
|
|
|
|
((nsFileSpec&)mFileToSave).Rename(nsSimpleCharString(thirdSpec.GetLeafName()));
|
|
|
|
if (NS_SUCCEEDED(mTempFileSpec->Rename(originalName)) && mTempFileSpec->Valid())
|
|
|
|
mFileToSave.Delete(PR_FALSE);
|
|
|
|
}
|
|
|
|
delete mTempFileSpec;
|
|
|
|
} // nsSaveViaTempStream::~nsSaveViaTempStream
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
nsSaveViaTempStream::~nsSaveViaTempStream()
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
{
|
|
|
|
delete mTempFileSpec;
|
|
|
|
} // nsSaveViaTempStream::~nsSaveViaTempStream
|
|
|
|
|
1998-12-19 02:06:54 +03:00
|
|
|
//========================================================================================
|
|
|
|
// Manipulators
|
|
|
|
//========================================================================================
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------
|
1999-02-25 23:49:47 +03:00
|
|
|
nsOutputStream& nsEndl(nsOutputStream& os)
|
1998-12-19 02:06:54 +03:00
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
{
|
2000-11-29 02:27:38 +03:00
|
|
|
#if defined(XP_WIN) || defined(XP_OS2)
|
1999-04-28 01:26:15 +04:00
|
|
|
os.write("\r\n", 2);
|
1999-10-05 07:00:13 +04:00
|
|
|
#elif defined (XP_MAC)
|
|
|
|
os.put('\r');
|
1999-04-28 01:26:15 +04:00
|
|
|
#else
|
1999-02-25 23:49:47 +03:00
|
|
|
os.put('\n');
|
1999-04-28 01:26:15 +04:00
|
|
|
#endif
|
1999-10-05 07:00:13 +04:00
|
|
|
//os.flush();
|
1999-02-25 23:49:47 +03:00
|
|
|
return os;
|
1999-03-20 05:34:54 +03:00
|
|
|
} // nsEndl
|