Removing Dir enumerator as it will be part of nsIFile

removing nsFileUtils.
Changing the name of nsIFile children to directoryEntries
removing nsIFile trucate.
Rewrote large parts of nsIFileImplWin to use native APIs.

not part of build
This commit is contained in:
dougt%netscape.com 1999-12-03 00:39:31 +00:00
Родитель ba0b558f0c
Коммит 6798955ef2
9 изменённых файлов: 821 добавлений и 820 удалений

Просмотреть файл

@ -1,38 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* 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/
*
* 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.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* 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.
*
* Contributor(s):
* Doug Turner <dougt@netscape.com>
*/
#ifndef _NSIFILEUTILS_H_
#define _NSIFILEUTILS_H_
#include "nscore.h"
#include "nsIFile.h"
#include "nsIDirectoryEnumerator.h"
// Helper function(s)
nsresult NS_COM NS_NewFile(nsIFile** file);
nsresult NS_COM NS_NewDirectoryEnumerator(nsIFile* parent, PRBool resolveSymlinks, nsIDirectoryEnumerator** enumerator);
#endif

Просмотреть файл

@ -1,44 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* 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/
*
* 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.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* 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.
*
* Contributor(s):
* Doug Turner <dougt@netscape.com>
*/
#ifndef _NSIDIRENUMERATORIMPL_H_
#define _NSIDIRENUMERATORIMPL_H_
#define NS_IDIRECTORYENUMERATOR_CID {0xe67dcbe0, 0x6a21, 0x11d3, {0x8c, 0x51, 0x00, 0x60, 0x97, 0x92, 0x27, 0x8c}}
// nsXPComInit needs to know about how we are implmented,
// so here we will export it. Other users should not depend
// on this
#ifdef XP_PC
#include "nsIDirEnumeratorImplWin.h"
#else
#ifdef XP_UNIX
#include "nsIDirEnumeratorImplUnix.h"
#else
#error NOT_IMPLEMENTED
#endif /* XP_UNIX */
#endif /* XP_PC */
#endif

Просмотреть файл

@ -1,116 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* 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/
*
* 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.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* 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.
*
* Contributor(s):
* Mike Shaver <shaver@mozilla.org>
*/
/*
* Implementation of nsIDirectoryEnumerator for ``Unixy'' systems.
*/
#include "nsIDirEnumeratorImplUnix.h"
#include "nsIFileImplUnix.h" // NSRESULT_FOR_ERRNO, etc.
#include "nsFileUtils.h"
nsIDirEnumeratorImpl::nsIDirEnumeratorImpl() :
mDir(nsnull), mEntry(nsnull)
{
NS_INIT_REFCNT();
}
nsIDirEnumeratorImpl::~nsIDirEnumeratorImpl()
{
if (mDir)
closedir(mDir);
}
NS_IMPL_ISUPPORTS1(nsIDirEnumeratorImpl, nsIDirectoryEnumerator)
NS_METHOD
nsIDirEnumeratorImpl::Create(nsISupports* outer, const nsIID& aIID,
void* *aInstancePtr)
{
NS_ENSURE_ARG_POINTER(aInstancePtr);
NS_ENSURE_PROPER_AGGREGATION(outer, aIID);
*aInstancePtr = 0;
nsCOMPtr<nsIDirectoryEnumerator> inst = new nsIDirEnumeratorImpl();
if (inst.get() == 0)
return NS_ERROR_OUT_OF_MEMORY;
return inst->QueryInterface(aIID, aInstancePtr);
}
NS_IMETHODIMP
nsIDirEnumeratorImpl::Init(nsIFile *parent, PRBool resolveSymlinks /*ignored*/)
{
nsXPIDLCString dirPath;
if (NS_FAILED(parent->GetPath(nsIFile::UNIX_PATH,
getter_Copies(dirPath))) ||
(const char *)dirPath == 0)
return NS_ERROR_FILE_INVALID_PATH;
mParent = parent;
mDir = opendir(dirPath);
if (!mDir)
return NSRESULT_FOR_ERRNO();
return getNextEntry();
}
NS_IMETHODIMP
nsIDirEnumeratorImpl::HasMoreElements(PRBool *result)
{
*result = mDir && mEntry;
return NS_OK;
}
NS_IMETHODIMP
nsIDirEnumeratorImpl::GetNext(nsISupports **_retval)
{
nsresult rv;
if (!mDir || !mEntry) {
*_retval = nsnull;
return NS_OK;
}
nsIFile *file = nsnull;
if (NS_FAILED(rv = NS_NewFile(&file)))
return rv;
if (NS_FAILED(rv = file->InitWithFile(mParent)) ||
NS_FAILED(rv = file->AppendPath(mEntry->d_name))) {
NS_RELEASE(file);
return rv;
}
*_retval = NS_STATIC_CAST(nsISupports *, file);
return getNextEntry();
}
NS_IMETHODIMP
nsIDirEnumeratorImpl::getNextEntry()
{
errno = 0;
mEntry = readdir(mDir);
if (mEntry)
return NS_OK;
return NSRESULT_FOR_ERRNO();
}

