gecko-dev/xpcom/io/nsIFile.idl

304 lines
9.6 KiB
Plaintext
Raw Normal View History

1999-12-02 21:45:50 +00:00
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
1999-10-25 22:45:56 +00: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/
1999-08-21 07:38:26 +00: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.
1999-10-25 22:45:56 +00:00
*
2000-05-15 06:41:00 +00:00
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
1999-08-21 07:38:26 +00:00
*
2000-05-15 06:41:00 +00:00
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998-1999 Netscape Communications Corporation. All
* Rights Reserved.
1999-10-25 22:45:56 +00:00
*
2000-05-15 06:41:00 +00:00
* Contributor(s):
1999-10-25 22:45:56 +00:00
* Doug Turner <dougt@netscape.com>
* Christopher Blizzard <blizzard@mozilla.org>
1999-08-21 07:38:26 +00:00
*/
1999-10-25 22:45:56 +00:00
1999-08-21 07:38:26 +00:00
// 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"
1999-12-02 21:45:50 +00:00
interface nsISimpleEnumerator;
1999-08-21 07:38:26 +00:00
[scriptable, uuid(c8c0a080-0868-11d3-915f-d9d889d48e3c)]
interface nsIFile : nsISupports
{
/**
* Create Types
*
2000-05-15 06:41:00 +00:00
* NORMAL_FILE_TYPE - A normal file.
* DIRECTORY_TYPE - A directory/folder.
*/
const unsigned long NORMAL_FILE_TYPE = 0;
const unsigned long DIRECTORY_TYPE = 1;
2000-05-15 06:41:00 +00:00
/**
* appendPath
*
2000-01-24 21:28:28 +00:00
* This function is used for constructing a descendant of the
2000-05-15 06:41:00 +00:00
* current nsIFile.
*
2000-05-15 06:41:00 +00:00
* @param relativePath
* A string which is intented to be a child node of the
* nsIFile.
*/
2000-01-24 21:28:28 +00:00
void append([const] in string node);
void appendUnicode([const] in wstring node);
2000-01-24 21:28:28 +00:00
/**
* Normalize the pathName (e.g. removing .. and . components on Unix).
*/
1999-12-02 21:45:50 +00:00
void normalize();
/**
* create
*
2000-05-15 06:41:00 +00:00
* This function will create a new file or directory in the
* file system. Any nodes that have not been created or
* resolved, will be. If the file or directory already
* exists create() will return NS_ERROR_FILE_ALREADY_EXISTS.
2000-05-15 06:41:00 +00:00
*
* @param type
1999-12-02 21:45:50 +00:00
* This specifies the type of file system object
* to be made. The only two types at this time
* are file and directory which are defined above.
* If the type is unrecongnized, we will return an
* error (NS_ERROR_FILE_UNKNOWN_TYPE).
*
* @param permissions
1999-12-02 21:45:50 +00:00
* This unix style octal permissions. This may
* be ignored on systems that do not need to do
* permissions.
*/
2000-05-15 06:41:00 +00:00
1999-12-02 21:45:50 +00:00
void create(in unsigned long type, in unsigned long permissions);
/**
2000-05-15 06:41:00 +00:00
* Accessor to the leaf name of the file itself.
*/
2000-01-24 21:28:28 +00:00
attribute string leafName;
attribute wstring unicodeLeafName;
2000-05-15 06:41:00 +00:00
/**
* copyTo
*
2000-05-15 06:41:00 +00:00
* This will copy this file to the specified newParentDir.
* If a newName is specified, the file will be renamed.
2000-05-15 06:41:00 +00:00
* If 'this' is not created we will return an error
* (NS_ERROR_FILE_TARGET_DOES_NOT_EXIST).
*
* copyTo will NOT resolve aliases/shortcuts during the copy.
*
* @param newParentDir
2000-05-15 06:41:00 +00:00
* This param is the destination directory. If the
* newParentDir is nsnull, copyTo() will simply
* rename the file. If the newParentDir is not
* null and does not exists, an error will be
1999-12-02 21:45:50 +00:00
* returned (NS_ERROR_FILE_DESTINATION_NOT_DIR)
*
* @param newName
1999-12-02 21:45:50 +00:00
* This param allows you to specify a new name
* for the file to be copied. This can be nsnull.
*
*/
1999-12-02 21:45:50 +00:00
void copyTo(in nsIFile newParentDir, [const] in string newName);
void copyToUnicode(in nsIFile newParentDir, [const] in wstring newName);
2000-05-15 06:41:00 +00:00
/**
* copyToFollowingLinks
*
* This function is identical to copyTo except it, as
* the name implies, follows symbolic links.
*/
1999-12-02 21:45:50 +00:00
void copyToFollowingLinks(in nsIFile newParentDir, [const] in string newName);
void copyToFollowingLinksUnicode(in nsIFile newParentDir, [const] in wstring newName);
2000-05-15 06:41:00 +00:00
/**
* moveTo
*
2000-05-15 06:41:00 +00:00
* This will move this file to the specified newParentDir.
* If a newName is specified, the file will be renamed.
2000-05-15 06:41:00 +00:00
* If 'this' is not created we will return an error
* (NS_ERROR_FILE_TARGET_DOES_NOT_EXIST).
*
* moveTo will NOT resolve aliases/shortcuts during the copy.
* moveTo will do the right thing and allow copies across
* volumes.
*
* @param newParentDir
2000-05-15 06:41:00 +00:00
* This param is the destination directory. If the
* newParentDir is nsnull, moveTo() will simply
* rename the file. If the newParentDir is not
* null and does not exists, an error will be
1999-12-02 21:45:50 +00:00
* returned (NS_ERROR_FILE_DESTINATION_NOT_DIR)
*
* @param newName
1999-12-02 21:45:50 +00:00
* This param allows you to specify a new name
* for the file to be moved. This can be nsnull.
*
*/
1999-12-02 21:45:50 +00:00
void moveTo(in nsIFile newParentDir, [const] in string newName);
void moveToUnicode(in nsIFile newParentDir, [const] in wstring newName);
/**
* This will try to execute this file. It will not block for
* execution. 'args' will be passed through on the command line
* if the OS supports that.
*/
void spawn([array, size_is(count)] in string args, in unsigned long count);
2000-05-15 06:41:00 +00:00
/**
* This will try to delete this file. The 'recursive' flag
* must be PR_TRUE to delete directories which are not empty.
*
* This will not resolve any symlinks.
*/
1999-12-02 21:45:50 +00:00
void delete(in boolean recursive);
1999-08-21 07:38:26 +00:00
/**
* Attributes of nsIFile.
*/
2000-05-15 06:41:00 +00:00
1999-12-02 21:45:50 +00:00
attribute unsigned long permissions;
attribute unsigned long permissionsOfLink;
2000-05-15 06:41:00 +00:00
/**
2000-05-21 05:42:57 +00:00
* File Times are to be in milliseconds from
2000-05-15 06:41:00 +00:00
* midnight (00:00:00), January 1, 1970 Greenwich Mean
* Time (GMT).
*/
1999-12-02 21:45:50 +00:00
attribute PRInt64 lastModificationDate;
attribute PRInt64 lastModificationDateOfLink;
2000-05-15 06:41:00 +00:00
/**
* WARNING! On the Mac getting/setting the file size with nsIFile
* only deals with the size of the data fork. If you need to
* know the size of the combined data and resource forks use the
* GetFileSizeWithResFork() method defined in nsILocalFileMac.h
*/
1999-12-02 21:45:50 +00:00
attribute PRInt64 fileSize;
readonly attribute PRInt64 fileSizeOfLink;
2000-05-15 06:41:00 +00:00
/**
* target & path
*
* Accessor to the string path. These strings are
2000-05-15 06:41:00 +00:00
* not guaranteed to be a usable path to pass to NSPR
* or the C stdlib. There are problems that affect
* platforms on which a path does not fully specify a
* file, because two volumes can have the same name.
* This is solved by holding "private", native data in
* the nsIFile implementation. This native data is lost
* when you convert to a string.
*
* DO NOT PASS TO USE WITH NSPR OR STDLIB.
*
* target:
* Find out what the symlink points at. Will give error
* (NS_ERROR_FILE_INVALID_PATH) if not a symlink.
*
* path:
* Find out what the nsIFile points at.
*/
1999-12-02 21:45:50 +00:00
readonly attribute string target;
readonly attribute wstring unicodeTarget;
1999-12-02 21:45:50 +00:00
readonly attribute string path;
readonly attribute wstring unicodePath;
2000-05-15 06:41:00 +00:00
1999-12-02 21:45:50 +00:00
boolean exists();
boolean isWritable();
boolean isReadable();
boolean isExecutable();
boolean isHidden();
boolean isDirectory();
boolean isFile();
boolean isSymlink();
/**
* Not a regular file, not a directory, not a symlink.
*/
2000-05-15 06:41:00 +00:00
boolean isSpecial();
/**
* clone()
*
* This function will allocate and initialize a nsIFile object to the
* exact location of the |this| nsIFile.
2000-05-15 06:41:00 +00:00
*
* @param file
* A nsIFile which this object will be initialize
* with.
*
*/
nsIFile clone();
/**
* Will determine if the inFile equals this.
*/
1999-12-02 21:45:50 +00:00
boolean equals(in nsIFile inFile);
2000-05-15 06:41:00 +00:00
/**
* Will determine if the inFile is a descendant
2000-05-15 06:41:00 +00:00
* If |recur| is true, it will descend subdirectories looking for
*/
boolean contains(in nsIFile inFile, in boolean recur);
1999-12-02 21:45:50 +00:00
/**
* Parent will be nsnull when this is at the top of the volume.
*/
readonly attribute nsIFile parent;
1999-12-02 21:45:50 +00:00
/**
* Returns an enumeration of the elements in a directory. Each
2000-05-15 06:41:00 +00:00
* element in the enumeration is an nsIFile.
1999-12-02 21:45:50 +00:00
*
* @return NS_ERROR_FILE_NOT_DIRECTORY if the current nsIFile does
* not specify a directory.
2000-05-15 06:41:00 +00:00
*/
readonly attribute nsISimpleEnumerator directoryEntries;
1999-08-21 07:38:26 +00:00
};
%{C++
#define NS_FILE_PROGID "component://netscape/file"
#define NS_FILE_CLASSNAME "File Specification"
2000-01-24 21:28:28 +00:00
////////////////////////////////////////////////////////////////////////////////
// Special Directories
#include "nsIServiceManager.h"
#include "nsIProperties.h"
#include "nsCOMPtr.h"
2000-01-28 23:38:20 +00:00
#define NS_DIRECTORY_SERVICE_CID {0xf00152d0,0xb40b,0x11d3,{0x8c, 0x9c, 0x00, 0x00, 0x64, 0x65, 0x73, 0x74}}
2000-01-24 21:28:28 +00:00
inline nsresult
NS_GetSpecialDirectory(const char* specialDirName, nsIFile* *result)
{
nsresult rv;
static NS_DEFINE_CID(kDirectoryServiceCID, NS_DIRECTORY_SERVICE_CID);
NS_WITH_SERVICE(nsIProperties, serv, kDirectoryServiceCID, &rv);
if (NS_FAILED(rv)) return rv;
2000-05-15 06:41:00 +00:00
2000-01-24 21:28:28 +00:00
nsCOMPtr<nsISupports> dir;
rv = serv->Get(specialDirName, NS_GET_IID(nsIFile), getter_AddRefs(dir));
if (NS_FAILED(rv)) return rv;
2000-01-24 21:28:28 +00:00
*result = (nsIFile*)dir.get();
if (*result)
NS_ADDREF(*result);
2000-01-24 21:28:28 +00:00
return NS_OK;
}
1999-12-02 21:45:50 +00:00
%}