Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Enumerations | Functions | Variables
nsLocalFileWin.cpp File Reference
#include "nsCOMPtr.h"
#include "nsMemory.h"
#include "nsLocalFile.h"
#include "nsIDirectoryEnumerator.h"
#include "nsNativeCharsetUtils.h"
#include "nsWinAPIs.h"
#include "nsISimpleEnumerator.h"
#include "nsIComponentManager.h"
#include "prtypes.h"
#include "prio.h"
#include "private/pprio.h"
#include "prprf.h"
#include "prmem.h"
#include "nsXPIDLString.h"
#include "nsReadableUtils.h"
#include <direct.h>
#include <windows.h>
#include "shellapi.h"
#include "shlguid.h"
#include <io.h>
#include <stdio.h>
#include <stdlib.h>
#include <mbstring.h>
#include "prproces.h"
#include "nsITimelineService.h"
#include "nsAutoLock.h"
#include "SpecialSystemDirectory.h"

Go to the source code of this file.

Classes

class  nsDriveEnumerator
class  ShortcutResolver
struct  _MDFileDesc
struct  PRFilePrivate
struct  nsDir
class  nsDirEnumerator
struct  LANGANDCODEPAGE
union  nsDir.entry

Defines

#define INVALID_SET_FILE_POINTER   ((DWORD)-1)
#define INVALID_FILE_ATTRIBUTES   ((DWORD)-1)
#define TOUPPER(u)

Enumerations

enum  _PRTriStateBool {
  _PR_TRI_TRUE = 1, _PR_TRI_FALSE = 0, _PR_TRI_UNKNOWN = -1, _PR_TRI_TRUE = 1,
  _PR_TRI_FALSE = 0, _PR_TRI_UNKNOWN = -1
}

Functions

static nsresult NS_CreateShortcutResolver ()
static void NS_DestroyShortcutResolver ()
static nsresult ConvertWinError (DWORD winErr)
static __int64 MyFileSeek64 (HANDLE aHandle, __int64 aDistance, DWORD aMoveMethod)
static PRBool IsShortcutPath (const nsAString &path)
static nsresult OpenFile (const nsAFlatString &name, PRIntn osflags, PRIntn mode, PRFileDesc **fd)
static void FileTimeToPRTime (const FILETIME *filetime, PRTime *prtm)
static nsresult GetFileInfo (const nsAFlatString &name, PRFileInfo64 *info)
static nsresult OpenDir (const nsAFlatString &name, nsDir **dir)
static nsresult ReadDir (nsDir *dir, PRDirFlags flags, nsString &name)
static nsresult CloseDir (nsDir *d)
nsresult NS_NewLocalFile (const nsAString &path, PRBool followLinks, nsILocalFile **result)
 Public Method to create an instance of a nsILocalFile.
nsresult NS_NewNativeLocalFile (const nsACString &path, PRBool followLinks, nsILocalFile **result)

Variables

static ShortcutResolvergResolver = nsnull

Class Documentation

struct _MDFileDesc

Definition at line 158 of file _beos.h.

Collaboration diagram for _MDFileDesc:
Class Members
PRBool accepted_socket
int connectReturnError
int connectReturnValue
PRBool connectValueValid
OTReason disconnectError
PRBool doListen
PRPackedBool exceptReady
PRBool io_model_committed
_MDSocketCallerInfo misc
PRLock * miscLock
PRPackedBool orderlyDisconnect
int osfd
PRInt32 osfd
PRNetAddr peer_addr
_MDSocketCallerInfo read
PRPackedBool readReady
PRInt32 sock_state
PRBool sync_file_io
_MDSocketCallerInfo write
PRPackedBool writeReady
struct PRFilePrivate

Definition at line 1728 of file primpl.h.

Collaboration diagram for PRFilePrivate:
Class Members
PRBool appendMode
_PRTriStateBool inheritable
PRIntn lockCount
_MDFileDesc md
PRFileDesc * next
PRBool nonblocking
PRInt32 rcvinprogress
PRInt32 rcvreq
RcvState rcvstate
PRInt32 state
PRFileDesc * writeEnd
PRInt32 xmtinprogress
PRInt32 xmtreq
XmtState xmtstate
struct nsDir

Definition at line 510 of file nsLocalFileWin.cpp.

Class Members
union nsDir entry
PRBool firstEntry
HANDLE handle
struct LANGANDCODEPAGE

Definition at line 1358 of file nsLocalFileWin.cpp.

Class Members
WORD wCodePage
WORD wLanguage
union nsDir.entry

Definition at line 513 of file nsLocalFileWin.cpp.

Class Members
WIN32_FIND_DATAA dataA
WIN32_FIND_DATAW dataW

