mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-02 07:05:24 +00:00
177 lines
5.4 KiB
Plaintext
177 lines
5.4 KiB
Plaintext
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
*
|
|
* The contents of this file are subject to the Netscape Public License
|
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
|
* http://www.mozilla.org/NPL/
|
|
*
|
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
|
* for the specific language governing rights and limitations under the
|
|
* NPL.
|
|
*
|
|
* The Initial Developer of this code under the NPL is Netscape
|
|
* Communications Corporation. Portions created by Netscape are
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
|
* Reserved.
|
|
*/
|
|
|
|
// This is the only correct cross-platform way to specify a file.
|
|
// Strings are not such a way. If you grew up on windows or unix, you
|
|
// may think they are. Welcome to reality.
|
|
|
|
#include "nsISupports.idl"
|
|
|
|
%{C++
|
|
#include "nsFileSpec.h" // for factory method
|
|
#include "nsIComponentManager.h" // for CreateInstance
|
|
%}
|
|
|
|
interface nsIFileURL;
|
|
interface nsIFilePath;
|
|
interface nsIOutputStream;
|
|
interface nsIInputStream;
|
|
|
|
// Define Progid and CID
|
|
%{C++
|
|
// {A5740FA2-146E-11d3-B00D-00C04FC2E79B}
|
|
#define NS_FILESPEC_CID \
|
|
{ 0xa5740fa2, 0x146e, 0x11d3, { 0xb0, 0xd, 0x0, 0xc0, 0x4f, 0xc2, 0xe7, 0x9b } }
|
|
|
|
#define NS_FILESPEC_PROGID "component://netscape/filespec"
|
|
#define NS_FILESPEC_CLASSNAME "File Spec"
|
|
|
|
%}
|
|
|
|
native nsFileSpec(nsFileSpec);
|
|
|
|
[scriptable, uuid(d8c0a080-0868-11d3-915f-d9d889d48e3c)]
|
|
interface nsIFileSpec : nsISupports
|
|
{
|
|
void fromFileSpec([const] in nsIFileSpec original);
|
|
|
|
attribute string URLString;
|
|
attribute string UnixStyleFilePath;
|
|
attribute string PersistentDescriptorString;
|
|
attribute string NativePath;
|
|
|
|
readonly attribute string NSPRPath;
|
|
|
|
void error();
|
|
|
|
boolean isValid();
|
|
boolean failed();
|
|
|
|
attribute string LeafName;
|
|
|
|
readonly attribute nsIFileSpec Parent;
|
|
readonly attribute nsIInputStream InputStream;
|
|
readonly attribute nsIOutputStream OutputStream;
|
|
[nonscriptable] readonly attribute nsFileSpec FileSpec;
|
|
|
|
attribute string FileContents;
|
|
|
|
void makeUnique();
|
|
void makeUniqueWithSuggestedName(in string suggestedName);
|
|
|
|
readonly attribute unsigned long ModDate;
|
|
boolean modDateChanged(in unsigned long oldStamp);
|
|
|
|
boolean isDirectory();
|
|
boolean isFile();
|
|
boolean exists();
|
|
|
|
readonly attribute unsigned long FileSize;
|
|
readonly attribute unsigned long DiskSpaceAvailable;
|
|
|
|
void AppendRelativeUnixPath(in string relativePath);
|
|
|
|
void createDir();
|
|
void rename([const] in string newLeafName);
|
|
void copyToDir([const] in nsIFileSpec newParentDir);
|
|
void moveToDir([const] in nsIFileSpec newParentDir);
|
|
void execute([const] in string args);
|
|
|
|
void openStreamForReading();
|
|
void openStreamForWriting();
|
|
void openStreamForReadingAndWriting();
|
|
void closeStream();
|
|
boolean isStreamOpen();
|
|
|
|
boolean eof();
|
|
long read(inout string buffer, in long requestedCount);
|
|
void readLine(inout string line, in long bufferSize, out boolean wasTruncated);
|
|
%{C++
|
|
// Check eof() before each call.
|
|
// CAUTION: false result only indicates line was truncated
|
|
// to fit buffer, or an error occurred (OTHER THAN eof).
|
|
%}
|
|
long write(in string data, in long requestedCount);
|
|
void flush();
|
|
|
|
void seek(in long offset);
|
|
long tell();
|
|
void endline();
|
|
|
|
};
|
|
|
|
// Define Progid and CID
|
|
%{C++
|
|
// {a3020981-2018-11d3-915f-a957795b7ebc}
|
|
#define NS_DIRECTORYITERATOR_CID \
|
|
{ 0xa3020981, 0x2018, 0x11d3, { 0x91, 0x5f, 0xa9, 0x57, 0x79, 0x5b, 0x7e, 0xbc } }
|
|
|
|
#define NS_DIRECTORYITERATOR_PROGID "component://netscape/directoryiterator"
|
|
#define NS_DIRECTORYITERATOR_CLASSNAME "nsIDirectoryIterator"
|
|
%}
|
|
|
|
[scriptable, uuid(d8c0a083-0868-11d3-915f-d9d889d48e3c)]
|
|
interface nsIDirectoryIterator : nsISupports
|
|
{
|
|
void Init(in nsIFileSpec parent);
|
|
boolean exists();
|
|
void next();
|
|
readonly attribute nsIFileSpec currentSpec;
|
|
};
|
|
|
|
%{C++
|
|
// Factory methods if you link with xpcom
|
|
NS_COM nsresult NS_NewFileSpecWithSpec(nsFileSpec aSrcFileSpec, nsIFileSpec **result);
|
|
NS_COM nsresult NS_NewFileSpec(nsIFileSpec** result);
|
|
NS_COM nsresult NS_NewDirectoryIterator(nsIDirectoryIterator** result);
|
|
|
|
// Factory methods if you do not link with xpcom. Consider using these
|
|
// with nsCOMPtr, too (though it requires linking with xpcom).
|
|
inline nsIFileSpec* NS_CreateFileSpec()
|
|
{
|
|
// #include nsIComponentManager.h
|
|
nsIFileSpec* spec = nsnull;
|
|
nsresult rv = nsComponentManager::CreateInstance(
|
|
(const char*)NS_FILESPEC_PROGID,
|
|
(nsISupports*)nsnull,
|
|
(const nsID&)nsIFileSpec::GetIID(),
|
|
(void**)&spec);
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "ERROR: Could not make a file spec.");
|
|
return spec;
|
|
}
|
|
|
|
inline nsIDirectoryIterator* NS_CreateDirectoryIterator()
|
|
{
|
|
// #include nsIComponentManager.h
|
|
nsIDirectoryIterator* iter = nsnull;
|
|
nsresult rv = nsComponentManager::CreateInstance(
|
|
(const char*)NS_DIRECTORYITERATOR_PROGID,
|
|
(nsISupports*)nsnull,
|
|
(const nsID&)nsIDirectoryIterator::GetIID(),
|
|
(void**)&iter);
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "ERROR: Could not make a directory iterator.");
|
|
return iter;
|
|
}
|
|
|
|
#define NS_BOOL_ACCESSOR(_method) { PRBool yes; return NS_SUCCEEDED(f->_method(&yes)) && yes; }
|
|
inline PRBool Exists(nsIFileSpec* f) NS_BOOL_ACCESSOR(exists)
|
|
inline PRBool Exists(nsIDirectoryIterator* f) NS_BOOL_ACCESSOR(exists)
|
|
inline PRBool IsDirectory(nsIFileSpec* f) NS_BOOL_ACCESSOR(isDirectory)
|
|
|
|
%}
|