michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsISupports.idl" michael@0: michael@0: %{C++ michael@0: struct PRFileDesc; michael@0: struct PRLibrary; michael@0: #include michael@0: %} michael@0: michael@0: [ptr] native PRFileDescStar(PRFileDesc); michael@0: [ptr] native PRLibraryStar(PRLibrary); michael@0: [ptr] native FILE(FILE); michael@0: michael@0: interface nsISimpleEnumerator; michael@0: michael@0: /** michael@0: * An nsIFile is an abstract representation of a filename. It manages michael@0: * filename encoding issues, pathname component separators ('/' vs. '\\' michael@0: * vs. ':') and weird stuff like differing volumes with identical names, as michael@0: * on pre-Darwin Macintoshes. michael@0: * michael@0: * This file has long introduced itself to new hackers with this opening michael@0: * paragraph: michael@0: * michael@0: * This is the only correct cross-platform way to specify a file. michael@0: * Strings are not such a way. If you grew up on windows or unix, you michael@0: * may think they are. Welcome to reality. michael@0: * michael@0: * While taking the pose struck here to heart would be uncalled for, one michael@0: * may safely conclude that writing cross-platform code is an embittering michael@0: * experience. michael@0: * michael@0: * All methods with string parameters have two forms. The preferred michael@0: * form operates on UCS-2 encoded characters strings. An alternate michael@0: * form operates on characters strings encoded in the "native" charset. michael@0: * michael@0: * A string containing characters encoded in the native charset cannot michael@0: * be safely passed to javascript via xpconnect. Therefore, the "native michael@0: * methods" are not scriptable. michael@0: */ michael@0: [scriptable, uuid(a99a6a06-f90d-4659-8fce-c2f87feb1167), builtinclass] michael@0: interface nsIFile : nsISupports michael@0: { michael@0: /** michael@0: * Create Types michael@0: * michael@0: * NORMAL_FILE_TYPE - A normal file. michael@0: * DIRECTORY_TYPE - A directory/folder. michael@0: */ michael@0: const unsigned long NORMAL_FILE_TYPE = 0; michael@0: const unsigned long DIRECTORY_TYPE = 1; michael@0: michael@0: /** michael@0: * append[Native] michael@0: * michael@0: * This function is used for constructing a descendent of the michael@0: * current nsIFile. michael@0: * michael@0: * @param node michael@0: * A string which is intended to be a child node of the nsIFile. michael@0: * For the |appendNative| method, the node must be in the native michael@0: * filesystem charset. michael@0: */ michael@0: void append(in AString node); michael@0: [noscript] void appendNative(in ACString node); michael@0: michael@0: /** michael@0: * Normalize the pathName (e.g. removing .. and . components on Unix). michael@0: */ michael@0: void normalize(); michael@0: michael@0: /** michael@0: * create michael@0: * michael@0: * This function will create a new file or directory in the michael@0: * file system. Any nodes that have not been created or michael@0: * resolved, will be. If the file or directory already michael@0: * exists create() will return NS_ERROR_FILE_ALREADY_EXISTS. michael@0: * michael@0: * @param type michael@0: * This specifies the type of file system object michael@0: * to be made. The only two types at this time michael@0: * are file and directory which are defined above. michael@0: * If the type is unrecongnized, we will return an michael@0: * error (NS_ERROR_FILE_UNKNOWN_TYPE). michael@0: * michael@0: * @param permissions michael@0: * The unix style octal permissions. This may michael@0: * be ignored on systems that do not need to do michael@0: * permissions. michael@0: */ michael@0: void create(in unsigned long type, in unsigned long permissions); michael@0: michael@0: /** michael@0: * Accessor to the leaf name of the file itself. michael@0: * For the |nativeLeafName| method, the nativeLeafName must michael@0: * be in the native filesystem charset. michael@0: */ michael@0: attribute AString leafName; michael@0: [noscript] attribute ACString nativeLeafName; michael@0: michael@0: /** michael@0: * copyTo[Native] michael@0: * michael@0: * This will copy this file to the specified newParentDir. michael@0: * If a newName is specified, the file will be renamed. michael@0: * If 'this' is not created we will return an error michael@0: * (NS_ERROR_FILE_TARGET_DOES_NOT_EXIST). michael@0: * michael@0: * copyTo may fail if the file already exists in the destination michael@0: * directory. michael@0: * michael@0: * copyTo will NOT resolve aliases/shortcuts during the copy. michael@0: * michael@0: * @param newParentDir michael@0: * This param is the destination directory. If the michael@0: * newParentDir is null, copyTo() will use the parent michael@0: * directory of this file. If the newParentDir is not michael@0: * empty and is not a directory, an error will be michael@0: * returned (NS_ERROR_FILE_DESTINATION_NOT_DIR). For the michael@0: * |CopyToNative| method, the newName must be in the michael@0: * native filesystem charset. michael@0: * michael@0: * @param newName michael@0: * This param allows you to specify a new name for michael@0: * the file to be copied. This param may be empty, in michael@0: * which case the current leaf name will be used. michael@0: */ michael@0: void copyTo(in nsIFile newParentDir, in AString newName); michael@0: [noscript] void CopyToNative(in nsIFile newParentDir, in ACString newName); michael@0: michael@0: /** michael@0: * copyToFollowingLinks[Native] michael@0: * michael@0: * This function is identical to copyTo with the exception that, michael@0: * as the name implies, it follows symbolic links. The XP_UNIX michael@0: * implementation always follow symbolic links when copying. For michael@0: * the |CopyToFollowingLinks| method, the newName must be in the michael@0: * native filesystem charset. michael@0: */ michael@0: void copyToFollowingLinks(in nsIFile newParentDir, in AString newName); michael@0: [noscript] void copyToFollowingLinksNative(in nsIFile newParentDir, in ACString newName); michael@0: michael@0: /** michael@0: * moveTo[Native] michael@0: * michael@0: * A method to move this file or directory to newParentDir. michael@0: * If a newName is specified, the file or directory will be renamed. michael@0: * If 'this' is not created we will return an error michael@0: * (NS_ERROR_FILE_TARGET_DOES_NOT_EXIST). michael@0: * If 'this' is a file, and the destination file already exists, moveTo michael@0: * will replace the old file. michael@0: * This object is updated to refer to the new file. michael@0: * michael@0: * moveTo will NOT resolve aliases/shortcuts during the copy. michael@0: * moveTo will do the right thing and allow copies across volumes. michael@0: * moveTo will return an error (NS_ERROR_FILE_DIR_NOT_EMPTY) if 'this' is michael@0: * a directory and the destination directory is not empty. michael@0: * moveTo will return an error (NS_ERROR_FILE_ACCESS_DENIED) if 'this' is michael@0: * a directory and the destination directory is not writable. michael@0: * michael@0: * @param newParentDir michael@0: * This param is the destination directory. If the michael@0: * newParentDir is empty, moveTo() will rename the file michael@0: * within its current directory. If the newParentDir is michael@0: * not empty and does not name a directory, an error will michael@0: * be returned (NS_ERROR_FILE_DESTINATION_NOT_DIR). For michael@0: * the |moveToNative| method, the newName must be in the michael@0: * native filesystem charset. michael@0: * michael@0: * @param newName michael@0: * This param allows you to specify a new name for michael@0: * the file to be moved. This param may be empty, in michael@0: * which case the current leaf name will be used. michael@0: */ michael@0: void moveTo(in nsIFile newParentDir, in AString newName); michael@0: [noscript] void moveToNative(in nsIFile newParentDir, in ACString newName); michael@0: michael@0: /** michael@0: * renameTo michael@0: * michael@0: * This method is identical to moveTo except that if this file or directory michael@0: * is moved to a a different volume, it fails and returns an error michael@0: * (NS_ERROR_FILE_ACCESS_DENIED). michael@0: * This object will still point to the old location after renaming. michael@0: */ michael@0: void renameTo(in nsIFile newParentDir, in AString newName); michael@0: michael@0: /** michael@0: * This will try to delete this file. The 'recursive' flag michael@0: * must be PR_TRUE to delete directories which are not empty. michael@0: * michael@0: * This will not resolve any symlinks. michael@0: */ michael@0: void remove(in boolean recursive); michael@0: michael@0: /** michael@0: * Attributes of nsIFile. michael@0: */ michael@0: michael@0: attribute unsigned long permissions; michael@0: attribute unsigned long permissionsOfLink; michael@0: michael@0: /** michael@0: * File Times are to be in milliseconds from michael@0: * midnight (00:00:00), January 1, 1970 Greenwich Mean michael@0: * Time (GMT). michael@0: */ michael@0: attribute PRTime lastModifiedTime; michael@0: attribute PRTime lastModifiedTimeOfLink; michael@0: michael@0: /** michael@0: * WARNING! On the Mac, getting/setting the file size with nsIFile michael@0: * only deals with the size of the data fork. If you need to michael@0: * know the size of the combined data and resource forks use the michael@0: * GetFileSizeWithResFork() method defined on nsILocalFileMac. michael@0: */ michael@0: attribute int64_t fileSize; michael@0: readonly attribute int64_t fileSizeOfLink; michael@0: michael@0: /** michael@0: * target & path michael@0: * michael@0: * Accessor to the string path. The native version of these michael@0: * strings are not guaranteed to be a usable path to pass to michael@0: * NSPR or the C stdlib. There are problems that affect michael@0: * platforms on which a path does not fully specify a file michael@0: * because two volumes can have the same name (e.g., mac). michael@0: * This is solved by holding "private", native data in the michael@0: * nsIFile implementation. This native data is lost when michael@0: * you convert to a string. michael@0: * michael@0: * DO NOT PASS TO USE WITH NSPR OR STDLIB! michael@0: * michael@0: * target michael@0: * Find out what the symlink points at. Will give error michael@0: * (NS_ERROR_FILE_INVALID_PATH) if not a symlink. michael@0: * michael@0: * path michael@0: * Find out what the nsIFile points at. michael@0: * michael@0: * Note that the ACString attributes are returned in the michael@0: * native filesystem charset. michael@0: * michael@0: */ michael@0: readonly attribute AString target; michael@0: [noscript] readonly attribute ACString nativeTarget; michael@0: readonly attribute AString path; michael@0: [noscript] readonly attribute ACString nativePath; michael@0: michael@0: boolean exists(); michael@0: boolean isWritable(); michael@0: boolean isReadable(); michael@0: boolean isExecutable(); michael@0: boolean isHidden(); michael@0: boolean isDirectory(); michael@0: boolean isFile(); michael@0: boolean isSymlink(); michael@0: /** michael@0: * Not a regular file, not a directory, not a symlink. michael@0: */ michael@0: boolean isSpecial(); michael@0: michael@0: /** michael@0: * createUnique michael@0: * michael@0: * This function will create a new file or directory in the michael@0: * file system. Any nodes that have not been created or michael@0: * resolved, will be. If this file already exists, we try michael@0: * variations on the leaf name "suggestedName" until we find michael@0: * one that did not already exist. michael@0: * michael@0: * If the search for nonexistent files takes too long michael@0: * (thousands of the variants already exist), we give up and michael@0: * return NS_ERROR_FILE_TOO_BIG. michael@0: * michael@0: * @param type michael@0: * This specifies the type of file system object michael@0: * to be made. The only two types at this time michael@0: * are file and directory which are defined above. michael@0: * If the type is unrecongnized, we will return an michael@0: * error (NS_ERROR_FILE_UNKNOWN_TYPE). michael@0: * michael@0: * @param permissions michael@0: * The unix style octal permissions. This may michael@0: * be ignored on systems that do not need to do michael@0: * permissions. michael@0: */ michael@0: void createUnique(in unsigned long type, in unsigned long permissions); michael@0: michael@0: /** michael@0: * clone() michael@0: * michael@0: * This function will allocate and initialize a nsIFile object to the michael@0: * exact location of the |this| nsIFile. michael@0: * michael@0: * @param file michael@0: * A nsIFile which this object will be initialize michael@0: * with. michael@0: * michael@0: */ michael@0: nsIFile clone(); michael@0: michael@0: /** michael@0: * Will determine if the inFile equals this. michael@0: */ michael@0: boolean equals(in nsIFile inFile); michael@0: michael@0: /** michael@0: * Will determine if inFile is a descendant of this file michael@0: * If |recur| is true, look in subdirectories too michael@0: */ michael@0: boolean contains(in nsIFile inFile, in boolean recur); michael@0: michael@0: /** michael@0: * Parent will be null when this is at the top of the volume. michael@0: */ michael@0: readonly attribute nsIFile parent; michael@0: michael@0: /** michael@0: * Returns an enumeration of the elements in a directory. Each michael@0: * element in the enumeration is an nsIFile. michael@0: * michael@0: * @throws NS_ERROR_FILE_NOT_DIRECTORY if the current nsIFile does michael@0: * not specify a directory. michael@0: */ michael@0: readonly attribute nsISimpleEnumerator directoryEntries; michael@0: michael@0: /** michael@0: * initWith[Native]Path michael@0: * michael@0: * This function will initialize the nsIFile object. Any michael@0: * internal state information will be reset. michael@0: * michael@0: * @param filePath michael@0: * A string which specifies a full file path to a michael@0: * location. Relative paths will be treated as an michael@0: * error (NS_ERROR_FILE_UNRECOGNIZED_PATH). For michael@0: * initWithNativePath, the filePath must be in the native michael@0: * filesystem charset. michael@0: */ michael@0: void initWithPath(in AString filePath); michael@0: [noscript] void initWithNativePath(in ACString filePath); michael@0: michael@0: /** michael@0: * initWithFile michael@0: * michael@0: * Initialize this object with another file michael@0: * michael@0: * @param aFile michael@0: * the file this becomes equivalent to michael@0: */ michael@0: void initWithFile(in nsIFile aFile); michael@0: michael@0: /** michael@0: * followLinks michael@0: * michael@0: * This attribute will determine if the nsLocalFile will auto michael@0: * resolve symbolic links. By default, this value will be false michael@0: * on all non unix systems. On unix, this attribute is effectively michael@0: * a noop. michael@0: */ michael@0: attribute boolean followLinks; michael@0: michael@0: /** michael@0: * Flag for openNSPRFileDesc(), to hint to the OS that the file will be michael@0: * read sequentially with agressive readahead. michael@0: */ michael@0: const unsigned long OS_READAHEAD = 0x40000000; michael@0: michael@0: /** michael@0: * Flag for openNSPRFileDesc(). Deprecated and unreliable! michael@0: * Instead use NS_OpenAnonymousTemporaryFile() to create a temporary michael@0: * file which will be deleted upon close! michael@0: */ michael@0: const unsigned long DELETE_ON_CLOSE = 0x80000000; michael@0: michael@0: /** michael@0: * Return the result of PR_Open on the file. The caller is michael@0: * responsible for calling PR_Close on the result. michael@0: * michael@0: * @param flags the PR_Open flags from prio.h, plus optionally michael@0: * OS_READAHEAD or DELETE_ON_CLOSE. OS_READAHEAD is a hint to the michael@0: * OS that the file will be read sequentially with agressive michael@0: * readahead. DELETE_ON_CLOSE is unreliable on Windows and is deprecated. michael@0: * Instead use NS_OpenAnonymousTemporaryFile() to create a temporary michael@0: * file which will be deleted upon close. michael@0: */ michael@0: [noscript] PRFileDescStar openNSPRFileDesc(in long flags, in long mode); michael@0: michael@0: /** michael@0: * Return the result of fopen on the file. The caller is michael@0: * responsible for calling fclose on the result. michael@0: */ michael@0: [noscript] FILE openANSIFileDesc(in string mode); michael@0: michael@0: /** michael@0: * Return the result of PR_LoadLibrary on the file. The caller is michael@0: * responsible for calling PR_UnloadLibrary on the result. michael@0: */ michael@0: [noscript] PRLibraryStar load(); michael@0: michael@0: // number of bytes available on disk to non-superuser michael@0: readonly attribute int64_t diskSpaceAvailable; michael@0: michael@0: /** michael@0: * appendRelative[Native]Path michael@0: * michael@0: * Append a relative path to the current path of the nsIFile object. michael@0: * michael@0: * @param relativeFilePath michael@0: * relativeFilePath is a native relative path. For security reasons, michael@0: * this cannot contain .. or cannot start with a directory separator. michael@0: * For the |appendRelativeNativePath| method, the relativeFilePath michael@0: * must be in the native filesystem charset. michael@0: */ michael@0: void appendRelativePath(in AString relativeFilePath); michael@0: [noscript] void appendRelativeNativePath(in ACString relativeFilePath); michael@0: michael@0: /** michael@0: * Accessor to a null terminated string which will specify michael@0: * the file in a persistent manner for disk storage. michael@0: * michael@0: * The character set of this attribute is undefined. DO NOT TRY TO michael@0: * INTERPRET IT AS HUMAN READABLE TEXT! michael@0: */ michael@0: attribute ACString persistentDescriptor; michael@0: michael@0: /** michael@0: * reveal michael@0: * michael@0: * Ask the operating system to open the folder which contains michael@0: * this file or folder. This routine only works on platforms which michael@0: * support the ability to open a folder and is run async on Windows. michael@0: * This routine must be called on the main. michael@0: */ michael@0: void reveal(); michael@0: michael@0: /** michael@0: * launch michael@0: * michael@0: * Ask the operating system to attempt to open the file. michael@0: * this really just simulates "double clicking" the file on your platform. michael@0: * This routine only works on platforms which support this functionality michael@0: * and is run async on Windows. This routine must be called on the michael@0: * main thread. michael@0: */ michael@0: void launch(); michael@0: michael@0: /** michael@0: * getRelativeDescriptor michael@0: * michael@0: * Returns a relative file path in an opaque, XP format. It is therefore michael@0: * not a native path. michael@0: * michael@0: * The character set of the string returned from this function is michael@0: * undefined. DO NOT TRY TO INTERPRET IT AS HUMAN READABLE TEXT! michael@0: * michael@0: * @param fromFile michael@0: * the file from which the descriptor is relative. michael@0: * There is no defined result if this param is null. michael@0: */ michael@0: ACString getRelativeDescriptor(in nsIFile fromFile); michael@0: michael@0: /** michael@0: * setRelativeDescriptor michael@0: * michael@0: * Initializes the file to the location relative to fromFile using michael@0: * a string returned by getRelativeDescriptor. michael@0: * michael@0: * @param fromFile michael@0: * the file to which the descriptor is relative michael@0: * @param relative michael@0: * the relative descriptor obtained from getRelativeDescriptor michael@0: */ michael@0: void setRelativeDescriptor(in nsIFile fromFile, in ACString relativeDesc); michael@0: }; michael@0: michael@0: %{C++ michael@0: #ifdef MOZILLA_INTERNAL_API michael@0: #include "nsDirectoryServiceUtils.h" michael@0: #endif michael@0: %}