Define Documentation

Definition at line 320 of file nsLocalFileWin.cpp.

Definition at line 316 of file nsLocalFileWin.cpp.

#define TOUPPER (   u)
Value:
(((u) >= L'a' && (u) <= L'z') ? \
                    (u) - (L'a' - L'A') : (u))

Definition at line 1166 of file nsLocalFileWin.cpp.


Enumeration Type Documentation

Enumerator:
_PR_TRI_TRUE 
_PR_TRI_FALSE 
_PR_TRI_UNKNOWN 
_PR_TRI_TRUE 
_PR_TRI_FALSE 
_PR_TRI_UNKNOWN 

Definition at line 363 of file nsLocalFileWin.cpp.


Function Documentation

static nsresult CloseDir ( nsDir d) [static]

Definition at line 625 of file nsLocalFileWin.cpp.

{
    NS_ENSURE_ARG(d);

    BOOL isOk = FindClose(d->handle);
    PR_DELETE(d);
    return isOk ? NS_OK : ConvertWinError(GetLastError());
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult ConvertWinError ( DWORD  winErr) [static]

Definition at line 265 of file nsLocalFileWin.cpp.

{
    nsresult rv;

    switch (winErr)
    {
        case ERROR_FILE_NOT_FOUND:
        case ERROR_PATH_NOT_FOUND:
        case ERROR_INVALID_DRIVE:
            rv = NS_ERROR_FILE_NOT_FOUND;
            break;
        case ERROR_ACCESS_DENIED:
        case ERROR_NOT_SAME_DEVICE:
            rv = NS_ERROR_FILE_ACCESS_DENIED;
            break;
        case ERROR_NOT_ENOUGH_MEMORY:
        case ERROR_INVALID_BLOCK:
        case ERROR_INVALID_HANDLE:
        case ERROR_ARENA_TRASHED:
            rv = NS_ERROR_OUT_OF_MEMORY;
            break;
        case ERROR_CURRENT_DIRECTORY:
            rv = NS_ERROR_FILE_DIR_NOT_EMPTY;
            break;
        case ERROR_WRITE_PROTECT:
            rv = NS_ERROR_FILE_READ_ONLY;
            break;
        case ERROR_HANDLE_DISK_FULL:
            rv = NS_ERROR_FILE_TOO_BIG;
            break;
        case ERROR_FILE_EXISTS:
        case ERROR_ALREADY_EXISTS:
        case ERROR_CANNOT_MAKE:
            rv = NS_ERROR_FILE_ALREADY_EXISTS;
            break;
        case ERROR_FILENAME_EXCED_RANGE:
            rv = NS_ERROR_FILE_NAME_TOO_LONG;
            break;
        case 0:
            rv = NS_OK;
            break;
        default:
            rv = NS_ERROR_FAILURE;
            break;
    }
    return rv;
}

Here is the caller graph for this function:

static void FileTimeToPRTime ( const FILETIME *  filetime,
PRTime prtm 
) [static]

Definition at line 453 of file nsLocalFileWin.cpp.

{
#ifdef __GNUC__
    const PRTime _pr_filetime_offset = 116444736000000000LL;
#else
    const PRTime _pr_filetime_offset = 116444736000000000i64;
#endif

    PR_ASSERT(sizeof(FILETIME) == sizeof(PRTime));
    ::CopyMemory(prtm, filetime, sizeof(PRTime));
#ifdef __GNUC__
    *prtm = (*prtm - _pr_filetime_offset) / 10LL;
#else
    *prtm = (*prtm - _pr_filetime_offset) / 10i64;
#endif
}

Here is the caller graph for this function:

static nsresult GetFileInfo ( const nsAFlatString name,
PRFileInfo64 info 
) [static]

Definition at line 473 of file nsLocalFileWin.cpp.

{
    WIN32_FILE_ATTRIBUTE_DATA fileData;

    if (name.IsEmpty() || name.FindCharInSet(L"?*") != kNotFound)
        return NS_ERROR_INVALID_ARG;

    // GetFileAttributesExW/A were confirmed to work correctly
    // with a filename ending with a slash and a root directory except on Win95
    // without MS IE 4 or later (see |mGetFileAttributesEx| in nsWinAPIs.cpp.)
    // Therefore, we don't need to add a fallback as done in 
    // _PR_MD_GETFILEINFO64 (w95io.c)
    if (!nsWinAPIs::mGetFileAttributesEx(name.get(), GetFileExInfoStandard,
                                         &fileData))
        return ConvertWinError(GetLastError());

    if (fileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
        info->type = PR_FILE_DIRECTORY;
    } else {
        info->type = PR_FILE_FILE;
    }

    info->size = fileData.nFileSizeHigh;
    info->size = (info->size << 32) + fileData.nFileSizeLow;

    FileTimeToPRTime(&fileData.ftLastWriteTime, &info->modifyTime);

    if (0 == fileData.ftCreationTime.dwLowDateTime &&
            0 == fileData.ftCreationTime.dwHighDateTime) {
        info->creationTime = info->modifyTime;
    } else {
        FileTimeToPRTime(&fileData.ftCreationTime, &info->creationTime);
    }

    return NS_OK;
}

Here is the call graph for this function:

static PRBool IsShortcutPath ( const nsAString &  path) [static]

Definition at line 340 of file nsLocalFileWin.cpp.

{
    // Under Windows, the shortcuts are just files with a ".lnk" extension. 
    // Note also that we don't resolve links in the middle of paths.
    // i.e. "c:\foo.lnk\bar.txt" is invalid.
    NS_ABORT_IF_FALSE(!path.IsEmpty(), "don't pass an empty string");
    PRInt32 len = path.Length();
    return (StringTail(path, 4).LowerCaseEqualsASCII(".lnk"));
}

Here is the call graph for this function:

static __int64 MyFileSeek64 ( HANDLE  aHandle,
__int64  aDistance,
DWORD  aMoveMethod 
) [static]

Definition at line 325 of file nsLocalFileWin.cpp.

{
    LARGE_INTEGER li;

    li.QuadPart = aDistance;
    li.LowPart = SetFilePointer(aHandle, li.LowPart, &li.HighPart, aMoveMethod);
    if (li.LowPart == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR)
    {
        li.QuadPart = -1;
    }

    return li.QuadPart;
}
static nsresult NS_CreateShortcutResolver ( ) [static]

Definition at line 242 of file nsLocalFileWin.cpp.

Here is the call graph for this function:

static void NS_DestroyShortcutResolver ( ) [static]

Definition at line 251 of file nsLocalFileWin.cpp.

{
    delete gResolver;
    gResolver = nsnull;
}
nsresult NS_NewLocalFile ( const nsAString &  path,
PRBool  followLinks,
nsILocalFile **  result 
)

Public Method to create an instance of a nsILocalFile.

This function may be called prior to NS_InitXPCOM.

FROZEN

Parameters:
pathA string which specifies a full file path to a location. Relative paths will be treated as an error (NS_ERROR_FILE_UNRECOGNIZED_PATH). |NS_NewNativeLocalFile|'s path must be in the filesystem charset.
followLinksThis attribute will determine if the nsLocalFile will auto resolve symbolic links. By default, this value will be false on all non unix systems. On unix, this attribute is effectively a noop.
resultInterface pointer to a new instance of an nsILocalFile
Returns:
NS_OK for success; other error codes indicate a failure.

Definition at line 2765 of file nsLocalFileWin.cpp.

{
    nsLocalFile* file = new nsLocalFile();
    if (file == nsnull)
        return NS_ERROR_OUT_OF_MEMORY;
    NS_ADDREF(file);

    file->SetFollowLinks(followLinks);

    if (!path.IsEmpty()) {
        nsresult rv = file->InitWithPath(path);
        if (NS_FAILED(rv)) {
            NS_RELEASE(file);
            return rv;
        }
    }

    *result = file;
    return NS_OK;
}

Here is the call graph for this function:

nsresult NS_NewNativeLocalFile ( const nsACString &  path,
PRBool  followLinks,
nsILocalFile **  result 
)

Definition at line 2915 of file nsLocalFileWin.cpp.

{
    nsAutoString buf;
    nsresult rv = NS_CopyNativeToUnicode(path, buf);
    if (NS_FAILED(rv)) {
        *result = nsnull;
        return rv;
    }
    return NS_NewLocalFile(buf, followLinks, result);
}

Here is the call graph for this function:

static nsresult OpenDir ( const nsAFlatString name,
nsDir **  dir 
) [static]

Definition at line 522 of file nsLocalFileWin.cpp.

{
    NS_ENSURE_ARG_POINTER(dir);

    *dir = nsnull;
    if (name.Length() + 3 >= MAX_PATH)
        return NS_ERROR_FILE_NAME_TOO_LONG;

    nsDir *d  = PR_NEW(nsDir);
    if (!d)
        return NS_ERROR_OUT_OF_MEMORY;

    nsAutoString filename(name);

     //If 'name' ends in a slash or backslash, do not append
     //another backslash.
    if (filename.Last() == L'/' || filename.Last() == L'\\')
        filename.AppendASCII("*");
    else 
        filename.AppendASCII("\\*");

    filename.ReplaceChar(L'/', L'\\');

    if (NS_UseUnicode()) 
        d->handle = ::FindFirstFileW(filename.get(), &(d->entry.dataW) );
    else
    {
        nsCAutoString filenameA;
        NS_CopyUnicodeToNative(filename, filenameA);
        d->handle = ::FindFirstFileA(filenameA.get(), &(d->entry.dataA) );
    }
    if ( d->handle == INVALID_HANDLE_VALUE )
    {
        PR_Free(d);
        return ConvertWinError(GetLastError());
    }
    d->firstEntry = PR_TRUE;

    *dir = d;
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult OpenFile ( const nsAFlatString name,
PRIntn  osflags,
PRIntn  mode,
PRFileDesc **  fd 
) [static]

Definition at line 396 of file nsLocalFileWin.cpp.

{
    
    // XXX : 'mode' is not translated !!!
    PRInt32 access = 0;
    PRInt32 flags = 0;
    PRInt32 flag6 = 0;

    if (osflags & PR_SYNC) flag6 = FILE_FLAG_WRITE_THROUGH;
 
    if (osflags & PR_RDONLY || osflags & PR_RDWR)
        access |= GENERIC_READ;
    if (osflags & PR_WRONLY || osflags & PR_RDWR)
        access |= GENERIC_WRITE;

    if ( osflags & PR_CREATE_FILE && osflags & PR_EXCL )
        flags = CREATE_NEW;
    else if (osflags & PR_CREATE_FILE) {
        if (osflags & PR_TRUNCATE)
            flags = CREATE_ALWAYS;
        else
            flags = OPEN_ALWAYS;
    } else {
        if (osflags & PR_TRUNCATE)
            flags = TRUNCATE_EXISTING;
        else
            flags = OPEN_EXISTING;
    }

    HANDLE file = nsWinAPIs::mCreateFile(name.get(), access,
                                         FILE_SHARE_READ|FILE_SHARE_WRITE,
                                         NULL, flags, flag6, NULL);

    if (file == INVALID_HANDLE_VALUE) { 
        *fd = nsnull;
        return ConvertWinError(GetLastError());
    }

    *fd = PR_ImportFile((PRInt32) file); 
    if (*fd) {
        // On Windows, _PR_HAVE_O_APPEND is not defined so that we have to
        // add it manually. (see |PR_Open| in nsprpub/pr/src/io/prfile.c)
        (*fd)->secret->appendMode = (PR_APPEND & osflags) ? PR_TRUE : PR_FALSE;
        return NS_OK;
    }

    nsresult rv = NS_ErrorAccordingToNSPR();

    CloseHandle(file);

    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult ReadDir ( nsDir dir,
PRDirFlags  flags,
nsString name 
) [static]

Definition at line 565 of file nsLocalFileWin.cpp.

{
    name.Truncate();
    NS_ENSURE_ARG(dir);

    while (1) {
        BOOL rv;
        if (dir->firstEntry)
        {
            dir->firstEntry = PR_FALSE;
            rv = 1;
        } else
            if (NS_UseUnicode())
                rv = ::FindNextFileW(dir->handle, &(dir->entry.dataW));
            else 
                rv = ::FindNextFileA(dir->handle, &(dir->entry.dataA));

        if (rv == 0)
            break;

        const PRUnichar *fileName;
        nsString tmp;
        if (NS_UseUnicode()) 
            fileName = (dir)->entry.dataW.cFileName;
        else 
        {
            NS_CopyNativeToUnicode(nsDependentCString((dir)->
                                                      entry.dataA.cFileName),
                                   tmp);
            fileName = tmp.get();
        }

        if ((flags & PR_SKIP_DOT) &&
            (fileName[0] == L'.') && (fileName[1] == L'\0'))
            continue;
        if ((flags & PR_SKIP_DOT_DOT) &&
            (fileName[0] == L'.') && (fileName[1] == L'.') &&
            (fileName[2] == L'\0'))
            continue;

        // Perhaps, we can just get away with using entry.dataW.dwFileAttributes
        // because dwFileAttributes is the first field of both WIN32_FIND_DATAW
        // and WIN32_FIND_DATAA, but let's be on the safe side here.
        DWORD attrib = NS_UseUnicode() ? dir->entry.dataW.dwFileAttributes :
                                         dir->entry.dataA.dwFileAttributes;
        if ((flags & PR_SKIP_HIDDEN) && (attrib & FILE_ATTRIBUTE_HIDDEN))
            continue;

        if (fileName == tmp.get())
            name = tmp;
        else 
            name = fileName;
        return NS_OK;
    }

    DWORD err = GetLastError();
    return err == ERROR_NO_MORE_FILES ? NS_OK : ConvertWinError(err);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 240 of file nsLocalFileWin.cpp.