2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1998-12-08 05:15:50 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04: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-08 05:15:50 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04: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-08 05:15:50 +03:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:43:54 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the NPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1998-12-08 05:15:50 +03:00
|
|
|
|
2000-04-25 05:48:02 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
|
|
THESE CLASSES ARE DEPRECIATED AND UNSUPPORTED! USE |nsIFile| and |nsILocalFile|.
|
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1998-12-09 01:45:42 +03:00
|
|
|
// First checked in on 98/11/20 by John R. McMullen in the wrong directory.
|
|
|
|
// Checked in again 98/12/04.
|
|
|
|
// Polished version 98/12/08.
|
1998-12-08 05:15:50 +03:00
|
|
|
|
|
|
|
//========================================================================================
|
|
|
|
//
|
1998-12-09 01:45:42 +03:00
|
|
|
// Classes defined:
|
|
|
|
//
|
1999-02-28 04:36:48 +03:00
|
|
|
// nsFilePath, nsFileURL, nsFileSpec, nsPersistentFileDescriptor
|
2001-10-12 06:57:59 +04:00
|
|
|
// nsDirectoryIterator.
|
1999-02-25 23:49:47 +03:00
|
|
|
//
|
|
|
|
// Q. How should I represent files at run time?
|
|
|
|
// A. Use nsFileSpec. Using char* will lose information on some platforms.
|
|
|
|
//
|
|
|
|
// Q. Then what are nsFilePath and nsFileURL for?
|
|
|
|
// A. Only when you need a char* parameter for legacy code.
|
|
|
|
//
|
|
|
|
// Q. How should I represent files in a persistent way (eg, in a disk file)?
|
|
|
|
// A. Use nsPersistentFileDescriptor. Convert to and from nsFileSpec at run time.
|
1998-12-09 01:45:42 +03:00
|
|
|
//
|
|
|
|
// This suite provides the following services:
|
|
|
|
//
|
|
|
|
// 1. Encapsulates all platform-specific file details, so that files can be
|
|
|
|
// described correctly without any platform #ifdefs
|
|
|
|
//
|
|
|
|
// 2. Type safety. This will fix the problems that used to occur because people
|
|
|
|
// confused file paths. They used to use const char*, which could mean three
|
|
|
|
// or four different things. Bugs were introduced as people coded, right up
|
|
|
|
// to the moment Communicator 4.5 shipped.
|
|
|
|
//
|
|
|
|
// 3. Used in conjunction with nsFileStream.h (q.v.), this supports all the power
|
1998-12-19 02:06:54 +03:00
|
|
|
// and readability of the ansi stream syntax.
|
1998-12-09 01:45:42 +03:00
|
|
|
//
|
|
|
|
// Basic example:
|
|
|
|
//
|
|
|
|
// nsFilePath myPath("/Development/iotest.txt");
|
|
|
|
//
|
1999-05-08 05:18:23 +04:00
|
|
|
// nsOutputFileStream testStream(nsFileSpec(myPath));
|
1998-12-19 02:06:54 +03:00
|
|
|
// testStream << "Hello World" << nsEndl;
|
1998-12-09 01:45:42 +03:00
|
|
|
//
|
|
|
|
// 4. Handy methods for manipulating file specifiers safely, e.g. MakeUnique(),
|
|
|
|
// SetLeafName(), Exists().
|
|
|
|
//
|
|
|
|
// 5. Easy cross-conversion.
|
|
|
|
//
|
|
|
|
// Examples:
|
|
|
|
//
|
1999-05-08 05:18:23 +04:00
|
|
|
// Initialize a URL from a string
|
1998-12-09 01:45:42 +03:00
|
|
|
//
|
|
|
|
// nsFileURL fileURL("file:///Development/MPW/MPW%20Shell");
|
|
|
|
//
|
1999-05-08 05:18:23 +04:00
|
|
|
// Initialize a Unix-style path from a URL
|
1998-12-09 01:45:42 +03:00
|
|
|
//
|
|
|
|
// nsFilePath filePath(fileURL);
|
|
|
|
//
|
1999-05-08 05:18:23 +04:00
|
|
|
// Initialize a file spec from a URL
|
1998-12-08 05:15:50 +03:00
|
|
|
//
|
1999-02-25 23:49:47 +03:00
|
|
|
// nsFileSpec fileSpec(fileURL);
|
1998-12-09 01:45:42 +03:00
|
|
|
//
|
1999-05-08 05:18:23 +04:00
|
|
|
// Make the spec unique.
|
1998-12-09 01:45:42 +03:00
|
|
|
//
|
|
|
|
// fileSpec.MakeUnique();
|
|
|
|
//
|
1999-05-08 05:18:23 +04:00
|
|
|
// Assign the spec to a URL (causing conversion)
|
1998-12-09 01:45:42 +03:00
|
|
|
//
|
|
|
|
// fileURL = fileSpec;
|
|
|
|
//
|
1999-05-08 05:18:23 +04:00
|
|
|
// Assign a unix path using a string
|
1998-12-09 01:45:42 +03:00
|
|
|
//
|
|
|
|
// filePath = "/Development/MPW/SysErrs.err";
|
|
|
|
//
|
1999-05-08 05:18:23 +04:00
|
|
|
// Assign to a file spec using a unix path (causing conversion).
|
1998-12-09 01:45:42 +03:00
|
|
|
//
|
|
|
|
// fileSpec = filePath;
|
|
|
|
//
|
1999-05-08 05:18:23 +04:00
|
|
|
// Make this unique.
|
1998-12-09 01:45:42 +03:00
|
|
|
//
|
|
|
|
// fileSpec.MakeUnique();
|
|
|
|
//
|
|
|
|
// 6. Fixes a bug that have been there for a long time, and
|
|
|
|
// is inevitable if you use NSPR alone, where files are described as paths.
|
|
|
|
//
|
|
|
|
// The problem affects platforms (Macintosh) in which a path does not fully
|
|
|
|
// specify a file, because two volumes can have the same name. This
|
|
|
|
// is solved by holding a "private" native file spec inside the
|
|
|
|
// nsFilePath and nsFileURL classes, which is used when appropriate.
|
|
|
|
//
|
1998-12-08 05:15:50 +03:00
|
|
|
//========================================================================================
|
|
|
|
|
1998-12-09 01:45:42 +03:00
|
|
|
#ifndef _FILESPEC_H_
|
|
|
|
#define _FILESPEC_H_
|
|
|
|
|
1998-12-12 04:25:32 +03:00
|
|
|
#include "nscore.h"
|
1999-02-25 23:49:47 +03:00
|
|
|
#include "nsError.h"
|
1999-02-28 04:36:48 +03:00
|
|
|
#include "nsString.h"
|
2001-09-29 12:28:41 +04:00
|
|
|
#include "nsReadableUtils.h"
|
1999-04-25 17:31:05 +04:00
|
|
|
#include "nsCRT.h"
|
1999-09-09 23:20:35 +04:00
|
|
|
#include "prtypes.h"
|
1999-09-21 07:09:39 +04:00
|
|
|
|
1998-12-09 08:09:28 +03:00
|
|
|
//========================================================================================
|
|
|
|
// Compiler-specific macros, as needed
|
|
|
|
//========================================================================================
|
2000-11-29 02:27:38 +03:00
|
|
|
#if !defined(NS_USING_NAMESPACE) && (defined(__MWERKS__) || defined(XP_WIN))
|
1998-12-09 08:09:28 +03:00
|
|
|
#define NS_USING_NAMESPACE
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef NS_USING_NAMESPACE
|
1998-12-11 06:17:47 +03:00
|
|
|
|
1998-12-09 08:09:28 +03:00
|
|
|
#define NS_NAMESPACE_PROTOTYPE
|
|
|
|
#define NS_NAMESPACE namespace
|
|
|
|
#define NS_NAMESPACE_END
|
1999-02-25 23:49:47 +03:00
|
|
|
#define NS_EXPLICIT explicit
|
1998-12-09 08:09:28 +03:00
|
|
|
#else
|
1998-12-11 06:17:47 +03:00
|
|
|
|
1998-12-09 08:09:28 +03:00
|
|
|
#define NS_NAMESPACE_PROTOTYPE static
|
|
|
|
#define NS_NAMESPACE struct
|
|
|
|
#define NS_NAMESPACE_END ;
|
1999-02-25 23:49:47 +03:00
|
|
|
#define NS_EXPLICIT
|
1998-12-11 06:17:47 +03:00
|
|
|
|
1998-12-09 08:09:28 +03:00
|
|
|
#endif
|
|
|
|
//=========================== End Compiler-specific macros ===============================
|
|
|
|
|
2000-04-21 02:59:30 +04:00
|
|
|
#include "nsILocalFile.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
|
2001-10-27 11:38:18 +04:00
|
|
|
#if defined(XP_MAC)
|
1998-12-08 05:15:50 +03:00
|
|
|
#include <Files.h>
|
2000-04-21 02:59:30 +04:00
|
|
|
#include "nsILocalFileMac.h"
|
2001-10-27 11:38:18 +04:00
|
|
|
#elif defined(XP_UNIX) || defined (XP_OS2) || defined(XP_BEOS)
|
2000-03-01 00:27:02 +03:00
|
|
|
#if defined(XP_OS2)
|
|
|
|
#define INCL_DOS
|
|
|
|
#define INCL_DOSERRORS
|
2001-06-15 07:48:00 +04:00
|
|
|
#define INCL_WIN
|
|
|
|
#define INCL_GPI
|
2000-03-01 00:27:02 +03:00
|
|
|
#include <os2.h>
|
|
|
|
#include <sys/types.h> // required for dirent.h
|
|
|
|
#include "prio.h"
|
|
|
|
#endif
|
1999-01-07 02:38:21 +03:00
|
|
|
#include <dirent.h>
|
2000-11-29 02:27:38 +03:00
|
|
|
#elif defined(XP_WIN)
|
1999-09-21 07:09:39 +04:00
|
|
|
|
|
|
|
// This clashes with some of the Win32 system headers (specifically,
|
|
|
|
// winbase.h). Hopefully they'll have been included first; else we may
|
|
|
|
// have problems. We could include winbase.h before doing this;
|
|
|
|
// unfortunately, it's bring in too much crap and'd slow stuff down
|
|
|
|
// more than it's worth doing.
|
|
|
|
#ifdef CreateDirectory
|
|
|
|
#undef CreateDirectory
|
|
|
|
#endif
|
|
|
|
|
1999-01-27 02:49:33 +03:00
|
|
|
#include "prio.h"
|
1998-12-08 05:15:50 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
//========================================================================================
|
|
|
|
// Here are the allowable ways to describe a file.
|
|
|
|
//========================================================================================
|
|
|
|
|
1999-02-25 23:49:47 +03:00
|
|
|
class nsFileSpec; // Preferred. For i/o use nsInputFileStream, nsOutputFileStream
|
1999-05-08 05:18:23 +04:00
|
|
|
class nsFilePath;
|
1998-12-08 05:15:50 +03:00
|
|
|
class nsFileURL;
|
1999-05-08 05:18:23 +04:00
|
|
|
class nsNSPRPath; // This can be passed to NSPR file I/O routines, if you must.
|
1999-02-25 23:49:47 +03:00
|
|
|
class nsPersistentFileDescriptor; // Used for storage across program launches.
|
1998-12-08 05:15:50 +03:00
|
|
|
|
|
|
|
#define kFileURLPrefix "file://"
|
|
|
|
#define kFileURLPrefixLength (7)
|
|
|
|
|
1999-02-25 23:49:47 +03:00
|
|
|
class nsOutputStream;
|
|
|
|
class nsInputStream;
|
1999-02-28 04:36:48 +03:00
|
|
|
class nsIOutputStream;
|
|
|
|
class nsIInputStream;
|
1999-02-25 23:49:47 +03:00
|
|
|
class nsOutputFileStream;
|
|
|
|
class nsInputFileStream;
|
1999-03-10 01:33:36 +03:00
|
|
|
class nsOutputConsoleStream;
|
1999-05-08 05:18:23 +04:00
|
|
|
|
1999-02-28 04:36:48 +03:00
|
|
|
class nsString;
|
1998-12-19 02:06:54 +03:00
|
|
|
|
2000-02-11 04:08:56 +03:00
|
|
|
class nsIUnicodeEncoder;
|
|
|
|
class nsIUnicodeDecoder;
|
|
|
|
|
1998-12-08 05:15:50 +03:00
|
|
|
//========================================================================================
|
1999-02-25 23:49:47 +03:00
|
|
|
// Conversion of native file errors to nsresult values. These are really only for use
|
|
|
|
// in the file module, clients of this interface shouldn't really need them.
|
|
|
|
// Error results returned from this interface have, in the low-order 16 bits,
|
|
|
|
// native errors that are masked to 16 bits. Assumption: a native error of 0 is success
|
|
|
|
// on all platforms. Note the way we define this using an inline function. This
|
|
|
|
// avoids multiple evaluation if people go NS_FILE_RESULT(function_call()).
|
|
|
|
#define NS_FILE_RESULT(x) ns_file_convert_result((PRInt32)x)
|
|
|
|
nsresult ns_file_convert_result(PRInt32 nativeErr);
|
|
|
|
#define NS_FILE_FAILURE NS_FILE_RESULT(-1)
|
|
|
|
|
1999-03-20 02:09:39 +03:00
|
|
|
//========================================================================================
|
2002-02-19 02:00:11 +03:00
|
|
|
class nsSimpleCharString
|
1999-03-20 02:09:39 +03:00
|
|
|
// An envelope for char*: reference counted. Used internally by all the nsFileSpec
|
|
|
|
// classes below.
|
|
|
|
//========================================================================================
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsSimpleCharString();
|
|
|
|
nsSimpleCharString(const char*);
|
|
|
|
nsSimpleCharString(const nsString&);
|
|
|
|
nsSimpleCharString(const nsSimpleCharString&);
|
|
|
|
nsSimpleCharString(const char* inData, PRUint32 inLength);
|
|
|
|
|
|
|
|
~nsSimpleCharString();
|
|
|
|
|
|
|
|
void operator = (const char*);
|
|
|
|
void operator = (const nsString&);
|
|
|
|
void operator = (const nsSimpleCharString&);
|
|
|
|
|
|
|
|
operator const char*() const { return mData ? mData->mString : 0; }
|
|
|
|
operator char* ()
|
|
|
|
{
|
|
|
|
ReallocData(Length()); // requires detaching if shared...
|
|
|
|
return mData ? mData->mString : 0;
|
|
|
|
}
|
|
|
|
PRBool operator == (const char*);
|
|
|
|
PRBool operator == (const nsString&);
|
|
|
|
PRBool operator == (const nsSimpleCharString&);
|
|
|
|
|
|
|
|
void operator += (const char* inString);
|
|
|
|
nsSimpleCharString operator + (const char* inString) const;
|
|
|
|
|
1999-11-03 10:39:19 +03:00
|
|
|
char operator [](int i) const { return mData ? mData->mString[i] : '\0'; }
|
1999-03-20 02:09:39 +03:00
|
|
|
char& operator [](int i)
|
|
|
|
{
|
|
|
|
if (i >= (int)Length())
|
1999-04-15 05:11:42 +04:00
|
|
|
ReallocData((PRUint32)i + 1);
|
1999-03-20 02:09:39 +03:00
|
|
|
return mData->mString[i]; // caveat appelator
|
|
|
|
}
|
|
|
|
char& operator [](unsigned int i) { return (*this)[(int)i]; }
|
|
|
|
|
|
|
|
void Catenate(const char* inString1, const char* inString2);
|
|
|
|
|
|
|
|
void SetToEmpty();
|
|
|
|
PRBool IsEmpty() const { return Length() == 0; }
|
|
|
|
|
|
|
|
PRUint32 Length() const { return mData ? mData->mLength : 0; }
|
1999-04-20 23:31:11 +04:00
|
|
|
void SetLength(PRUint32 inLength) { ReallocData(inLength); }
|
1999-03-20 02:09:39 +03:00
|
|
|
void CopyFrom(const char* inData, PRUint32 inLength);
|
|
|
|
void LeafReplace(char inSeparator, const char* inLeafName);
|
|
|
|
char* GetLeaf(char inSeparator) const; // use PR_Free()
|
|
|
|
void Unescape();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
void AddRefData();
|
|
|
|
void ReleaseData();
|
|
|
|
void ReallocData(PRUint32 inLength);
|
|
|
|
|
1999-05-08 05:18:23 +04:00
|
|
|
//--------------------------------------------------
|
|
|
|
// Data
|
|
|
|
//--------------------------------------------------
|
|
|
|
|
1999-03-20 02:09:39 +03:00
|
|
|
protected:
|
1999-05-08 05:18:23 +04:00
|
|
|
|
1999-03-20 02:09:39 +03:00
|
|
|
struct Data {
|
|
|
|
int mRefCount;
|
|
|
|
PRUint32 mLength;
|
|
|
|
char mString[1];
|
|
|
|
};
|
|
|
|
Data* mData;
|
|
|
|
}; // class nsSimpleCharString
|
|
|
|
|
1999-02-25 23:49:47 +03:00
|
|
|
//========================================================================================
|
1999-05-26 05:38:36 +04:00
|
|
|
class NS_COM nsFileSpec
|
1998-12-09 01:45:42 +03:00
|
|
|
// This is whatever each platform really prefers to describe files as. Declared first
|
1999-03-11 00:02:58 +03:00
|
|
|
// because the other two types have an embedded nsFileSpec object.
|
1998-12-08 05:15:50 +03:00
|
|
|
//========================================================================================
|
|
|
|
{
|
1998-12-09 01:45:42 +03:00
|
|
|
public:
|
1999-02-25 23:49:47 +03:00
|
|
|
nsFileSpec();
|
1999-04-15 23:39:23 +04:00
|
|
|
|
|
|
|
// These two meathods take *native* file paths.
|
1999-05-08 05:18:23 +04:00
|
|
|
NS_EXPLICIT nsFileSpec(const char* inNativePath, PRBool inCreateDirs = PR_FALSE);
|
|
|
|
NS_EXPLICIT nsFileSpec(const nsString& inNativePath, PRBool inCreateDirs = PR_FALSE);
|
1999-04-15 23:39:23 +04:00
|
|
|
|
1999-04-10 04:27:09 +04:00
|
|
|
|
1999-02-25 23:49:47 +03:00
|
|
|
NS_EXPLICIT nsFileSpec(const nsFilePath& inPath);
|
|
|
|
NS_EXPLICIT nsFileSpec(const nsFileURL& inURL);
|
|
|
|
nsFileSpec(const nsFileSpec& inPath);
|
|
|
|
virtual ~nsFileSpec();
|
1998-12-09 01:45:42 +03:00
|
|
|
|
1999-04-15 23:39:23 +04:00
|
|
|
// These two operands take *native* file paths.
|
1999-05-08 05:18:23 +04:00
|
|
|
void operator = (const char* inNativePath);
|
1999-04-15 23:39:23 +04:00
|
|
|
|
1998-12-09 01:45:42 +03:00
|
|
|
void operator = (const nsFilePath& inPath);
|
|
|
|
void operator = (const nsFileURL& inURL);
|
1999-02-25 23:49:47 +03:00
|
|
|
void operator = (const nsFileSpec& inOther);
|
|
|
|
void operator = (const nsPersistentFileDescriptor& inOther);
|
1998-12-08 05:15:50 +03:00
|
|
|
|
1999-03-10 01:33:36 +03:00
|
|
|
PRBool operator ==(const nsFileSpec& inOther) const;
|
|
|
|
PRBool operator !=(const nsFileSpec& inOther) const;
|
|
|
|
|
1999-10-12 01:19:06 +04:00
|
|
|
|
|
|
|
// Returns a native path, and allows the
|
|
|
|
// path to be "passed" to legacy code. This practice
|
|
|
|
// is VERY EVIL and should only be used to support legacy
|
|
|
|
// code. Using it guarantees bugs on Macintosh.
|
|
|
|
// The path is cached and freed by the nsFileSpec destructor
|
|
|
|
// so do not delete (or free) it. See also nsNSPRPath below,
|
|
|
|
// if you really must pass a string to PR_OpenFile().
|
|
|
|
// Doing so will introduce two automatic bugs.
|
|
|
|
const char* GetCString() const;
|
|
|
|
|
|
|
|
// Same as GetCString (please read the comments).
|
|
|
|
// Do not try to free this!
|
1999-03-13 09:38:57 +03:00
|
|
|
operator const char* () const { return GetCString(); }
|
1999-10-12 01:19:06 +04:00
|
|
|
|
|
|
|
// Same as GetCString (please read the comments).
|
|
|
|
// Do not try to free this!
|
1999-05-08 05:18:23 +04:00
|
|
|
const char* GetNativePathCString() const { return GetCString(); }
|
1999-10-12 01:19:06 +04:00
|
|
|
|
|
|
|
PRBool IsChildOf(nsFileSpec &possibleParent);
|
1999-01-27 02:49:33 +03:00
|
|
|
|
2001-10-27 11:38:18 +04:00
|
|
|
#if defined(XP_MAC)
|
1998-12-09 01:45:42 +03:00
|
|
|
// For Macintosh people, this is meant to be useful in its own right as a C++ version
|
1998-12-09 11:47:30 +03:00
|
|
|
// of the FSSpec struct.
|
1999-02-25 23:49:47 +03:00
|
|
|
nsFileSpec(
|
1998-12-09 01:45:42 +03:00
|
|
|
short vRefNum,
|
|
|
|
long parID,
|
1999-07-27 02:09:42 +04:00
|
|
|
ConstStr255Param name,
|
|
|
|
PRBool resolveAlias = PR_TRUE);
|
|
|
|
|
|
|
|
nsFileSpec(const FSSpec& inSpec, PRBool resolveAlias = PR_TRUE);
|
1999-06-03 05:28:52 +04:00
|
|
|
void operator = (const FSSpec& inSpec);
|
1998-12-09 01:45:42 +03:00
|
|
|
|
|
|
|
operator FSSpec* () { return &mSpec; }
|
|
|
|
operator const FSSpec* const () { return &mSpec; }
|
1998-12-09 11:47:30 +03:00
|
|
|
operator FSSpec& () { return mSpec; }
|
1998-12-09 01:45:42 +03:00
|
|
|
operator const FSSpec& () const { return mSpec; }
|
1999-03-13 09:38:57 +03:00
|
|
|
|
|
|
|
const FSSpec& GetFSSpec() const { return mSpec; }
|
|
|
|
FSSpec& GetFSSpec() { return mSpec; }
|
|
|
|
ConstFSSpecPtr GetFSSpecPtr() const { return &mSpec; }
|
|
|
|
FSSpecPtr GetFSSpecPtr() { return &mSpec; }
|
1998-12-09 11:47:30 +03:00
|
|
|
void MakeAliasSafe();
|
1998-12-09 01:45:42 +03:00
|
|
|
void MakeUnique(ConstStr255Param inSuggestedLeafName);
|
|
|
|
StringPtr GetLeafPName() { return mSpec.name; }
|
|
|
|
ConstStr255Param GetLeafPName() const { return mSpec.name; }
|
1999-04-23 21:18:24 +04:00
|
|
|
|
|
|
|
OSErr GetCatInfo(CInfoPBRec& outInfo) const;
|
1999-10-12 01:19:06 +04:00
|
|
|
|
1999-08-18 06:17:21 +04:00
|
|
|
OSErr SetFileTypeAndCreator(OSType type, OSType creator);
|
|
|
|
OSErr GetFileTypeAndCreator(OSType* type, OSType* creator);
|
1999-10-12 01:19:06 +04:00
|
|
|
|
1998-12-09 11:47:30 +03:00
|
|
|
#endif // end of Macintosh utility methods.
|
|
|
|
|
1999-02-25 23:49:47 +03:00
|
|
|
PRBool Valid() const { return NS_SUCCEEDED(Error()); }
|
1999-03-10 01:33:36 +03:00
|
|
|
nsresult Error() const
|
|
|
|
{
|
2001-10-27 11:38:18 +04:00
|
|
|
#if !defined(XP_MAC)
|
1999-03-20 02:09:39 +03:00
|
|
|
if (mPath.IsEmpty() && NS_SUCCEEDED(mError))
|
1999-05-08 05:18:23 +04:00
|
|
|
((nsFileSpec*)this)->mError = NS_ERROR_NOT_INITIALIZED;
|
2001-10-27 11:38:18 +04:00
|
|
|
#endif
|
1999-03-10 01:33:36 +03:00
|
|
|
return mError;
|
|
|
|
}
|
1999-04-15 05:11:42 +04:00
|
|
|
PRBool Failed() const { return (PRBool)NS_FAILED(Error()); }
|
1998-12-08 05:15:50 +03:00
|
|
|
|
1999-05-08 05:18:23 +04:00
|
|
|
//--------------------------------------------------
|
|
|
|
// Queries and path algebra. These do not modify the disk.
|
|
|
|
//--------------------------------------------------
|
1998-12-09 11:47:30 +03:00
|
|
|
|
1999-04-25 17:31:05 +04:00
|
|
|
char* GetLeafName() const; // Allocated. Use nsCRT::free().
|
1999-10-12 01:19:06 +04:00
|
|
|
// inLeafName can be a relative path, so this allows
|
|
|
|
// one kind of concatenation of "paths".
|
1998-12-09 11:47:30 +03:00
|
|
|
void SetLeafName(const char* inLeafName);
|
1999-10-12 01:19:06 +04:00
|
|
|
|
|
|
|
// Return the filespec of the parent directory. Used
|
|
|
|
// in conjunction with GetLeafName(), this lets you
|
|
|
|
// parse a path into a list of node names. Beware,
|
|
|
|
// however, that the top node is still not a name,
|
|
|
|
// but a spec. Volumes on Macintosh can have identical
|
|
|
|
// names. Perhaps could be used for an operator --() ?
|
1999-02-25 23:49:47 +03:00
|
|
|
void GetParent(nsFileSpec& outSpec) const;
|
1999-10-12 01:19:06 +04:00
|
|
|
|
|
|
|
|
|
|
|
// ie nsFileSpec::TimeStamp. This is 32 bits now,
|
|
|
|
// but might change, eg, to a 64-bit class. So use the
|
|
|
|
// typedef, and use a streaming operator to convert
|
|
|
|
// to a string, so that your code won't break. It's
|
|
|
|
// none of your business what the number means. Don't
|
|
|
|
// rely on the implementation.
|
|
|
|
typedef PRUint32 TimeStamp;
|
|
|
|
|
|
|
|
// This will return different values on different
|
|
|
|
// platforms, even for the same file (eg, on a server).
|
|
|
|
// But if the platform is constant, it will increase after
|
|
|
|
// every file modification.
|
1999-03-11 00:02:58 +03:00
|
|
|
void GetModDate(TimeStamp& outStamp) const;
|
1999-10-12 01:19:06 +04:00
|
|
|
|
1999-03-11 00:02:58 +03:00
|
|
|
PRBool ModDateChanged(const TimeStamp& oldStamp) const
|
|
|
|
{
|
|
|
|
TimeStamp newStamp;
|
|
|
|
GetModDate(newStamp);
|
|
|
|
return newStamp != oldStamp;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32 GetFileSize() const;
|
1999-09-11 00:03:56 +04:00
|
|
|
PRInt64 GetDiskSpaceAvailable() const;
|
1999-03-11 00:02:58 +03:00
|
|
|
|
1999-05-08 05:18:23 +04:00
|
|
|
nsFileSpec operator + (const char* inRelativeUnixPath) const;
|
1999-10-12 01:19:06 +04:00
|
|
|
|
|
|
|
// Concatenate the relative path to this directory.
|
|
|
|
// Used for constructing the filespec of a descendant.
|
|
|
|
// This must be a directory for this to work. This differs
|
|
|
|
// from SetLeafName(), since the latter will work
|
|
|
|
// starting with a sibling of the directory and throws
|
|
|
|
// away its leaf information, whereas this one assumes
|
|
|
|
// this is a directory, and the relative path starts
|
|
|
|
// "below" this.
|
1999-05-08 05:18:23 +04:00
|
|
|
void operator += (const char* inRelativeUnixPath);
|
1999-10-12 01:19:06 +04:00
|
|
|
|
1999-01-07 02:38:21 +03:00
|
|
|
|
1998-12-09 01:45:42 +03:00
|
|
|
void MakeUnique();
|
1998-12-09 11:47:30 +03:00
|
|
|
void MakeUnique(const char* inSuggestedLeafName);
|
1998-12-09 01:45:42 +03:00
|
|
|
|
1999-10-12 01:19:06 +04:00
|
|
|
|
|
|
|
PRBool IsDirectory() const; // More stringent than Exists()
|
|
|
|
PRBool IsFile() const; // More stringent than Exists()
|
1999-02-25 23:49:47 +03:00
|
|
|
PRBool Exists() const;
|
1999-01-07 02:38:21 +03:00
|
|
|
|
1999-07-21 21:56:01 +04:00
|
|
|
PRBool IsHidden() const;
|
|
|
|
|
1999-07-27 02:09:42 +04:00
|
|
|
PRBool IsSymlink() const;
|
1999-10-12 01:19:06 +04:00
|
|
|
|
1999-05-08 05:18:23 +04:00
|
|
|
//--------------------------------------------------
|
|
|
|
// Creation and deletion of objects. These can modify the disk.
|
|
|
|
//--------------------------------------------------
|
1999-01-07 02:38:21 +03:00
|
|
|
|
1999-10-12 01:19:06 +04:00
|
|
|
// Called for the spec of an alias. Modifies the spec to
|
|
|
|
// point to the original. Sets mError.
|
1999-07-27 02:09:42 +04:00
|
|
|
nsresult ResolveSymlink(PRBool& wasSymlink);
|
|
|
|
|
2000-02-05 01:57:37 +03:00
|
|
|
void CreateDirectory(int mode = 0775 /* for unix */);
|
|
|
|
void CreateDir(int mode = 0775) { CreateDirectory(mode); }
|
1999-04-15 05:11:42 +04:00
|
|
|
// workaround for yet another VC++ bug with long identifiers.
|
1999-02-28 04:36:48 +03:00
|
|
|
void Delete(PRBool inRecursive) const;
|
1999-11-19 04:42:46 +03:00
|
|
|
nsresult Truncate(PRInt32 aNewLength) const;
|
1999-07-05 05:39:42 +04:00
|
|
|
void RecursiveCopy(nsFileSpec newDir) const;
|
1999-01-07 02:38:21 +03:00
|
|
|
|
1999-02-25 23:49:47 +03:00
|
|
|
nsresult Rename(const char* inNewName); // not const: gets updated
|
1999-10-21 04:40:39 +04:00
|
|
|
nsresult CopyToDir(const nsFileSpec& inNewParentDirectory) const;
|
|
|
|
nsresult MoveToDir(const nsFileSpec& inNewParentDirectory);
|
1999-02-25 23:49:47 +03:00
|
|
|
nsresult Execute(const char* args) const;
|
1999-10-12 01:19:06 +04:00
|
|
|
|
2000-02-11 04:08:56 +03:00
|
|
|
protected:
|
|
|
|
|
1999-05-08 05:18:23 +04:00
|
|
|
//--------------------------------------------------
|
|
|
|
// Data
|
|
|
|
//--------------------------------------------------
|
1999-01-07 02:38:21 +03:00
|
|
|
|
1999-03-10 01:33:36 +03:00
|
|
|
protected:
|
1999-10-12 01:19:06 +04:00
|
|
|
|
|
|
|
// Clear the nsFileSpec contents, resetting it
|
|
|
|
// to the uninitialized state;
|
|
|
|
void Clear();
|
|
|
|
|
1998-12-09 01:45:42 +03:00
|
|
|
friend class nsFilePath;
|
1999-03-13 09:38:57 +03:00
|
|
|
friend class nsFileURL;
|
1999-03-11 00:02:58 +03:00
|
|
|
friend class nsDirectoryIterator;
|
2001-10-27 11:38:18 +04:00
|
|
|
#if defined(XP_MAC)
|
1998-12-09 08:09:28 +03:00
|
|
|
FSSpec mSpec;
|
1998-12-08 05:15:50 +03:00
|
|
|
#endif
|
1999-03-20 02:09:39 +03:00
|
|
|
nsSimpleCharString mPath;
|
1999-02-25 23:49:47 +03:00
|
|
|
nsresult mError;
|
1999-10-12 01:19:06 +04:00
|
|
|
|
2002-02-19 02:00:11 +03:00
|
|
|
private:
|
|
|
|
NS_EXPLICIT nsFileSpec(const nsPersistentFileDescriptor& inURL);
|
|
|
|
|
1999-02-25 23:49:47 +03:00
|
|
|
}; // class nsFileSpec
|
|
|
|
|
|
|
|
// FOR HISTORICAL REASONS:
|
|
|
|
|
|
|
|
typedef nsFileSpec nsNativeFileSpec;
|
1998-12-08 05:15:50 +03:00
|
|
|
|
|
|
|
//========================================================================================
|
1999-05-26 05:38:36 +04:00
|
|
|
class NS_COM nsFileURL
|
1998-12-09 01:45:42 +03:00
|
|
|
// This is an escaped string that looks like "file:///foo/bar/mumble%20fish". Since URLs
|
|
|
|
// are the standard way of doing things in mozilla, this allows a string constructor,
|
|
|
|
// which just stashes the string with no conversion.
|
1998-12-08 05:15:50 +03:00
|
|
|
//========================================================================================
|
|
|
|
{
|
1998-12-09 01:45:42 +03:00
|
|
|
public:
|
|
|
|
nsFileURL(const nsFileURL& inURL);
|
1999-05-08 05:18:23 +04:00
|
|
|
NS_EXPLICIT nsFileURL(const char* inURLString, PRBool inCreateDirs = PR_FALSE);
|
|
|
|
NS_EXPLICIT nsFileURL(const nsString& inURLString, PRBool inCreateDirs = PR_FALSE);
|
1999-02-25 23:49:47 +03:00
|
|
|
NS_EXPLICIT nsFileURL(const nsFilePath& inPath);
|
|
|
|
NS_EXPLICIT nsFileURL(const nsFileSpec& inPath);
|
1998-12-09 11:47:30 +03:00
|
|
|
virtual ~nsFileURL();
|
1998-12-09 01:45:42 +03:00
|
|
|
|
1998-12-09 11:47:30 +03:00
|
|
|
// nsString GetString() const { return mPath; }
|
1998-12-09 01:45:42 +03:00
|
|
|
// may be needed for implementation reasons,
|
|
|
|
// but should not provide a conversion constructor.
|
|
|
|
|
|
|
|
void operator = (const nsFileURL& inURL);
|
1999-05-08 05:18:23 +04:00
|
|
|
void operator = (const char* inURLString);
|
|
|
|
void operator = (const nsString& inURLString)
|
1999-02-28 04:36:48 +03:00
|
|
|
{
|
2001-10-12 06:57:59 +04:00
|
|
|
*this = NS_LossyConvertUCS2toASCII(inURLString).get();
|
1999-02-28 04:36:48 +03:00
|
|
|
}
|
1998-12-09 01:45:42 +03:00
|
|
|
void operator = (const nsFilePath& inOther);
|
1999-02-25 23:49:47 +03:00
|
|
|
void operator = (const nsFileSpec& inOther);
|
1998-12-08 05:15:50 +03:00
|
|
|
|
1999-03-20 02:09:39 +03:00
|
|
|
void operator +=(const char* inRelativeUnixPath);
|
|
|
|
nsFileURL operator +(const char* inRelativeUnixPath) const;
|
|
|
|
operator const char* () const { return (const char*)mURL; } // deprecated.
|
1999-05-08 05:18:23 +04:00
|
|
|
const char* GetURLString() const { return (const char*)mURL; }
|
|
|
|
// Not allocated, so don't free it.
|
1999-03-20 02:09:39 +03:00
|
|
|
const char* GetAsString() const { return (const char*)mURL; }
|
1999-05-08 05:18:23 +04:00
|
|
|
// Not allocated, so don't free it.
|
1998-12-09 11:47:30 +03:00
|
|
|
|
2001-10-27 11:38:18 +04:00
|
|
|
#if defined(XP_MAC)
|
1999-02-25 23:49:47 +03:00
|
|
|
// Accessor to allow quick assignment to a mFileSpec
|
|
|
|
const nsFileSpec& GetFileSpec() const { return mFileSpec; }
|
1998-12-08 05:15:50 +03:00
|
|
|
#endif
|
1999-03-20 02:09:39 +03:00
|
|
|
|
1999-05-08 05:18:23 +04:00
|
|
|
//--------------------------------------------------
|
|
|
|
// Data
|
|
|
|
//--------------------------------------------------
|
|
|
|
|
1999-03-10 01:33:36 +03:00
|
|
|
protected:
|
1999-01-07 02:38:21 +03:00
|
|
|
friend class nsFilePath; // to allow construction of nsFilePath
|
1999-03-20 02:09:39 +03:00
|
|
|
nsSimpleCharString mURL;
|
|
|
|
|
2001-10-27 11:38:18 +04:00
|
|
|
#if defined(XP_MAC)
|
1998-12-09 01:45:42 +03:00
|
|
|
// Since the path on the macintosh does not uniquely specify a file (volumes
|
1999-02-25 23:49:47 +03:00
|
|
|
// can have the same name), stash the secret nsFileSpec, too.
|
|
|
|
nsFileSpec mFileSpec;
|
1998-12-08 05:15:50 +03:00
|
|
|
#endif
|
|
|
|
}; // class nsFileURL
|
|
|
|
|
|
|
|
//========================================================================================
|
1999-05-26 05:38:36 +04:00
|
|
|
class NS_COM nsFilePath
|
1999-03-13 09:38:57 +03:00
|
|
|
// This is a string that looks like "/foo/bar/mumble fish". Same as nsFileURL, but
|
|
|
|
// without the "file:// prefix", and NOT %20 ENCODED! Strings passed in must be
|
|
|
|
// valid unix-style paths in this format.
|
1998-12-08 05:15:50 +03:00
|
|
|
//========================================================================================
|
|
|
|
{
|
1998-12-09 01:45:42 +03:00
|
|
|
public:
|
|
|
|
nsFilePath(const nsFilePath& inPath);
|
1999-05-08 05:18:23 +04:00
|
|
|
NS_EXPLICIT nsFilePath(const char* inUnixPathString, PRBool inCreateDirs = PR_FALSE);
|
|
|
|
NS_EXPLICIT nsFilePath(const nsString& inUnixPathString, PRBool inCreateDirs = PR_FALSE);
|
1999-02-25 23:49:47 +03:00
|
|
|
NS_EXPLICIT nsFilePath(const nsFileURL& inURL);
|
|
|
|
NS_EXPLICIT nsFilePath(const nsFileSpec& inPath);
|
1998-12-09 11:47:30 +03:00
|
|
|
virtual ~nsFilePath();
|
1998-12-09 01:45:42 +03:00
|
|
|
|
|
|
|
|
1998-12-09 11:47:30 +03:00
|
|
|
operator const char* () const { return mPath; }
|
1999-04-10 04:27:09 +04:00
|
|
|
// This will return a UNIX string. If you
|
|
|
|
// need a string that can be passed into
|
1999-05-08 05:18:23 +04:00
|
|
|
// NSPR, take a look at the nsNSPRPath class.
|
1998-12-09 01:45:42 +03:00
|
|
|
|
|
|
|
void operator = (const nsFilePath& inPath);
|
1999-05-08 05:18:23 +04:00
|
|
|
void operator = (const char* inUnixPathString);
|
|
|
|
void operator = (const nsString& inUnixPathString)
|
1999-02-28 04:36:48 +03:00
|
|
|
{
|
2001-10-12 06:57:59 +04:00
|
|
|
*this = NS_LossyConvertUCS2toASCII(inUnixPathString).get();
|
1999-02-28 04:36:48 +03:00
|
|
|
}
|
1998-12-09 01:45:42 +03:00
|
|
|
void operator = (const nsFileURL& inURL);
|
1999-02-25 23:49:47 +03:00
|
|
|
void operator = (const nsFileSpec& inOther);
|
1998-12-08 05:15:50 +03:00
|
|
|
|
1999-03-20 02:09:39 +03:00
|
|
|
void operator +=(const char* inRelativeUnixPath);
|
|
|
|
nsFilePath operator +(const char* inRelativeUnixPath) const;
|
|
|
|
|
2001-10-27 11:38:18 +04:00
|
|
|
#if defined(XP_MAC)
|
1998-12-09 01:45:42 +03:00
|
|
|
public:
|
1999-02-25 23:49:47 +03:00
|
|
|
// Accessor to allow quick assignment to a mFileSpec
|
|
|
|
const nsFileSpec& GetFileSpec() const { return mFileSpec; }
|
1998-12-08 05:15:50 +03:00
|
|
|
#endif
|
|
|
|
|
1999-05-08 05:18:23 +04:00
|
|
|
//--------------------------------------------------
|
|
|
|
// Data
|
|
|
|
//--------------------------------------------------
|
|
|
|
|
1998-12-09 01:45:42 +03:00
|
|
|
private:
|
1998-12-08 05:15:50 +03:00
|
|
|
|
1999-03-20 02:09:39 +03:00
|
|
|
nsSimpleCharString mPath;
|
2001-10-27 11:38:18 +04:00
|
|
|
#if defined(XP_MAC)
|
1998-12-09 01:45:42 +03:00
|
|
|
// Since the path on the macintosh does not uniquely specify a file (volumes
|
1999-02-25 23:49:47 +03:00
|
|
|
// can have the same name), stash the secret nsFileSpec, too.
|
|
|
|
nsFileSpec mFileSpec;
|
1998-12-08 05:15:50 +03:00
|
|
|
#endif
|
1998-12-09 01:45:42 +03:00
|
|
|
}; // class nsFilePath
|
1998-12-08 05:15:50 +03:00
|
|
|
|
1999-02-25 23:49:47 +03:00
|
|
|
//========================================================================================
|
2002-02-19 02:00:11 +03:00
|
|
|
class nsPersistentFileDescriptor
|
1999-03-10 01:33:36 +03:00
|
|
|
// To save information about a file's location in another file, initialize
|
|
|
|
// one of these from your nsFileSpec, and then write this out to your output stream.
|
|
|
|
// To retrieve the info, create one of these, read its value from an input stream.
|
|
|
|
// and then make an nsFileSpec from it.
|
1999-02-25 23:49:47 +03:00
|
|
|
//========================================================================================
|
|
|
|
{
|
|
|
|
public:
|
1999-03-20 02:09:39 +03:00
|
|
|
nsPersistentFileDescriptor() {}
|
1999-02-25 23:49:47 +03:00
|
|
|
// For use prior to reading in from a stream
|
1999-05-26 05:38:36 +04:00
|
|
|
nsPersistentFileDescriptor(const nsPersistentFileDescriptor& inEncodedData);
|
1999-02-25 23:49:47 +03:00
|
|
|
virtual ~nsPersistentFileDescriptor();
|
1999-05-26 05:38:36 +04:00
|
|
|
void operator = (const nsPersistentFileDescriptor& inEncodedData);
|
1999-02-25 23:49:47 +03:00
|
|
|
|
|
|
|
// Conversions
|
1999-05-26 05:38:36 +04:00
|
|
|
NS_EXPLICIT nsPersistentFileDescriptor(const nsFileSpec& inSpec);
|
|
|
|
void operator = (const nsFileSpec& inSpec);
|
1999-02-25 23:49:47 +03:00
|
|
|
|
1999-05-08 05:18:23 +04:00
|
|
|
// The following four functions are declared here (as friends). Their implementations
|
|
|
|
// are in mozilla/base/src/nsFileSpecStreaming.cpp.
|
|
|
|
|
|
|
|
friend nsresult Read(nsIInputStream* aStream, nsPersistentFileDescriptor&);
|
|
|
|
friend nsresult Write(nsIOutputStream* aStream, const nsPersistentFileDescriptor&);
|
1999-02-28 04:36:48 +03:00
|
|
|
// writes the data to a file
|
1999-05-26 05:38:36 +04:00
|
|
|
friend NS_COM nsInputStream& operator >> (nsInputStream&, nsPersistentFileDescriptor&);
|
1999-02-25 23:49:47 +03:00
|
|
|
// reads the data from a file
|
1999-05-26 05:38:36 +04:00
|
|
|
friend NS_COM nsOutputStream& operator << (nsOutputStream&, const nsPersistentFileDescriptor&);
|
1999-02-25 23:49:47 +03:00
|
|
|
// writes the data to a file
|
|
|
|
friend class nsFileSpec;
|
|
|
|
|
2002-02-19 02:00:11 +03:00
|
|
|
void GetData(nsAFlatCString& outData) const;
|
|
|
|
void SetData(const nsAFlatCString& inData);
|
1999-06-03 05:40:47 +04:00
|
|
|
void SetData(const char* inData, PRInt32 inSize);
|
1999-02-25 23:49:47 +03:00
|
|
|
|
1999-05-08 05:18:23 +04:00
|
|
|
//--------------------------------------------------
|
|
|
|
// Data
|
|
|
|
//--------------------------------------------------
|
|
|
|
|
1999-03-10 01:33:36 +03:00
|
|
|
protected:
|
1999-02-25 23:49:47 +03:00
|
|
|
|
1999-03-20 02:09:39 +03:00
|
|
|
nsSimpleCharString mDescriptorString;
|
1999-02-25 23:49:47 +03:00
|
|
|
|
|
|
|
}; // class nsPersistentFileDescriptor
|
|
|
|
|
1999-01-07 02:38:21 +03:00
|
|
|
//========================================================================================
|
1999-05-26 05:38:36 +04:00
|
|
|
class NS_COM nsDirectoryIterator
|
1999-01-07 02:38:21 +03:00
|
|
|
// Example:
|
|
|
|
//
|
1999-02-25 23:49:47 +03:00
|
|
|
// nsFileSpec parentDir(...); // directory over whose children we shall iterate
|
1999-07-27 02:09:42 +04:00
|
|
|
// for (nsDirectoryIterator i(parentDir, PR_FALSE); i.Exists(); i++)
|
1999-01-07 02:38:21 +03:00
|
|
|
// {
|
1999-03-20 02:09:39 +03:00
|
|
|
// // do something with i.Spec()
|
1999-01-07 02:38:21 +03:00
|
|
|
// }
|
|
|
|
//
|
1999-07-27 02:09:42 +04:00
|
|
|
// - or -
|
1999-01-07 02:38:21 +03:00
|
|
|
//
|
1999-07-27 02:09:42 +04:00
|
|
|
// for (nsDirectoryIterator i(parentDir, PR_TRUE); i.Exists(); i--)
|
1999-01-07 02:38:21 +03:00
|
|
|
// {
|
1999-03-20 02:09:39 +03:00
|
|
|
// // do something with i.Spec()
|
1999-01-07 02:38:21 +03:00
|
|
|
// }
|
1999-07-27 02:09:42 +04:00
|
|
|
// This one passed the PR_TRUE flag which will resolve any symlink encountered.
|
1999-01-07 02:38:21 +03:00
|
|
|
//========================================================================================
|
|
|
|
{
|
|
|
|
public:
|
1999-07-27 02:09:42 +04:00
|
|
|
nsDirectoryIterator( const nsFileSpec& parent,
|
|
|
|
PRBool resoveSymLinks);
|
2001-10-27 11:38:18 +04:00
|
|
|
#if !defined(XP_MAC)
|
1999-01-07 02:38:21 +03:00
|
|
|
// Macintosh currently doesn't allocate, so needn't clean up.
|
|
|
|
virtual ~nsDirectoryIterator();
|
|
|
|
#endif
|
1999-02-25 23:49:47 +03:00
|
|
|
PRBool Exists() const { return mExists; }
|
1999-01-07 02:38:21 +03:00
|
|
|
nsDirectoryIterator& operator ++(); // moves to the next item, if any.
|
|
|
|
nsDirectoryIterator& operator ++(int) { return ++(*this); } // post-increment.
|
|
|
|
nsDirectoryIterator& operator --(); // moves to the previous item, if any.
|
|
|
|
nsDirectoryIterator& operator --(int) { return --(*this); } // post-decrement.
|
1999-02-25 23:49:47 +03:00
|
|
|
operator nsFileSpec&() { return mCurrent; }
|
1999-03-20 02:09:39 +03:00
|
|
|
|
|
|
|
nsFileSpec& Spec() { return mCurrent; }
|
|
|
|
|
1999-01-07 02:38:21 +03:00
|
|
|
private:
|
1999-05-08 05:18:23 +04:00
|
|
|
|
|
|
|
#if defined(XP_MAC)
|
|
|
|
OSErr SetToIndex();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//--------------------------------------------------
|
|
|
|
// Data
|
|
|
|
//--------------------------------------------------
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
1999-02-25 23:49:47 +03:00
|
|
|
nsFileSpec mCurrent;
|
1999-02-28 04:36:48 +03:00
|
|
|
PRBool mExists;
|
1999-07-29 18:24:47 +04:00
|
|
|
PRBool mResoveSymLinks;
|
|
|
|
|
2001-10-27 11:38:18 +04:00
|
|
|
#if (defined(XP_UNIX) || defined(XP_BEOS) || defined (XP_WIN) || defined(XP_OS2))
|
1999-07-29 18:24:47 +04:00
|
|
|
nsFileSpec mStarting;
|
|
|
|
#endif
|
|
|
|
|
2001-10-27 11:38:18 +04:00
|
|
|
#if defined(XP_MAC)
|
|
|
|
short mVRefNum;
|
|
|
|
long mParID;
|
|
|
|
short mIndex;
|
|
|
|
short mMaxIndex;
|
|
|
|
#elif defined(XP_UNIX) || defined(XP_BEOS)
|
1999-07-29 18:24:47 +04:00
|
|
|
DIR* mDir;
|
2000-11-29 02:27:38 +03:00
|
|
|
#elif defined(XP_WIN) || defined(XP_OS2)
|
1999-04-02 00:06:46 +04:00
|
|
|
PRDir* mDir; // XXX why not use PRDir for Unix too?
|
1999-01-07 02:38:21 +03:00
|
|
|
#endif
|
|
|
|
}; // class nsDirectoryIterator
|
|
|
|
|
1999-04-10 04:27:09 +04:00
|
|
|
//========================================================================================
|
1999-05-26 05:38:36 +04:00
|
|
|
class NS_COM nsNSPRPath
|
1999-04-26 23:05:00 +04:00
|
|
|
// This class will allow you to pass any one of the nsFile* classes directly into NSPR
|
1999-04-10 04:27:09 +04:00
|
|
|
// without the need to worry about whether you have the right kind of filepath or not.
|
|
|
|
// It will also take care of cleaning up any allocated memory.
|
|
|
|
//========================================================================================
|
|
|
|
{
|
|
|
|
public:
|
1999-05-08 05:18:23 +04:00
|
|
|
NS_EXPLICIT nsNSPRPath(const nsFileSpec& inSpec)
|
|
|
|
: mFilePath(inSpec), modifiedNSPRPath(nsnull) {}
|
|
|
|
NS_EXPLICIT nsNSPRPath(const nsFileURL& inURL)
|
|
|
|
: mFilePath(inURL), modifiedNSPRPath(nsnull) {}
|
|
|
|
NS_EXPLICIT nsNSPRPath(const nsFilePath& inUnixPath)
|
|
|
|
: mFilePath(inUnixPath), modifiedNSPRPath(nsnull) {}
|
1999-04-10 04:27:09 +04:00
|
|
|
|
1999-05-08 05:18:23 +04:00
|
|
|
virtual ~nsNSPRPath();
|
1999-04-10 04:27:09 +04:00
|
|
|
|
1999-04-26 23:05:00 +04:00
|
|
|
operator const char*() const;
|
1999-05-08 05:18:23 +04:00
|
|
|
// Returns the path
|
|
|
|
// that NSPR file routines expect on each platform.
|
|
|
|
// Concerning constness, this can modify
|
|
|
|
// modifiedNSPRPath, but it's really just "mutable".
|
|
|
|
|
|
|
|
//--------------------------------------------------
|
|
|
|
// Data
|
|
|
|
//--------------------------------------------------
|
|
|
|
|
1999-04-10 04:27:09 +04:00
|
|
|
private:
|
1999-05-08 05:18:23 +04:00
|
|
|
|
|
|
|
nsFilePath mFilePath;
|
2000-11-29 02:27:38 +03:00
|
|
|
char* modifiedNSPRPath; // Currently used only on XP_WIN,XP_OS2
|
1999-05-08 05:18:23 +04:00
|
|
|
}; // class nsNSPRPath
|
|
|
|
|
2000-04-21 02:59:30 +04:00
|
|
|
|
|
|
|
NS_COM nsresult NS_FileSpecToIFile(nsFileSpec* fileSpec, nsILocalFile* *result);
|
|
|
|
|
1998-12-08 05:15:50 +03:00
|
|
|
#endif // _FILESPEC_H_
|