Просмотреть файл

@ -1,67 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* 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/
*
* 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.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* 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.
*
* Contributor(s):
* Mike Shaver <shaver@mozilla.org>
*/
/*
* Implementation of nsIDirectoryEnumerator for ``Unixy'' systems.
*/
#ifndef _NSIDIRENUMERATORIMPLUNIX_H_
#define _NSIDIRENUMERATORIMPLUNIX_H_
#include <sys/types.h>
#include <dirent.h>
#include "nscore.h"
#include "nsCOMPtr.h"
#include "nsIFile.h"
#include "nsIDirectoryEnumerator.h"
#include "nsIDirEnumeratorImpl.h"
class NS_COM
nsIDirEnumeratorImpl : public nsIDirectoryEnumerator
{
public:
NS_DEFINE_STATIC_CID_ACCESSOR(NS_IDIRECTORYENUMERATOR_CID)
nsIDirEnumeratorImpl();
virtual ~nsIDirEnumeratorImpl();
static NS_METHOD Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr);
// nsISupports interface
NS_DECL_ISUPPORTS
NS_DECL_NSISIMPLEENUMERATOR
// nsIDirectoryIterator interface
NS_DECL_NSIDIRECTORYENUMERATOR
protected:
NS_IMETHOD getNextEntry();
DIR *mDir;
struct dirent *mEntry;
nsCOMPtr<nsIFile> mParent;
};
#endif /* _NSIDIRENUMERATORIMPLUNIX_H_ */

Просмотреть файл

@ -1,133 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* 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/
*
* 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.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* 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.
*
* Contributor(s):
* Doug Turner <dougt@netscape.com>
*/
#include "nsIComponentManager.h"
#include "nsIDirEnumeratorImpl.h"
#include "nsIDirEnumeratorImplWin.h"
#include "nsFileUtils.h"
nsIDirEnumeratorImpl::nsIDirEnumeratorImpl()
{
NS_INIT_REFCNT();
mDir = nsnull;
}
nsIDirEnumeratorImpl::~nsIDirEnumeratorImpl()
{
if (mDir)
PR_CloseDir(mDir);
}
/* nsISupports interface implementation. */
NS_IMPL_ISUPPORTS1(nsIDirEnumeratorImpl, nsIDirectoryEnumerator)
NS_METHOD
nsIDirEnumeratorImpl::Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr)
{
NS_ENSURE_ARG_POINTER(aInstancePtr);
NS_ENSURE_PROPER_AGGREGATION(outer, aIID);
nsIDirEnumeratorImpl* inst = new nsIDirEnumeratorImpl();
if (inst == NULL)
return NS_ERROR_OUT_OF_MEMORY;
nsresult rv = inst->QueryInterface(aIID, aInstancePtr);
if (NS_FAILED(rv))
{
delete inst;
return rv;
}
return NS_OK;
}
NS_IMETHODIMP
nsIDirEnumeratorImpl::Init(nsIFile *parent, PRBool resolveSymlinks)
{
char* filepath;
parent->GetPath(nsIFile::NSPR_PATH, &filepath);
if (filepath == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
mDir = PR_OpenDir(filepath);
if (mDir == nsnull) // not a directory
return NS_ERROR_FAILURE;
nsAllocator::Free(filepath);
mParent = parent;
mResolveSymlinks = resolveSymlinks;
return NS_NewFile(&mNext);
}
/* boolean HasMoreElements (); */
NS_IMETHODIMP
nsIDirEnumeratorImpl::HasMoreElements(PRBool *result)
{
nsresult rv;
*result = PR_FALSE;
if (mDir)
{
PRDirEntry* entry = PR_ReadDir(mDir, PR_SKIP_BOTH);
if (entry == nsnull)
return NS_OK;
mNext->InitWithFile(mParent);
rv = mNext->AppendPath(entry->name);
if (NS_FAILED(rv))
return rv;
}
*result = PR_TRUE;
return NS_OK;
}
/* nsISupports GetNext (); */
NS_IMETHODIMP
nsIDirEnumeratorImpl::GetNext(nsISupports **_retval)
{
nsresult rv;
PRBool hasMore;
rv = HasMoreElements(&hasMore);
if (NS_FAILED(rv))
return rv;
nsIFile *file;
rv = NS_NewFile(&file);
if (NS_FAILED(rv))
return rv;
rv = file->InitWithFile(mNext);
*_retval = file; // TODO: QI needed?
return rv;
}

Просмотреть файл

@ -1,61 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* 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/
*
* 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.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* 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.
*
* Contributor(s):
* Doug Turner <dougt@netscape.com>
*/
#ifndef _NSIDIRENUMERATORIMPLWIN_H_
#define _NSIDIRENUMERATORIMPLWIN_H_
#include "nscore.h"
#include "prio.h"
#include "nsIDirectoryEnumerator.h"
#include "nsIDirEnumeratorImpl.h"
class NS_COM
nsIDirEnumeratorImpl : public nsIDirectoryEnumerator
{
public:
NS_DEFINE_STATIC_CID_ACCESSOR(NS_IDIRECTORYENUMERATOR_CID)
nsIDirEnumeratorImpl();
virtual ~nsIDirEnumeratorImpl();
static NS_METHOD Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr);
// nsISupports interface
NS_DECL_ISUPPORTS
NS_DECL_NSISIMPLEENUMERATOR
// nsIDirectoryIterator interface
NS_DECL_NSIDIRECTORYENUMERATOR
protected:
PRDir* mDir;
nsIFile *mParent;
nsIFile *mNext;
PRBool mResolveSymlinks;
const nsIFile *mStarting;
};
#endif

