2000-05-01 22:21:43 +00: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-05 20:44:11 +00:00
|
|
|
* IBM Corp.
|
2000-05-01 22:21:43 +00:00
|
|
|
*/
|
|
|
|
|
2000-06-20 14:06:00 +00:00
|
|
|
|
2000-05-01 22:21:43 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2000-06-03 09:46:12 +00:00
|
|
|
#include "nsMemory.h"
|
2000-06-20 14:06:00 +00:00
|
|
|
|
2003-06-18 23:19:11 +00:00
|
|
|
#include "nsLocalFile.h"
|
2002-10-06 00:29:46 +00:00
|
|
|
#include "nsNativeCharsetUtils.h"
|
2002-04-24 03:47:06 +00:00
|
|
|
|
2000-06-20 14:06:00 +00:00
|
|
|
#include "nsISimpleEnumerator.h"
|
|
|
|
#include "nsIComponentManager.h"
|
2000-05-01 22:21:43 +00:00
|
|
|
#include "prtypes.h"
|
|
|
|
#include "prio.h"
|
2000-06-20 14:06:00 +00:00
|
|
|
|
|
|
|
#include <ctype.h> // needed for toupper
|
|
|
|
#include <string.h>
|
|
|
|
|
2001-06-22 02:57:07 +00:00
|
|
|
#include "nsXPIDLString.h"
|
2001-11-11 01:42:10 +00:00
|
|
|
#include "nsReadableUtils.h"
|
2001-06-22 02:57:07 +00:00
|
|
|
#include "prproces.h"
|
2002-04-24 03:47:06 +00:00
|
|
|
#include "prthread.h"
|
2001-06-22 02:57:07 +00:00
|
|
|
|
|
|
|
|
2000-06-20 14:06:00 +00:00
|
|
|
static unsigned char* PR_CALLBACK
|
|
|
|
_mbschr( const unsigned char* stringToSearch, int charToSearchFor);
|
2001-01-31 21:58:27 +00:00
|
|
|
extern unsigned char*
|
2000-06-20 14:06:00 +00:00
|
|
|
_mbsrchr( const unsigned char* stringToSearch, int charToSearchFor);
|
2000-07-20 14:54:24 +00:00
|
|
|
static nsresult PR_CALLBACK
|
|
|
|
CreateDirectoryA( PSZ resolvedPath, PEAOP2 ppEABuf);
|
2000-10-05 20:44:11 +00:00
|
|
|
static int isleadbyte(int c);
|
2000-05-01 22:21:43 +00:00
|
|
|
|
|
|
|
#ifdef XP_OS2_VACPP
|
|
|
|
#include <direct.h>
|
|
|
|
#else
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
2000-06-21 01:35:21 +00:00
|
|
|
#include <io.h>
|
2000-05-01 22:21:43 +00:00
|
|
|
|
|
|
|
|
2000-06-20 14:06:00 +00: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 14:54:24 +00:00
|
|
|
case ERROR_FILE_EXISTS:
|
|
|
|
case ERROR_ALREADY_EXISTS:
|
|
|
|
case ERROR_CANNOT_MAKE:
|
|
|
|
rv = NS_ERROR_FILE_ALREADY_EXISTS;
|
|
|
|
break;
|
2000-06-20 14:06:00 +00: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-01 22:21:43 +00:00
|
|
|
|
2000-06-20 14:06:00 +00: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-01 22:21:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
class nsDirEnumerator : public nsISimpleEnumerator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
nsDirEnumerator() : mDir(nsnull)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult Init(nsILocalFile* parent)
|
|
|
|
{
|
2002-04-27 05:33:09 +00:00
|
|
|
nsCAutoString filepath;
|
|
|
|
parent->GetNativeTarget(filepath);
|
2000-05-01 22:21:43 +00:00
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
if (filepath.IsEmpty())
|
2000-05-01 22:21:43 +00:00
|
|
|
{
|
2002-04-27 05:33:09 +00:00
|
|
|
parent->GetNativePath(filepath);
|
2000-05-01 22:21:43 +00:00
|
|
|
}
|
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
if (filepath.IsEmpty())
|
2000-05-01 22:21:43 +00:00
|
|
|
{
|
2002-04-27 05:33:09 +00:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
2000-05-01 22:21:43 +00:00
|
|
|
}
|
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
mDir = PR_OpenDir(filepath.get());
|
2000-05-01 22:21:43 +00: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 14:06:00 +00:00
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
rv = file->AppendNative(nsDependentCString(entry->name));
|
2000-05-01 22:21:43 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2000-06-20 14:06:00 +00:00
|
|
|
|
2000-05-01 22:21:43 +00:00
|
|
|
// make sure the thing exists. If it does, try the next one.
|
|
|
|
PRBool exists;
|
2002-04-27 05:33:09 +00:00
|
|
|
rv = file->Exists(&exists);
|
2000-05-01 22:21:43 +00:00
|
|
|
if (NS_FAILED(rv) || !exists)
|
|
|
|
{
|
|
|
|
return HasMoreElements(result);
|
|
|
|
}
|
2000-06-20 14:06:00 +00:00
|
|
|
|
2000-05-01 22:21:43 +00: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 10:58:39 +00:00
|
|
|
mNext = nsnull;
|
2000-05-01 22:21:43 +00: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 01:48:11 +00:00
|
|
|
NS_IMPL_ISUPPORTS1(nsDirEnumerator, nsISimpleEnumerator)
|
2000-05-01 22:21:43 +00:00
|
|
|
|
|
|
|
|
2000-06-20 14:06:00 +00:00
|
|
|
nsLocalFile::nsLocalFile()
|
2000-05-01 22:21:43 +00:00
|
|
|
{
|
2000-06-20 14:06:00 +00:00
|
|
|
mLastResolution = PR_FALSE;
|
2000-07-20 14:54:24 +00:00
|
|
|
mFollowSymlinks = PR_FALSE;
|
2000-06-20 14:06:00 +00:00
|
|
|
MakeDirty();
|
2000-05-01 22:21:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsLocalFile::~nsLocalFile()
|
|
|
|
{
|
2000-06-20 14:06:00 +00:00
|
|
|
}
|
2000-05-01 22:21:43 +00:00
|
|
|
|
2000-06-20 14:06:00 +00:00
|
|
|
/* nsISupports interface implementation. */
|
2000-05-01 22:21:43 +00: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 14:06:00 +00:00
|
|
|
// This function resets any cached information about the file.
|
|
|
|
void
|
|
|
|
nsLocalFile::MakeDirty()
|
|
|
|
{
|
|
|
|
mDirty = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ResolvePath
|
|
|
|
// this function will walk the native path of |this| resolving any symbolic
|
|
|
|
// links found. The new resulting path will be placed into mResolvedPath.
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsLocalFile::ResolvePath(const char* workingPath, PRBool resolveTerminal, char** resolvedPath)
|
|
|
|
{
|
|
|
|
// Get the native path for |this|
|
|
|
|
char* filePath = (char*) nsMemory::Clone( workingPath, strlen(workingPath)+1 );
|
|
|
|
|
|
|
|
if (filePath == nsnull)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
// We are going to walk the native file path
|
|
|
|
// and stop at each slash. For each partial
|
|
|
|
// path (the string to the left of the slash)
|
|
|
|
// we will check to see if it is a shortcut.
|
|
|
|
// if it is, we will resolve it and continue
|
|
|
|
// with that resolved path.
|
|
|
|
|
|
|
|
// Get the first slash.
|
|
|
|
char* slash = strchr(filePath, '\\');
|
|
|
|
|
|
|
|
if (slash == nsnull)
|
|
|
|
{
|
|
|
|
if (filePath[0] != nsnull && filePath[1] == ':' && filePath[2] == '\0')
|
|
|
|
{
|
|
|
|
// we have a drive letter and a colon (eg 'c:'
|
|
|
|
// this is resolve already
|
|
|
|
|
2000-10-05 20:44:11 +00:00
|
|
|
int filePathLen = strlen(filePath);
|
|
|
|
char* rp = (char*) nsMemory::Alloc( filePathLen + 2 );
|
|
|
|
if (!rp)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
memcpy( rp, filePath, filePathLen );
|
|
|
|
rp[filePathLen] = '\\';
|
|
|
|
rp[filePathLen+1] = 0;
|
|
|
|
*resolvedPath = rp;
|
2000-06-20 14:06:00 +00:00
|
|
|
|
|
|
|
nsMemory::Free(filePath);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nsMemory::Free(filePath);
|
|
|
|
return NS_ERROR_FILE_INVALID_PATH;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// We really cant have just a drive letter as
|
|
|
|
// a shortcut, so we will skip the first '\\'
|
|
|
|
slash = strchr(++slash, '\\');
|
|
|
|
|
|
|
|
while (slash || resolveTerminal)
|
|
|
|
{
|
|
|
|
// Change the slash into a null so that
|
|
|
|
// we can use the partial path. It is is
|
|
|
|
// null, we know it is the terminal node.
|
|
|
|
|
|
|
|
if (slash)
|
|
|
|
{
|
|
|
|
*slash = '\0';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (resolveTerminal)
|
|
|
|
{
|
|
|
|
// this is our last time in this loop.
|
|
|
|
// set loop condition to false
|
|
|
|
|
|
|
|
resolveTerminal = PR_FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// something is wrong. we should not have
|
|
|
|
// both slash being null and resolveTerminal
|
|
|
|
// not set!
|
|
|
|
nsMemory::Free(filePath);
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (slash)
|
|
|
|
{
|
|
|
|
*slash = '\\';
|
|
|
|
++slash;
|
|
|
|
slash = strchr(slash, '\\');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-12-23 23:23:41 +00:00
|
|
|
// kill any trailing separator
|
2000-06-20 14:06:00 +00:00
|
|
|
char* temp = filePath;
|
|
|
|
int len = strlen(temp) - 1;
|
|
|
|
if(temp[len] == '\\')
|
|
|
|
temp[len] = '\0';
|
|
|
|
|
|
|
|
*resolvedPath = filePath;
|
2003-01-01 21:20:37 +00:00
|
|
|
return NS_OK;
|
2000-06-20 14:06:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsLocalFile::ResolveAndStat(PRBool resolveTerminal)
|
|
|
|
{
|
|
|
|
if (!mDirty && mLastResolution == resolveTerminal)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
mLastResolution = resolveTerminal;
|
2000-07-20 14:54:24 +00:00
|
|
|
mResolvedPath.Assign(mWorkingPath); //until we know better.
|
2000-06-20 14:06:00 +00:00
|
|
|
|
|
|
|
// First we will see if the workingPath exists. If it does, then we
|
|
|
|
// can simply use that as the resolved path. This simplification can
|
|
|
|
// be done on windows cause its symlinks (shortcuts) use the .lnk
|
|
|
|
// file extension.
|
|
|
|
|
|
|
|
char temp[4];
|
2001-03-02 09:26:57 +00:00
|
|
|
const char* workingFilePath = mWorkingPath.get();
|
2000-06-20 14:06:00 +00: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-14 21:17:43 +00:00
|
|
|
DosError(FERR_DISABLEHARDERR);
|
2000-06-20 14:06:00 +00:00
|
|
|
PRStatus status = PR_GetFileInfo64(nsprPath, &mFileInfo64);
|
2002-01-14 21:17:43 +00:00
|
|
|
DosError(FERR_ENABLEHARDERR);
|
2000-06-20 14:06:00 +00:00
|
|
|
if ( status == PR_SUCCESS )
|
|
|
|
{
|
2000-07-20 14:54:24 +00:00
|
|
|
if (!resolveTerminal)
|
|
|
|
{
|
|
|
|
mDirty = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-10-05 20:44:11 +00:00
|
|
|
// check to see that this is shortcut, i.e., the leaf is ".lnk"
|
|
|
|
// if the length < 4, then it's not a link.
|
2000-07-20 14:54:24 +00:00
|
|
|
|
|
|
|
int pathLen = strlen(workingFilePath);
|
|
|
|
const char* leaf = workingFilePath + pathLen - 4;
|
|
|
|
|
2000-10-05 20:44:11 +00:00
|
|
|
if (pathLen < 4)
|
2000-07-20 14:54:24 +00:00
|
|
|
{
|
2000-10-05 20:44:11 +00:00
|
|
|
mDirty = PR_FALSE;
|
2000-07-20 14:54:24 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-06-20 14:06:00 +00:00
|
|
|
}
|
2000-07-20 14:54:24 +00:00
|
|
|
|
2000-06-20 14:06:00 +00:00
|
|
|
nsresult result;
|
|
|
|
|
|
|
|
// okay, something is wrong with the working path. We will try to resolve it.
|
|
|
|
|
|
|
|
char *resolvePath;
|
|
|
|
|
|
|
|
result = ResolvePath(workingFilePath, resolveTerminal, &resolvePath);
|
|
|
|
if (NS_FAILED(result))
|
2000-07-20 14:54:24 +00:00
|
|
|
return NS_ERROR_FILE_NOT_FOUND;
|
2000-06-20 14:06:00 +00:00
|
|
|
|
|
|
|
mResolvedPath.Assign(resolvePath);
|
|
|
|
nsMemory::Free(resolvePath);
|
|
|
|
|
2002-01-14 21:17:43 +00:00
|
|
|
DosError(FERR_DISABLEHARDERR);
|
2001-11-11 01:42:10 +00:00
|
|
|
status = PR_GetFileInfo64(mResolvedPath.get(), &mFileInfo64);
|
2002-01-14 21:17:43 +00:00
|
|
|
DosError(FERR_ENABLEHARDERR);
|
2000-06-20 14:06:00 +00:00
|
|
|
|
|
|
|
if ( status == PR_SUCCESS )
|
|
|
|
mDirty = PR_FALSE;
|
|
|
|
else
|
|
|
|
result = NS_ERROR_FILE_NOT_FOUND;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-05-01 22:21:43 +00:00
|
|
|
nsLocalFile::Clone(nsIFile **file)
|
|
|
|
{
|
2002-03-20 03:16:09 +00:00
|
|
|
nsresult rv;
|
2000-05-01 22:21:43 +00:00
|
|
|
|
2002-03-20 03:16:09 +00:00
|
|
|
nsCOMPtr<nsILocalFile> localFile;
|
2000-05-01 22:21:43 +00:00
|
|
|
|
2002-04-27 07:34:27 +00:00
|
|
|
rv = NS_NewNativeLocalFile(mWorkingPath, mFollowSymlinks, getter_AddRefs(localFile));
|
2002-03-20 03:16:09 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && localFile)
|
|
|
|
{
|
|
|
|
return localFile->QueryInterface(NS_GET_IID(nsIFile), (void**)file);
|
|
|
|
}
|
2000-05-01 22:21:43 +00:00
|
|
|
|
2002-03-20 03:16:09 +00:00
|
|
|
return rv;
|
2000-05-01 22:21:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-04-27 05:33:09 +00:00
|
|
|
nsLocalFile::InitWithNativePath(const nsACString &filePath)
|
2000-05-01 22:21:43 +00:00
|
|
|
{
|
2000-06-20 14:06:00 +00:00
|
|
|
MakeDirty();
|
2002-04-27 05:33:09 +00: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 14:06:00 +00: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 05:33:09 +00:00
|
|
|
char *path = nsnull;
|
|
|
|
PRInt32 pathLen = 0;
|
|
|
|
|
|
|
|
if ( ( (secondChar == ':') && !FindCharInReadable('/', begin, end) ) || // normal path
|
|
|
|
( (firstChar == '\\') && (secondChar == '\\') ) ) // network path
|
2000-05-01 22:21:43 +00:00
|
|
|
{
|
|
|
|
// This is a native path
|
2002-04-27 05:33:09 +00:00
|
|
|
path = ToNewCString(filePath);
|
|
|
|
pathLen = filePath.Length();
|
2000-05-01 22:21:43 +00:00
|
|
|
}
|
2002-04-27 05:33:09 +00:00
|
|
|
|
|
|
|
if (path == nsnull)
|
2000-05-01 22:21:43 +00:00
|
|
|
return NS_ERROR_FILE_UNRECOGNIZED_PATH;
|
|
|
|
|
2002-04-27 05:33:09 +00: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 14:06:00 +00:00
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
mWorkingPath.Adopt(path, pathLen);
|
2000-05-01 22:21:43 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::OpenNSPRFileDesc(PRInt32 flags, PRInt32 mode, PRFileDesc **_retval)
|
|
|
|
{
|
2000-06-20 14:06:00 +00:00
|
|
|
nsresult rv = ResolveAndStat(PR_TRUE);
|
|
|
|
if (NS_FAILED(rv) && rv != NS_ERROR_FILE_NOT_FOUND)
|
|
|
|
return rv;
|
|
|
|
|
2001-11-11 01:42:10 +00:00
|
|
|
*_retval = PR_Open(mResolvedPath.get(), flags, mode);
|
2000-05-01 22:21:43 +00:00
|
|
|
|
|
|
|
if (*_retval)
|
|
|
|
return NS_OK;
|
2000-06-20 14:06:00 +00:00
|
|
|
|
|
|
|
return NS_ErrorAccordingToNSPR();
|
2000-05-01 22:21:43 +00:00
|
|
|
}
|
|
|
|
|
2000-06-20 14:06:00 +00:00
|
|
|
|
2000-05-01 22:21:43 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::OpenANSIFileDesc(const char *mode, FILE * *_retval)
|
|
|
|
{
|
2000-06-20 14:06:00 +00:00
|
|
|
nsresult rv = ResolveAndStat(PR_TRUE);
|
|
|
|
if (NS_FAILED(rv) && rv != NS_ERROR_FILE_NOT_FOUND)
|
|
|
|
return rv;
|
2000-05-01 22:21:43 +00:00
|
|
|
|
2001-11-11 01:42:10 +00:00
|
|
|
*_retval = fopen(mResolvedPath.get(), mode);
|
2000-05-01 22:21:43 +00:00
|
|
|
|
|
|
|
if (*_retval)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2000-06-20 14:06:00 +00:00
|
|
|
|
|
|
|
|
2000-05-01 22:21:43 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::Create(PRUint32 type, PRUint32 attributes)
|
|
|
|
{
|
|
|
|
if (type != NORMAL_FILE_TYPE && type != DIRECTORY_TYPE)
|
|
|
|
return NS_ERROR_FILE_UNKNOWN_TYPE;
|
|
|
|
|
2000-06-20 14:06:00 +00:00
|
|
|
nsresult rv = ResolveAndStat(PR_FALSE);
|
|
|
|
if (NS_FAILED(rv) && rv != NS_ERROR_FILE_NOT_FOUND)
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
// create nested directories to target
|
2001-03-02 09:26:57 +00:00
|
|
|
unsigned char* slash = _mbschr((const unsigned char*) mResolvedPath.get(), '\\');
|
2000-05-01 22:21:43 +00:00
|
|
|
|
|
|
|
|
2002-02-12 22:14:32 +00:00
|
|
|
if (slash)
|
|
|
|
{
|
|
|
|
// skip the first '\\'
|
|
|
|
++slash;
|
|
|
|
slash = _mbschr(slash, '\\');
|
|
|
|
|
|
|
|
while (slash)
|
|
|
|
{
|
|
|
|
*slash = '\0';
|
|
|
|
|
|
|
|
rv = CreateDirectoryA(NS_CONST_CAST(char*, mResolvedPath.get()), NULL);
|
|
|
|
if (rv) {
|
|
|
|
rv = ConvertOS2Error(rv);
|
|
|
|
if (rv != NS_ERROR_FILE_ALREADY_EXISTS) return rv;
|
|
|
|
}
|
|
|
|
*slash = '\\';
|
|
|
|
++slash;
|
|
|
|
slash = _mbschr(slash, '\\');
|
2000-07-20 14:54:24 +00:00
|
|
|
}
|
2000-06-20 14:06:00 +00:00
|
|
|
}
|
2000-05-01 22:21:43 +00:00
|
|
|
|
2000-06-20 14:06:00 +00:00
|
|
|
if (type == NORMAL_FILE_TYPE)
|
|
|
|
{
|
2001-11-11 01:42:10 +00:00
|
|
|
PRFileDesc* file = PR_Open(mResolvedPath.get(), PR_RDONLY | PR_CREATE_FILE | PR_APPEND | PR_EXCL, attributes);
|
2000-06-27 03:35:32 +00:00
|
|
|
if (!file) return NS_ERROR_FILE_ALREADY_EXISTS;
|
|
|
|
|
|
|
|
PR_Close(file);
|
2000-06-20 14:06:00 +00:00
|
|
|
return NS_OK;
|
2000-05-01 22:21:43 +00:00
|
|
|
}
|
|
|
|
|
2000-06-20 14:06:00 +00:00
|
|
|
if (type == DIRECTORY_TYPE)
|
|
|
|
{
|
2001-03-20 07:47:40 +00:00
|
|
|
rv = CreateDirectoryA(NS_CONST_CAST(char*, mResolvedPath.get()), NULL);
|
2000-07-20 14:54:24 +00:00
|
|
|
if (rv)
|
|
|
|
return ConvertOS2Error(rv);
|
|
|
|
else
|
|
|
|
return NS_OK;
|
2000-05-01 22:21:43 +00:00
|
|
|
}
|
2000-06-20 14:06:00 +00:00
|
|
|
|
|
|
|
return NS_ERROR_FILE_UNKNOWN_TYPE;
|
2000-05-01 22:21:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-04-27 05:33:09 +00:00
|
|
|
nsLocalFile::AppendNative(const nsACString &node)
|
2000-05-25 14:23:27 +00:00
|
|
|
{
|
2002-09-03 22:40:45 +00:00
|
|
|
if (node.IsEmpty())
|
|
|
|
return NS_OK;
|
|
|
|
|
2000-06-20 14:06:00 +00:00
|
|
|
// Append only one component. Check for subdirs.
|
2002-04-27 05:33:09 +00:00
|
|
|
// XXX can we avoid the PromiseFlatCString call?
|
2002-09-03 22:40:45 +00:00
|
|
|
if (_mbschr((const unsigned char*) PromiseFlatCString(node).get(), '\\') != nsnull)
|
2000-06-20 14:06:00 +00:00
|
|
|
return NS_ERROR_FILE_UNRECOGNIZED_PATH;
|
2002-09-03 22:40:45 +00:00
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
return AppendRelativeNativePath(node);
|
2000-05-25 14:23:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-04-27 05:33:09 +00:00
|
|
|
nsLocalFile::AppendRelativeNativePath(const nsACString &node)
|
2000-05-01 22:21:43 +00:00
|
|
|
{
|
2000-06-20 14:06:00 +00:00
|
|
|
// Cannot start with a / or have .. or have / anywhere
|
2002-04-27 05:33:09 +00:00
|
|
|
nsACString::const_iterator begin, end;
|
|
|
|
node.BeginReading(begin);
|
|
|
|
node.EndReading(end);
|
|
|
|
if (node.IsEmpty() || FindCharInReadable('/', begin, end))
|
2000-05-01 22:21:43 +00:00
|
|
|
{
|
|
|
|
return NS_ERROR_FILE_UNRECOGNIZED_PATH;
|
|
|
|
}
|
2000-06-20 14:06:00 +00:00
|
|
|
MakeDirty();
|
2002-04-27 05:33:09 +00:00
|
|
|
mWorkingPath.Append(NS_LITERAL_CSTRING("\\") + node);
|
2000-05-22 19:38:22 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-05-01 22:21:43 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::Normalize()
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-04-27 05:33:09 +00:00
|
|
|
nsLocalFile::GetNativeLeafName(nsACString &aLeafName)
|
2000-05-01 22:21:43 +00:00
|
|
|
{
|
2002-04-27 05:33:09 +00:00
|
|
|
aLeafName.Truncate();
|
2000-05-01 22:21:43 +00:00
|
|
|
|
2001-03-02 09:26:57 +00:00
|
|
|
const char* temp = mWorkingPath.get();
|
2000-05-01 22:21:43 +00:00
|
|
|
if(temp == nsnull)
|
|
|
|
return NS_ERROR_FILE_UNRECOGNIZED_PATH;
|
|
|
|
|
2000-06-20 14:06:00 +00:00
|
|
|
const char* leaf = (const char*) _mbsrchr((const unsigned char*) temp, '\\');
|
2000-05-01 22:21:43 +00:00
|
|
|
|
2000-06-20 14:06:00 +00:00
|
|
|
// if the working path is just a node without any lashes.
|
2000-05-01 22:21:43 +00:00
|
|
|
if (leaf == nsnull)
|
|
|
|
leaf = temp;
|
|
|
|
else
|
|
|
|
leaf++;
|
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
aLeafName.Assign(leaf);
|
2000-05-01 22:21:43 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-04-27 05:33:09 +00:00
|
|
|
nsLocalFile::SetNativeLeafName(const nsACString &aLeafName)
|
2000-05-01 22:21:43 +00:00
|
|
|
{
|
2000-06-20 14:06:00 +00:00
|
|
|
MakeDirty();
|
|
|
|
|
2001-03-02 09:26:57 +00:00
|
|
|
const unsigned char* temp = (const unsigned char*) mWorkingPath.get();
|
2000-05-01 22:21:43 +00:00
|
|
|
if(temp == nsnull)
|
|
|
|
return NS_ERROR_FILE_UNRECOGNIZED_PATH;
|
|
|
|
|
2000-06-20 14:06:00 +00:00
|
|
|
// cannot use nsCString::RFindChar() due to 0x5c problem
|
|
|
|
PRInt32 offset = (PRInt32) (_mbsrchr(temp, '\\') - temp);
|
2000-05-01 22:21:43 +00:00
|
|
|
if (offset)
|
|
|
|
{
|
2000-06-20 14:06:00 +00:00
|
|
|
mWorkingPath.Truncate(offset+1);
|
2000-05-01 22:21:43 +00:00
|
|
|
}
|
2000-06-20 14:06:00 +00:00
|
|
|
mWorkingPath.Append(aLeafName);
|
2000-05-01 22:21:43 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-06-20 14:06:00 +00:00
|
|
|
|
2000-05-01 22:21:43 +00:00
|
|
|
NS_IMETHODIMP
|
2002-04-27 05:33:09 +00:00
|
|
|
nsLocalFile::GetNativePath(nsACString &_retval)
|
2000-05-01 22:21:43 +00:00
|
|
|
{
|
2002-04-27 05:33:09 +00:00
|
|
|
_retval = mWorkingPath;
|
2000-05-01 22:21:43 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2002-04-27 05:33:09 +00:00
|
|
|
nsLocalFile::CopySingleFile(nsIFile *sourceFile, nsIFile *destParent, const nsACString &newName, PRBool followSymlinks, PRBool move)
|
2000-05-01 22:21:43 +00:00
|
|
|
{
|
2000-06-20 14:06:00 +00:00
|
|
|
nsresult rv;
|
2002-04-27 05:33:09 +00:00
|
|
|
nsCAutoString filePath;
|
2000-05-01 22:21:43 +00:00
|
|
|
|
2000-06-20 14:06:00 +00:00
|
|
|
// get the path that we are going to copy to.
|
|
|
|
// Since windows does not know how to auto
|
|
|
|
// resolve shortcust, we must work with the
|
|
|
|
// target.
|
2002-04-27 05:33:09 +00:00
|
|
|
nsCAutoString destPath;
|
|
|
|
destParent->GetNativeTarget(destPath);
|
2000-05-25 14:23:27 +00:00
|
|
|
|
2000-06-20 14:06:00 +00:00
|
|
|
destPath.Append("\\");
|
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
if (newName.IsEmpty())
|
2000-06-20 14:06:00 +00:00
|
|
|
{
|
2002-04-27 05:33:09 +00:00
|
|
|
nsCAutoString aFileName;
|
|
|
|
sourceFile->GetNativeLeafName(aFileName);
|
2000-06-20 14:06:00 +00:00
|
|
|
destPath.Append(aFileName);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
destPath.Append(newName);
|
|
|
|
}
|
2000-05-25 14:23:27 +00:00
|
|
|
|
2000-06-20 14:06:00 +00:00
|
|
|
|
|
|
|
if (followSymlinks)
|
|
|
|
{
|
2002-04-27 05:33:09 +00:00
|
|
|
rv = sourceFile->GetNativeTarget(filePath);
|
|
|
|
if (filePath.IsEmpty())
|
|
|
|
rv = sourceFile->GetNativePath(filePath);
|
2000-06-20 14:06:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-04-27 05:33:09 +00:00
|
|
|
rv = sourceFile->GetNativePath(filePath);
|
2000-06-20 14:06:00 +00:00
|
|
|
}
|
2000-05-01 22:21:43 +00:00
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2001-03-23 03:21:22 +00:00
|
|
|
APIRET rc = NO_ERROR;
|
|
|
|
|
|
|
|
if( move )
|
|
|
|
{
|
2002-04-27 05:33:09 +00:00
|
|
|
rc = DosMove(filePath.get(), (PSZ)NS_CONST_CAST(char*, destPath.get()));
|
2001-03-23 03:21:22 +00:00
|
|
|
}
|
|
|
|
|
2002-11-14 19:41:18 +00:00
|
|
|
if (!move || rc == ERROR_NOT_SAME_DEVICE || rc == ERROR_ACCESS_DENIED) {
|
2001-03-23 03:21:22 +00: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 05:46:34 +00: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 04:29:57 +00: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 05:33:09 +00:00
|
|
|
strcat(achProgram, filePath.get());
|
2001-02-07 04:29:57 +00:00
|
|
|
strcat(achProgram, " ");
|
2001-03-20 07:47:40 +00:00
|
|
|
strcat(achProgram, (PSZ)NS_CONST_CAST(char*, destPath.get()));
|
2001-02-07 04:29:57 +00: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 03:21:22 +00:00
|
|
|
|
|
|
|
} /* rc == 65 */
|
2001-05-29 22:21:11 +00: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 05:33:09 +00:00
|
|
|
DosDelete( filePath.get() );
|
2001-05-29 22:21:11 +00:00
|
|
|
}
|
2001-03-23 03:21:22 +00:00
|
|
|
} /* !move or ERROR */
|
2000-06-20 14:06:00 +00:00
|
|
|
|
2001-02-07 04:29:57 +00:00
|
|
|
if (rc)
|
|
|
|
rv = ConvertOS2Error(rc);
|
2000-06-20 14:06:00 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
2002-04-27 05:33:09 +00:00
|
|
|
nsLocalFile::CopyMove(nsIFile *aParentDir, const nsACString &newName, PRBool followSymlinks, PRBool move)
|
2000-06-20 14:06:00 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIFile> newParentDir = aParentDir;
|
|
|
|
// check to see if this exists, otherwise return an error.
|
|
|
|
// we will check this by resolving. If the user wants us
|
|
|
|
// to follow links, then we are talking about the target,
|
|
|
|
// hence we can use the |followSymlinks| parameter.
|
|
|
|
nsresult rv = ResolveAndStat(followSymlinks);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (!newParentDir)
|
|
|
|
{
|
|
|
|
// no parent was specified. We must rename.
|
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
if (newName.IsEmpty())
|
2000-06-20 14:06:00 +00: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)
|
|
|
|
{
|
|
|
|
if (followSymlinks)
|
|
|
|
{
|
|
|
|
PRBool isLink;
|
|
|
|
newParentDir->IsSymlink(&isLink);
|
|
|
|
if (isLink)
|
|
|
|
{
|
2002-04-27 05:33:09 +00:00
|
|
|
nsCAutoString target;
|
|
|
|
newParentDir->GetNativeTarget(target);
|
2000-06-20 14:06:00 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsILocalFile> realDest = new nsLocalFile();
|
|
|
|
if (realDest == nsnull)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
rv = realDest->InitWithNativePath(target);
|
2000-06-20 14:06:00 +00:00
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
return CopyMove(realDest, newName, followSymlinks, move);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return NS_ERROR_FILE_DESTINATION_NOT_DIR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check to see if we are a directory, if so enumerate it.
|
|
|
|
|
|
|
|
PRBool isDir;
|
|
|
|
IsDirectory(&isDir);
|
|
|
|
PRBool isSymlink;
|
|
|
|
IsSymlink(&isSymlink);
|
|
|
|
|
|
|
|
if (!isDir || (isSymlink && !followSymlinks))
|
|
|
|
{
|
|
|
|
rv = CopySingleFile(this, newParentDir, newName, followSymlinks, move);
|
|
|
|
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 05:33:09 +00:00
|
|
|
nsCAutoString allocatedNewName;
|
|
|
|
if (newName.IsEmpty())
|
2000-06-20 14:06:00 +00:00
|
|
|
{
|
|
|
|
PRBool isLink;
|
|
|
|
IsSymlink(&isLink);
|
|
|
|
if (isLink)
|
|
|
|
{
|
2002-04-27 05:33:09 +00:00
|
|
|
nsCAutoString temp;
|
|
|
|
GetNativeTarget(temp);
|
|
|
|
const char* leaf = (const char*) _mbsrchr((const unsigned char*) temp.get(), '\\');
|
2000-06-20 14:06:00 +00:00
|
|
|
if (leaf[0] == '\\')
|
|
|
|
leaf++;
|
2002-04-27 05:33:09 +00:00
|
|
|
allocatedNewName = leaf;
|
2000-06-20 14:06:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-04-27 05:33:09 +00:00
|
|
|
GetNativeLeafName(allocatedNewName);// this should be the leaf name of the
|
2000-06-20 14:06:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-04-27 05:33:09 +00:00
|
|
|
allocatedNewName = newName;
|
2000-06-20 14:06:00 +00:00
|
|
|
}
|
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
rv = target->AppendNative(allocatedNewName);
|
2000-06-20 14:06:00 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
allocatedNewName.Truncate();
|
2000-06-20 14:06:00 +00: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);
|
|
|
|
file->IsSymlink(&isLink);
|
|
|
|
|
|
|
|
if (move)
|
|
|
|
{
|
|
|
|
if (followSymlinks)
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
else
|
2002-04-27 05:33:09 +00:00
|
|
|
rv = file->MoveToNative(target, nsCString());
|
2000-06-20 14:06:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (followSymlinks)
|
2002-04-27 05:33:09 +00:00
|
|
|
rv = file->CopyToFollowingLinksNative(target, nsCString());
|
2000-06-20 14:06:00 +00:00
|
|
|
else
|
2002-04-27 05:33:09 +00:00
|
|
|
rv = file->CopyToNative(target, nsCString());
|
2000-06-20 14:06:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
iterator->HasMoreElements(&more);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If we moved, we want to adjust this.
|
|
|
|
if (move)
|
|
|
|
{
|
|
|
|
MakeDirty();
|
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
nsCAutoString newParentPath;
|
|
|
|
newParentDir->GetNativePath(newParentPath);
|
2000-06-20 14:06:00 +00:00
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
if (newParentPath.IsEmpty())
|
2000-06-20 14:06:00 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
if (newName.IsEmpty())
|
2000-06-20 14:06:00 +00:00
|
|
|
{
|
2002-04-27 05:33:09 +00:00
|
|
|
nsCAutoString aFileName;
|
|
|
|
GetNativeLeafName(aFileName);
|
2000-06-20 14:06:00 +00:00
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
InitWithNativePath(newParentPath);
|
|
|
|
AppendNative(aFileName);
|
2000-06-20 14:06:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-04-27 05:33:09 +00:00
|
|
|
InitWithNativePath(newParentPath);
|
|
|
|
AppendNative(newName);
|
2000-06-20 14:06:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-04-27 05:33:09 +00:00
|
|
|
nsLocalFile::CopyToNative(nsIFile *newParentDir, const nsACString &newName)
|
2000-06-20 14:06:00 +00:00
|
|
|
{
|
|
|
|
return CopyMove(newParentDir, newName, PR_FALSE, PR_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-04-27 05:33:09 +00:00
|
|
|
nsLocalFile::CopyToFollowingLinksNative(nsIFile *newParentDir, const nsACString &newName)
|
2000-06-20 14:06:00 +00:00
|
|
|
{
|
|
|
|
return CopyMove(newParentDir, newName, PR_TRUE, PR_FALSE);
|
|
|
|
}
|
2000-05-01 22:21:43 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-04-27 05:33:09 +00:00
|
|
|
nsLocalFile::MoveToNative(nsIFile *newParentDir, const nsACString &newName)
|
2000-05-01 22:21:43 +00:00
|
|
|
{
|
2000-06-20 14:06:00 +00:00
|
|
|
return CopyMove(newParentDir, newName, PR_FALSE, PR_TRUE);
|
2000-05-01 22:21:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-06-20 14:06:00 +00:00
|
|
|
nsLocalFile::Load(PRLibrary * *_retval)
|
2000-05-01 22:21:43 +00:00
|
|
|
{
|
|
|
|
PRBool isFile;
|
|
|
|
nsresult rv = IsFile(&isFile);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (! isFile)
|
|
|
|
return NS_ERROR_FILE_IS_DIRECTORY;
|
|
|
|
|
2001-11-11 01:42:10 +00:00
|
|
|
*_retval = PR_LoadLibrary(mResolvedPath.get());
|
2000-05-01 22:21:43 +00:00
|
|
|
|
|
|
|
if (*_retval)
|
|
|
|
return NS_OK;
|
|
|
|
|
2000-06-20 14:06:00 +00:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
2000-05-01 22:21:43 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-07-24 18:38:25 +00:00
|
|
|
nsLocalFile::Remove(PRBool recursive)
|
2000-05-01 22:21:43 +00:00
|
|
|
{
|
|
|
|
PRBool isDir;
|
|
|
|
|
|
|
|
nsresult rv = IsDirectory(&isDir);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2001-03-02 09:26:57 +00:00
|
|
|
const char *filePath = mResolvedPath.get();
|
2000-05-01 22:21:43 +00:00
|
|
|
|
|
|
|
if (isDir)
|
|
|
|
{
|
|
|
|
if (recursive)
|
|
|
|
{
|
|
|
|
nsDirEnumerator* dirEnum = new nsDirEnumerator();
|
2000-06-20 14:06:00 +00:00
|
|
|
if (dirEnum == nsnull)
|
2000-05-01 22:21:43 +00: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 18:38:25 +00:00
|
|
|
file->Remove(recursive);
|
2000-05-01 22:21:43 +00:00
|
|
|
|
|
|
|
iterator->HasMoreElements(&more);
|
|
|
|
}
|
|
|
|
}
|
2000-06-20 14:06:00 +00:00
|
|
|
#ifdef XP_OS2_VACPP
|
2003-06-18 23:19:11 +00:00
|
|
|
rv = rmdir((char *) filePath) == -1 ? NSRESULT_FOR_ERRNO() : NS_OK;
|
2000-06-20 14:06:00 +00:00
|
|
|
#else
|
2003-06-18 23:19:11 +00:00
|
|
|
rv = rmdir(filePath) == -1 ? NSRESULT_FOR_ERRNO() : NS_OK;
|
2000-06-20 14:06:00 +00:00
|
|
|
#endif
|
2000-05-01 22:21:43 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-06-18 23:19:11 +00:00
|
|
|
rv = remove(filePath) == -1 ? NSRESULT_FOR_ERRNO() : NS_OK;
|
2000-05-01 22:21:43 +00:00
|
|
|
}
|
|
|
|
|
2000-06-20 14:06:00 +00:00
|
|
|
MakeDirty();
|
2002-01-26 00:38:37 +00:00
|
|
|
return rv;
|
2000-05-01 22:21:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-11-26 08:05:05 +00:00
|
|
|
nsLocalFile::GetLastModifiedTime(PRInt64 *aLastModifiedTime)
|
2000-05-01 22:21:43 +00:00
|
|
|
{
|
2001-11-26 08:05:05 +00:00
|
|
|
NS_ENSURE_ARG(aLastModifiedTime);
|
2000-06-20 14:06:00 +00:00
|
|
|
|
2001-11-26 08:05:05 +00:00
|
|
|
*aLastModifiedTime = 0;
|
2000-06-20 14:06:00 +00:00
|
|
|
|
|
|
|
nsresult rv = ResolveAndStat(PR_TRUE);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
// microseconds -> milliseconds
|
2001-11-26 08:05:05 +00:00
|
|
|
*aLastModifiedTime = mFileInfo64.modifyTime / PR_USEC_PER_MSEC;
|
2000-05-01 22:21:43 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-06-20 14:06:00 +00:00
|
|
|
|
2000-05-01 22:21:43 +00:00
|
|
|
NS_IMETHODIMP
|
2001-11-26 08:05:05 +00:00
|
|
|
nsLocalFile::GetLastModifiedTimeOfLink(PRInt64 *aLastModifiedTime)
|
2000-05-01 22:21:43 +00:00
|
|
|
{
|
2001-11-26 08:05:05 +00:00
|
|
|
NS_ENSURE_ARG(aLastModifiedTime);
|
2000-06-20 14:06:00 +00:00
|
|
|
|
2001-11-26 08:05:05 +00:00
|
|
|
*aLastModifiedTime = 0;
|
2000-06-20 14:06:00 +00:00
|
|
|
|
|
|
|
nsresult rv = ResolveAndStat(PR_FALSE);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
// microseconds -> milliseconds
|
2001-11-26 08:05:05 +00:00
|
|
|
*aLastModifiedTime = mFileInfo64.modifyTime / PR_USEC_PER_MSEC;
|
2000-06-20 14:06:00 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
2000-05-01 22:21:43 +00:00
|
|
|
}
|
|
|
|
|
2000-06-20 14:06:00 +00:00
|
|
|
|
2000-05-01 22:21:43 +00:00
|
|
|
NS_IMETHODIMP
|
2001-11-26 08:05:05 +00:00
|
|
|
nsLocalFile::SetLastModifiedTime(PRInt64 aLastModifiedTime)
|
2000-05-01 22:21:43 +00:00
|
|
|
{
|
2001-11-26 08:05:05 +00:00
|
|
|
return nsLocalFile::SetModDate(aLastModifiedTime, PR_TRUE);
|
2000-05-01 22:21:43 +00:00
|
|
|
}
|
|
|
|
|
2000-06-20 14:06:00 +00:00
|
|
|
|
2000-05-01 22:21:43 +00:00
|
|
|
NS_IMETHODIMP
|
2001-11-26 08:05:05 +00:00
|
|
|
nsLocalFile::SetLastModifiedTimeOfLink(PRInt64 aLastModifiedTime)
|
2000-05-01 22:21:43 +00:00
|
|
|
{
|
2001-11-26 08:05:05 +00:00
|
|
|
return nsLocalFile::SetModDate(aLastModifiedTime, PR_FALSE);
|
2000-05-01 22:21:43 +00:00
|
|
|
}
|
|
|
|
|
2000-06-20 14:06:00 +00:00
|
|
|
nsresult
|
2001-11-26 08:05:05 +00:00
|
|
|
nsLocalFile::SetModDate(PRInt64 aLastModifiedTime, PRBool resolveTerminal)
|
2000-06-20 14:06:00 +00:00
|
|
|
{
|
|
|
|
nsresult rv = ResolveAndStat(resolveTerminal);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2001-03-02 09:26:57 +00:00
|
|
|
const char *filePath = mResolvedPath.get();
|
2000-06-20 14:06:00 +00: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 08:05:05 +00:00
|
|
|
PR_ExplodeTime(aLastModifiedTime * PR_USEC_PER_MSEC, PR_LocalTimeParameters, &pret);
|
2002-10-09 02:37:48 +00: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 14:06:00 +00: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-01 22:21:43 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::GetPermissions(PRUint32 *aPermissions)
|
|
|
|
{
|
2000-06-20 14:06:00 +00:00
|
|
|
nsresult rv = ResolveAndStat(PR_TRUE);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2001-03-02 09:26:57 +00:00
|
|
|
const char *filePath = mResolvedPath.get();
|
2000-06-20 14:06:00 +00:00
|
|
|
|
|
|
|
|
2000-05-01 22:21:43 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::GetPermissionsOfLink(PRUint32 *aPermissionsOfLink)
|
|
|
|
{
|
2000-06-20 14:06:00 +00:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2000-05-01 22:21:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::SetPermissions(PRUint32 aPermissions)
|
|
|
|
{
|
2000-06-20 14:06:00 +00:00
|
|
|
nsresult rv = ResolveAndStat(PR_TRUE);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2001-03-02 09:26:57 +00:00
|
|
|
const char *filePath = mResolvedPath.get();
|
2000-06-20 14:06:00 +00:00
|
|
|
if( chmod(filePath, aPermissions) == -1 )
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return NS_OK;
|
2000-05-01 22:21:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::SetPermissionsOfLink(PRUint32 aPermissions)
|
|
|
|
{
|
2000-06-20 14:06:00 +00:00
|
|
|
nsresult rv = ResolveAndStat(PR_FALSE);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2001-03-02 09:26:57 +00:00
|
|
|
const char *filePath = mResolvedPath.get();
|
2000-06-20 14:06:00 +00:00
|
|
|
if( chmod(filePath, aPermissions) == -1 )
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return NS_OK;
|
2000-05-01 22:21:43 +00:00
|
|
|
}
|
|
|
|
|
2000-06-20 14:06:00 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-05-01 22:21:43 +00:00
|
|
|
nsLocalFile::GetFileSize(PRInt64 *aFileSize)
|
|
|
|
{
|
2000-06-20 14:06:00 +00:00
|
|
|
NS_ENSURE_ARG(aFileSize);
|
|
|
|
|
|
|
|
*aFileSize = 0;
|
|
|
|
|
|
|
|
nsresult rv = ResolveAndStat(PR_TRUE);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
|
|
|
|
*aFileSize = mFileInfo64.size;
|
2000-05-01 22:21:43 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::SetFileSize(PRInt64 aFileSize)
|
|
|
|
{
|
|
|
|
|
2000-06-20 14:06:00 +00:00
|
|
|
nsresult rv = ResolveAndStat(PR_TRUE);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
2000-05-01 22:21:43 +00:00
|
|
|
return rv;
|
2000-06-20 14:06:00 +00:00
|
|
|
|
2001-03-02 09:26:57 +00:00
|
|
|
const char *filePath = mResolvedPath.get();
|
2000-06-20 14:06:00 +00: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 05:46:34 +00:00
|
|
|
|
2000-06-20 14:06:00 +00:00
|
|
|
if (rc != NO_ERROR)
|
|
|
|
{
|
|
|
|
MakeDirty();
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2003-01-01 21:20:37 +00:00
|
|
|
|
2000-06-20 14:06:00 +00: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-01 22:21:43 +00:00
|
|
|
else
|
2000-06-20 14:06:00 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
MakeDirty();
|
2000-05-01 22:21:43 +00:00
|
|
|
return NS_OK;
|
2000-06-20 14:06:00 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
MakeDirty();
|
|
|
|
DosClose(hFile);
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-05-01 22:21:43 +00:00
|
|
|
}
|
|
|
|
|
2000-06-20 14:06:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::GetFileSizeOfLink(PRInt64 *aFileSize)
|
2000-05-01 22:21:43 +00:00
|
|
|
{
|
2000-06-20 14:06:00 +00:00
|
|
|
NS_ENSURE_ARG(aFileSize);
|
|
|
|
|
|
|
|
*aFileSize = 0;
|
2000-05-01 22:21:43 +00:00
|
|
|
|
2000-06-20 14:06:00 +00:00
|
|
|
nsresult rv = ResolveAndStat(PR_FALSE);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
*aFileSize = mFileInfo64.size;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::GetDiskSpaceAvailable(PRInt64 *aDiskSpaceAvailable)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aDiskSpaceAvailable);
|
|
|
|
|
|
|
|
ResolveAndStat(PR_FALSE);
|
|
|
|
|
|
|
|
ULONG ulDriveNo = toupper(mResolvedPath.CharAt(0)) + 1 - 'A';
|
|
|
|
FSALLOCATE fsAllocate;
|
2002-06-05 04:02:33 +00:00
|
|
|
APIRET rc = DosQueryFSInfo(ulDriveNo,
|
|
|
|
FSIL_ALLOC,
|
|
|
|
&fsAllocate,
|
|
|
|
sizeof(fsAllocate));
|
2000-06-20 14:06:00 +00:00
|
|
|
|
2002-06-05 04:02:33 +00:00
|
|
|
if (rc != NO_ERROR)
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-06-20 14:06:00 +00:00
|
|
|
|
2002-06-05 04:02:33 +00:00
|
|
|
*aDiskSpaceAvailable = fsAllocate.cUnitAvail;
|
|
|
|
*aDiskSpaceAvailable *= fsAllocate.cSectorUnit;
|
|
|
|
*aDiskSpaceAvailable *= fsAllocate.cbSector;
|
2000-05-01 22:21:43 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::GetParent(nsIFile * *aParent)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aParent);
|
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
nsCAutoString parentPath(mWorkingPath);
|
2000-05-01 22:21:43 +00:00
|
|
|
|
2000-06-20 14:06:00 +00:00
|
|
|
// cannot use nsCString::RFindChar() due to 0x5c problem
|
2001-03-02 09:26:57 +00:00
|
|
|
PRInt32 offset = (PRInt32) (_mbsrchr((const unsigned char *) parentPath.get(), '\\')
|
|
|
|
- (const unsigned char *) parentPath.get());
|
2000-10-05 20:44:11 +00:00
|
|
|
if (offset < 0)
|
2000-05-01 22:21:43 +00:00
|
|
|
return NS_ERROR_FILE_UNRECOGNIZED_PATH;
|
|
|
|
|
|
|
|
parentPath.Truncate(offset);
|
|
|
|
|
|
|
|
nsCOMPtr<nsILocalFile> localFile;
|
2002-04-27 05:33:09 +00:00
|
|
|
nsresult rv = NS_NewNativeLocalFile(parentPath, mFollowSymlinks, getter_AddRefs(localFile));
|
2000-05-01 22:21:43 +00:00
|
|
|
|
|
|
|
if(NS_SUCCEEDED(rv) && localFile)
|
|
|
|
{
|
2002-04-27 05:33:09 +00:00
|
|
|
return CallQueryInterface(localFile, aParent);
|
2000-05-01 22:21:43 +00:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::Exists(PRBool *_retval)
|
|
|
|
{
|
2000-06-20 14:06:00 +00:00
|
|
|
NS_ENSURE_ARG(_retval);
|
|
|
|
|
|
|
|
MakeDirty();
|
|
|
|
nsresult rv = ResolveAndStat( PR_TRUE );
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
*_retval = PR_TRUE;
|
|
|
|
else
|
|
|
|
*_retval = PR_FALSE;
|
|
|
|
|
2000-05-01 22:21:43 +00:00
|
|
|
return NS_OK;
|
2000-06-20 14:06:00 +00:00
|
|
|
}
|
2000-05-01 22:21:43 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::IsWritable(PRBool *_retval)
|
|
|
|
{
|
2000-06-20 14:06:00 +00:00
|
|
|
NS_ENSURE_ARG(_retval);
|
|
|
|
*_retval = PR_FALSE;
|
|
|
|
|
|
|
|
nsresult rv = ResolveAndStat(PR_TRUE);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2001-03-02 09:26:57 +00:00
|
|
|
const char *workingFilePath = mWorkingPath.get();
|
2000-06-20 14:06:00 +00: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-01 22:21:43 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::IsReadable(PRBool *_retval)
|
|
|
|
{
|
2000-06-20 14:06:00 +00:00
|
|
|
NS_ENSURE_ARG(_retval);
|
|
|
|
*_retval = PR_FALSE;
|
|
|
|
|
|
|
|
nsresult rv = ResolveAndStat( PR_TRUE );
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
*_retval = PR_TRUE;
|
|
|
|
return NS_OK;
|
2000-05-01 22:21:43 +00:00
|
|
|
}
|
|
|
|
|
2000-06-20 14:06:00 +00:00
|
|
|
|
2000-05-01 22:21:43 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::IsExecutable(PRBool *_retval)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(_retval);
|
2000-06-20 14:06:00 +00:00
|
|
|
*_retval = PR_FALSE;
|
2000-05-01 22:21:43 +00:00
|
|
|
|
|
|
|
|
2000-06-20 14:06:00 +00:00
|
|
|
nsresult rv = ResolveAndStat( PR_TRUE );
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
nsCAutoString path;
|
2000-06-20 14:06:00 +00:00
|
|
|
PRBool symLink;
|
|
|
|
|
|
|
|
rv = IsSymlink(&symLink);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (symLink)
|
2002-04-27 05:33:09 +00:00
|
|
|
GetNativeTarget(path);
|
2000-05-01 22:21:43 +00:00
|
|
|
else
|
2002-04-27 05:33:09 +00:00
|
|
|
GetNativePath(path);
|
2000-06-20 14:06:00 +00:00
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
const char* leaf = (const char*) _mbsrchr((const unsigned char*) path.get(), '\\');
|
2000-06-20 14:06:00 +00:00
|
|
|
|
|
|
|
if ( (strstr(leaf, ".bat") != nsnull) ||
|
|
|
|
(strstr(leaf, ".exe") != nsnull) ||
|
|
|
|
(strstr(leaf, ".cmd") != nsnull) ||
|
|
|
|
(strstr(leaf, ".com") != nsnull) ) {
|
|
|
|
*_retval = PR_TRUE;
|
|
|
|
} else {
|
2000-05-01 22:21:43 +00:00
|
|
|
*_retval = PR_FALSE;
|
2000-06-20 14:06:00 +00:00
|
|
|
}
|
|
|
|
|
2000-05-01 22:21:43 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-06-20 14:06:00 +00:00
|
|
|
|
2000-05-01 22:21:43 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::IsDirectory(PRBool *_retval)
|
|
|
|
{
|
2000-06-20 14:06:00 +00:00
|
|
|
NS_ENSURE_ARG(_retval);
|
|
|
|
*_retval = PR_FALSE;
|
|
|
|
|
|
|
|
nsresult rv = ResolveAndStat(PR_TRUE);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
*_retval = (mFileInfo64.type == PR_FILE_DIRECTORY);
|
|
|
|
|
2000-05-01 22:21:43 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::IsFile(PRBool *_retval)
|
|
|
|
{
|
2000-06-20 14:06:00 +00:00
|
|
|
NS_ENSURE_ARG(_retval);
|
|
|
|
*_retval = PR_FALSE;
|
|
|
|
|
|
|
|
nsresult rv = ResolveAndStat(PR_TRUE);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
*_retval = (mFileInfo64.type == PR_FILE_FILE);
|
|
|
|
return rv;
|
2000-05-01 22:21:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::IsHidden(PRBool *_retval)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(_retval);
|
2000-06-20 14:06:00 +00:00
|
|
|
*_retval = PR_FALSE;
|
2000-05-01 22:21:43 +00:00
|
|
|
|
2000-06-20 14:06:00 +00:00
|
|
|
nsresult rv = ResolveAndStat(PR_TRUE);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
2000-05-01 22:21:43 +00:00
|
|
|
return rv;
|
2000-06-20 14:06:00 +00:00
|
|
|
|
2001-03-02 09:26:57 +00:00
|
|
|
const char *workingFilePath = mWorkingPath.get();
|
2000-06-20 14:06:00 +00: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-01 22:21:43 +00:00
|
|
|
|
2000-06-20 14:06:00 +00:00
|
|
|
*_retval = ((pathInfo.attrFile & FILE_HIDDEN) != 0);
|
|
|
|
|
|
|
|
return NS_OK;
|
2000-05-01 22:21:43 +00:00
|
|
|
}
|
|
|
|
|
2000-06-20 14:06:00 +00:00
|
|
|
|
2000-05-01 22:21:43 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::IsSymlink(PRBool *_retval)
|
|
|
|
{
|
2003-01-01 21:20:37 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
|
|
|
// No Symlinks on OS/2
|
2000-06-20 14:06:00 +00:00
|
|
|
*_retval = PR_FALSE;
|
|
|
|
|
2000-05-01 22:21:43 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::IsSpecial(PRBool *_retval)
|
|
|
|
{
|
2000-06-20 14:06:00 +00:00
|
|
|
NS_ENSURE_ARG(_retval);
|
|
|
|
*_retval = PR_FALSE;
|
|
|
|
|
|
|
|
nsresult rv = ResolveAndStat(PR_TRUE);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2001-03-02 09:26:57 +00:00
|
|
|
const char *workingFilePath = mWorkingPath.get();
|
2000-06-20 14:06:00 +00: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-01 22:21:43 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::Equals(nsIFile *inFile, PRBool *_retval)
|
|
|
|
{
|
2000-06-20 14:06:00 +00:00
|
|
|
NS_ENSURE_ARG(inFile);
|
|
|
|
NS_ENSURE_ARG(_retval);
|
2000-05-01 22:21:43 +00:00
|
|
|
*_retval = PR_FALSE;
|
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
nsCAutoString inFilePath;
|
|
|
|
inFile->GetNativePath(inFilePath);
|
2000-05-01 22:21:43 +00:00
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
*_retval = inFilePath.Equals(mWorkingPath);
|
2000-05-01 22:21:43 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::Contains(nsIFile *inFile, PRBool recur, PRBool *_retval)
|
|
|
|
{
|
|
|
|
*_retval = PR_FALSE;
|
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
nsCAutoString myFilePath;
|
|
|
|
if ( NS_FAILED(GetNativeTarget(myFilePath)))
|
|
|
|
GetNativePath(myFilePath);
|
2000-05-01 22:21:43 +00:00
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
PRInt32 myFilePathLen = myFilePath.Length();
|
2000-05-01 22:21:43 +00:00
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
nsCAutoString inFilePath;
|
|
|
|
if ( NS_FAILED(inFile->GetNativeTarget(inFilePath)))
|
|
|
|
inFile->GetNativePath(inFilePath);
|
2000-05-01 22:21:43 +00:00
|
|
|
|
2003-04-18 02:22:17 +00:00
|
|
|
if ( strnicmp( myFilePath.get(), inFilePath.get(), myFilePathLen) == 0)
|
2000-05-01 22:21:43 +00:00
|
|
|
{
|
|
|
|
// now make sure that the |inFile|'s path has a trailing
|
|
|
|
// separator.
|
|
|
|
|
|
|
|
if (inFilePath[myFilePathLen] == '\\')
|
|
|
|
{
|
|
|
|
*_retval = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-06-20 14:06:00 +00:00
|
|
|
|
|
|
|
|
2000-05-01 22:21:43 +00:00
|
|
|
NS_IMETHODIMP
|
2002-04-27 05:33:09 +00:00
|
|
|
nsLocalFile::GetNativeTarget(nsACString &_retval)
|
2000-05-01 22:21:43 +00:00
|
|
|
{
|
2002-04-27 05:33:09 +00:00
|
|
|
_retval.Truncate();
|
2000-06-20 14:06:00 +00:00
|
|
|
#if STRICT_FAKE_SYMLINKS
|
|
|
|
PRBool symLink;
|
|
|
|
|
|
|
|
nsresult rv = IsSymlink(&symLink);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (!symLink)
|
|
|
|
{
|
|
|
|
return NS_ERROR_FILE_INVALID_PATH;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
ResolveAndStat(PR_TRUE);
|
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
_retval = mResolvedPath;
|
2000-05-01 22:21:43 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-06-20 14:06:00 +00:00
|
|
|
|
2000-07-12 23:31:31 +00:00
|
|
|
/* attribute PRBool followLinks; */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::GetFollowLinks(PRBool *aFollowLinks)
|
|
|
|
{
|
|
|
|
*aFollowLinks = mFollowSymlinks;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::SetFollowLinks(PRBool aFollowLinks)
|
|
|
|
{
|
|
|
|
MakeDirty();
|
|
|
|
mFollowSymlinks = aFollowLinks;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-07-20 14:54:24 +00:00
|
|
|
|
2000-05-01 22:21:43 +00:00
|
|
|
NS_IMETHODIMP
|
2000-06-20 14:06:00 +00:00
|
|
|
nsLocalFile::GetDirectoryEntries(nsISimpleEnumerator * *entries)
|
2000-05-01 22:21:43 +00:00
|
|
|
{
|
2000-06-20 14:06:00 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
*entries = nsnull;
|
2000-05-01 22:21:43 +00:00
|
|
|
|
2000-06-20 14:06:00 +00:00
|
|
|
PRBool isDir;
|
|
|
|
rv = IsDirectory(&isDir);
|
2000-05-01 22:21:43 +00: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 14:06:00 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
{
|
2000-05-01 22:21:43 +00:00
|
|
|
NS_RELEASE(dirEnum);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
*entries = dirEnum;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-07-17 15:01:10 +00:00
|
|
|
NS_IMETHODIMP
|
2002-04-27 05:33:09 +00:00
|
|
|
nsLocalFile::GetPersistentDescriptor(nsACString &aPersistentDescriptor)
|
2000-07-17 15:01:10 +00:00
|
|
|
{
|
2002-04-27 05:33:09 +00:00
|
|
|
return GetNativePath(aPersistentDescriptor);
|
2000-07-17 15:01:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-04-27 05:33:09 +00:00
|
|
|
nsLocalFile::SetPersistentDescriptor(const nsACString &aPersistentDescriptor)
|
2000-07-17 15:01:10 +00:00
|
|
|
{
|
2002-04-27 05:33:09 +00:00
|
|
|
return InitWithNativePath(aPersistentDescriptor);
|
2000-07-17 15:01:10 +00:00
|
|
|
}
|
|
|
|
|
2001-01-31 21:04:04 +00:00
|
|
|
#ifndef OPEN_DEFAULT
|
2003-01-22 04:58:09 +00:00
|
|
|
#define OPEN_DEFAULT 0
|
|
|
|
#define OPEN_CONTENTS 1
|
2001-01-31 21:04:04 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2001-01-30 05:02:48 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::Reveal()
|
|
|
|
{
|
2001-08-22 04:33:17 +00:00
|
|
|
PRBool isDirectory = PR_FALSE;
|
2002-04-27 05:33:09 +00:00
|
|
|
nsCAutoString path;
|
2001-08-22 04:33:17 +00:00
|
|
|
|
|
|
|
IsDirectory(&isDirectory);
|
|
|
|
if (isDirectory)
|
|
|
|
{
|
2002-04-27 05:33:09 +00:00
|
|
|
GetNativePath(path);
|
2001-08-22 04:33:17 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIFile> parent;
|
|
|
|
GetParent(getter_AddRefs(parent));
|
|
|
|
if (parent)
|
2002-04-27 05:33:09 +00:00
|
|
|
parent->GetNativePath(path);
|
2001-08-22 04:33:17 +00:00
|
|
|
}
|
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
HOBJECT hobject = WinQueryObject(path.get());
|
2003-01-22 04:58:09 +00:00
|
|
|
WinSetFocus(HWND_DESKTOP, HWND_DESKTOP);
|
|
|
|
WinOpenObject( hobject, OPEN_CONTENTS, TRUE);
|
2001-01-31 21:04:04 +00:00
|
|
|
|
|
|
|
// we don't care if it succeeded or failed.
|
|
|
|
return NS_OK;
|
2001-01-30 05:02:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::Launch()
|
|
|
|
{
|
2002-04-27 05:33:09 +00:00
|
|
|
HOBJECT hobject = WinQueryObject(mWorkingPath.get());
|
2003-01-22 04:58:09 +00:00
|
|
|
WinSetFocus(HWND_DESKTOP, HWND_DESKTOP);
|
2001-08-22 04:33:17 +00:00
|
|
|
WinOpenObject( hobject, OPEN_DEFAULT, TRUE);
|
|
|
|
|
|
|
|
// we don't care if it succeeded or failed.
|
|
|
|
return NS_OK;
|
2001-01-30 05:02:48 +00:00
|
|
|
}
|
2000-06-20 14:06:00 +00:00
|
|
|
|
2000-05-01 22:21:43 +00:00
|
|
|
nsresult
|
2002-04-27 05:33:09 +00:00
|
|
|
NS_NewNativeLocalFile(const nsACString &path, PRBool followLinks, nsILocalFile* *result)
|
2000-05-01 22:21:43 +00:00
|
|
|
{
|
|
|
|
nsLocalFile* file = new nsLocalFile();
|
|
|
|
if (file == nsnull)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(file);
|
|
|
|
|
2000-07-12 23:31:31 +00:00
|
|
|
file->SetFollowLinks(followLinks);
|
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
if (!path.IsEmpty()) {
|
|
|
|
nsresult rv = file->InitWithNativePath(path);
|
2000-07-20 14:54:24 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_RELEASE(file);
|
|
|
|
return rv;
|
|
|
|
}
|
2000-05-01 22:21:43 +00:00
|
|
|
}
|
2000-07-20 14:54:24 +00:00
|
|
|
|
2000-05-01 22:21:43 +00:00
|
|
|
*result = file;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-06-20 14:06:00 +00:00
|
|
|
// Locates the first occurrence of charToSearchFor in the stringToSearch
|
|
|
|
static unsigned char* PR_CALLBACK
|
|
|
|
_mbschr( const unsigned char* stringToSearch, int charToSearchFor)
|
|
|
|
{
|
2000-10-05 20:44:11 +00: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 14:06:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Locates last occurence of charToSearchFor in the stringToSearch
|
2001-01-31 21:58:27 +00:00
|
|
|
extern unsigned char*
|
2000-06-20 14:06:00 +00:00
|
|
|
_mbsrchr( const unsigned char* stringToSearch, int charToSearchFor)
|
|
|
|
{
|
2000-10-05 20:44:11 +00:00
|
|
|
int length = strlen((const char*)stringToSearch);
|
|
|
|
const unsigned char* p = stringToSearch+length;
|
2000-06-20 14:06:00 +00:00
|
|
|
do {
|
2000-10-05 20:44:11 +00: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-01 22:21:43 +00:00
|
|
|
}
|
2000-07-20 14:54:24 +00:00
|
|
|
|
|
|
|
// Implement equivalent of Win32 CreateDirectoryA
|
|
|
|
static nsresult PR_CALLBACK
|
|
|
|
CreateDirectoryA( PSZ resolvedPath, PEAOP2 ppEABuf)
|
|
|
|
{
|
|
|
|
APIRET rc;
|
|
|
|
nsresult rv;
|
|
|
|
FILESTATUS3 pathInfo;
|
|
|
|
|
|
|
|
rc = DosCreateDir( resolvedPath, ppEABuf );
|
|
|
|
if (rc != NO_ERROR) {
|
|
|
|
rv = ConvertOS2Error(rc);
|
|
|
|
|
|
|
|
// Check if directory already exists and if so, reflect that in the return value
|
|
|
|
rc = DosQueryPathInfo(resolvedPath,
|
|
|
|
FIL_STANDARD, // Level 1 info
|
|
|
|
&pathInfo,
|
|
|
|
sizeof(pathInfo));
|
|
|
|
if (rc == NO_ERROR)
|
|
|
|
rv = ERROR_FILE_EXISTS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
rv = rc;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
2000-10-05 20:44:11 +00:00
|
|
|
|
|
|
|
static int isleadbyte(int c)
|
|
|
|
{
|
|
|
|
static BOOL bDBCSFilled=FALSE;
|
2000-11-02 15:41:44 +00:00
|
|
|
static BYTE DBCSInfo[12] = { 0 }; /* According to the Control Program Guide&Ref,
|
2000-10-05 20:44:11 +00:00
|
|
|
12 bytes is sufficient */
|
2000-11-02 15:41:44 +00:00
|
|
|
BYTE *curr;
|
2000-10-05 20:44:11 +00: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 03:47:06 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-05-07 23:07:19 +00:00
|
|
|
nsLocalFile::InitWithPath(const nsAString &filePath)
|
2002-04-24 03:47:06 +00:00
|
|
|
{
|
2002-05-07 23:07:19 +00:00
|
|
|
if (filePath.IsEmpty())
|
|
|
|
return InitWithNativePath(nsCString());
|
2002-04-24 03:47:06 +00:00
|
|
|
|
2002-10-06 00:29:46 +00:00
|
|
|
nsCAutoString tmp;
|
|
|
|
nsresult rv = NS_CopyUnicodeToNative(filePath, tmp);
|
2002-04-24 03:47:06 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2002-04-27 05:33:09 +00:00
|
|
|
return InitWithNativePath(tmp);
|
2002-04-24 03:47:06 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-05-07 23:07:19 +00:00
|
|
|
nsLocalFile::Append(const nsAString &node)
|
2002-04-24 03:47:06 +00:00
|
|
|
{
|
2002-05-07 23:07:19 +00:00
|
|
|
if (node.IsEmpty())
|
2002-04-24 03:47:06 +00:00
|
|
|
return NS_OK;
|
|
|
|
|
2002-10-06 00:29:46 +00:00
|
|
|
nsCAutoString tmp;
|
|
|
|
nsresult rv = NS_CopyUnicodeToNative(node, tmp);
|
2002-04-24 03:47:06 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2002-04-27 05:33:09 +00:00
|
|
|
return AppendNative(tmp);
|
2002-04-24 03:47:06 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-05-07 23:07:19 +00:00
|
|
|
nsLocalFile::AppendRelativePath(const nsAString &node)
|
2002-04-24 03:47:06 +00:00
|
|
|
{
|
2002-05-07 23:07:19 +00:00
|
|
|
if (node.IsEmpty())
|
2002-04-24 03:47:06 +00:00
|
|
|
return NS_OK;
|
|
|
|
|
2002-10-06 00:29:46 +00:00
|
|
|
nsCAutoString tmp;
|
|
|
|
nsresult rv = NS_CopyUnicodeToNative(node, tmp);
|
2002-04-24 03:47:06 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2002-04-27 05:33:09 +00:00
|
|
|
return AppendRelativeNativePath(tmp);
|
2002-04-24 03:47:06 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-05-07 23:07:19 +00:00
|
|
|
nsLocalFile::GetLeafName(nsAString &aLeafName)
|
2002-04-24 03:47:06 +00:00
|
|
|
{
|
2002-04-27 05:33:09 +00:00
|
|
|
nsCAutoString tmp;
|
|
|
|
nsresult rv = GetNativeLeafName(tmp);
|
2002-04-24 03:47:06 +00:00
|
|
|
|
2002-10-06 00:29:46 +00:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
rv = NS_CopyNativeToUnicode(tmp, aLeafName);
|
2002-04-24 03:47:06 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-05-07 23:07:19 +00:00
|
|
|
nsLocalFile::SetLeafName(const nsAString &aLeafName)
|
2002-04-24 03:47:06 +00:00
|
|
|
{
|
2002-05-07 23:07:19 +00:00
|
|
|
if (aLeafName.IsEmpty())
|
|
|
|
return SetNativeLeafName(nsCString());
|
2002-04-24 03:47:06 +00:00
|
|
|
|
2002-10-06 00:29:46 +00:00
|
|
|
nsCAutoString tmp;
|
|
|
|
nsresult rv = NS_CopyUnicodeToNative(aLeafName, tmp);
|
2002-04-24 03:47:06 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2002-04-27 05:33:09 +00:00
|
|
|
return SetNativeLeafName(tmp);
|
2002-04-24 03:47:06 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-05-07 23:07:19 +00:00
|
|
|
nsLocalFile::GetPath(nsAString &_retval)
|
2002-04-24 03:47:06 +00:00
|
|
|
{
|
2002-10-06 00:29:46 +00:00
|
|
|
return NS_CopyNativeToUnicode(mWorkingPath, _retval);
|
2002-04-24 03:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-05-07 23:07:19 +00:00
|
|
|
nsLocalFile::CopyTo(nsIFile *newParentDir, const nsAString &newName)
|
2002-04-24 03:47:06 +00:00
|
|
|
{
|
2002-05-07 23:07:19 +00:00
|
|
|
if (newName.IsEmpty())
|
2002-04-27 05:33:09 +00:00
|
|
|
return CopyToNative(newParentDir, nsCString());
|
2002-04-24 03:47:06 +00:00
|
|
|
|
2002-10-06 00:29:46 +00:00
|
|
|
nsCAutoString tmp;
|
|
|
|
nsresult rv = NS_CopyUnicodeToNative(newName, tmp);
|
2002-04-24 03:47:06 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2002-04-27 05:33:09 +00:00
|
|
|
return CopyToNative(newParentDir, tmp);
|
2002-04-24 03:47:06 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-05-07 23:07:19 +00:00
|
|
|
nsLocalFile::CopyToFollowingLinks(nsIFile *newParentDir, const nsAString &newName)
|
2002-04-24 03:47:06 +00:00
|
|
|
{
|
2002-05-07 23:07:19 +00:00
|
|
|
if (newName.IsEmpty())
|
2002-04-27 05:33:09 +00:00
|
|
|
return CopyToFollowingLinksNative(newParentDir, nsCString());
|
2002-04-24 03:47:06 +00:00
|
|
|
|
2002-10-06 00:29:46 +00:00
|
|
|
nsCAutoString tmp;
|
|
|
|
nsresult rv = NS_CopyUnicodeToNative(newName, tmp);
|
2002-04-24 03:47:06 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2002-04-27 05:33:09 +00:00
|
|
|
return CopyToFollowingLinksNative(newParentDir, tmp);
|
2002-04-24 03:47:06 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-05-07 23:07:19 +00:00
|
|
|
nsLocalFile::MoveTo(nsIFile *newParentDir, const nsAString &newName)
|
2002-04-24 03:47:06 +00:00
|
|
|
{
|
2002-05-07 23:07:19 +00:00
|
|
|
if (newName.IsEmpty())
|
2002-04-27 05:33:09 +00:00
|
|
|
return MoveToNative(newParentDir, nsCString());
|
2002-04-24 03:47:06 +00:00
|
|
|
|
2002-10-06 00:29:46 +00:00
|
|
|
nsCAutoString tmp;
|
|
|
|
nsresult rv = NS_CopyUnicodeToNative(newName, tmp);
|
2002-04-24 03:47:06 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2002-04-27 05:33:09 +00:00
|
|
|
return MoveToNative(newParentDir, tmp);
|
2002-04-24 03:47:06 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-05-07 23:07:19 +00:00
|
|
|
nsLocalFile::GetTarget(nsAString &_retval)
|
2002-04-24 03:47:06 +00:00
|
|
|
{
|
2002-04-27 05:33:09 +00:00
|
|
|
nsCAutoString tmp;
|
|
|
|
nsresult rv = GetNativeTarget(tmp);
|
2002-04-24 03:47:06 +00:00
|
|
|
|
2002-10-06 00:29:46 +00:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
rv = NS_CopyNativeToUnicode(tmp, _retval);
|
2002-04-24 03:47:06 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2002-05-07 23:07:19 +00:00
|
|
|
NS_NewLocalFile(const nsAString &path, PRBool followLinks, nsILocalFile* *result)
|
2002-04-24 03:47:06 +00:00
|
|
|
{
|
2002-05-07 23:07:19 +00:00
|
|
|
if (path.IsEmpty())
|
|
|
|
return NS_NewNativeLocalFile(nsCString(), followLinks, result);
|
2002-04-24 03:47:06 +00:00
|
|
|
|
2002-10-06 00:29:46 +00:00
|
|
|
nsCAutoString tmp;
|
|
|
|
nsresult rv = NS_CopyUnicodeToNative(path, tmp);
|
2002-04-24 03:47:06 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2002-04-27 05:33:09 +00:00
|
|
|
return NS_NewNativeLocalFile(tmp, followLinks, result);
|
2002-04-24 03:47:06 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-04-27 05:33:09 +00:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// global init/shutdown
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void
|
|
|
|
nsLocalFile::GlobalInit()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsLocalFile::GlobalShutdown()
|
|
|
|
{
|
|
|
|
}
|