mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 03:15:11 +00:00
Initial checkin of nsIFile windows implementation. bug 13320. r=dougt
Not hooked up to build, yet.
This commit is contained in:
parent
c478236f6f
commit
0f1164855f
31
xpcom/io/nsFileUtils.cpp
Normal file
31
xpcom/io/nsFileUtils.cpp
Normal file
@ -0,0 +1,31 @@
|
||||
#include "nscore.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIFile.h"
|
||||
#include "nsIDirectoryEnumerator.h"
|
||||
#include "nsIDirEnumeratorImpl.h"
|
||||
#include "nsFileUtils.h"
|
||||
|
||||
|
||||
nsresult NS_COM
|
||||
NS_NewFile(nsIFile** file)
|
||||
{
|
||||
return nsComponentManager::CreateInstance(NS_FILE_PROGID,
|
||||
nsnull,
|
||||
nsCOMTypeInfo<nsIFile>::GetIID(),
|
||||
(void**)file);
|
||||
}
|
||||
|
||||
nsresult NS_COM
|
||||
NS_NewDirectoryEnumerator(nsIFile* parent, PRBool resolveSymlinks, nsIDirectoryEnumerator** enumerator)
|
||||
{
|
||||
nsresult rv = nsComponentManager::CreateInstance(NS_DIRECTORY_ENUMERATOR_PROGID,
|
||||
nsnull,
|
||||
nsCOMTypeInfo<nsIDirectoryEnumerator>::GetIID(),
|
||||
(void**)enumerator);
|
||||
|
||||
if (NS_SUCCEEDED(rv) && *enumerator)
|
||||
{
|
||||
(*enumerator)->Init(parent, resolveSymlinks);
|
||||
}
|
||||
return rv;
|
||||
}
|
38
xpcom/io/nsFileUtils.h
Normal file
38
xpcom/io/nsFileUtils.h
Normal file
@ -0,0 +1,38 @@
|
||||
/* -*- 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.0 (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.
|
||||
*
|
||||
* Contributors:
|
||||
* 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
|
40
xpcom/io/nsIDirEnumeratorImpl.h
Normal file
40
xpcom/io/nsIDirEnumeratorImpl.h
Normal file
@ -0,0 +1,40 @@
|
||||
/* -*- 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.0 (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.
|
||||
*
|
||||
* Contributors:
|
||||
* 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
|
||||
#error NOT_IMPLEMENTED
|
||||
#endif
|
||||
|
||||
#endif
|
148
xpcom/io/nsIDirEnumeratorImplWin.cpp
Normal file
148
xpcom/io/nsIDirEnumeratorImplWin.cpp
Normal file
@ -0,0 +1,148 @@
|
||||
/* -*- 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.0 (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.
|
||||
*
|
||||
* Contributors:
|
||||
* 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()
|
||||
{
|
||||
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction");
|
||||
|
||||
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); // TODO. entry->name maybe a NATIVE_PATH
|
||||
|
||||
// if (mResoveSymLinks)
|
||||
//{
|
||||
// PRBool isSymlink;
|
||||
// mNext->IsSymlink(&isSymlink);
|
||||
|
||||
//if (isSymlink)
|
||||
//{
|
||||
// // initalized mNext to the resolved file.
|
||||
//}
|
||||
//}
|
||||
|
||||
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;
|
||||
}
|
61
xpcom/io/nsIDirEnumeratorImplWin.h
Normal file
61
xpcom/io/nsIDirEnumeratorImplWin.h
Normal file
@ -0,0 +1,61 @@
|
||||
/* -*- 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.0 (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.
|
||||
*
|
||||
* Contributors:
|
||||
* 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
|
40
xpcom/io/nsIFileImpl.h
Normal file
40
xpcom/io/nsIFileImpl.h
Normal file
@ -0,0 +1,40 @@
|
||||
/* -*- 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.0 (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.
|
||||
*
|
||||
* Contributors:
|
||||
* Doug Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
#ifndef _NSIFILEIMPL_H_
|
||||
#define _NSIFILEIMPL_H_
|
||||
|
||||
#define NS_IFILEIMPL_CID {0x2e23e220, 0x60be, 0x11d3, {0x8c, 0x4a, 0x00, 0x00, 0x64, 0x65, 0x73, 0x74}}
|
||||
|
||||
// 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 "nsIFileImplWin.h"
|
||||
#else
|
||||
#error NOT_IMPLEMENTED
|
||||
#endif
|
||||
|
||||
#endif
|
1000
xpcom/io/nsIFileImplWin.cpp
Normal file
1000
xpcom/io/nsIFileImplWin.cpp
Normal file
File diff suppressed because it is too large
Load Diff
86
xpcom/io/nsIFileImplWin.h
Normal file
86
xpcom/io/nsIFileImplWin.h
Normal file
@ -0,0 +1,86 @@
|
||||
/* -*- 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.0 (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.
|
||||
*
|
||||
* Contributors:
|
||||
* Doug Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
#ifndef _NSIFILEIMPLWIN_H_
|
||||
#define _NSIFILEIMPLWIN_H_
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsError.h"
|
||||
#include "nsString.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsIFile.h"
|
||||
#include "nsIFactory.h"
|
||||
#include "nsIFileImpl.h"
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
class NS_COM nsIFileImpl : public nsIFile
|
||||
{
|
||||
public:
|
||||
NS_DEFINE_STATIC_CID_ACCESSOR(NS_IFILEIMPL_CID)
|
||||
|
||||
nsIFileImpl();
|
||||
virtual ~nsIFileImpl();
|
||||
|
||||
static NS_METHOD Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr);
|
||||
|
||||
// nsISupports interface
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIFile interface
|
||||
NS_DECL_NSIFILE
|
||||
|
||||
private:
|
||||
|
||||
// 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;
|
||||
|
||||
// for buffered stat calls.
|
||||
struct stat mBuffered_st;
|
||||
int mBuffered_stat_rv;
|
||||
|
||||
void convertToNative(PRUint32 type, const char* filePath, char** nativeFilePath);
|
||||
void convertFromNative(PRUint32 type, const char* inFilePath, char** outFilePath);
|
||||
|
||||
nsresult resolveWorkingPath();
|
||||
|
||||
nsresult bufferedStat(struct stat *st);
|
||||
void makeDirty();
|
||||
|
||||
nsresult copymove(nsIFile *newParentDir, const char *newName, PRBool followSymlinks, PRBool move);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user