2000-05-02 02:21:43 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; 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-2000 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Henry Sobotka <sobotka@axess.com>
|
2000-10-06 00:44:11 +04:00
|
|
|
* IBM Corp.
|
2000-05-02 02:21:43 +04:00
|
|
|
*/
|
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
|
2000-05-02 02:21:43 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2000-06-03 13:46:12 +04:00
|
|
|
#include "nsMemory.h"
|
2000-06-20 18:06:00 +04:00
|
|
|
|
2003-06-19 03:19:11 +04:00
|
|
|
#include "nsLocalFile.h"
|
2002-10-06 04:29:46 +04:00
|
|
|
#include "nsNativeCharsetUtils.h"
|
2002-04-24 07:47:06 +04:00
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
#include "nsISimpleEnumerator.h"
|
|
|
|
#include "nsIComponentManager.h"
|
2000-05-02 02:21:43 +04:00
|
|
|
#include "prtypes.h"
|
|
|
|
#include "prio.h"
|
2000-06-20 18:06:00 +04:00
|
|
|
|
|
|
|
#include <ctype.h> // needed for toupper
|
|
|
|
#include <string.h>
|
|
|
|
|
2001-06-22 06:57:07 +04:00
|
|
|
#include "nsXPIDLString.h"
|
2001-11-11 04:42:10 +03:00
|
|
|
#include "nsReadableUtils.h"
|
2001-06-22 06:57:07 +04:00
|
|
|
#include "prproces.h"
|
2002-04-24 07:47:06 +04:00
|
|
|
#include "prthread.h"
|
2001-06-22 06:57:07 +04:00
|
|
|
|
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
static unsigned char* PR_CALLBACK
|
|
|
|
_mbschr( const unsigned char* stringToSearch, int charToSearchFor);
|
2001-02-01 00:58:27 +03:00
|
|
|
extern unsigned char*
|
2000-06-20 18:06:00 +04:00
|
|
|
_mbsrchr( const unsigned char* stringToSearch, int charToSearchFor);
|
2000-07-20 18:54:24 +04:00
|
|
|
static nsresult PR_CALLBACK
|
2003-06-20 01:53:26 +04:00
|
|
|
CreateDirectoryA( PSZ path, PEAOP2 ppEABuf);
|
2000-10-06 00:44:11 +04:00
|
|
|
static int isleadbyte(int c);
|
2000-05-02 02:21:43 +04:00
|
|
|
|
|
|
|
#include <unistd.h>
|
2000-06-21 05:35:21 +04:00
|
|
|
#include <io.h>
|
2000-05-02 02:21:43 +04:00
|
|
|
|
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
static nsresult ConvertOS2Error(int err)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
switch (err)
|
|
|
|
{
|
|
|
|
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;
|
2000-07-20 18:54:24 +04:00
|
|
|
case ERROR_FILE_EXISTS:
|
|
|
|
case ERROR_ALREADY_EXISTS:
|
|
|
|
case ERROR_CANNOT_MAKE:
|
|
|
|
rv = NS_ERROR_FILE_ALREADY_EXISTS;
|
|
|
|
break;
|
2000-06-20 18:06:00 +04:00
|
|
|
case 0:
|
|
|
|
rv = NS_OK;
|
|
|
|
default:
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
myLL_II2L(PRInt32 hi, PRInt32 lo, PRInt64 *result)
|
|
|
|
{
|
|
|
|
PRInt64 a64, b64; // probably could have been done with
|
|
|
|
// only one PRInt64, but these are macros,
|
|
|
|
// and I am a wimp.
|
|
|
|
|
|
|
|
// put hi in the low bits of a64.
|
|
|
|
LL_I2L(a64, hi);
|
|
|
|
// now shift it to the upperbit and place it the result in result
|
|
|
|
LL_SHL(b64, a64, 32);
|
|
|
|
// now put the low bits on by adding them to the result.
|
|
|
|
LL_ADD(*result, b64, lo);
|
|
|
|
}
|
|
|
|
|
2000-05-02 02:21:43 +04:00
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
static void
|
|
|
|
myLL_L2II(PRInt64 result, PRInt32 *hi, PRInt32 *lo )
|
|
|
|
{
|
|
|
|
PRInt64 a64, b64; // probably could have been done with
|
|
|
|
// only one PRInt64, but these are macros,
|
|
|
|
// and I am a wimp.
|
|
|
|
|
|
|
|
// shift the hi word to the low word, then push it into a long.
|
|
|
|
LL_SHR(a64, result, 32);
|
|
|
|
LL_L2I(*hi, a64);
|
|
|
|
|
|
|
|
// shift the low word to the hi word first, then shift it back.
|
|
|
|
LL_SHL(b64, result, 32);
|
|
|
|
LL_SHR(a64, b64, 32);
|
|
|
|
LL_L2I(*lo, a64);
|
|
|
|
}
|
2000-05-02 02:21:43 +04:00
|
|
|
|
|
|
|
|
|
|
|
class nsDirEnumerator : public nsISimpleEnumerator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
nsDirEnumerator() : mDir(nsnull)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult Init(nsILocalFile* parent)
|
|
|
|
{
|
2002-04-27 09:33:09 +04:00
|
|
|
nsCAutoString filepath;
|
|
|
|
parent->GetNativeTarget(filepath);
|
2000-05-02 02:21:43 +04:00
|
|
|
|
2002-04-27 09:33:09 +04:00
|
|
|
if (filepath.IsEmpty())
|
2000-05-02 02:21:43 +04:00
|
|
|
{
|
2002-04-27 09:33:09 +04:00
|
|
|
parent->GetNativePath(filepath);
|
2000-05-02 02:21:43 +04:00
|
|
|
}
|
|
|
|
|
2002-04-27 09:33:09 +04:00
|
|
|
if (filepath.IsEmpty())
|
2000-05-02 02:21:43 +04:00
|
|
|
{
|
2002-04-27 09:33:09 +04:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
2000-05-02 02:21:43 +04:00
|
|
|
}
|
|
|
|
|
2002-04-27 09:33:09 +04:00
|
|
|
mDir = PR_OpenDir(filepath.get());
|
2000-05-02 02:21:43 +04:00
|
|
|
if (mDir == nsnull) // not a directory?
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
mParent = parent;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD HasMoreElements(PRBool *result)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
if (mNext == nsnull && mDir)
|
|
|
|
{
|
|
|
|
PRDirEntry* entry = PR_ReadDir(mDir, PR_SKIP_BOTH);
|
|
|
|
if (entry == nsnull)
|
|
|
|
{
|
|
|
|
// end of dir entries
|
|
|
|
|
|
|
|
PRStatus status = PR_CloseDir(mDir);
|
|
|
|
if (status != PR_SUCCESS)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
mDir = nsnull;
|
|
|
|
|
|
|
|
*result = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
rv = mParent->Clone(getter_AddRefs(file));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2000-06-20 18:06:00 +04:00
|
|
|
|
2002-04-27 09:33:09 +04:00
|
|
|
rv = file->AppendNative(nsDependentCString(entry->name));
|
2000-05-02 02:21:43 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2000-06-20 18:06:00 +04:00
|
|
|
|
2000-05-02 02:21:43 +04:00
|
|
|
// make sure the thing exists. If it does, try the next one.
|
|
|
|
PRBool exists;
|
2002-04-27 09:33:09 +04:00
|
|
|
rv = file->Exists(&exists);
|
2000-05-02 02:21:43 +04:00
|
|
|
if (NS_FAILED(rv) || !exists)
|
|
|
|
{
|
|
|
|
return HasMoreElements(result);
|
|
|
|
}
|
2000-06-20 18:06:00 +04:00
|
|
|
|
2000-05-02 02:21:43 +04:00
|
|
|
mNext = do_QueryInterface(file);
|
|
|
|
}
|
|
|
|
*result = mNext != nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD GetNext(nsISupports **result)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
PRBool hasMore;
|
|
|
|
rv = HasMoreElements(&hasMore);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
*result = mNext; // might return nsnull
|
|
|
|
NS_IF_ADDREF(*result);
|
|
|
|
|
2001-10-07 14:58:39 +04:00
|
|
|
mNext = nsnull;
|
2000-05-02 02:21:43 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~nsDirEnumerator()
|
|
|
|
{
|
|
|
|
if (mDir)
|
|
|
|
{
|
|
|
|
PRStatus status = PR_CloseDir(mDir);
|
|
|
|
NS_ASSERTION(status == PR_SUCCESS, "close failed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
PRDir* mDir;
|
|
|
|
nsCOMPtr<nsILocalFile> mParent;
|
|
|
|
nsCOMPtr<nsILocalFile> mNext;
|
|
|
|
};
|
|
|
|
|
2001-08-21 05:48:11 +04:00
|
|
|
NS_IMPL_ISUPPORTS1(nsDirEnumerator, nsISimpleEnumerator)
|
2000-05-02 02:21:43 +04:00
|
|
|
|
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
nsLocalFile::nsLocalFile()
|
2000-05-02 02:21:43 +04:00
|
|
|
{
|
2000-06-20 18:06:00 +04:00
|
|
|
MakeDirty();
|
2000-05-02 02:21:43 +04:00
|
|
|
}
|
|
|
|
|
2003-07-19 02:14:16 +04:00
|
|
|
nsLocalFile::nsLocalFile(const nsLocalFile& other)
|
|
|
|
: mDirty(other.mDirty)
|
|
|
|
, mWorkingPath(other.mWorkingPath)
|
|
|
|
, mFileInfo64(other.mFileInfo64)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2000-05-02 02:21:43 +04:00
|
|
|
nsLocalFile::~nsLocalFile()
|
|
|
|
{
|
2000-06-20 18:06:00 +04:00
|
|
|
}
|
2000-05-02 02:21:43 +04:00
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
/* nsISupports interface implementation. */
|
2000-05-02 02:21:43 +04:00
|
|
|
NS_IMPL_THREADSAFE_ISUPPORTS2(nsLocalFile, nsILocalFile, nsIFile)
|
|
|
|
|
|
|
|
NS_METHOD
|
|
|
|
nsLocalFile::nsLocalFileConstructor(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aInstancePtr);
|
|
|
|
NS_ENSURE_NO_AGGREGATION(outer);
|
|
|
|
|
|
|
|
nsLocalFile* inst = new nsLocalFile();
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
// This function resets any cached information about the file.
|
|
|
|
void
|
|
|
|
nsLocalFile::MakeDirty()
|
|
|
|
{
|
|
|
|
mDirty = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2003-06-20 01:53:26 +04:00
|
|
|
nsLocalFile::Stat()
|
2000-06-20 18:06:00 +04:00
|
|
|
{
|
2003-06-20 01:53:26 +04:00
|
|
|
if (!mDirty)
|
2000-06-20 18:06:00 +04:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
char temp[4];
|
2001-03-02 12:26:57 +03:00
|
|
|
const char* workingFilePath = mWorkingPath.get();
|
2000-06-20 18:06:00 +04:00
|
|
|
const char* nsprPath = workingFilePath;
|
|
|
|
|
|
|
|
if (mWorkingPath.Length() == 2 && mWorkingPath.CharAt(1) == ':') {
|
|
|
|
temp[0] = workingFilePath[0];
|
|
|
|
temp[1] = workingFilePath[1];
|
|
|
|
temp[2] = '\\';
|
|
|
|
temp[3] = '\0';
|
|
|
|
nsprPath = temp;
|
|
|
|
}
|
|
|
|
|
2002-01-15 00:17:43 +03:00
|
|
|
DosError(FERR_DISABLEHARDERR);
|
2000-06-20 18:06:00 +04:00
|
|
|
PRStatus status = PR_GetFileInfo64(nsprPath, &mFileInfo64);
|
2002-01-15 00:17:43 +03:00
|
|
|
DosError(FERR_ENABLEHARDERR);
|
2000-06-20 18:06:00 +04:00
|
|
|
if ( status == PR_SUCCESS )
|
2003-06-20 01:53:26 +04:00
|
|
|
return NS_OK;
|
2000-06-20 18:06:00 +04:00
|
|
|
|
2003-06-20 01:53:26 +04:00
|
|
|
return NS_ERROR_FILE_NOT_FOUND;
|
2000-06-20 18:06:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-05-02 02:21:43 +04:00
|
|
|
nsLocalFile::Clone(nsIFile **file)
|
|
|
|
{
|
2003-07-19 02:14:16 +04:00
|
|
|
// Just copy-construct ourselves
|
|
|
|
*file = new nsLocalFile(*this);
|
|
|
|
if (!*file)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2000-05-02 02:21:43 +04:00
|
|
|
|
2003-07-19 02:14:16 +04:00
|
|
|
NS_ADDREF(*file);
|
2002-03-20 06:16:09 +03:00
|
|
|
|
2003-07-19 02:14:16 +04:00
|
|
|
return NS_OK;
|
2000-05-02 02:21:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-04-27 09:33:09 +04:00
|
|
|
nsLocalFile::InitWithNativePath(const nsACString &filePath)
|
2000-05-02 02:21:43 +04:00
|
|
|
{
|
2000-06-20 18:06:00 +04:00
|
|
|
MakeDirty();
|
2002-04-27 09:33:09 +04:00
|
|
|
|
|
|
|
nsACString::const_iterator begin, end;
|
|
|
|
filePath.BeginReading(begin);
|
|
|
|
filePath.EndReading(end);
|
|
|
|
|
|
|
|
// input string must not be empty
|
|
|
|
if (begin == end)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
char firstChar = *begin;
|
|
|
|
char secondChar = *(++begin);
|
2000-06-20 18:06:00 +04:00
|
|
|
|
|
|
|
// just do a sanity check. if it has any forward slashes, it is not a Native path
|
|
|
|
// on windows. Also, it must have a colon at after the first char.
|
|
|
|
|
2002-04-27 09:33:09 +04:00
|
|
|
char *path = nsnull;
|
|
|
|
PRInt32 pathLen = 0;
|
|
|
|
|
|
|
|
if ( ( (secondChar == ':') && !FindCharInReadable('/', begin, end) ) || // normal path
|
|
|
|
( (firstChar == '\\') && (secondChar == '\\') ) ) // network path
|
2000-05-02 02:21:43 +04:00
|
|
|
{
|
|
|
|
// This is a native path
|
2002-04-27 09:33:09 +04:00
|
|
|
path = ToNewCString(filePath);
|
|
|
|
pathLen = filePath.Length();
|
2000-05-02 02:21:43 +04:00
|
|
|
}
|
2002-04-27 09:33:09 +04:00
|
|
|
|
|
|
|
if (path == nsnull)
|
2000-05-02 02:21:43 +04:00
|
|
|
return NS_ERROR_FILE_UNRECOGNIZED_PATH;
|
|
|
|
|
2002-04-27 09:33:09 +04:00
|
|
|
// kill any trailing '\' provided it isn't the second char of DBCS
|
|
|
|
PRInt32 len = pathLen - 1;
|
|
|
|
if (path[len] == '\\' && !::isleadbyte(path[len-1]))
|
|
|
|
{
|
|
|
|
path[len] = '\0';
|
|
|
|
pathLen = len;
|
|
|
|
}
|
2000-06-20 18:06:00 +04:00
|
|
|
|
2002-04-27 09:33:09 +04:00
|
|
|
mWorkingPath.Adopt(path, pathLen);
|
2000-05-02 02:21:43 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::OpenNSPRFileDesc(PRInt32 flags, PRInt32 mode, PRFileDesc **_retval)
|
|
|
|
{
|
2003-06-20 01:53:26 +04:00
|
|
|
nsresult rv = Stat();
|
2000-06-20 18:06:00 +04:00
|
|
|
if (NS_FAILED(rv) && rv != NS_ERROR_FILE_NOT_FOUND)
|
|
|
|
return rv;
|
|
|
|
|
2003-06-20 01:53:26 +04:00
|
|
|
*_retval = PR_Open(mWorkingPath.get(), flags, mode);
|
2000-05-02 02:21:43 +04:00
|
|
|
|
|
|
|
if (*_retval)
|
|
|
|
return NS_OK;
|
2000-06-20 18:06:00 +04:00
|
|
|
|
|
|
|
return NS_ErrorAccordingToNSPR();
|
2000-05-02 02:21:43 +04:00
|
|
|
}
|
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
|
2000-05-02 02:21:43 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::OpenANSIFileDesc(const char *mode, FILE * *_retval)
|
|
|
|
{
|
2003-06-20 01:53:26 +04:00
|
|
|
nsresult rv = Stat();
|
2000-06-20 18:06:00 +04:00
|
|
|
if (NS_FAILED(rv) && rv != NS_ERROR_FILE_NOT_FOUND)
|
|
|
|
return rv;
|
2000-05-02 02:21:43 +04:00
|
|
|
|
2003-06-20 01:53:26 +04:00
|
|
|
*_retval = fopen(mWorkingPath.get(), mode);
|
2000-05-02 02:21:43 +04:00
|
|
|
|
|
|
|
if (*_retval)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
|
|
|
|
|
2000-05-02 02:21:43 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::Create(PRUint32 type, PRUint32 attributes)
|
|
|
|
{
|
|
|
|
if (type != NORMAL_FILE_TYPE && type != DIRECTORY_TYPE)
|
|
|
|
return NS_ERROR_FILE_UNKNOWN_TYPE;
|
|
|
|
|
2003-06-20 01:53:26 +04:00
|
|
|
nsresult rv = Stat();
|
2000-06-20 18:06:00 +04:00
|
|
|
if (NS_FAILED(rv) && rv != NS_ERROR_FILE_NOT_FOUND)
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
// create nested directories to target
|
2003-06-20 01:53:26 +04:00
|
|
|
unsigned char* slash = _mbschr((const unsigned char*) mWorkingPath.get(), '\\');
|
2000-05-02 02:21:43 +04:00
|
|
|
|
|
|
|
|
2002-02-13 01:14:32 +03:00
|
|
|
if (slash)
|
|
|
|
{
|
|
|
|
// skip the first '\\'
|
|
|
|
++slash;
|
|
|
|
slash = _mbschr(slash, '\\');
|
|
|
|
|
|
|
|
while (slash)
|
|
|
|
{
|
|
|
|
*slash = '\0';
|
|
|
|
|
2003-06-20 01:53:26 +04:00
|
|
|
rv = CreateDirectoryA(NS_CONST_CAST(char*, mWorkingPath.get()), NULL);
|
2002-02-13 01:14:32 +03:00
|
|
|
if (rv) {
|
|
|
|
rv = ConvertOS2Error(rv);
|
|
|
|
if (rv != NS_ERROR_FILE_ALREADY_EXISTS) return rv;
|
|
|
|
}
|
|
|
|
*slash = '\\';
|
|
|
|
++slash;
|
|
|
|
slash = _mbschr(slash, '\\');
|
2000-07-20 18:54:24 +04:00
|
|
|
}
|
2000-06-20 18:06:00 +04:00
|
|
|
}
|
2000-05-02 02:21:43 +04:00
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
if (type == NORMAL_FILE_TYPE)
|
|
|
|
{
|
2003-06-20 01:53:26 +04:00
|
|
|
PRFileDesc* file = PR_Open(mWorkingPath.get(), PR_RDONLY | PR_CREATE_FILE | PR_APPEND | PR_EXCL, attributes);
|
2000-06-27 07:35:32 +04:00
|
|
|
if (!file) return NS_ERROR_FILE_ALREADY_EXISTS;
|
|
|
|
|
|
|
|
PR_Close(file);
|
2000-06-20 18:06:00 +04:00
|
|
|
return NS_OK;
|
2000-05-02 02:21:43 +04:00
|
|
|
}
|
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
if (type == DIRECTORY_TYPE)
|
|
|
|
{
|
2003-06-20 01:53:26 +04:00
|
|
|
rv = CreateDirectoryA(NS_CONST_CAST(char*, mWorkingPath.get()), NULL);
|
2000-07-20 18:54:24 +04:00
|
|
|
if (rv)
|
|
|
|
return ConvertOS2Error(rv);
|
|
|
|
else
|
|
|
|
return NS_OK;
|
2000-05-02 02:21:43 +04:00
|
|
|
}
|
2000-06-20 18:06:00 +04:00
|
|
|
|
|
|
|
return NS_ERROR_FILE_UNKNOWN_TYPE;
|
2000-05-02 02:21:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-04-27 09:33:09 +04:00
|
|
|
nsLocalFile::AppendNative(const nsACString &node)
|
2000-05-25 18:23:27 +04:00
|
|
|
{
|
2002-09-04 02:40:45 +04:00
|
|
|
if (node.IsEmpty())
|
|
|
|
return NS_OK;
|
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
// Append only one component. Check for subdirs.
|
2002-04-27 09:33:09 +04:00
|
|
|
// XXX can we avoid the PromiseFlatCString call?
|
2002-09-04 02:40:45 +04:00
|
|
|
if (_mbschr((const unsigned char*) PromiseFlatCString(node).get(), '\\') != nsnull)
|
2000-06-20 18:06:00 +04:00
|
|
|
return NS_ERROR_FILE_UNRECOGNIZED_PATH;
|
2002-09-04 02:40:45 +04:00
|
|
|
|
2002-04-27 09:33:09 +04:00
|
|
|
return AppendRelativeNativePath(node);
|
2000-05-25 18:23:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-04-27 09:33:09 +04:00
|
|
|
nsLocalFile::AppendRelativeNativePath(const nsACString &node)
|
2000-05-02 02:21:43 +04:00
|
|
|
{
|
2000-06-20 18:06:00 +04:00
|
|
|
// Cannot start with a / or have .. or have / anywhere
|
2002-04-27 09:33:09 +04:00
|
|
|
nsACString::const_iterator begin, end;
|
|
|
|
node.BeginReading(begin);
|
|
|
|
node.EndReading(end);
|
|
|
|
if (node.IsEmpty() || FindCharInReadable('/', begin, end))
|
2000-05-02 02:21:43 +04:00
|
|
|
{
|
|
|
|
return NS_ERROR_FILE_UNRECOGNIZED_PATH;
|
|
|
|
}
|
2000-06-20 18:06:00 +04:00
|
|
|
MakeDirty();
|
2002-04-27 09:33:09 +04:00
|
|
|
mWorkingPath.Append(NS_LITERAL_CSTRING("\\") + node);
|
2000-05-22 23:38:22 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-05-02 02:21:43 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::Normalize()
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-04-27 09:33:09 +04:00
|
|
|
nsLocalFile::GetNativeLeafName(nsACString &aLeafName)
|
2000-05-02 02:21:43 +04:00
|
|
|
{
|
2002-04-27 09:33:09 +04:00
|
|
|
aLeafName.Truncate();
|
2000-05-02 02:21:43 +04:00
|
|
|
|
2001-03-02 12:26:57 +03:00
|
|
|
const char* temp = mWorkingPath.get();
|
2000-05-02 02:21:43 +04:00
|
|
|
if(temp == nsnull)
|
|
|
|
return NS_ERROR_FILE_UNRECOGNIZED_PATH;
|
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
const char* leaf = (const char*) _mbsrchr((const unsigned char*) temp, '\\');
|
2000-05-02 02:21:43 +04:00
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
// if the working path is just a node without any lashes.
|
2000-05-02 02:21:43 +04:00
|
|
|
if (leaf == nsnull)
|
|
|
|
leaf = temp;
|
|
|
|
else
|
|
|
|
leaf++;
|
|
|
|
|
2002-04-27 09:33:09 +04:00
|
|
|
aLeafName.Assign(leaf);
|
2000-05-02 02:21:43 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-04-27 09:33:09 +04:00
|
|
|
nsLocalFile::SetNativeLeafName(const nsACString &aLeafName)
|
2000-05-02 02:21:43 +04:00
|
|
|
{
|
2000-06-20 18:06:00 +04:00
|
|
|
MakeDirty();
|
|
|
|
|
2001-03-02 12:26:57 +03:00
|
|
|
const unsigned char* temp = (const unsigned char*) mWorkingPath.get();
|
2000-05-02 02:21:43 +04:00
|
|
|
if(temp == nsnull)
|
|
|
|
return NS_ERROR_FILE_UNRECOGNIZED_PATH;
|
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
// cannot use nsCString::RFindChar() due to 0x5c problem
|
|
|
|
PRInt32 offset = (PRInt32) (_mbsrchr(temp, '\\') - temp);
|
2000-05-02 02:21:43 +04:00
|
|
|
if (offset)
|
|
|
|
{
|
2000-06-20 18:06:00 +04:00
|
|
|
mWorkingPath.Truncate(offset+1);
|
2000-05-02 02:21:43 +04:00
|
|
|
}
|
2000-06-20 18:06:00 +04:00
|
|
|
mWorkingPath.Append(aLeafName);
|
2000-05-02 02:21:43 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
|
2000-05-02 02:21:43 +04:00
|
|
|
NS_IMETHODIMP
|
2002-04-27 09:33:09 +04:00
|
|
|
nsLocalFile::GetNativePath(nsACString &_retval)
|
2000-05-02 02:21:43 +04:00
|
|
|
{
|
2002-04-27 09:33:09 +04:00
|
|
|
_retval = mWorkingPath;
|
2000-05-02 02:21:43 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2003-06-20 01:53:26 +04:00
|
|
|
nsLocalFile::CopySingleFile(nsIFile *sourceFile, nsIFile *destParent, const nsACString &newName, PRBool move)
|
2000-05-02 02:21:43 +04:00
|
|
|
{
|
2000-06-20 18:06:00 +04:00
|
|
|
nsresult rv;
|
2002-04-27 09:33:09 +04:00
|
|
|
nsCAutoString filePath;
|
2000-05-02 02:21:43 +04:00
|
|
|
|
2002-04-27 09:33:09 +04:00
|
|
|
nsCAutoString destPath;
|
|
|
|
destParent->GetNativeTarget(destPath);
|
2000-05-25 18:23:27 +04:00
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
destPath.Append("\\");
|
|
|
|
|
2002-04-27 09:33:09 +04:00
|
|
|
if (newName.IsEmpty())
|
2000-06-20 18:06:00 +04:00
|
|
|
{
|
2002-04-27 09:33:09 +04:00
|
|
|
nsCAutoString aFileName;
|
|
|
|
sourceFile->GetNativeLeafName(aFileName);
|
2000-06-20 18:06:00 +04:00
|
|
|
destPath.Append(aFileName);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
destPath.Append(newName);
|
|
|
|
}
|
|
|
|
|
2003-06-20 01:53:26 +04:00
|
|
|
rv = sourceFile->GetNativePath(filePath);
|
|
|
|
|
2000-05-02 02:21:43 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2001-03-23 06:21:22 +03:00
|
|
|
APIRET rc = NO_ERROR;
|
|
|
|
|
|
|
|
if( move )
|
|
|
|
{
|
2002-04-27 09:33:09 +04:00
|
|
|
rc = DosMove(filePath.get(), (PSZ)NS_CONST_CAST(char*, destPath.get()));
|
2001-03-23 06:21:22 +03:00
|
|
|
}
|
|
|
|
|
2002-11-14 22:41:18 +03:00
|
|
|
if (!move || rc == ERROR_NOT_SAME_DEVICE || rc == ERROR_ACCESS_DENIED) {
|
2001-03-23 06:21:22 +03:00
|
|
|
/* will get an error if the destination and source files aren't on the
|
|
|
|
* same drive. "MoveFile()" on Windows will go ahead and move the
|
|
|
|
* file without error, so we need to do the same IBM-AKR
|
|
|
|
*/
|
2002-07-17 09:46:34 +04:00
|
|
|
do {
|
|
|
|
rc = DosCopy(filePath.get(), (PSZ)NS_CONST_CAST(char*, destPath.get()), DCPY_EXISTING);
|
|
|
|
if (rc == ERROR_TOO_MANY_OPEN_FILES) {
|
|
|
|
ULONG CurMaxFH = 0;
|
|
|
|
LONG ReqCount = 20;
|
|
|
|
APIRET rc2;
|
|
|
|
rc2 = DosSetRelMaxFH(&ReqCount, &CurMaxFH);
|
|
|
|
if (rc2 != NO_ERROR) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (rc == ERROR_TOO_MANY_OPEN_FILES);
|
|
|
|
|
2001-02-07 07:29:57 +03:00
|
|
|
/* WSOD2 HACK */
|
|
|
|
if (rc == 65) { // NETWORK_ACCESS_DENIED
|
|
|
|
CHAR achProgram[CCHMAXPATH]; // buffer for program name, parameters
|
|
|
|
RESULTCODES rescResults; // buffer for results of dosexecpgm
|
|
|
|
|
|
|
|
strcpy(achProgram, "CMD.EXE /C ");
|
|
|
|
strcat(achProgram, """COPY ");
|
2002-04-27 09:33:09 +04:00
|
|
|
strcat(achProgram, filePath.get());
|
2001-02-07 07:29:57 +03:00
|
|
|
strcat(achProgram, " ");
|
2001-03-20 10:47:40 +03:00
|
|
|
strcat(achProgram, (PSZ)NS_CONST_CAST(char*, destPath.get()));
|
2001-02-07 07:29:57 +03:00
|
|
|
strcat(achProgram, """");
|
|
|
|
achProgram[strlen(achProgram) + 1] = '\0';
|
|
|
|
achProgram[7] = '\0';
|
|
|
|
DosExecPgm(NULL, 0,
|
|
|
|
EXEC_SYNC, achProgram, (PSZ)NULL,
|
|
|
|
&rescResults, achProgram);
|
|
|
|
rc = 0; // Assume it worked
|
2001-03-23 06:21:22 +03:00
|
|
|
|
|
|
|
} /* rc == 65 */
|
2001-05-30 02:21:11 +04:00
|
|
|
/* moving the file is supposed to act like a rename, so delete the
|
|
|
|
* original file if we got this far without error
|
|
|
|
*/
|
|
|
|
if( move && (rc == NO_ERROR) )
|
|
|
|
{
|
2002-04-27 09:33:09 +04:00
|
|
|
DosDelete( filePath.get() );
|
2001-05-30 02:21:11 +04:00
|
|
|
}
|
2001-03-23 06:21:22 +03:00
|
|
|
} /* !move or ERROR */
|
2000-06-20 18:06:00 +04:00
|
|
|
|
2001-02-07 07:29:57 +03:00
|
|
|
if (rc)
|
|
|
|
rv = ConvertOS2Error(rc);
|
2000-06-20 18:06:00 +04:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
2003-06-20 01:53:26 +04:00
|
|
|
nsLocalFile::CopyMove(nsIFile *aParentDir, const nsACString &newName, PRBool move)
|
2000-06-20 18:06:00 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIFile> newParentDir = aParentDir;
|
2003-06-20 01:53:26 +04:00
|
|
|
|
|
|
|
nsresult rv = Stat();
|
2000-06-20 18:06:00 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (!newParentDir)
|
|
|
|
{
|
|
|
|
// no parent was specified. We must rename.
|
|
|
|
|
2002-04-27 09:33:09 +04:00
|
|
|
if (newName.IsEmpty())
|
2000-06-20 18:06:00 +04:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
rv = GetParent(getter_AddRefs(newParentDir));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!newParentDir)
|
|
|
|
return NS_ERROR_FILE_DESTINATION_NOT_DIR;
|
|
|
|
|
|
|
|
// make sure it exists and is a directory. Create it if not there.
|
|
|
|
PRBool exists;
|
|
|
|
newParentDir->Exists(&exists);
|
|
|
|
if (exists == PR_FALSE)
|
|
|
|
{
|
|
|
|
rv = newParentDir->Create(DIRECTORY_TYPE, 0644); // TODO, what permissions should we use
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PRBool isDir;
|
|
|
|
newParentDir->IsDirectory(&isDir);
|
|
|
|
if (isDir == PR_FALSE)
|
|
|
|
{
|
2003-06-20 01:53:26 +04:00
|
|
|
return NS_ERROR_FILE_DESTINATION_NOT_DIR;
|
2000-06-20 18:06:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check to see if we are a directory, if so enumerate it.
|
|
|
|
|
|
|
|
PRBool isDir;
|
|
|
|
IsDirectory(&isDir);
|
|
|
|
|
2003-06-20 01:53:26 +04:00
|
|
|
if (!isDir)
|
2000-06-20 18:06:00 +04:00
|
|
|
{
|
2003-06-20 01:53:26 +04:00
|
|
|
rv = CopySingleFile(this, newParentDir, newName, move);
|
2000-06-20 18:06:00 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// create a new target destination in the new parentDir;
|
|
|
|
nsCOMPtr<nsIFile> target;
|
|
|
|
rv = newParentDir->Clone(getter_AddRefs(target));
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2002-04-27 09:33:09 +04:00
|
|
|
nsCAutoString allocatedNewName;
|
|
|
|
if (newName.IsEmpty())
|
2000-06-20 18:06:00 +04:00
|
|
|
{
|
2003-06-20 01:53:26 +04:00
|
|
|
GetNativeLeafName(allocatedNewName);// this should be the leaf name of the
|
2000-06-20 18:06:00 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-04-27 09:33:09 +04:00
|
|
|
allocatedNewName = newName;
|
2000-06-20 18:06:00 +04:00
|
|
|
}
|
|
|
|
|
2002-04-27 09:33:09 +04:00
|
|
|
rv = target->AppendNative(allocatedNewName);
|
2000-06-20 18:06:00 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2002-04-27 09:33:09 +04:00
|
|
|
allocatedNewName.Truncate();
|
2000-06-20 18:06:00 +04:00
|
|
|
|
|
|
|
target->Create(DIRECTORY_TYPE, 0644); // TODO, what permissions should we use
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
nsDirEnumerator* dirEnum = new nsDirEnumerator();
|
|
|
|
if (!dirEnum)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
rv = dirEnum->Init(this);
|
|
|
|
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> iterator = do_QueryInterface(dirEnum);
|
|
|
|
|
|
|
|
PRBool more;
|
|
|
|
iterator->HasMoreElements(&more);
|
|
|
|
while (more)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsISupports> item;
|
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
iterator->GetNext(getter_AddRefs(item));
|
|
|
|
file = do_QueryInterface(item);
|
|
|
|
PRBool isDir, isLink;
|
|
|
|
|
|
|
|
file->IsDirectory(&isDir);
|
|
|
|
|
|
|
|
if (move)
|
|
|
|
{
|
2003-06-20 01:53:26 +04:00
|
|
|
rv = file->MoveToNative(target, nsCString());
|
2000-06-20 18:06:00 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-06-20 01:53:26 +04:00
|
|
|
rv = file->CopyToNative(target, nsCString());
|
2000-06-20 18:06:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
iterator->HasMoreElements(&more);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If we moved, we want to adjust this.
|
|
|
|
if (move)
|
|
|
|
{
|
|
|
|
MakeDirty();
|
|
|
|
|
2002-04-27 09:33:09 +04:00
|
|
|
nsCAutoString newParentPath;
|
|
|
|
newParentDir->GetNativePath(newParentPath);
|
2000-06-20 18:06:00 +04:00
|
|
|
|
2002-04-27 09:33:09 +04:00
|
|
|
if (newParentPath.IsEmpty())
|
2000-06-20 18:06:00 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2002-04-27 09:33:09 +04:00
|
|
|
if (newName.IsEmpty())
|
2000-06-20 18:06:00 +04:00
|
|
|
{
|
2002-04-27 09:33:09 +04:00
|
|
|
nsCAutoString aFileName;
|
|
|
|
GetNativeLeafName(aFileName);
|
2000-06-20 18:06:00 +04:00
|
|
|
|
2002-04-27 09:33:09 +04:00
|
|
|
InitWithNativePath(newParentPath);
|
|
|
|
AppendNative(aFileName);
|
2000-06-20 18:06:00 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-04-27 09:33:09 +04:00
|
|
|
InitWithNativePath(newParentPath);
|
|
|
|
AppendNative(newName);
|
2000-06-20 18:06:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-04-27 09:33:09 +04:00
|
|
|
nsLocalFile::CopyToNative(nsIFile *newParentDir, const nsACString &newName)
|
2000-06-20 18:06:00 +04:00
|
|
|
{
|
2003-06-20 01:53:26 +04:00
|
|
|
return CopyMove(newParentDir, newName, PR_FALSE);
|
2000-06-20 18:06:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-04-27 09:33:09 +04:00
|
|
|
nsLocalFile::CopyToFollowingLinksNative(nsIFile *newParentDir, const nsACString &newName)
|
2000-06-20 18:06:00 +04:00
|
|
|
{
|
2003-06-20 01:53:26 +04:00
|
|
|
return CopyMove(newParentDir, newName, PR_FALSE);
|
2000-06-20 18:06:00 +04:00
|
|
|
}
|
2000-05-02 02:21:43 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-04-27 09:33:09 +04:00
|
|
|
nsLocalFile::MoveToNative(nsIFile *newParentDir, const nsACString &newName)
|
2000-05-02 02:21:43 +04:00
|
|
|
{
|
2003-06-20 01:53:26 +04:00
|
|
|
return CopyMove(newParentDir, newName, PR_TRUE);
|
2000-05-02 02:21:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-06-20 18:06:00 +04:00
|
|
|
nsLocalFile::Load(PRLibrary * *_retval)
|
2000-05-02 02:21:43 +04:00
|
|
|
{
|
|
|
|
PRBool isFile;
|
|
|
|
nsresult rv = IsFile(&isFile);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (! isFile)
|
|
|
|
return NS_ERROR_FILE_IS_DIRECTORY;
|
|
|
|
|
2003-06-20 01:53:26 +04:00
|
|
|
*_retval = PR_LoadLibrary(mWorkingPath.get());
|
2000-05-02 02:21:43 +04:00
|
|
|
|
|
|
|
if (*_retval)
|
|
|
|
return NS_OK;
|
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
2000-05-02 02:21:43 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-07-24 22:38:25 +04:00
|
|
|
nsLocalFile::Remove(PRBool recursive)
|
2000-05-02 02:21:43 +04:00
|
|
|
{
|
|
|
|
PRBool isDir;
|
|
|
|
|
|
|
|
nsresult rv = IsDirectory(&isDir);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2003-06-20 01:53:26 +04:00
|
|
|
const char *filePath = mWorkingPath.get();
|
2000-05-02 02:21:43 +04:00
|
|
|
|
|
|
|
if (isDir)
|
|
|
|
{
|
|
|
|
if (recursive)
|
|
|
|
{
|
|
|
|
nsDirEnumerator* dirEnum = new nsDirEnumerator();
|
2000-06-20 18:06:00 +04:00
|
|
|
if (dirEnum == nsnull)
|
2000-05-02 02:21:43 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
rv = dirEnum->Init(this);
|
|
|
|
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> iterator = do_QueryInterface(dirEnum);
|
|
|
|
|
|
|
|
PRBool more;
|
|
|
|
iterator->HasMoreElements(&more);
|
|
|
|
while (more)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsISupports> item;
|
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
iterator->GetNext(getter_AddRefs(item));
|
|
|
|
file = do_QueryInterface(item);
|
|
|
|
|
2001-07-24 22:38:25 +04:00
|
|
|
file->Remove(recursive);
|
2000-05-02 02:21:43 +04:00
|
|
|
|
|
|
|
iterator->HasMoreElements(&more);
|
|
|
|
}
|
|
|
|
}
|
2003-06-19 03:19:11 +04:00
|
|
|
rv = rmdir(filePath) == -1 ? NSRESULT_FOR_ERRNO() : NS_OK;
|
2000-05-02 02:21:43 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-06-19 03:19:11 +04:00
|
|
|
rv = remove(filePath) == -1 ? NSRESULT_FOR_ERRNO() : NS_OK;
|
2000-05-02 02:21:43 +04:00
|
|
|
}
|
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
MakeDirty();
|
2002-01-26 03:38:37 +03:00
|
|
|
return rv;
|
2000-05-02 02:21:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-11-26 11:05:05 +03:00
|
|
|
nsLocalFile::GetLastModifiedTime(PRInt64 *aLastModifiedTime)
|
2000-05-02 02:21:43 +04:00
|
|
|
{
|
2001-11-26 11:05:05 +03:00
|
|
|
NS_ENSURE_ARG(aLastModifiedTime);
|
2000-06-20 18:06:00 +04:00
|
|
|
|
2001-11-26 11:05:05 +03:00
|
|
|
*aLastModifiedTime = 0;
|
2000-06-20 18:06:00 +04:00
|
|
|
|
2003-06-20 01:53:26 +04:00
|
|
|
nsresult rv = Stat();
|
2000-06-20 18:06:00 +04:00
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
// microseconds -> milliseconds
|
2001-11-26 11:05:05 +03:00
|
|
|
*aLastModifiedTime = mFileInfo64.modifyTime / PR_USEC_PER_MSEC;
|
2000-05-02 02:21:43 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
|
2000-05-02 02:21:43 +04:00
|
|
|
NS_IMETHODIMP
|
2001-11-26 11:05:05 +03:00
|
|
|
nsLocalFile::GetLastModifiedTimeOfLink(PRInt64 *aLastModifiedTime)
|
2000-05-02 02:21:43 +04:00
|
|
|
{
|
2003-06-20 01:53:26 +04:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2000-05-02 02:21:43 +04:00
|
|
|
}
|
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
|
2000-05-02 02:21:43 +04:00
|
|
|
NS_IMETHODIMP
|
2001-11-26 11:05:05 +03:00
|
|
|
nsLocalFile::SetLastModifiedTime(PRInt64 aLastModifiedTime)
|
2000-05-02 02:21:43 +04:00
|
|
|
{
|
2003-06-20 01:53:26 +04:00
|
|
|
return nsLocalFile::SetModDate(aLastModifiedTime);
|
2000-05-02 02:21:43 +04:00
|
|
|
}
|
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
|
2000-05-02 02:21:43 +04:00
|
|
|
NS_IMETHODIMP
|
2001-11-26 11:05:05 +03:00
|
|
|
nsLocalFile::SetLastModifiedTimeOfLink(PRInt64 aLastModifiedTime)
|
2000-05-02 02:21:43 +04:00
|
|
|
{
|
2003-06-20 01:53:26 +04:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2000-05-02 02:21:43 +04:00
|
|
|
}
|
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
nsresult
|
2003-06-20 01:53:26 +04:00
|
|
|
nsLocalFile::SetModDate(PRInt64 aLastModifiedTime)
|
2000-06-20 18:06:00 +04:00
|
|
|
{
|
2003-06-20 01:53:26 +04:00
|
|
|
nsresult rv = Stat();
|
2000-06-20 18:06:00 +04:00
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2003-06-20 01:53:26 +04:00
|
|
|
const char *filePath = mWorkingPath.get();
|
2000-06-20 18:06:00 +04:00
|
|
|
|
|
|
|
PRExplodedTime pret;
|
|
|
|
FILESTATUS3 pathInfo;
|
|
|
|
|
|
|
|
rv = DosQueryPathInfo(filePath,
|
|
|
|
FIL_STANDARD, // Level 1 info
|
|
|
|
&pathInfo,
|
|
|
|
sizeof(pathInfo));
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
{
|
|
|
|
rv = ConvertOS2Error(rv);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// PR_ExplodeTime expects usecs...
|
2001-11-26 11:05:05 +03:00
|
|
|
PR_ExplodeTime(aLastModifiedTime * PR_USEC_PER_MSEC, PR_LocalTimeParameters, &pret);
|
2002-10-09 06:37:48 +04:00
|
|
|
/* fdateLastWrite.year is based off of 1980 */
|
|
|
|
if (pret.tm_year >= 1980)
|
|
|
|
pathInfo.fdateLastWrite.year = pret.tm_year-1980;
|
|
|
|
else
|
|
|
|
pathInfo.fdateLastWrite.year = pret.tm_year;
|
2000-06-20 18:06:00 +04:00
|
|
|
pathInfo.fdateLastWrite.month = pret.tm_month + 1; // Convert start offset -- Win32: Jan=1; NSPR: Jan=0
|
|
|
|
// ???? OS2TODO st.wDayOfWeek = pret.tm_wday;
|
|
|
|
pathInfo.fdateLastWrite.day = pret.tm_mday;
|
|
|
|
pathInfo.ftimeLastWrite.hours = pret.tm_hour;
|
|
|
|
pathInfo.ftimeLastWrite.minutes = pret.tm_min;
|
|
|
|
pathInfo.ftimeLastWrite.twosecs = pret.tm_sec / 2; // adjust for twosecs?
|
|
|
|
// ??? OS2TODO st.wMilliseconds = pret.tm_usec/1000;
|
|
|
|
|
|
|
|
rv = DosSetPathInfo(filePath,
|
|
|
|
FIL_STANDARD, // Level 1 info
|
|
|
|
&pathInfo,
|
|
|
|
sizeof(pathInfo),
|
|
|
|
0UL);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
MakeDirty();
|
|
|
|
return rv;
|
|
|
|
}
|
2000-05-02 02:21:43 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::GetPermissions(PRUint32 *aPermissions)
|
|
|
|
{
|
2003-06-20 01:53:26 +04:00
|
|
|
nsresult rv = Stat();
|
2000-06-20 18:06:00 +04:00
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2003-06-20 01:53:26 +04:00
|
|
|
const char *filePath = mWorkingPath.get();
|
2000-06-20 18:06:00 +04:00
|
|
|
|
|
|
|
|
2000-05-02 02:21:43 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::GetPermissionsOfLink(PRUint32 *aPermissionsOfLink)
|
|
|
|
{
|
2000-06-20 18:06:00 +04:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2000-05-02 02:21:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::SetPermissions(PRUint32 aPermissions)
|
|
|
|
{
|
2003-06-20 01:53:26 +04:00
|
|
|
nsresult rv = Stat();
|
2000-06-20 18:06:00 +04:00
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2003-06-20 01:53:26 +04:00
|
|
|
const char *filePath = mWorkingPath.get();
|
2000-06-20 18:06:00 +04:00
|
|
|
if( chmod(filePath, aPermissions) == -1 )
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return NS_OK;
|
2000-05-02 02:21:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::SetPermissionsOfLink(PRUint32 aPermissions)
|
|
|
|
{
|
2003-06-20 01:53:26 +04:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2000-05-02 02:21:43 +04:00
|
|
|
}
|
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-05-02 02:21:43 +04:00
|
|
|
nsLocalFile::GetFileSize(PRInt64 *aFileSize)
|
|
|
|
{
|
2000-06-20 18:06:00 +04:00
|
|
|
NS_ENSURE_ARG(aFileSize);
|
|
|
|
|
|
|
|
*aFileSize = 0;
|
|
|
|
|
2003-06-20 01:53:26 +04:00
|
|
|
nsresult rv = Stat();
|
2000-06-20 18:06:00 +04:00
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
|
|
|
|
*aFileSize = mFileInfo64.size;
|
2000-05-02 02:21:43 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::SetFileSize(PRInt64 aFileSize)
|
|
|
|
{
|
|
|
|
|
2003-06-20 01:53:26 +04:00
|
|
|
nsresult rv = Stat();
|
2000-06-20 18:06:00 +04:00
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
2000-05-02 02:21:43 +04:00
|
|
|
return rv;
|
2000-06-20 18:06:00 +04:00
|
|
|
|
2003-06-20 01:53:26 +04:00
|
|
|
const char *filePath = mWorkingPath.get();
|
2000-06-20 18:06:00 +04:00
|
|
|
|
|
|
|
|
|
|
|
APIRET rc;
|
|
|
|
HFILE hFile;
|
|
|
|
ULONG actionTaken;
|
|
|
|
|
|
|
|
rc = DosOpen(filePath,
|
|
|
|
&hFile,
|
|
|
|
&actionTaken,
|
|
|
|
0,
|
|
|
|
FILE_NORMAL,
|
|
|
|
OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
|
|
|
|
OPEN_SHARE_DENYREADWRITE | OPEN_ACCESS_READWRITE,
|
|
|
|
NULL);
|
2002-07-17 09:46:34 +04:00
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
if (rc != NO_ERROR)
|
|
|
|
{
|
|
|
|
MakeDirty();
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2003-01-02 00:20:37 +03:00
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
// Seek to new, desired end of file
|
|
|
|
PRInt32 hi, lo;
|
|
|
|
myLL_L2II(aFileSize, &hi, &lo );
|
|
|
|
|
|
|
|
rc = DosSetFileSize(hFile, lo);
|
|
|
|
if (rc == NO_ERROR)
|
|
|
|
DosClose(hFile);
|
2000-05-02 02:21:43 +04:00
|
|
|
else
|
2000-06-20 18:06:00 +04:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
MakeDirty();
|
2000-05-02 02:21:43 +04:00
|
|
|
return NS_OK;
|
2000-06-20 18:06:00 +04:00
|
|
|
|
|
|
|
error:
|
|
|
|
MakeDirty();
|
|
|
|
DosClose(hFile);
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-05-02 02:21:43 +04:00
|
|
|
}
|
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::GetFileSizeOfLink(PRInt64 *aFileSize)
|
2000-05-02 02:21:43 +04:00
|
|
|
{
|
2003-06-20 01:53:26 +04:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2000-06-20 18:06:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::GetDiskSpaceAvailable(PRInt64 *aDiskSpaceAvailable)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aDiskSpaceAvailable);
|
|
|
|
|
2003-06-20 01:53:26 +04:00
|
|
|
ULONG ulDriveNo = toupper(mWorkingPath.CharAt(0)) + 1 - 'A';
|
2000-06-20 18:06:00 +04:00
|
|
|
FSALLOCATE fsAllocate;
|
2002-06-05 08:02:33 +04:00
|
|
|
APIRET rc = DosQueryFSInfo(ulDriveNo,
|
|
|
|
FSIL_ALLOC,
|
|
|
|
&fsAllocate,
|
|
|
|
sizeof(fsAllocate));
|
2000-06-20 18:06:00 +04:00
|
|
|
|
2002-06-05 08:02:33 +04:00
|
|
|
if (rc != NO_ERROR)
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-06-20 18:06:00 +04:00
|
|
|
|
2002-06-05 08:02:33 +04:00
|
|
|
*aDiskSpaceAvailable = fsAllocate.cUnitAvail;
|
|
|
|
*aDiskSpaceAvailable *= fsAllocate.cSectorUnit;
|
|
|
|
*aDiskSpaceAvailable *= fsAllocate.cbSector;
|
2000-05-02 02:21:43 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::GetParent(nsIFile * *aParent)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aParent);
|
|
|
|
|
2002-04-27 09:33:09 +04:00
|
|
|
nsCAutoString parentPath(mWorkingPath);
|
2000-05-02 02:21:43 +04:00
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
// cannot use nsCString::RFindChar() due to 0x5c problem
|
2001-03-02 12:26:57 +03:00
|
|
|
PRInt32 offset = (PRInt32) (_mbsrchr((const unsigned char *) parentPath.get(), '\\')
|
|
|
|
- (const unsigned char *) parentPath.get());
|
2000-10-06 00:44:11 +04:00
|
|
|
if (offset < 0)
|
2000-05-02 02:21:43 +04:00
|
|
|
return NS_ERROR_FILE_UNRECOGNIZED_PATH;
|
|
|
|
|
|
|
|
parentPath.Truncate(offset);
|
|
|
|
|
|
|
|
nsCOMPtr<nsILocalFile> localFile;
|
2003-06-20 01:53:26 +04:00
|
|
|
nsresult rv = NS_NewNativeLocalFile(parentPath, PR_TRUE, getter_AddRefs(localFile));
|
2000-05-02 02:21:43 +04:00
|
|
|
|
|
|
|
if(NS_SUCCEEDED(rv) && localFile)
|
|
|
|
{
|
2002-04-27 09:33:09 +04:00
|
|
|
return CallQueryInterface(localFile, aParent);
|
2000-05-02 02:21:43 +04:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::Exists(PRBool *_retval)
|
|
|
|
{
|
2000-06-20 18:06:00 +04:00
|
|
|
NS_ENSURE_ARG(_retval);
|
|
|
|
|
|
|
|
MakeDirty();
|
2003-06-20 01:53:26 +04:00
|
|
|
*_retval = NS_SUCCEEDED(Stat());
|
|
|
|
|
2000-05-02 02:21:43 +04:00
|
|
|
return NS_OK;
|
2000-06-20 18:06:00 +04:00
|
|
|
}
|
2000-05-02 02:21:43 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::IsWritable(PRBool *_retval)
|
|
|
|
{
|
2000-06-20 18:06:00 +04:00
|
|
|
NS_ENSURE_ARG(_retval);
|
|
|
|
*_retval = PR_FALSE;
|
|
|
|
|
2003-06-20 01:53:26 +04:00
|
|
|
nsresult rv = Stat();
|
2000-06-20 18:06:00 +04:00
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2001-03-02 12:26:57 +03:00
|
|
|
const char *workingFilePath = mWorkingPath.get();
|
2000-06-20 18:06:00 +04:00
|
|
|
|
|
|
|
APIRET rc;
|
|
|
|
FILESTATUS3 pathInfo;
|
|
|
|
|
|
|
|
rc = DosQueryPathInfo(workingFilePath,
|
|
|
|
FIL_STANDARD, // Level 1 info
|
|
|
|
&pathInfo,
|
|
|
|
sizeof(pathInfo));
|
|
|
|
|
|
|
|
if (rc != NO_ERROR)
|
|
|
|
{
|
|
|
|
rc = ConvertOS2Error(rc);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
*_retval = !((pathInfo.attrFile & FILE_READONLY) != 0);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-05-02 02:21:43 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::IsReadable(PRBool *_retval)
|
|
|
|
{
|
2000-06-20 18:06:00 +04:00
|
|
|
NS_ENSURE_ARG(_retval);
|
|
|
|
*_retval = PR_FALSE;
|
|
|
|
|
2003-06-20 01:53:26 +04:00
|
|
|
nsresult rv = Stat();
|
2000-06-20 18:06:00 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
*_retval = PR_TRUE;
|
|
|
|
return NS_OK;
|
2000-05-02 02:21:43 +04:00
|
|
|
}
|
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
|
2000-05-02 02:21:43 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::IsExecutable(PRBool *_retval)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(_retval);
|
2000-06-20 18:06:00 +04:00
|
|
|
*_retval = PR_FALSE;
|
2000-05-02 02:21:43 +04:00
|
|
|
|
2003-06-20 01:53:26 +04:00
|
|
|
nsresult rv = Stat();
|
2000-06-20 18:06:00 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2002-04-27 09:33:09 +04:00
|
|
|
nsCAutoString path;
|
2003-06-20 01:53:26 +04:00
|
|
|
GetNativeTarget(path);
|
2000-06-20 18:06:00 +04:00
|
|
|
|
2002-04-27 09:33:09 +04:00
|
|
|
const char* leaf = (const char*) _mbsrchr((const unsigned char*) path.get(), '\\');
|
2000-06-20 18:06:00 +04:00
|
|
|
|
|
|
|
if ( (strstr(leaf, ".bat") != nsnull) ||
|
|
|
|
(strstr(leaf, ".exe") != nsnull) ||
|
|
|
|
(strstr(leaf, ".cmd") != nsnull) ||
|
|
|
|
(strstr(leaf, ".com") != nsnull) ) {
|
|
|
|
*_retval = PR_TRUE;
|
|
|
|
} else {
|
2000-05-02 02:21:43 +04:00
|
|
|
*_retval = PR_FALSE;
|
2000-06-20 18:06:00 +04:00
|
|
|
}
|
|
|
|
|
2000-05-02 02:21:43 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
|
2000-05-02 02:21:43 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::IsDirectory(PRBool *_retval)
|
|
|
|
{
|
2000-06-20 18:06:00 +04:00
|
|
|
NS_ENSURE_ARG(_retval);
|
|
|
|
*_retval = PR_FALSE;
|
|
|
|
|
2003-06-20 01:53:26 +04:00
|
|
|
nsresult rv = Stat();
|
2000-06-20 18:06:00 +04:00
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
*_retval = (mFileInfo64.type == PR_FILE_DIRECTORY);
|
|
|
|
|
2000-05-02 02:21:43 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::IsFile(PRBool *_retval)
|
|
|
|
{
|
2000-06-20 18:06:00 +04:00
|
|
|
NS_ENSURE_ARG(_retval);
|
|
|
|
*_retval = PR_FALSE;
|
|
|
|
|
2003-06-20 01:53:26 +04:00
|
|
|
nsresult rv = Stat();
|
2000-06-20 18:06:00 +04:00
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
*_retval = (mFileInfo64.type == PR_FILE_FILE);
|
|
|
|
return rv;
|
2000-05-02 02:21:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::IsHidden(PRBool *_retval)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(_retval);
|
2000-06-20 18:06:00 +04:00
|
|
|
*_retval = PR_FALSE;
|
2000-05-02 02:21:43 +04:00
|
|
|
|
2003-06-20 01:53:26 +04:00
|
|
|
nsresult rv = Stat();
|
2000-06-20 18:06:00 +04:00
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
2000-05-02 02:21:43 +04:00
|
|
|
return rv;
|
2000-06-20 18:06:00 +04:00
|
|
|
|
2001-03-02 12:26:57 +03:00
|
|
|
const char *workingFilePath = mWorkingPath.get();
|
2000-06-20 18:06:00 +04:00
|
|
|
|
|
|
|
APIRET rc;
|
|
|
|
FILESTATUS3 pathInfo;
|
|
|
|
|
|
|
|
rc = DosQueryPathInfo(workingFilePath,
|
|
|
|
FIL_STANDARD, // Level 1 info
|
|
|
|
&pathInfo,
|
|
|
|
sizeof(pathInfo));
|
|
|
|
|
|
|
|
if (rc != NO_ERROR)
|
|
|
|
{
|
|
|
|
rc = ConvertOS2Error(rc);
|
|
|
|
return rc;
|
|
|
|
}
|
2000-05-02 02:21:43 +04:00
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
*_retval = ((pathInfo.attrFile & FILE_HIDDEN) != 0);
|
|
|
|
|
|
|
|
return NS_OK;
|
2000-05-02 02:21:43 +04:00
|
|
|
}
|
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
|
2000-05-02 02:21:43 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::IsSymlink(PRBool *_retval)
|
|
|
|
{
|
2003-01-02 00:20:37 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
|
|
|
// No Symlinks on OS/2
|
2000-06-20 18:06:00 +04:00
|
|
|
*_retval = PR_FALSE;
|
|
|
|
|
2000-05-02 02:21:43 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::IsSpecial(PRBool *_retval)
|
|
|
|
{
|
2000-06-20 18:06:00 +04:00
|
|
|
NS_ENSURE_ARG(_retval);
|
|
|
|
*_retval = PR_FALSE;
|
|
|
|
|
2003-06-20 01:53:26 +04:00
|
|
|
nsresult rv = Stat();
|
2000-06-20 18:06:00 +04:00
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2001-03-02 12:26:57 +03:00
|
|
|
const char *workingFilePath = mWorkingPath.get();
|
2000-06-20 18:06:00 +04:00
|
|
|
|
|
|
|
APIRET rc;
|
|
|
|
FILESTATUS3 pathInfo;
|
|
|
|
|
|
|
|
rc = DosQueryPathInfo(workingFilePath,
|
|
|
|
FIL_STANDARD, // Level 1 info
|
|
|
|
&pathInfo,
|
|
|
|
sizeof(pathInfo));
|
|
|
|
|
|
|
|
if (rc != NO_ERROR)
|
|
|
|
{
|
|
|
|
rc = ConvertOS2Error(rc);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
*_retval = ((pathInfo.attrFile & FILE_SYSTEM) != 0);
|
|
|
|
|
2000-05-02 02:21:43 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::Equals(nsIFile *inFile, PRBool *_retval)
|
|
|
|
{
|
2000-06-20 18:06:00 +04:00
|
|
|
NS_ENSURE_ARG(inFile);
|
|
|
|
NS_ENSURE_ARG(_retval);
|
2000-05-02 02:21:43 +04:00
|
|
|
*_retval = PR_FALSE;
|
|
|
|
|
2002-04-27 09:33:09 +04:00
|
|
|
nsCAutoString inFilePath;
|
|
|
|
inFile->GetNativePath(inFilePath);
|
2000-05-02 02:21:43 +04:00
|
|
|
|
2002-04-27 09:33:09 +04:00
|
|
|
*_retval = inFilePath.Equals(mWorkingPath);
|
2000-05-02 02:21:43 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::Contains(nsIFile *inFile, PRBool recur, PRBool *_retval)
|
|
|
|
{
|
|
|
|
*_retval = PR_FALSE;
|
|
|
|
|
2002-04-27 09:33:09 +04:00
|
|
|
nsCAutoString myFilePath;
|
|
|
|
if ( NS_FAILED(GetNativeTarget(myFilePath)))
|
|
|
|
GetNativePath(myFilePath);
|
2000-05-02 02:21:43 +04:00
|
|
|
|
2002-04-27 09:33:09 +04:00
|
|
|
PRInt32 myFilePathLen = myFilePath.Length();
|
2000-05-02 02:21:43 +04:00
|
|
|
|
2002-04-27 09:33:09 +04:00
|
|
|
nsCAutoString inFilePath;
|
|
|
|
if ( NS_FAILED(inFile->GetNativeTarget(inFilePath)))
|
|
|
|
inFile->GetNativePath(inFilePath);
|
2000-05-02 02:21:43 +04:00
|
|
|
|
2003-04-18 06:22:17 +04:00
|
|
|
if ( strnicmp( myFilePath.get(), inFilePath.get(), myFilePathLen) == 0)
|
2000-05-02 02:21:43 +04:00
|
|
|
{
|
|
|
|
// now make sure that the |inFile|'s path has a trailing
|
|
|
|
// separator.
|
|
|
|
|
|
|
|
if (inFilePath[myFilePathLen] == '\\')
|
|
|
|
{
|
|
|
|
*_retval = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-04-27 09:33:09 +04:00
|
|
|
nsLocalFile::GetNativeTarget(nsACString &_retval)
|
2000-05-02 02:21:43 +04:00
|
|
|
{
|
2003-06-20 01:53:26 +04:00
|
|
|
_retval = mWorkingPath;
|
2000-05-02 02:21:43 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-07-13 03:31:31 +04:00
|
|
|
/* attribute PRBool followLinks; */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::GetFollowLinks(PRBool *aFollowLinks)
|
|
|
|
{
|
2003-06-20 01:53:26 +04:00
|
|
|
*aFollowLinks = PR_TRUE;
|
2000-07-13 03:31:31 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::SetFollowLinks(PRBool aFollowLinks)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-05-02 02:21:43 +04:00
|
|
|
NS_IMETHODIMP
|
2000-06-20 18:06:00 +04:00
|
|
|
nsLocalFile::GetDirectoryEntries(nsISimpleEnumerator * *entries)
|
2000-05-02 02:21:43 +04:00
|
|
|
{
|
2000-06-20 18:06:00 +04:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
*entries = nsnull;
|
2000-05-02 02:21:43 +04:00
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
PRBool isDir;
|
|
|
|
rv = IsDirectory(&isDir);
|
2000-05-02 02:21:43 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
if (!isDir)
|
|
|
|
return NS_ERROR_FILE_NOT_DIRECTORY;
|
|
|
|
|
|
|
|
nsDirEnumerator* dirEnum = new nsDirEnumerator();
|
|
|
|
if (dirEnum == nsnull)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(dirEnum);
|
|
|
|
rv = dirEnum->Init(this);
|
2000-06-20 18:06:00 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
{
|
2000-05-02 02:21:43 +04:00
|
|
|
NS_RELEASE(dirEnum);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
*entries = dirEnum;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-07-17 19:01:10 +04:00
|
|
|
NS_IMETHODIMP
|
2002-04-27 09:33:09 +04:00
|
|
|
nsLocalFile::GetPersistentDescriptor(nsACString &aPersistentDescriptor)
|
2000-07-17 19:01:10 +04:00
|
|
|
{
|
2002-04-27 09:33:09 +04:00
|
|
|
return GetNativePath(aPersistentDescriptor);
|
2000-07-17 19:01:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-04-27 09:33:09 +04:00
|
|
|
nsLocalFile::SetPersistentDescriptor(const nsACString &aPersistentDescriptor)
|
2000-07-17 19:01:10 +04:00
|
|
|
{
|
2002-04-27 09:33:09 +04:00
|
|
|
return InitWithNativePath(aPersistentDescriptor);
|
2000-07-17 19:01:10 +04:00
|
|
|
}
|
|
|
|
|
2001-02-01 00:04:04 +03:00
|
|
|
#ifndef OPEN_DEFAULT
|
2003-01-22 07:58:09 +03:00
|
|
|
#define OPEN_DEFAULT 0
|
|
|
|
#define OPEN_CONTENTS 1
|
2001-02-01 00:04:04 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2001-01-30 08:02:48 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::Reveal()
|
|
|
|
{
|
2001-08-22 08:33:17 +04:00
|
|
|
PRBool isDirectory = PR_FALSE;
|
2002-04-27 09:33:09 +04:00
|
|
|
nsCAutoString path;
|
2001-08-22 08:33:17 +04:00
|
|
|
|
|
|
|
IsDirectory(&isDirectory);
|
|
|
|
if (isDirectory)
|
|
|
|
{
|
2002-04-27 09:33:09 +04:00
|
|
|
GetNativePath(path);
|
2001-08-22 08:33:17 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIFile> parent;
|
|
|
|
GetParent(getter_AddRefs(parent));
|
|
|
|
if (parent)
|
2002-04-27 09:33:09 +04:00
|
|
|
parent->GetNativePath(path);
|
2001-08-22 08:33:17 +04:00
|
|
|
}
|
|
|
|
|
2002-04-27 09:33:09 +04:00
|
|
|
HOBJECT hobject = WinQueryObject(path.get());
|
2003-01-22 07:58:09 +03:00
|
|
|
WinSetFocus(HWND_DESKTOP, HWND_DESKTOP);
|
|
|
|
WinOpenObject( hobject, OPEN_CONTENTS, TRUE);
|
2001-02-01 00:04:04 +03:00
|
|
|
|
|
|
|
// we don't care if it succeeded or failed.
|
|
|
|
return NS_OK;
|
2001-01-30 08:02:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::Launch()
|
|
|
|
{
|
2002-04-27 09:33:09 +04:00
|
|
|
HOBJECT hobject = WinQueryObject(mWorkingPath.get());
|
2003-01-22 07:58:09 +03:00
|
|
|
WinSetFocus(HWND_DESKTOP, HWND_DESKTOP);
|
2001-08-22 08:33:17 +04:00
|
|
|
WinOpenObject( hobject, OPEN_DEFAULT, TRUE);
|
|
|
|
|
|
|
|
// we don't care if it succeeded or failed.
|
|
|
|
return NS_OK;
|
2001-01-30 08:02:48 +03:00
|
|
|
}
|
2000-06-20 18:06:00 +04:00
|
|
|
|
2000-05-02 02:21:43 +04:00
|
|
|
nsresult
|
2002-04-27 09:33:09 +04:00
|
|
|
NS_NewNativeLocalFile(const nsACString &path, PRBool followLinks, nsILocalFile* *result)
|
2000-05-02 02:21:43 +04:00
|
|
|
{
|
|
|
|
nsLocalFile* file = new nsLocalFile();
|
|
|
|
if (file == nsnull)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(file);
|
|
|
|
|
2002-04-27 09:33:09 +04:00
|
|
|
if (!path.IsEmpty()) {
|
|
|
|
nsresult rv = file->InitWithNativePath(path);
|
2000-07-20 18:54:24 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_RELEASE(file);
|
|
|
|
return rv;
|
|
|
|
}
|
2000-05-02 02:21:43 +04:00
|
|
|
}
|
2000-07-20 18:54:24 +04:00
|
|
|
|
2000-05-02 02:21:43 +04:00
|
|
|
*result = file;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
// Locates the first occurrence of charToSearchFor in the stringToSearch
|
|
|
|
static unsigned char* PR_CALLBACK
|
|
|
|
_mbschr( const unsigned char* stringToSearch, int charToSearchFor)
|
|
|
|
{
|
2000-10-06 00:44:11 +04:00
|
|
|
const unsigned char* p = stringToSearch;
|
|
|
|
do {
|
|
|
|
if (*p == charToSearchFor)
|
|
|
|
break;
|
|
|
|
p = (const unsigned char*)WinNextChar(0,0,0,(char*)p);
|
|
|
|
} while (*p); /* enddo */
|
|
|
|
// Result is p or NULL
|
|
|
|
return *p ? (unsigned char*)p : NULL;
|
2000-06-20 18:06:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Locates last occurence of charToSearchFor in the stringToSearch
|
2001-02-01 00:58:27 +03:00
|
|
|
extern unsigned char*
|
2000-06-20 18:06:00 +04:00
|
|
|
_mbsrchr( const unsigned char* stringToSearch, int charToSearchFor)
|
|
|
|
{
|
2000-10-06 00:44:11 +04:00
|
|
|
int length = strlen((const char*)stringToSearch);
|
|
|
|
const unsigned char* p = stringToSearch+length;
|
2000-06-20 18:06:00 +04:00
|
|
|
do {
|
2000-10-06 00:44:11 +04:00
|
|
|
if (*p == charToSearchFor)
|
|
|
|
break;
|
|
|
|
p = (const unsigned char*)WinPrevChar(0,0,0,(char*)stringToSearch,(char*)p);
|
|
|
|
} while (p > stringToSearch); /* enddo */
|
|
|
|
// Result is p or NULL
|
|
|
|
return (*p == charToSearchFor) ? (unsigned char*)p : NULL;
|
2000-05-02 02:21:43 +04:00
|
|
|
}
|
2000-07-20 18:54:24 +04:00
|
|
|
|
|
|
|
// Implement equivalent of Win32 CreateDirectoryA
|
|
|
|
static nsresult PR_CALLBACK
|
2003-06-20 01:53:26 +04:00
|
|
|
CreateDirectoryA( PSZ path, PEAOP2 ppEABuf)
|
2000-07-20 18:54:24 +04:00
|
|
|
{
|
|
|
|
APIRET rc;
|
|
|
|
nsresult rv;
|
|
|
|
FILESTATUS3 pathInfo;
|
|
|
|
|
2003-06-20 01:53:26 +04:00
|
|
|
rc = DosCreateDir( path, ppEABuf );
|
2000-07-20 18:54:24 +04:00
|
|
|
if (rc != NO_ERROR) {
|
|
|
|
rv = ConvertOS2Error(rc);
|
|
|
|
|
|
|
|
// Check if directory already exists and if so, reflect that in the return value
|
2003-06-20 01:53:26 +04:00
|
|
|
rc = DosQueryPathInfo(path,
|
|
|
|
FIL_STANDARD, // Level 1 info
|
|
|
|
&pathInfo,
|
|
|
|
sizeof(pathInfo));
|
2000-07-20 18:54:24 +04:00
|
|
|
if (rc == NO_ERROR)
|
|
|
|
rv = ERROR_FILE_EXISTS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
rv = rc;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
2000-10-06 00:44:11 +04:00
|
|
|
|
|
|
|
static int isleadbyte(int c)
|
|
|
|
{
|
|
|
|
static BOOL bDBCSFilled=FALSE;
|
2000-11-02 18:41:44 +03:00
|
|
|
static BYTE DBCSInfo[12] = { 0 }; /* According to the Control Program Guide&Ref,
|
2000-10-06 00:44:11 +04:00
|
|
|
12 bytes is sufficient */
|
2000-11-02 18:41:44 +03:00
|
|
|
BYTE *curr;
|
2000-10-06 00:44:11 +04:00
|
|
|
BOOL retval = FALSE;
|
|
|
|
|
|
|
|
if( !bDBCSFilled ) {
|
|
|
|
COUNTRYCODE ctrycodeInfo = { 0 };
|
|
|
|
APIRET rc = NO_ERROR;
|
|
|
|
ctrycodeInfo.country = 0; /* Current Country */
|
|
|
|
ctrycodeInfo.codepage = 0; /* Current Codepage */
|
|
|
|
|
|
|
|
rc = DosQueryDBCSEnv( sizeof( DBCSInfo ),
|
|
|
|
&ctrycodeInfo,
|
|
|
|
DBCSInfo );
|
|
|
|
if( rc != NO_ERROR ) {
|
|
|
|
/* we had an error, do something? */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
bDBCSFilled=TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
curr = DBCSInfo;
|
|
|
|
/* DBCSInfo returned by DosQueryDBCSEnv is terminated with two '0' bytes in a row */
|
|
|
|
while(( *curr != 0 ) && ( *(curr+1) != 0)) {
|
|
|
|
if(( c >= *curr ) && ( c <= *(curr+1) )) {
|
|
|
|
retval=TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
curr+=2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
2002-04-24 07:47:06 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-05-08 03:07:19 +04:00
|
|
|
nsLocalFile::InitWithPath(const nsAString &filePath)
|
2002-04-24 07:47:06 +04:00
|
|
|
{
|
2002-05-08 03:07:19 +04:00
|
|
|
if (filePath.IsEmpty())
|
|
|
|
return InitWithNativePath(nsCString());
|
2002-04-24 07:47:06 +04:00
|
|
|
|
2002-10-06 04:29:46 +04:00
|
|
|
nsCAutoString tmp;
|
|
|
|
nsresult rv = NS_CopyUnicodeToNative(filePath, tmp);
|
2002-04-24 07:47:06 +04:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2002-04-27 09:33:09 +04:00
|
|
|
return InitWithNativePath(tmp);
|
2002-04-24 07:47:06 +04:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-05-08 03:07:19 +04:00
|
|
|
nsLocalFile::Append(const nsAString &node)
|
2002-04-24 07:47:06 +04:00
|
|
|
{
|
2002-05-08 03:07:19 +04:00
|
|
|
if (node.IsEmpty())
|
2002-04-24 07:47:06 +04:00
|
|
|
return NS_OK;
|
|
|
|
|
2002-10-06 04:29:46 +04:00
|
|
|
nsCAutoString tmp;
|
|
|
|
nsresult rv = NS_CopyUnicodeToNative(node, tmp);
|
2002-04-24 07:47:06 +04:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2002-04-27 09:33:09 +04:00
|
|
|
return AppendNative(tmp);
|
2002-04-24 07:47:06 +04:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-05-08 03:07:19 +04:00
|
|
|
nsLocalFile::AppendRelativePath(const nsAString &node)
|
2002-04-24 07:47:06 +04:00
|
|
|
{
|
2002-05-08 03:07:19 +04:00
|
|
|
if (node.IsEmpty())
|
2002-04-24 07:47:06 +04:00
|
|
|
return NS_OK;
|
|
|
|
|
2002-10-06 04:29:46 +04:00
|
|
|
nsCAutoString tmp;
|
|
|
|
nsresult rv = NS_CopyUnicodeToNative(node, tmp);
|
2002-04-24 07:47:06 +04:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2002-04-27 09:33:09 +04:00
|
|
|
return AppendRelativeNativePath(tmp);
|
2002-04-24 07:47:06 +04:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-05-08 03:07:19 +04:00
|
|
|
nsLocalFile::GetLeafName(nsAString &aLeafName)
|
2002-04-24 07:47:06 +04:00
|
|
|
{
|
2002-04-27 09:33:09 +04:00
|
|
|
nsCAutoString tmp;
|
|
|
|
nsresult rv = GetNativeLeafName(tmp);
|
2002-04-24 07:47:06 +04:00
|
|
|
|
2002-10-06 04:29:46 +04:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
rv = NS_CopyNativeToUnicode(tmp, aLeafName);
|
2002-04-24 07:47:06 +04:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-05-08 03:07:19 +04:00
|
|
|
nsLocalFile::SetLeafName(const nsAString &aLeafName)
|
2002-04-24 07:47:06 +04:00
|
|
|
{
|
2002-05-08 03:07:19 +04:00
|
|
|
if (aLeafName.IsEmpty())
|
|
|
|
return SetNativeLeafName(nsCString());
|
2002-04-24 07:47:06 +04:00
|
|
|
|
2002-10-06 04:29:46 +04:00
|
|
|
nsCAutoString tmp;
|
|
|
|
nsresult rv = NS_CopyUnicodeToNative(aLeafName, tmp);
|
2002-04-24 07:47:06 +04:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2002-04-27 09:33:09 +04:00
|
|
|
return SetNativeLeafName(tmp);
|
2002-04-24 07:47:06 +04:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-05-08 03:07:19 +04:00
|
|
|
nsLocalFile::GetPath(nsAString &_retval)
|
2002-04-24 07:47:06 +04:00
|
|
|
{
|
2002-10-06 04:29:46 +04:00
|
|
|
return NS_CopyNativeToUnicode(mWorkingPath, _retval);
|
2002-04-24 07:47:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-05-08 03:07:19 +04:00
|
|
|
nsLocalFile::CopyTo(nsIFile *newParentDir, const nsAString &newName)
|
2002-04-24 07:47:06 +04:00
|
|
|
{
|
2002-05-08 03:07:19 +04:00
|
|
|
if (newName.IsEmpty())
|
2002-04-27 09:33:09 +04:00
|
|
|
return CopyToNative(newParentDir, nsCString());
|
2002-04-24 07:47:06 +04:00
|
|
|
|
2002-10-06 04:29:46 +04:00
|
|
|
nsCAutoString tmp;
|
|
|
|
nsresult rv = NS_CopyUnicodeToNative(newName, tmp);
|
2002-04-24 07:47:06 +04:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2002-04-27 09:33:09 +04:00
|
|
|
return CopyToNative(newParentDir, tmp);
|
2002-04-24 07:47:06 +04:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-05-08 03:07:19 +04:00
|
|
|
nsLocalFile::CopyToFollowingLinks(nsIFile *newParentDir, const nsAString &newName)
|
2002-04-24 07:47:06 +04:00
|
|
|
{
|
2002-05-08 03:07:19 +04:00
|
|
|
if (newName.IsEmpty())
|
2002-04-27 09:33:09 +04:00
|
|
|
return CopyToFollowingLinksNative(newParentDir, nsCString());
|
2002-04-24 07:47:06 +04:00
|
|
|
|
2002-10-06 04:29:46 +04:00
|
|
|
nsCAutoString tmp;
|
|
|
|
nsresult rv = NS_CopyUnicodeToNative(newName, tmp);
|
2002-04-24 07:47:06 +04:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2002-04-27 09:33:09 +04:00
|
|
|
return CopyToFollowingLinksNative(newParentDir, tmp);
|
2002-04-24 07:47:06 +04:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-05-08 03:07:19 +04:00
|
|
|
nsLocalFile::MoveTo(nsIFile *newParentDir, const nsAString &newName)
|
2002-04-24 07:47:06 +04:00
|
|
|
{
|
2002-05-08 03:07:19 +04:00
|
|
|
if (newName.IsEmpty())
|
2002-04-27 09:33:09 +04:00
|
|
|
return MoveToNative(newParentDir, nsCString());
|
2002-04-24 07:47:06 +04:00
|
|
|
|
2002-10-06 04:29:46 +04:00
|
|
|
nsCAutoString tmp;
|
|
|
|
nsresult rv = NS_CopyUnicodeToNative(newName, tmp);
|
2002-04-24 07:47:06 +04:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2002-04-27 09:33:09 +04:00
|
|
|
return MoveToNative(newParentDir, tmp);
|
2002-04-24 07:47:06 +04:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-05-08 03:07:19 +04:00
|
|
|
nsLocalFile::GetTarget(nsAString &_retval)
|
2002-04-24 07:47:06 +04:00
|
|
|
{
|
2002-04-27 09:33:09 +04:00
|
|
|
nsCAutoString tmp;
|
|
|
|
nsresult rv = GetNativeTarget(tmp);
|
2002-04-24 07:47:06 +04:00
|
|
|
|
2002-10-06 04:29:46 +04:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
rv = NS_CopyNativeToUnicode(tmp, _retval);
|
2002-04-24 07:47:06 +04:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2002-05-08 03:07:19 +04:00
|
|
|
NS_NewLocalFile(const nsAString &path, PRBool followLinks, nsILocalFile* *result)
|
2002-04-24 07:47:06 +04:00
|
|
|
{
|
2003-07-29 01:02:45 +04:00
|
|
|
nsCAutoString buf;
|
|
|
|
nsresult rv = NS_CopyUnicodeToNative(path, buf);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
*result = nsnull;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_NewNativeLocalFile(buf, followLinks, result);
|
2002-04-24 07:47:06 +04:00
|
|
|
}
|
2002-04-27 09:33:09 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// global init/shutdown
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void
|
|
|
|
nsLocalFile::GlobalInit()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsLocalFile::GlobalShutdown()
|
|
|
|
{
|
|
|
|
}
|