Просмотреть файл

@ -179,11 +179,6 @@ interface nsIFile : nsISupports
*/
void delete(in boolean recursive);
/**
* Truncate the file to the given length.
*/
void truncate(in unsigned long length);
/**
* Attributes of nsIFile.
*/
@ -221,12 +216,6 @@ interface nsIFile : nsISupports
readonly attribute string target;
readonly attribute string path;
/**
* Parent will be nsnull when this is at the top of the volume.
*/
readonly attribute nsIFile parent;
boolean exists();
boolean isWritable();
boolean isReadable();
@ -252,6 +241,11 @@ interface nsIFile : nsISupports
boolean isContainedIn(in nsIFile inFile, in boolean recur);
/**
* Parent will be nsnull when this is at the top of the volume.
*/
readonly attribute nsIFile parent;
/**
* Returns an enumeration of the elements in a directory. Each
* element in the enumeration is an nsIFile.
@ -259,7 +253,7 @@ interface nsIFile : nsISupports
* @return NS_ERROR_FILE_NOT_DIRECTORY if the current nsIFile does
* not specify a directory.
*/
readonly attribute nsISimpleEnumerator children;
readonly attribute nsISimpleEnumerator directoryEntries;
};
%{C++

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -30,12 +30,24 @@
#include "nsString.h"
#include "nsCRT.h"
#include "nsIFile.h"
#include "nsILocalFile.h"
#include "nsIFactory.h"
#include "nsIFileImpl.h"
#include "windows.h"
// For older version (<6.0) of the VC Compiler
#if (_MSC_VER == 1100)
#define INITGUID
#include "objbase.h"
DEFINE_OLEGUID(IID_IPersistFile, 0x0000010BL, 0, 0);
#endif
#include "shlobj.h"
#include <sys/stat.h>
class NS_COM nsIFileImpl : public nsIFile
class NS_COM nsIFileImpl : public nsILocalFile
{
public:
NS_DEFINE_STATIC_CID_ACCESSOR(NS_IFILEIMPL_CID)
@ -50,33 +62,34 @@ public:
// nsIFile interface
NS_DECL_NSIFILE
// nsILocalFile interface
NS_DECL_NSILOCALFILE
private:
// this is the flag which indicates if I can used cached information about the file
PRBool mStatDirty;
// this string will alway be in native format!
nsCString mWorkingPath;
// this is the flag which indicates if I can used cached information about the files
// resolved stat.
PRBool mResolutionDirty;
// this will be the resolve path which will *NEVER* be return to the user
nsCString mResolvedPath;
// this is the flag which indicates if I can used cached information about the file's
// stat information
PRBool mStatDirty;
IPersistFile* mPersistFile;
IShellLink* mShellLink;
// for buffered stat calls.
struct stat mBuffered_st;
int mBuffered_stat_rv;
nsresult resolveWorkingPath();
nsresult bufferedStat(struct stat *st);
void makeDirty();
nsresult copymove(nsIFile *newParentDir, const char *newName, PRBool followSymlinks, PRBool move);
WIN32_FILE_ATTRIBUTE_DATA mFileAttrData;
void MakeDirty();
nsresult ResolveAndStat(PRBool resolveTerminal);
nsresult ResolvePath(const char* workingPath, PRBool resolveTerminal, char** resolvedPath);
nsresult CopyMove(nsIFile *newParentDir, const char *newName, PRBool followSymlinks, PRBool move);
};