2005-07-08 20:18:44 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2004-04-18 18:21:17 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2000-05-02 02:21:43 +04:00
|
|
|
*
|
2004-04-18 18:21:17 +04:00
|
|
|
* The contents of this file are subject to the Mozilla 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/MPL/
|
2000-05-02 02:21:43 +04:00
|
|
|
*
|
2004-04-18 18:21:17 +04:00
|
|
|
* 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.
|
2000-05-02 02:21:43 +04:00
|
|
|
*
|
2004-04-18 18:21:17 +04:00
|
|
|
* The Original Code is Mozilla Communicator client code, released
|
|
|
|
* March 31, 1998.
|
2000-05-02 02:21:43 +04:00
|
|
|
*
|
2004-04-18 18:21:17 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998-2000
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Henry Sobotka <sobotka@axess.com>
|
|
|
|
* IBM Corp.
|
2005-04-22 17:21:23 +04:00
|
|
|
* Rich Walsh <dragtext@e-vertise.com>
|
2004-04-18 18:21:17 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2000-05-02 02:21:43 +04:00
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
// N.B. the ns* & pr* headers below will #include all
|
|
|
|
// of the standard library headers this file requires
|
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"
|
2005-04-23 05:39:51 +04:00
|
|
|
#include "nsIDirectoryEnumerator.h"
|
2000-06-20 18:06:00 +04:00
|
|
|
#include "nsIComponentManager.h"
|
2007-07-25 20:53:37 +04:00
|
|
|
#include "nsIProgrammingLanguage.h"
|
2000-05-02 02:21:43 +04:00
|
|
|
#include "prtypes.h"
|
|
|
|
#include "prio.h"
|
2000-06-20 18:06:00 +04:00
|
|
|
|
2001-11-11 04:42:10 +03:00
|
|
|
#include "nsReadableUtils.h"
|
2005-04-22 17:21:23 +04:00
|
|
|
#include "nsISupportsPrimitives.h"
|
2006-04-14 18:02:57 +04:00
|
|
|
#include "nsIMutableArray.h"
|
2006-11-15 01:06:00 +03:00
|
|
|
#include "nsTraceRefcntImpl.h"
|
2001-06-22 06:57:07 +04:00
|
|
|
|
2006-12-16 17:55:00 +03:00
|
|
|
#define CHECK_mWorkingPath() \
|
|
|
|
PR_BEGIN_MACRO \
|
|
|
|
if (mWorkingPath.IsEmpty()) \
|
|
|
|
return NS_ERROR_NOT_INITIALIZED; \
|
|
|
|
PR_END_MACRO
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// static helper functions
|
|
|
|
//-----------------------------------------------------------------------------
|
2000-05-02 02:21:43 +04:00
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
static nsresult ConvertOS2Error(int err)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
2005-07-08 20:18:44 +04:00
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
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;
|
2005-07-08 20:18:44 +04:00
|
|
|
case ERROR_FILENAME_EXCED_RANGE:
|
|
|
|
rv = NS_ERROR_FILE_NAME_TOO_LONG;
|
|
|
|
break;
|
2000-06-20 18:06:00 +04:00
|
|
|
case 0:
|
|
|
|
rv = NS_OK;
|
2005-07-08 20:18:44 +04:00
|
|
|
default:
|
2000-06-20 18:06:00 +04:00
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
myLL_L2II(PRInt64 result, PRInt32 *hi, PRInt32 *lo )
|
|
|
|
{
|
2005-07-08 20:18:44 +04:00
|
|
|
PRInt64 a64, b64; // probably could have been done with
|
|
|
|
// only one PRInt64, but these are macros,
|
2000-06-20 18:06:00 +04:00
|
|
|
// and I am a wimp.
|
2005-07-08 20:18:44 +04:00
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
// 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
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
// Locates the first occurrence of charToSearchFor in the stringToSearch
|
|
|
|
static unsigned char* PR_CALLBACK
|
|
|
|
_mbschr(const unsigned char* stringToSearch, int charToSearchFor)
|
|
|
|
{
|
|
|
|
const unsigned char* p = stringToSearch;
|
|
|
|
|
|
|
|
do {
|
|
|
|
if (*p == charToSearchFor)
|
|
|
|
break;
|
|
|
|
p = (const unsigned char*)WinNextChar(0,0,0,(char*)p);
|
|
|
|
} while (*p);
|
|
|
|
|
|
|
|
// Result is p or NULL
|
|
|
|
return *p ? (unsigned char*)p : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Locates the first occurrence of subString in the stringToSearch
|
|
|
|
static unsigned char* PR_CALLBACK
|
|
|
|
_mbsstr(const unsigned char* stringToSearch, const unsigned char* subString)
|
|
|
|
{
|
|
|
|
const unsigned char* pStr = stringToSearch;
|
|
|
|
const unsigned char* pSub = subString;
|
|
|
|
|
|
|
|
do {
|
|
|
|
while (*pStr && *pStr != *pSub)
|
|
|
|
pStr = (const unsigned char*)WinNextChar(0,0,0,(char*)pStr);
|
|
|
|
|
|
|
|
if (!*pStr)
|
|
|
|
break;
|
|
|
|
|
|
|
|
const unsigned char* pNxt = pStr;
|
|
|
|
do {
|
|
|
|
pSub = (const unsigned char*)WinNextChar(0,0,0,(char*)pSub);
|
|
|
|
pNxt = (const unsigned char*)WinNextChar(0,0,0,(char*)pNxt);
|
|
|
|
} while (*pSub && *pSub == *pNxt);
|
|
|
|
|
|
|
|
if (!*pSub)
|
|
|
|
break;
|
|
|
|
|
|
|
|
pSub = subString;
|
|
|
|
pStr = (const unsigned char*)WinNextChar(0,0,0,(char*)pStr);
|
|
|
|
|
|
|
|
} while (*pStr);
|
|
|
|
|
|
|
|
// if we got to the end of pSub, we've found it
|
|
|
|
return *pSub ? NULL : (unsigned char*)pStr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Locates last occurence of charToSearchFor in the stringToSearch
|
2006-03-10 19:01:26 +03:00
|
|
|
NS_EXPORT unsigned char*
|
2005-07-08 20:18:44 +04:00
|
|
|
_mbsrchr(const unsigned char* stringToSearch, int charToSearchFor)
|
|
|
|
{
|
|
|
|
int length = strlen((const char*)stringToSearch);
|
|
|
|
const unsigned char* p = stringToSearch+length;
|
|
|
|
|
|
|
|
do {
|
|
|
|
if (*p == charToSearchFor)
|
|
|
|
break;
|
|
|
|
p = (const unsigned char*)WinPrevChar(0,0,0,(char*)stringToSearch,(char*)p);
|
|
|
|
} while (p > stringToSearch);
|
|
|
|
|
|
|
|
// Result is p or NULL
|
|
|
|
return (*p == charToSearchFor) ? (unsigned char*)p : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Implement equivalent of Win32 CreateDirectoryA
|
|
|
|
static nsresult PR_CALLBACK
|
|
|
|
CreateDirectoryA(PSZ path, PEAOP2 ppEABuf)
|
|
|
|
{
|
|
|
|
APIRET rc;
|
|
|
|
nsresult rv;
|
|
|
|
FILESTATUS3 pathInfo;
|
|
|
|
|
|
|
|
rc = DosCreateDir(path, ppEABuf);
|
|
|
|
if (rc != NO_ERROR)
|
|
|
|
{
|
|
|
|
rv = ConvertOS2Error(rc);
|
|
|
|
|
|
|
|
// Check if directory already exists and if so,
|
|
|
|
// reflect that in the return value
|
|
|
|
rc = DosQueryPathInfo(path, FIL_STANDARD,
|
|
|
|
&pathInfo, sizeof(pathInfo));
|
|
|
|
if (rc == NO_ERROR)
|
|
|
|
rv = ERROR_FILE_EXISTS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
rv = rc;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int isleadbyte(int c)
|
|
|
|
{
|
|
|
|
static BOOL bDBCSFilled = FALSE;
|
|
|
|
// According to the Control Program Guide&Ref, 12 bytes is sufficient
|
|
|
|
static BYTE DBCSInfo[12] = { 0 };
|
|
|
|
BYTE *curr;
|
|
|
|
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);
|
|
|
|
// we had an error, do something?
|
|
|
|
if (rc != NO_ERROR)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
bDBCSFilled=TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// DBCSInfo returned by DosQueryDBCSEnv is terminated
|
|
|
|
// with two '0' bytes in a row
|
|
|
|
curr = DBCSInfo;
|
|
|
|
while(*curr != 0 && *(curr+1) != 0)
|
|
|
|
{
|
|
|
|
if(c >= *curr && c <= *(curr+1))
|
|
|
|
{
|
|
|
|
retval=TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
curr+=2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2005-04-25 17:06:43 +04:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsDirEnumerator
|
|
|
|
//-----------------------------------------------------------------------------
|
2000-05-02 02:21:43 +04:00
|
|
|
|
2005-04-23 05:39:51 +04:00
|
|
|
class nsDirEnumerator : public nsISimpleEnumerator,
|
|
|
|
public nsIDirectoryEnumerator
|
2000-05-02 02:21:43 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
nsDirEnumerator() : mDir(nsnull)
|
2000-05-02 02:21:43 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
nsresult Init(nsILocalFile* parent)
|
2000-05-02 02:21:43 +04:00
|
|
|
{
|
2002-04-27 09:33:09 +04:00
|
|
|
nsCAutoString filepath;
|
|
|
|
parent->GetNativeTarget(filepath);
|
2005-07-08 20:18:44 +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
|
|
|
}
|
2005-07-08 20:18:44 +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;
|
|
|
|
|
2005-04-25 17:06:43 +04:00
|
|
|
mParent = parent;
|
2000-05-02 02:21:43 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
NS_IMETHOD HasMoreElements(PRBool *result)
|
2000-05-02 02:21:43 +04:00
|
|
|
{
|
|
|
|
nsresult rv;
|
2005-07-08 20:18:44 +04:00
|
|
|
if (mNext == nsnull && mDir)
|
2000-05-02 02:21:43 +04:00
|
|
|
{
|
|
|
|
PRDirEntry* entry = PR_ReadDir(mDir, PR_SKIP_BOTH);
|
2005-07-08 20:18:44 +04:00
|
|
|
if (entry == nsnull)
|
2000-05-02 02:21:43 +04:00
|
|
|
{
|
|
|
|
// 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));
|
2005-07-08 20:18:44 +04:00
|
|
|
if (NS_FAILED(rv))
|
2000-05-02 02:21:43 +04:00
|
|
|
return rv;
|
2005-07-08 20:18:44 +04:00
|
|
|
|
2002-04-27 09:33:09 +04:00
|
|
|
rv = file->AppendNative(nsDependentCString(entry->name));
|
2005-07-08 20:18:44 +04:00
|
|
|
if (NS_FAILED(rv))
|
2000-05-02 02:21:43 +04:00
|
|
|
return rv;
|
2005-07-08 20:18:44 +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);
|
2005-07-08 20:18:44 +04:00
|
|
|
if (NS_FAILED(rv) || !exists)
|
2000-05-02 02:21:43 +04:00
|
|
|
{
|
2005-07-08 20:18:44 +04:00
|
|
|
return HasMoreElements(result);
|
2000-05-02 02:21:43 +04:00
|
|
|
}
|
2005-07-08 20:18:44 +04:00
|
|
|
|
2000-05-02 02:21:43 +04:00
|
|
|
mNext = do_QueryInterface(file);
|
|
|
|
}
|
|
|
|
*result = mNext != nsnull;
|
2005-04-23 05:39:51 +04:00
|
|
|
if (!*result)
|
|
|
|
Close();
|
2000-05-02 02:21:43 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
NS_IMETHOD GetNext(nsISupports **result)
|
2000-05-02 02:21:43 +04:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
PRBool hasMore;
|
|
|
|
rv = HasMoreElements(&hasMore);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
*result = mNext; // might return nsnull
|
|
|
|
NS_IF_ADDREF(*result);
|
2005-07-08 20:18:44 +04:00
|
|
|
|
2001-10-07 14:58:39 +04:00
|
|
|
mNext = nsnull;
|
2000-05-02 02:21:43 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-04-23 05:39:51 +04:00
|
|
|
NS_IMETHOD GetNextFile(nsIFile **result)
|
|
|
|
{
|
|
|
|
*result = nsnull;
|
|
|
|
PRBool hasMore = PR_FALSE;
|
|
|
|
nsresult rv = HasMoreElements(&hasMore);
|
|
|
|
if (NS_FAILED(rv) || !hasMore)
|
|
|
|
return rv;
|
|
|
|
*result = mNext;
|
|
|
|
NS_IF_ADDREF(*result);
|
|
|
|
mNext = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Close()
|
2000-05-02 02:21:43 +04:00
|
|
|
{
|
2005-04-23 05:39:51 +04:00
|
|
|
if (mDir)
|
2000-05-02 02:21:43 +04:00
|
|
|
{
|
|
|
|
PRStatus status = PR_CloseDir(mDir);
|
|
|
|
NS_ASSERTION(status == PR_SUCCESS, "close failed");
|
2005-04-25 17:06:43 +04:00
|
|
|
if (status != PR_SUCCESS)
|
|
|
|
return NS_ERROR_FAILURE;
|
2005-04-23 05:39:51 +04:00
|
|
|
mDir = nsnull;
|
2000-05-02 02:21:43 +04:00
|
|
|
}
|
2005-04-23 05:39:51 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-04-25 17:06:43 +04:00
|
|
|
// dtor can be non-virtual since there are no subclasses, but must be
|
|
|
|
// public to use the class on the stack.
|
|
|
|
~nsDirEnumerator()
|
2005-04-23 05:39:51 +04:00
|
|
|
{
|
|
|
|
Close();
|
2000-05-02 02:21:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
PRDir* mDir;
|
|
|
|
nsCOMPtr<nsILocalFile> mParent;
|
|
|
|
nsCOMPtr<nsILocalFile> mNext;
|
|
|
|
};
|
|
|
|
|
2005-04-23 05:39:51 +04:00
|
|
|
NS_IMPL_ISUPPORTS2(nsDirEnumerator, nsISimpleEnumerator, nsIDirectoryEnumerator)
|
2000-05-02 02:21:43 +04:00
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsDriveEnumerator
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class nsDriveEnumerator : public nsISimpleEnumerator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsDriveEnumerator();
|
|
|
|
virtual ~nsDriveEnumerator();
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSISIMPLEENUMERATOR
|
|
|
|
nsresult Init();
|
|
|
|
|
|
|
|
private:
|
|
|
|
// mDrives is a bitmap representing the available drives
|
|
|
|
// mLetter is incremented each time mDrives is shifted rightward
|
|
|
|
PRUint32 mDrives;
|
|
|
|
PRUint8 mLetter;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(nsDriveEnumerator, nsISimpleEnumerator)
|
|
|
|
|
|
|
|
nsDriveEnumerator::nsDriveEnumerator()
|
|
|
|
: mDrives(0), mLetter(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDriveEnumerator::~nsDriveEnumerator()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsDriveEnumerator::Init()
|
|
|
|
{
|
|
|
|
ULONG ulCurrent;
|
|
|
|
|
|
|
|
// bits 0-25 in mDrives represent each possible drive, A-Z
|
|
|
|
DosError(FERR_DISABLEHARDERR);
|
|
|
|
APIRET rc = DosQueryCurrentDisk(&ulCurrent, (PULONG)&mDrives);
|
|
|
|
DosError(FERR_ENABLEHARDERR);
|
|
|
|
if (rc)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
mLetter = 'A';
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDriveEnumerator::HasMoreElements(PRBool *aHasMore)
|
|
|
|
{
|
|
|
|
// no more bits means no more drives
|
|
|
|
*aHasMore = (mDrives != 0);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDriveEnumerator::GetNext(nsISupports **aNext)
|
|
|
|
{
|
|
|
|
if (!mDrives)
|
|
|
|
{
|
|
|
|
*aNext = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if bit 0 is off, advance to the next bit that's on
|
|
|
|
while ((mDrives & 1) == 0)
|
|
|
|
{
|
|
|
|
mDrives >>= 1;
|
|
|
|
mLetter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// format a drive string, then advance to the next possible drive
|
|
|
|
char drive[4] = "x:\\";
|
|
|
|
drive[0] = mLetter;
|
|
|
|
mDrives >>= 1;
|
|
|
|
mLetter++;
|
|
|
|
|
|
|
|
nsILocalFile *file;
|
|
|
|
nsresult rv = NS_NewNativeLocalFile(nsDependentCString(drive),
|
|
|
|
PR_FALSE, &file);
|
|
|
|
*aNext = file;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2005-04-22 17:21:23 +04:00
|
|
|
// class TypeEaEnumerator - a convenience for accessing
|
|
|
|
// a file's .TYPE extended attribute
|
2005-07-08 20:18:44 +04:00
|
|
|
//-----------------------------------------------------------------------------
|
2005-04-22 17:21:23 +04:00
|
|
|
|
|
|
|
// this struct describes the first entry for an MVMT or MVST EA;
|
|
|
|
// .TYPE is supposed to be MVMT but is sometimes malformed as MVST
|
|
|
|
|
|
|
|
typedef struct _MVHDR {
|
|
|
|
USHORT usEAType;
|
|
|
|
USHORT usCodePage;
|
|
|
|
USHORT usNumEntries;
|
|
|
|
USHORT usDataType;
|
|
|
|
USHORT usDataLth;
|
|
|
|
char data[1];
|
|
|
|
} MVHDR;
|
|
|
|
|
|
|
|
typedef MVHDR *PMVHDR;
|
|
|
|
|
|
|
|
|
|
|
|
class TypeEaEnumerator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TypeEaEnumerator() : mEaBuf(nsnull) { }
|
|
|
|
~TypeEaEnumerator() { if (mEaBuf) NS_Free(mEaBuf); }
|
|
|
|
|
|
|
|
nsresult Init(nsLocalFile * aFile);
|
|
|
|
char * GetNext(PRUint32 *lth);
|
|
|
|
|
|
|
|
private:
|
|
|
|
char * mEaBuf;
|
|
|
|
char * mpCur;
|
|
|
|
PMVHDR mpMvh;
|
|
|
|
USHORT mLth;
|
|
|
|
USHORT mCtr;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
nsresult TypeEaEnumerator::Init(nsLocalFile * aFile)
|
|
|
|
{
|
|
|
|
#define EABUFSIZE 512
|
|
|
|
|
|
|
|
// provide a buffer for the results
|
|
|
|
mEaBuf = (char*)NS_Alloc(EABUFSIZE);
|
|
|
|
if (!mEaBuf)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
PFEA2LIST pfea2list = (PFEA2LIST)mEaBuf;
|
|
|
|
pfea2list->cbList = EABUFSIZE;
|
|
|
|
|
|
|
|
// ask for the .TYPE extended attribute
|
|
|
|
nsresult rv = aFile->GetEA(".TYPE", pfea2list);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
// point at the data - it starts immediately after the EA's name;
|
|
|
|
// then confirm the EA is MVMT (correct) or MVST (acceptable)
|
|
|
|
mpMvh = (PMVHDR)&(pfea2list->list[0].szName[pfea2list->list[0].cbName+1]);
|
|
|
|
if (mpMvh->usEAType != EAT_MVMT)
|
|
|
|
if (mpMvh->usEAType != EAT_MVST || mpMvh->usDataType != EAT_ASCII)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// init the variables that tell us where we are in the lsit
|
|
|
|
mLth = 0;
|
|
|
|
mCtr = 0;
|
|
|
|
mpCur = (char*)(mpMvh->usEAType == EAT_MVMT ?
|
|
|
|
&mpMvh->usDataType : &mpMvh->usDataLth);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char * TypeEaEnumerator::GetNext(PRUint32 *lth)
|
|
|
|
{
|
|
|
|
char * result = nsnull;
|
|
|
|
|
|
|
|
// this is a loop so we can skip invalid entries if needed;
|
|
|
|
// normally, it will break out on the first iteration
|
|
|
|
while (mCtr++ < mpMvh->usNumEntries) {
|
|
|
|
|
|
|
|
// advance to the next entry
|
|
|
|
mpCur += mLth;
|
|
|
|
|
|
|
|
// if MVMT, ensure the datatype is OK, then advance
|
|
|
|
// to the length field present in both formats
|
|
|
|
if (mpMvh->usEAType == EAT_MVMT) {
|
|
|
|
if (*((PUSHORT)mpCur) != EAT_ASCII)
|
|
|
|
continue;
|
|
|
|
mpCur += sizeof(USHORT);
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the data's length, point at the data itself, then exit
|
|
|
|
mLth = *lth = *((PUSHORT)mpCur);
|
|
|
|
mpCur += sizeof(USHORT);
|
|
|
|
result = mpCur;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsLocalFile <public>
|
|
|
|
//-----------------------------------------------------------------------------
|
2000-05-02 02:21:43 +04:00
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
nsLocalFile::nsLocalFile()
|
2005-09-14 02:08:52 +04:00
|
|
|
: mDirty(PR_TRUE)
|
2000-05-02 02:21:43 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2005-07-08 20:18:44 +04:00
|
|
|
|
2000-05-02 02:21:43 +04:00
|
|
|
nsresult rv = inst->QueryInterface(aIID, aInstancePtr);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
{
|
|
|
|
delete inst;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsLocalFile::nsISupports
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2007-07-25 20:53:37 +04:00
|
|
|
NS_IMPL_THREADSAFE_ADDREF(nsLocalFile)
|
|
|
|
NS_IMPL_THREADSAFE_RELEASE(nsLocalFile)
|
|
|
|
NS_IMPL_QUERY_INTERFACE5_CI(nsLocalFile,
|
|
|
|
nsILocalFile,
|
|
|
|
nsIFile,
|
|
|
|
nsILocalFileOS2,
|
|
|
|
nsIHashable,
|
|
|
|
nsIClassInfo)
|
|
|
|
NS_IMPL_CI_INTERFACE_GETTER4(nsLocalFile,
|
|
|
|
nsILocalFile,
|
|
|
|
nsIFile,
|
|
|
|
nsILocalFileOS2,
|
|
|
|
nsIHashable)
|
|
|
|
|
|
|
|
NS_DECL_CLASSINFO(nsLocalFile)
|
|
|
|
NS_IMPL_THREADSAFE_CI(nsLocalFile)
|
2005-07-08 20:18:44 +04:00
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsLocalFile <private>
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
nsLocalFile::nsLocalFile(const nsLocalFile& other)
|
2005-09-14 02:08:52 +04:00
|
|
|
: mDirty(PR_TRUE)
|
2005-07-08 20:18:44 +04:00
|
|
|
, mWorkingPath(other.mWorkingPath)
|
2000-06-20 18:06:00 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
|
|
|
|
// Stat the path. After a successful return the path is
|
|
|
|
// guaranteed valid and the members of mFileInfo64 can be used.
|
2000-06-20 18:06:00 +04:00
|
|
|
nsresult
|
2003-06-20 01:53:26 +04:00
|
|
|
nsLocalFile::Stat()
|
2000-06-20 18:06:00 +04:00
|
|
|
{
|
2005-07-08 20:18:44 +04:00
|
|
|
// if we aren't dirty then we are already done
|
2003-06-20 01:53:26 +04:00
|
|
|
if (!mDirty)
|
2000-06-20 18:06:00 +04:00
|
|
|
return NS_OK;
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
// we can't stat anything that isn't a valid NSPR addressable path
|
|
|
|
if (mWorkingPath.IsEmpty())
|
|
|
|
return NS_ERROR_FILE_INVALID_PATH;
|
2000-06-20 18:06:00 +04:00
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
// hack designed to work around bug 134796 until it is fixed
|
|
|
|
char temp[4];
|
|
|
|
const char *nsprPath = mWorkingPath.get();
|
|
|
|
if (mWorkingPath.Length() == 2 && mWorkingPath.CharAt(1) == ':')
|
|
|
|
{
|
|
|
|
temp[0] = mWorkingPath[0];
|
|
|
|
temp[1] = mWorkingPath[1];
|
2000-06-20 18:06:00 +04:00
|
|
|
temp[2] = '\\';
|
|
|
|
temp[3] = '\0';
|
|
|
|
nsprPath = temp;
|
|
|
|
}
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
// see if the working path exists
|
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);
|
2005-07-08 20:18:44 +04:00
|
|
|
if (status != PR_SUCCESS)
|
|
|
|
return NS_ERROR_FILE_NOT_FOUND;
|
2000-06-20 18:06:00 +04:00
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
mDirty = PR_FALSE;
|
|
|
|
return NS_OK;
|
2000-06-20 18:06:00 +04:00
|
|
|
}
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsLocalFile::nsIFile,nsILocalFile
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
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);
|
2005-07-08 20:18:44 +04:00
|
|
|
|
2003-07-19 02:14:16 +04:00
|
|
|
return NS_OK;
|
2000-05-02 02:21:43 +04:00
|
|
|
}
|
|
|
|
|
2005-07-08 20:18:44 +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);
|
2005-07-08 20:18:44 +04:00
|
|
|
|
|
|
|
// just do a sanity check. if it has any forward slashes, it is not
|
|
|
|
// a Native path. 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;
|
|
|
|
}
|
2005-07-08 20:18:44 +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;
|
|
|
|
}
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
NS_IMETHODIMP
|
2000-05-02 02:21:43 +04:00
|
|
|
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)
|
2005-07-08 20:18:44 +04:00
|
|
|
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
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
NS_IMETHODIMP
|
2000-05-02 02:21:43 +04:00
|
|
|
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)
|
2005-07-08 20:18:44 +04:00
|
|
|
return rv;
|
|
|
|
|
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
|
|
|
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
NS_IMETHODIMP
|
2000-05-02 02:21:43 +04:00
|
|
|
nsLocalFile::Create(PRUint32 type, PRUint32 attributes)
|
2005-07-08 20:18:44 +04:00
|
|
|
{
|
2000-05-02 02:21:43 +04:00
|
|
|
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)
|
2005-07-08 20:18:44 +04:00
|
|
|
return rv;
|
2000-05-02 02:21:43 +04:00
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
// create directories to target
|
|
|
|
//
|
|
|
|
// A given local file can be either one of these forms:
|
|
|
|
//
|
|
|
|
// - normal: X:\some\path\on\this\drive
|
|
|
|
// ^--- start here
|
|
|
|
//
|
|
|
|
// - UNC path: \\machine\volume\some\path\on\this\drive
|
|
|
|
// ^--- start here
|
|
|
|
//
|
|
|
|
// Skip the first 'X:\' for the first form, and skip the first full
|
|
|
|
// '\\machine\volume\' segment for the second form.
|
|
|
|
|
|
|
|
unsigned char* path = (unsigned char*) mWorkingPath.BeginWriting();
|
|
|
|
|
|
|
|
if (path[0] == '\\' && path[1] == '\\')
|
|
|
|
{
|
|
|
|
// dealing with a UNC path here; skip past '\\machine\'
|
|
|
|
path = _mbschr(path + 2, '\\');
|
|
|
|
if (!path)
|
|
|
|
return NS_ERROR_FILE_INVALID_PATH;
|
|
|
|
++path;
|
|
|
|
}
|
|
|
|
|
|
|
|
// search for first slash after the drive (or volume) name
|
|
|
|
unsigned char* slash = _mbschr(path, '\\');
|
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, '\\');
|
2005-07-08 20:18:44 +04:00
|
|
|
|
2002-02-13 01:14:32 +03:00
|
|
|
while (slash)
|
|
|
|
{
|
|
|
|
*slash = '\0';
|
2005-07-08 20:18:44 +04:00
|
|
|
|
2007-07-08 11:08:04 +04:00
|
|
|
rv = CreateDirectoryA(const_cast<char*>(mWorkingPath.get()), NULL);
|
2005-07-08 20:18:44 +04: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);
|
2007-03-23 02:01:14 +03:00
|
|
|
if (!file) return NS_ERROR_FILE_ALREADY_EXISTS;
|
2005-07-08 20:18:44 +04:00
|
|
|
|
2000-06-27 07:35:32 +04:00
|
|
|
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)
|
|
|
|
{
|
2007-07-08 11:08:04 +04:00
|
|
|
rv = CreateDirectoryA(const_cast<char*>(mWorkingPath.get()), NULL);
|
2005-07-08 20:18:44 +04:00
|
|
|
if (rv)
|
2000-07-20 18:54:24 +04:00
|
|
|
return ConvertOS2Error(rv);
|
2005-07-08 20:18:44 +04:00
|
|
|
else
|
2000-07-20 18:54:24 +04:00
|
|
|
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
|
|
|
}
|
2005-07-08 20:18:44 +04:00
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-04-27 09:33:09 +04:00
|
|
|
nsLocalFile::AppendNative(const nsACString &node)
|
2005-07-08 20:18:44 +04:00
|
|
|
{
|
|
|
|
// append this path, multiple components are not permitted
|
|
|
|
return AppendNativeInternal(PromiseFlatCString(node), PR_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::AppendRelativeNativePath(const nsACString &node)
|
|
|
|
{
|
|
|
|
// append this path, multiple components are permitted
|
|
|
|
return AppendNativeInternal(PromiseFlatCString(node), PR_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsLocalFile::AppendNativeInternal(const nsAFlatCString &node, PRBool multipleComponents)
|
2000-05-25 18:23:27 +04:00
|
|
|
{
|
2002-09-04 02:40:45 +04:00
|
|
|
if (node.IsEmpty())
|
|
|
|
return NS_OK;
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
// check the relative path for validity
|
|
|
|
const unsigned char * nodePath = (const unsigned char *) node.get();
|
|
|
|
if (*nodePath == '\\' // can't start with an '\'
|
|
|
|
|| _mbschr(nodePath, '/') // can't contain /
|
|
|
|
|| node.Equals("..")) // can't be ..
|
2000-06-20 18:06:00 +04:00
|
|
|
return NS_ERROR_FILE_UNRECOGNIZED_PATH;
|
2002-09-04 02:40:45 +04:00
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
if (multipleComponents)
|
2000-05-02 02:21:43 +04:00
|
|
|
{
|
2005-07-08 20:18:44 +04:00
|
|
|
// can't contain .. as a path component. Ensure that the valid components
|
|
|
|
// "foo..foo", "..foo", and "foo.." are not falsely detected, but the invalid
|
|
|
|
// paths "..\", "foo\..", "foo\..\foo", "..\foo", etc are.
|
|
|
|
const unsigned char * doubleDot = _mbsstr(nodePath, (const unsigned char *)"\\..");
|
|
|
|
while (doubleDot)
|
|
|
|
{
|
|
|
|
doubleDot += 3;
|
|
|
|
if (*doubleDot == '\0' || *doubleDot == '\\')
|
|
|
|
return NS_ERROR_FILE_UNRECOGNIZED_PATH;
|
|
|
|
doubleDot = _mbsstr(doubleDot, (unsigned char *)"\\..");
|
|
|
|
}
|
|
|
|
// catches the remaining cases of prefixes (i.e. '..\')
|
|
|
|
// note: this is a substitute for Win32's _mbsncmp(nodePath, "..\\", 3)
|
|
|
|
if (*nodePath == '.') {
|
|
|
|
nodePath = (const unsigned char*)WinNextChar(0,0,0,(char*)nodePath);
|
|
|
|
if (*nodePath == '.' &&
|
|
|
|
*WinNextChar(0,0,0,(char*)nodePath) == '\\')
|
|
|
|
return NS_ERROR_FILE_UNRECOGNIZED_PATH;
|
|
|
|
}
|
2000-05-02 02:21:43 +04:00
|
|
|
}
|
2005-07-08 20:18:44 +04:00
|
|
|
else if (_mbschr(nodePath, '\\')) // single components can't contain '\'
|
|
|
|
return NS_ERROR_FILE_UNRECOGNIZED_PATH;
|
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
MakeDirty();
|
2005-07-08 20:18:44 +04:00
|
|
|
|
2002-04-27 09:33:09 +04:00
|
|
|
mWorkingPath.Append(NS_LITERAL_CSTRING("\\") + node);
|
2005-07-08 20:18:44 +04:00
|
|
|
|
2000-05-22 23:38:22 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-05-02 02:21:43 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::Normalize()
|
|
|
|
{
|
2005-07-08 20:18:44 +04:00
|
|
|
// XXX See bug 187957 comment 18 for possible problems with this implementation.
|
|
|
|
|
|
|
|
if (mWorkingPath.IsEmpty())
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// work in unicode for ease
|
|
|
|
nsAutoString path;
|
|
|
|
NS_CopyNativeToUnicode(mWorkingPath, path);
|
|
|
|
|
|
|
|
// find the index of the root backslash for the path. Everything before
|
|
|
|
// this is considered fully normalized and cannot be ascended beyond
|
|
|
|
// using ".." For a local drive this is the first slash (e.g. "c:\").
|
|
|
|
// For a UNC path it is the slash following the share name
|
|
|
|
// (e.g. "\\server\share\").
|
|
|
|
PRInt32 rootIdx = 2; // default to local drive
|
|
|
|
if (path.First() == '\\') // if a share then calculate the rootIdx
|
|
|
|
{
|
|
|
|
rootIdx = path.FindChar('\\', 2); // skip \\ in front of the server
|
|
|
|
if (rootIdx == kNotFound)
|
|
|
|
return NS_OK; // already normalized
|
|
|
|
rootIdx = path.FindChar('\\', rootIdx+1);
|
|
|
|
if (rootIdx == kNotFound)
|
|
|
|
return NS_OK; // already normalized
|
|
|
|
}
|
|
|
|
else if (path.CharAt(rootIdx) != '\\')
|
|
|
|
{
|
|
|
|
// The path has been specified relative to the current working directory
|
|
|
|
// for that drive. To normalize it, the current working directory for
|
|
|
|
// that drive needs to be inserted before the supplied relative path
|
|
|
|
// which will provide an absolute path (and the rootIdx will still be 2).
|
|
|
|
char drv[4] = "A:.";
|
|
|
|
char cwd[CCHMAXPATH];
|
|
|
|
|
|
|
|
drv[0] = mWorkingPath.First();
|
|
|
|
if (DosQueryPathInfo(drv, FIL_QUERYFULLNAME, cwd, sizeof(cwd)))
|
|
|
|
return NS_ERROR_FILE_NOT_FOUND;
|
|
|
|
|
|
|
|
nsAutoString currentDir;
|
|
|
|
NS_CopyNativeToUnicode(nsDependentCString(cwd), currentDir);
|
|
|
|
|
|
|
|
if (currentDir.Last() == '\\')
|
|
|
|
path.Replace(0, 2, currentDir);
|
|
|
|
else
|
|
|
|
path.Replace(0, 2, currentDir + NS_LITERAL_STRING("\\"));
|
|
|
|
}
|
|
|
|
NS_POSTCONDITION(0 < rootIdx && rootIdx < (PRInt32)path.Length(), "rootIdx is invalid");
|
|
|
|
NS_POSTCONDITION(path.CharAt(rootIdx) == '\\', "rootIdx is invalid");
|
|
|
|
|
|
|
|
// if there is nothing following the root path then it is already normalized
|
|
|
|
if (rootIdx + 1 == (PRInt32)path.Length())
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// assign the root
|
|
|
|
nsAutoString normal;
|
|
|
|
const PRUnichar * pathBuffer = path.get(); // simplify access to the buffer
|
|
|
|
normal.SetCapacity(path.Length()); // it won't ever grow longer
|
|
|
|
normal.Assign(pathBuffer, rootIdx);
|
|
|
|
|
|
|
|
// Normalize the path components. The actions taken are:
|
|
|
|
//
|
|
|
|
// "\\" condense to single backslash
|
|
|
|
// "." remove from path
|
|
|
|
// ".." up a directory
|
|
|
|
// "..." remove from path (any number of dots > 2)
|
|
|
|
//
|
|
|
|
// The last form is something that Windows 95 and 98 supported and
|
|
|
|
// is a shortcut for changing up multiple directories. Windows XP
|
|
|
|
// and ilk ignore it in a path, as is done here.
|
|
|
|
PRInt32 len, begin, end = rootIdx;
|
|
|
|
while (end < (PRInt32)path.Length())
|
|
|
|
{
|
|
|
|
// find the current segment (text between the backslashes) to
|
|
|
|
// be examined, this will set the following variables:
|
|
|
|
// begin == index of first char in segment
|
|
|
|
// end == index 1 char after last char in segment
|
|
|
|
// len == length of segment
|
|
|
|
begin = end + 1;
|
|
|
|
end = path.FindChar('\\', begin);
|
|
|
|
if (end == kNotFound)
|
|
|
|
end = path.Length();
|
|
|
|
len = end - begin;
|
|
|
|
|
|
|
|
// ignore double backslashes
|
|
|
|
if (len == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// len != 0, and interesting paths always begin with a dot
|
|
|
|
if (pathBuffer[begin] == '.')
|
|
|
|
{
|
|
|
|
// ignore single dots
|
|
|
|
if (len == 1)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// handle multiple dots
|
|
|
|
if (len >= 2 && pathBuffer[begin+1] == '.')
|
|
|
|
{
|
|
|
|
// back up a path component on double dot
|
|
|
|
if (len == 2)
|
|
|
|
{
|
|
|
|
PRInt32 prev = normal.RFindChar('\\');
|
|
|
|
if (prev >= rootIdx)
|
|
|
|
normal.Truncate(prev);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// length is > 2 and the first two characters are dots.
|
|
|
|
// if the rest of the string is dots, then ignore it.
|
|
|
|
int idx = len - 1;
|
|
|
|
for (; idx >= 2; --idx)
|
|
|
|
{
|
|
|
|
if (pathBuffer[begin+idx] != '.')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// this is true if the loop above didn't break
|
|
|
|
// and all characters in this segment are dots.
|
|
|
|
if (idx < 2)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// add the current component to the path, including the preceding backslash
|
|
|
|
normal.Append(pathBuffer + begin - 1, len + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// kill trailing dots and spaces.
|
|
|
|
PRInt32 filePathLen = normal.Length() - 1;
|
|
|
|
while(filePathLen > 0 && (normal[filePathLen] == ' ' || normal[filePathLen] == '.'))
|
|
|
|
{
|
|
|
|
normal.Truncate(filePathLen--);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_CopyUnicodeToNative(normal, mWorkingPath);
|
|
|
|
MakeDirty();
|
|
|
|
|
2000-05-02 02:21:43 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
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, '\\');
|
2005-07-08 20:18:44 +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;
|
|
|
|
}
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
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();
|
2005-07-08 20:18:44 +04:00
|
|
|
|
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
|
|
|
|
2005-07-08 20:18:44 +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;
|
|
|
|
}
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
//-----------------------------------------------------------------------------
|
2005-04-22 17:21:23 +04:00
|
|
|
|
|
|
|
// get any single extended attribute for the current file or directory
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsLocalFile::GetEA(const char *eaName, PFEA2LIST pfea2list)
|
|
|
|
{
|
|
|
|
// ensure we have an out-buffer whose length is specified
|
|
|
|
if (!pfea2list || !pfea2list->cbList)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// the gea2list's name field is only 1 byte long;
|
|
|
|
// this expands its allocation to hold a 33 byte name
|
|
|
|
union {
|
|
|
|
GEA2LIST gea2list;
|
|
|
|
char dummy[sizeof(GEA2LIST)+32];
|
|
|
|
};
|
|
|
|
EAOP2 eaop2;
|
|
|
|
|
|
|
|
eaop2.fpFEA2List = pfea2list;
|
|
|
|
eaop2.fpGEA2List = &gea2list;
|
|
|
|
|
|
|
|
// fill in the request structure
|
|
|
|
dummy[sizeof(GEA2LIST)+31] = 0;
|
|
|
|
gea2list.list[0].oNextEntryOffset = 0;
|
|
|
|
strcpy(gea2list.list[0].szName, eaName);
|
|
|
|
gea2list.list[0].cbName = strlen(gea2list.list[0].szName);
|
|
|
|
gea2list.cbList = sizeof(GEA2LIST) + gea2list.list[0].cbName;
|
|
|
|
|
|
|
|
// see what we get - this will succeed even if the EA doesn't exist
|
|
|
|
APIRET rc = DosQueryPathInfo(mWorkingPath.get(), FIL_QUERYEASFROMLIST,
|
|
|
|
&eaop2, sizeof(eaop2));
|
|
|
|
if (rc)
|
|
|
|
return ConvertOS2Error(rc);
|
|
|
|
|
|
|
|
// if the data length is zero, requested EA doesn't exist
|
|
|
|
if (!pfea2list->list[0].cbValue)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// return an array of file types or null if there are none
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::GetFileTypes(nsIArray **_retval)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(_retval);
|
|
|
|
*_retval = 0;
|
|
|
|
|
|
|
|
// fetch the .TYPE ea & prepare for enumeration
|
|
|
|
TypeEaEnumerator typeEnum;
|
|
|
|
nsresult rv = typeEnum.Init(this);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
// create an array that's scriptable
|
2006-04-14 18:02:57 +04:00
|
|
|
nsCOMPtr<nsIMutableArray> mutArray =
|
|
|
|
do_CreateInstance(NS_ARRAY_CONTRACTID);
|
|
|
|
NS_ENSURE_STATE(mutArray);
|
2005-04-22 17:21:23 +04:00
|
|
|
|
|
|
|
PRInt32 cnt;
|
|
|
|
PRUint32 lth;
|
|
|
|
char * ptr;
|
|
|
|
|
|
|
|
// get each file type, convert to a CString, then add to the array
|
|
|
|
for (cnt=0, ptr=typeEnum.GetNext(<h); ptr; ptr=typeEnum.GetNext(<h)) {
|
|
|
|
nsCOMPtr<nsISupportsCString> typeString(
|
|
|
|
do_CreateInstance(NS_SUPPORTS_CSTRING_CONTRACTID, &rv));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsCAutoString temp;
|
|
|
|
temp.Assign(ptr, lth);
|
|
|
|
typeString->SetData(temp);
|
|
|
|
mutArray->AppendElement(typeString, PR_FALSE);
|
|
|
|
cnt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if the array has any contents, addref & return it
|
|
|
|
if (cnt) {
|
|
|
|
*_retval = mutArray;
|
|
|
|
NS_ADDREF(*_retval);
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// see if the file is of the requested type
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::IsFileType(const nsACString& fileType, PRBool *_retval)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(_retval);
|
|
|
|
*_retval = PR_FALSE;
|
|
|
|
|
|
|
|
// fetch the .TYPE ea & prepare for enumeration
|
|
|
|
TypeEaEnumerator typeEnum;
|
|
|
|
nsresult rv = typeEnum.Init(this);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
PRUint32 lth;
|
|
|
|
char * ptr;
|
|
|
|
|
|
|
|
// compare each type to the request; if there's a match, exit
|
|
|
|
for (ptr = typeEnum.GetNext(<h); ptr; ptr = typeEnum.GetNext(<h))
|
|
|
|
if (fileType.EqualsASCII(ptr, lth)) {
|
|
|
|
*_retval = PR_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
//-----------------------------------------------------------------------------
|
2005-04-22 17:21:23 +04:00
|
|
|
|
2006-06-27 00:40:08 +04:00
|
|
|
// this struct combines an FEA2LIST, an FEA2, plus additional fields
|
|
|
|
// needed to write a .TYPE EA in the correct EAT_MVMT format
|
|
|
|
#pragma pack(1)
|
|
|
|
typedef struct _TYPEEA {
|
|
|
|
struct {
|
|
|
|
ULONG ulcbList;
|
|
|
|
ULONG uloNextEntryOffset;
|
|
|
|
BYTE bfEA;
|
|
|
|
BYTE bcbName;
|
|
|
|
USHORT uscbValue;
|
|
|
|
char chszName[sizeof(".TYPE")];
|
|
|
|
} hdr;
|
|
|
|
struct {
|
|
|
|
USHORT usEAType;
|
|
|
|
USHORT usCodePage;
|
|
|
|
USHORT usNumEntries;
|
|
|
|
USHORT usDataType;
|
|
|
|
USHORT usDataLth;
|
|
|
|
} info;
|
|
|
|
char data[1];
|
|
|
|
} TYPEEA;
|
|
|
|
|
|
|
|
typedef struct _TYPEEA2 {
|
|
|
|
USHORT usDataType;
|
|
|
|
USHORT usDataLth;
|
|
|
|
} TYPEEA2;
|
|
|
|
#pragma pack()
|
|
|
|
|
|
|
|
// writes one or more .TYPE extended attributes taken
|
|
|
|
// from a comma-delimited string
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::SetFileTypes(const nsACString& fileTypes)
|
|
|
|
{
|
|
|
|
if (fileTypes.IsEmpty())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
PRUint32 cnt = CountCharInReadable(fileTypes, ',');
|
|
|
|
PRUint32 lth = fileTypes.Length() - cnt + (cnt * sizeof(TYPEEA2));
|
|
|
|
PRUint32 size = sizeof(TYPEEA) + lth;
|
|
|
|
|
|
|
|
char *pBuf = (char*)NS_Alloc(size);
|
|
|
|
if (!pBuf)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
TYPEEA *pEA = (TYPEEA *)pBuf;
|
|
|
|
|
|
|
|
// the buffer has an extra byte due to TYPEEA.data[1]
|
|
|
|
pEA->hdr.ulcbList = size - 1;
|
|
|
|
pEA->hdr.uloNextEntryOffset = 0;
|
|
|
|
pEA->hdr.bfEA = 0;
|
|
|
|
pEA->hdr.bcbName = sizeof(".TYPE") - 1;
|
|
|
|
pEA->hdr.uscbValue = sizeof(pEA->info) + lth;
|
|
|
|
strcpy(pEA->hdr.chszName, ".TYPE");
|
|
|
|
|
|
|
|
pEA->info.usEAType = EAT_MVMT;
|
|
|
|
pEA->info.usCodePage = 0;
|
|
|
|
pEA->info.usNumEntries = ++cnt;
|
|
|
|
|
|
|
|
nsACString::const_iterator begin, end, delim;
|
|
|
|
fileTypes.BeginReading(begin);
|
|
|
|
fileTypes.EndReading(end);
|
|
|
|
delim = begin;
|
|
|
|
|
|
|
|
// fill in type & length, copy the current type name (which
|
|
|
|
// is not zero-terminated), then advance the ptr so the next
|
|
|
|
// iteration can reuse the trailing members of the structure
|
|
|
|
do {
|
|
|
|
FindCharInReadable( ',', delim, end);
|
|
|
|
lth = delim.get() - begin.get();
|
|
|
|
pEA->info.usDataType = EAT_ASCII;
|
|
|
|
pEA->info.usDataLth = lth;
|
|
|
|
memcpy(pEA->data, begin.get(), lth);
|
|
|
|
pEA = (TYPEEA *)((char*)pEA + lth + sizeof(TYPEEA2));
|
|
|
|
begin = ++delim;
|
|
|
|
} while (--cnt);
|
|
|
|
|
|
|
|
// write the EA, then free the buffer
|
|
|
|
EAOP2 eaop2;
|
|
|
|
eaop2.fpGEA2List = 0;
|
|
|
|
eaop2.fpFEA2List = (PFEA2LIST)pBuf;
|
|
|
|
|
|
|
|
int rc = DosSetPathInfo(mWorkingPath.get(), FIL_QUERYEASIZE,
|
|
|
|
&eaop2, sizeof(eaop2), 0);
|
|
|
|
NS_Free(pBuf);
|
|
|
|
|
|
|
|
if (rc)
|
|
|
|
return ConvertOS2Error(rc);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// this struct combines an FEA2LIST, an FEA2, plus additional fields
|
|
|
|
// needed to write a .SUBJECT EA in the correct EAT_ASCII format;
|
|
|
|
#pragma pack(1)
|
|
|
|
typedef struct _SUBJEA {
|
|
|
|
struct {
|
|
|
|
ULONG ulcbList;
|
|
|
|
ULONG uloNextEntryOffset;
|
|
|
|
BYTE bfEA;
|
|
|
|
BYTE bcbName;
|
|
|
|
USHORT uscbValue;
|
|
|
|
char chszName[sizeof(".SUBJECT")];
|
|
|
|
} hdr;
|
|
|
|
struct {
|
|
|
|
USHORT usEAType;
|
|
|
|
USHORT usDataLth;
|
|
|
|
} info;
|
|
|
|
char data[1];
|
|
|
|
} SUBJEA;
|
|
|
|
#pragma pack()
|
|
|
|
|
|
|
|
// saves the file's source URI in its .SUBJECT extended attribute
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::SetFileSource(const nsACString& aURI)
|
|
|
|
{
|
|
|
|
if (aURI.IsEmpty())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// this includes an extra character for the spec's trailing null
|
|
|
|
PRUint32 lth = sizeof(SUBJEA) + aURI.Length();
|
|
|
|
char * pBuf = (char*)NS_Alloc(lth);
|
|
|
|
if (!pBuf)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
SUBJEA *pEA = (SUBJEA *)pBuf;
|
|
|
|
|
|
|
|
// the trailing null doesn't get saved, so don't include it in the size
|
|
|
|
pEA->hdr.ulcbList = lth - 1;
|
|
|
|
pEA->hdr.uloNextEntryOffset = 0;
|
|
|
|
pEA->hdr.bfEA = 0;
|
|
|
|
pEA->hdr.bcbName = sizeof(".SUBJECT") - 1;
|
|
|
|
pEA->hdr.uscbValue = sizeof(pEA->info) + aURI.Length();
|
|
|
|
strcpy(pEA->hdr.chszName, ".SUBJECT");
|
|
|
|
pEA->info.usEAType = EAT_ASCII;
|
|
|
|
pEA->info.usDataLth = aURI.Length();
|
|
|
|
strcpy(pEA->data, PromiseFlatCString(aURI).get());
|
|
|
|
|
|
|
|
// write the EA, then free the buffer
|
|
|
|
EAOP2 eaop2;
|
|
|
|
eaop2.fpGEA2List = 0;
|
|
|
|
eaop2.fpFEA2List = (PFEA2LIST)pEA;
|
|
|
|
|
|
|
|
int rc = DosSetPathInfo(mWorkingPath.get(), FIL_QUERYEASIZE,
|
|
|
|
&eaop2, sizeof(eaop2), 0);
|
|
|
|
NS_Free(pBuf);
|
|
|
|
|
|
|
|
if (rc)
|
|
|
|
return ConvertOS2Error(rc);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2000-05-02 02:21:43 +04:00
|
|
|
nsresult
|
2005-07-08 20:18:44 +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;
|
2005-07-08 20:18:44 +04:00
|
|
|
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);
|
|
|
|
}
|
2005-07-08 20:18:44 +04:00
|
|
|
|
2003-06-20 01:53:26 +04:00
|
|
|
rv = sourceFile->GetNativePath(filePath);
|
2005-07-08 20:18:44 +04:00
|
|
|
|
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;
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
if (move)
|
2007-07-08 11:08:04 +04:00
|
|
|
rc = DosMove(filePath.get(), (PSZ)const_cast<char*>(destPath.get()));
|
2001-03-23 06:21:22 +03:00
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
if (!move || rc == ERROR_NOT_SAME_DEVICE || rc == ERROR_ACCESS_DENIED)
|
|
|
|
{
|
|
|
|
// 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 {
|
2007-07-08 11:08:04 +04:00
|
|
|
rc = DosCopy(filePath.get(), (PSZ)const_cast<char*>(destPath.get()), DCPY_EXISTING);
|
2005-07-08 20:18:44 +04:00
|
|
|
if (rc == ERROR_TOO_MANY_OPEN_FILES) {
|
|
|
|
ULONG CurMaxFH = 0;
|
|
|
|
LONG ReqCount = 20;
|
|
|
|
APIRET rc2;
|
|
|
|
rc2 = DosSetRelMaxFH(&ReqCount, &CurMaxFH);
|
|
|
|
if (rc2 != NO_ERROR)
|
|
|
|
break;
|
|
|
|
}
|
2002-07-17 09:46:34 +04:00
|
|
|
} while (rc == ERROR_TOO_MANY_OPEN_FILES);
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
// WSOD2 HACK - NETWORK_ACCESS_DENIED
|
|
|
|
if (rc == 65)
|
2001-05-30 02:21:11 +04:00
|
|
|
{
|
2005-07-08 20:18:44 +04:00
|
|
|
CHAR achProgram[CCHMAXPATH]; // buffer for program name, parameters
|
|
|
|
RESULTCODES rescResults; // buffer for results of dosexecpgm
|
|
|
|
|
|
|
|
strcpy(achProgram, "CMD.EXE /C ");
|
|
|
|
strcat(achProgram, """COPY ");
|
|
|
|
strcat(achProgram, filePath.get());
|
|
|
|
strcat(achProgram, " ");
|
2007-07-08 11:08:04 +04:00
|
|
|
strcat(achProgram, (PSZ)const_cast<char*>(destPath.get()));
|
2005-07-08 20:18:44 +04: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
|
|
|
|
|
|
|
|
} // rc == 65
|
|
|
|
|
|
|
|
// 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))
|
|
|
|
DosDelete( filePath.get());
|
|
|
|
|
|
|
|
} // !move or ERROR
|
|
|
|
|
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
|
|
|
{
|
2006-12-16 17:55:00 +03:00
|
|
|
// Check we are correctly initialized.
|
|
|
|
CHECK_mWorkingPath();
|
|
|
|
|
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.
|
2005-07-08 20:18:44 +04:00
|
|
|
|
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;
|
2005-07-08 20:18:44 +04:00
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
// make sure it exists and is a directory. Create it if not there.
|
|
|
|
PRBool exists;
|
|
|
|
newParentDir->Exists(&exists);
|
2005-07-08 20:18:44 +04:00
|
|
|
if (!exists)
|
2000-06-20 18:06:00 +04:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-27 08:38:21 +04:00
|
|
|
// Try different ways to move/copy files/directories
|
|
|
|
PRBool done = PR_FALSE;
|
2000-06-20 18:06:00 +04:00
|
|
|
PRBool isDir;
|
|
|
|
IsDirectory(&isDir);
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
// Try to move the file or directory, or try to copy a single file
|
2005-04-27 08:38:21 +04:00
|
|
|
if (move || !isDir)
|
2000-06-20 18:06:00 +04:00
|
|
|
{
|
2005-07-08 20:18:44 +04:00
|
|
|
// when moving things, first try to just MoveFile it,
|
|
|
|
// even if it is a directory
|
2003-06-20 01:53:26 +04:00
|
|
|
rv = CopySingleFile(this, newParentDir, newName, move);
|
2005-04-27 08:38:21 +04:00
|
|
|
done = NS_SUCCEEDED(rv);
|
|
|
|
// If we are moving a directory and that fails, fallback on directory
|
|
|
|
// enumeration. See bug 231300 for details.
|
|
|
|
if (!done && !(move && isDir))
|
2005-07-08 20:18:44 +04:00
|
|
|
return rv;
|
2000-06-20 18:06:00 +04:00
|
|
|
}
|
2005-07-08 20:18:44 +04:00
|
|
|
|
2005-04-27 08:38:21 +04:00
|
|
|
// Not able to copy or move directly, so enumerate it
|
|
|
|
if (!done)
|
2000-06-20 18:06:00 +04:00
|
|
|
{
|
|
|
|
// create a new target destination in the new parentDir;
|
|
|
|
nsCOMPtr<nsIFile> target;
|
|
|
|
rv = newParentDir->Clone(getter_AddRefs(target));
|
2005-07-08 20:18:44 +04:00
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
2000-06-20 18:06:00 +04:00
|
|
|
return rv;
|
2005-07-08 20:18:44 +04:00
|
|
|
|
2002-04-27 09:33:09 +04:00
|
|
|
nsCAutoString allocatedNewName;
|
|
|
|
if (newName.IsEmpty())
|
2000-06-20 18:06:00 +04:00
|
|
|
{
|
2005-07-08 20:18:44 +04:00
|
|
|
GetNativeLeafName(allocatedNewName);
|
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
|
|
|
}
|
2005-07-08 20:18:44 +04:00
|
|
|
|
2002-04-27 09:33:09 +04:00
|
|
|
rv = target->AppendNative(allocatedNewName);
|
2005-07-08 20:18:44 +04:00
|
|
|
if (NS_FAILED(rv))
|
2000-06-20 18:06:00 +04:00
|
|
|
return rv;
|
|
|
|
|
2002-04-27 09:33:09 +04:00
|
|
|
allocatedNewName.Truncate();
|
2000-06-20 18:06:00 +04:00
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
// check if the destination directory already exists
|
|
|
|
target->Exists(&exists);
|
|
|
|
if (!exists)
|
|
|
|
{
|
|
|
|
// if the destination directory cannot be created, return an error
|
|
|
|
rv = target->Create(DIRECTORY_TYPE, 0644); // TODO, what permissions should we use
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// check if the destination directory is writable and empty
|
|
|
|
PRBool isWritable;
|
|
|
|
|
|
|
|
target->IsWritable(&isWritable);
|
|
|
|
if (!isWritable)
|
|
|
|
return NS_ERROR_FILE_ACCESS_DENIED;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> targetIterator;
|
|
|
|
rv = target->GetDirectoryEntries(getter_AddRefs(targetIterator));
|
|
|
|
|
|
|
|
PRBool more;
|
|
|
|
targetIterator->HasMoreElements(&more);
|
|
|
|
// return error if target directory is not empty
|
|
|
|
if (more)
|
|
|
|
return NS_ERROR_FILE_DIR_NOT_EMPTY;
|
|
|
|
}
|
|
|
|
|
2005-04-25 17:06:43 +04:00
|
|
|
nsDirEnumerator dirEnum;
|
2005-07-08 20:18:44 +04:00
|
|
|
|
2005-04-25 17:06:43 +04:00
|
|
|
rv = dirEnum.Init(this);
|
|
|
|
if (NS_FAILED(rv)) {
|
2006-02-23 12:36:43 +03:00
|
|
|
NS_WARNING("dirEnum initialization failed");
|
2005-04-25 17:06:43 +04:00
|
|
|
return rv;
|
|
|
|
}
|
2000-06-20 18:06:00 +04:00
|
|
|
|
|
|
|
PRBool more;
|
2005-04-25 17:06:43 +04:00
|
|
|
while (NS_SUCCEEDED(dirEnum.HasMoreElements(&more)) && more)
|
2000-06-20 18:06:00 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsISupports> item;
|
|
|
|
nsCOMPtr<nsIFile> file;
|
2005-04-25 17:06:43 +04:00
|
|
|
dirEnum.GetNext(getter_AddRefs(item));
|
2000-06-20 18:06:00 +04:00
|
|
|
file = do_QueryInterface(item);
|
2005-07-08 20:18:44 +04:00
|
|
|
if (file)
|
2000-06-20 18:06:00 +04:00
|
|
|
{
|
2005-04-25 17:06:43 +04:00
|
|
|
if (move)
|
|
|
|
{
|
|
|
|
rv = file->MoveToNative(target, EmptyCString());
|
2005-07-08 20:18:44 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv,rv);
|
2005-04-25 17:06:43 +04:00
|
|
|
}
|
|
|
|
else
|
2005-07-08 20:18:44 +04:00
|
|
|
{
|
2005-04-25 17:06:43 +04:00
|
|
|
rv = file->CopyToNative(target, EmptyCString());
|
2005-07-08 20:18:44 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv,rv);
|
2005-04-25 17:06:43 +04:00
|
|
|
}
|
2000-06-20 18:06:00 +04:00
|
|
|
}
|
|
|
|
}
|
2004-04-09 00:30:37 +04:00
|
|
|
// we've finished moving all the children of this directory
|
|
|
|
// in the new directory. so now delete the directory
|
|
|
|
// note, we don't need to do a recursive delete.
|
|
|
|
// MoveTo() is recursive. At this point,
|
2005-07-08 20:18:44 +04:00
|
|
|
// we've already moved the children of the current folder
|
2004-04-09 00:30:37 +04:00
|
|
|
// to the new location. nothing should be left in the folder.
|
|
|
|
if (move)
|
|
|
|
{
|
2005-07-08 20:18:44 +04:00
|
|
|
rv = Remove(PR_FALSE); // recursive
|
2004-04-09 00:30:37 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv,rv);
|
|
|
|
}
|
2000-06-20 18:06:00 +04:00
|
|
|
}
|
2005-07-08 20:18:44 +04:00
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
|
|
|
|
// If we moved, we want to adjust this.
|
|
|
|
if (move)
|
|
|
|
{
|
|
|
|
MakeDirty();
|
2005-07-08 20:18:44 +04:00
|
|
|
|
2002-04-27 09:33:09 +04:00
|
|
|
nsCAutoString newParentPath;
|
|
|
|
newParentDir->GetNativePath(newParentPath);
|
2005-07-08 20:18:44 +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);
|
2005-07-08 20:18:44 +04:00
|
|
|
|
2002-04-27 09:33:09 +04:00
|
|
|
InitWithNativePath(newParentPath);
|
2005-07-08 20:18:44 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2005-07-08 20:18:44 +04:00
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2005-07-08 20:18:44 +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
|
|
|
|
2005-07-08 20:18:44 +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
|
|
|
}
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
NS_IMETHODIMP
|
2000-06-20 18:06:00 +04:00
|
|
|
nsLocalFile::Load(PRLibrary * *_retval)
|
2000-05-02 02:21:43 +04:00
|
|
|
{
|
2006-12-16 17:55:00 +03:00
|
|
|
// Check we are correctly initialized.
|
|
|
|
CHECK_mWorkingPath();
|
|
|
|
|
2000-05-02 02:21:43 +04:00
|
|
|
PRBool isFile;
|
|
|
|
nsresult rv = IsFile(&isFile);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2005-07-08 20:18:44 +04:00
|
|
|
|
2006-11-15 01:06:00 +03:00
|
|
|
if (!isFile)
|
2000-05-02 02:21:43 +04:00
|
|
|
return NS_ERROR_FILE_IS_DIRECTORY;
|
|
|
|
|
2006-11-15 01:06:00 +03:00
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
nsTraceRefcntImpl::SetActivityIsLegal(PR_FALSE);
|
|
|
|
#endif
|
|
|
|
|
2003-06-20 01:53:26 +04:00
|
|
|
*_retval = PR_LoadLibrary(mWorkingPath.get());
|
2005-07-08 20:18:44 +04:00
|
|
|
|
2006-11-15 01:06:00 +03:00
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
nsTraceRefcntImpl::SetActivityIsLegal(PR_TRUE);
|
|
|
|
#endif
|
|
|
|
|
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
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
NS_IMETHODIMP
|
2001-07-24 22:38:25 +04:00
|
|
|
nsLocalFile::Remove(PRBool recursive)
|
2000-05-02 02:21:43 +04:00
|
|
|
{
|
2006-12-16 17:55:00 +03:00
|
|
|
// Check we are correctly initialized.
|
|
|
|
CHECK_mWorkingPath();
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
PRBool isDir = PR_FALSE;
|
|
|
|
|
2000-05-02 02:21:43 +04:00
|
|
|
nsresult rv = IsDirectory(&isDir);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (isDir)
|
|
|
|
{
|
|
|
|
if (recursive)
|
|
|
|
{
|
2005-04-25 17:06:43 +04:00
|
|
|
nsDirEnumerator dirEnum;
|
|
|
|
|
|
|
|
rv = dirEnum.Init(this);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2000-05-02 02:21:43 +04:00
|
|
|
|
|
|
|
PRBool more;
|
2005-04-25 17:06:43 +04:00
|
|
|
while (NS_SUCCEEDED(dirEnum.HasMoreElements(&more)) && more)
|
2000-05-02 02:21:43 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsISupports> item;
|
2005-04-25 17:06:43 +04:00
|
|
|
dirEnum.GetNext(getter_AddRefs(item));
|
|
|
|
nsCOMPtr<nsIFile> file = do_QueryInterface(item);
|
|
|
|
if (file)
|
|
|
|
file->Remove(recursive);
|
2000-05-02 02:21:43 +04:00
|
|
|
}
|
|
|
|
}
|
2005-07-08 20:18:44 +04:00
|
|
|
rv = rmdir(mWorkingPath.get());
|
2000-05-02 02:21:43 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-07-08 20:18:44 +04:00
|
|
|
rv = remove(mWorkingPath.get());
|
2000-05-02 02:21:43 +04:00
|
|
|
}
|
2005-07-08 20:18:44 +04:00
|
|
|
|
|
|
|
// fixup error code if necessary...
|
|
|
|
if (rv == (nsresult)-1)
|
|
|
|
rv = NSRESULT_FOR_ERRNO();
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
NS_IMETHODIMP
|
2001-11-26 11:05:05 +03:00
|
|
|
nsLocalFile::GetLastModifiedTime(PRInt64 *aLastModifiedTime)
|
2000-05-02 02:21:43 +04:00
|
|
|
{
|
2006-12-16 17:55:00 +03:00
|
|
|
// Check we are correctly initialized.
|
|
|
|
CHECK_mWorkingPath();
|
|
|
|
|
2001-11-26 11:05:05 +03:00
|
|
|
NS_ENSURE_ARG(aLastModifiedTime);
|
2000-06-20 18:06:00 +04:00
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
*aLastModifiedTime = 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;
|
2005-07-08 20:18:44 +04:00
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
// microseconds -> milliseconds
|
2005-07-08 20:18:44 +04:00
|
|
|
PRInt64 usecPerMsec;
|
|
|
|
LL_I2L(usecPerMsec, PR_USEC_PER_MSEC);
|
|
|
|
LL_DIV(*aLastModifiedTime, mFileInfo64.modifyTime, usecPerMsec);
|
2000-05-02 02:21:43 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
|
2005-07-08 20:18:44 +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
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
NS_IMETHODIMP
|
2001-11-26 11:05:05 +03:00
|
|
|
nsLocalFile::SetLastModifiedTime(PRInt64 aLastModifiedTime)
|
2000-05-02 02:21:43 +04:00
|
|
|
{
|
2006-12-16 17:55:00 +03:00
|
|
|
// Check we are correctly initialized.
|
|
|
|
CHECK_mWorkingPath();
|
|
|
|
|
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
|
|
|
|
2005-07-08 20:18:44 +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();
|
2005-07-08 20:18:44 +04:00
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2005-07-08 20:18:44 +04:00
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
PRExplodedTime pret;
|
|
|
|
FILESTATUS3 pathInfo;
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
// Level 1 info
|
|
|
|
rv = DosQueryPathInfo(mWorkingPath.get(), FIL_STANDARD,
|
|
|
|
&pathInfo, sizeof(pathInfo));
|
2000-06-20 18:06:00 +04:00
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
{
|
|
|
|
rv = ConvertOS2Error(rv);
|
|
|
|
return rv;
|
|
|
|
}
|
2005-07-08 20:18:44 +04:00
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
// PR_ExplodeTime expects usecs...
|
2001-11-26 11:05:05 +03:00
|
|
|
PR_ExplodeTime(aLastModifiedTime * PR_USEC_PER_MSEC, PR_LocalTimeParameters, &pret);
|
2005-07-08 20:18:44 +04:00
|
|
|
|
|
|
|
// fdateLastWrite.year is based off of 1980
|
2002-10-09 06:37:48 +04:00
|
|
|
if (pret.tm_year >= 1980)
|
2005-07-08 20:18:44 +04:00
|
|
|
pathInfo.fdateLastWrite.year = pret.tm_year-1980;
|
2002-10-09 06:37:48 +04:00
|
|
|
else
|
2005-07-08 20:18:44 +04:00
|
|
|
pathInfo.fdateLastWrite.year = pret.tm_year;
|
|
|
|
|
|
|
|
// Convert start offset -- OS/2: Jan=1; NSPR: Jan=0
|
|
|
|
pathInfo.fdateLastWrite.month = pret.tm_month + 1;
|
|
|
|
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;
|
|
|
|
|
|
|
|
rv = DosSetPathInfo(mWorkingPath.get(), FIL_STANDARD,
|
|
|
|
&pathInfo, sizeof(pathInfo), 0UL);
|
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
MakeDirty();
|
|
|
|
return rv;
|
|
|
|
}
|
2000-05-02 02:21:43 +04:00
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
NS_IMETHODIMP
|
2000-05-02 02:21:43 +04:00
|
|
|
nsLocalFile::GetPermissions(PRUint32 *aPermissions)
|
|
|
|
{
|
2005-07-08 20:18:44 +04:00
|
|
|
NS_ENSURE_ARG(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;
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
PRBool isWritable, isExecutable;
|
|
|
|
IsWritable(&isWritable);
|
|
|
|
IsExecutable(&isExecutable);
|
|
|
|
|
|
|
|
*aPermissions = PR_IRUSR|PR_IRGRP|PR_IROTH; // all read
|
|
|
|
if (isWritable)
|
|
|
|
*aPermissions |= PR_IWUSR|PR_IWGRP|PR_IWOTH; // all write
|
|
|
|
if (isExecutable)
|
|
|
|
*aPermissions |= PR_IXUSR|PR_IXGRP|PR_IXOTH; // all execute
|
2000-06-20 18:06:00 +04:00
|
|
|
|
2000-05-02 02:21:43 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
NS_IMETHODIMP
|
2000-05-02 02:21:43 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
// the only Unix-style permission OS/2 knows is whether a file is
|
|
|
|
// writable; as a matter of policy, a browser shouldn't be able
|
|
|
|
// to change any of the other DOS-style attributes; to enforce
|
|
|
|
// this, we use DosSetPathInfo() rather than chmod()
|
|
|
|
NS_IMETHODIMP
|
2000-05-02 02:21:43 +04:00
|
|
|
nsLocalFile::SetPermissions(PRUint32 aPermissions)
|
|
|
|
{
|
2006-12-16 17:55:00 +03:00
|
|
|
// Check we are correctly initialized.
|
|
|
|
CHECK_mWorkingPath();
|
|
|
|
|
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;
|
2005-07-08 20:18:44 +04:00
|
|
|
|
|
|
|
APIRET rc;
|
|
|
|
FILESTATUS3 pathInfo;
|
|
|
|
|
|
|
|
// Level 1 info
|
|
|
|
rc = DosQueryPathInfo(mWorkingPath.get(), FIL_STANDARD,
|
|
|
|
&pathInfo, sizeof(pathInfo));
|
|
|
|
|
|
|
|
if (rc != NO_ERROR)
|
|
|
|
return ConvertOS2Error(rc);
|
|
|
|
|
|
|
|
ULONG attr = 0;
|
|
|
|
if (!(aPermissions & (PR_IWUSR|PR_IWGRP|PR_IWOTH)))
|
|
|
|
attr = FILE_READONLY;
|
|
|
|
|
|
|
|
if (attr == (pathInfo.attrFile & FILE_READONLY))
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
pathInfo.attrFile ^= FILE_READONLY;
|
|
|
|
|
|
|
|
rc = DosSetPathInfo(mWorkingPath.get(), FIL_STANDARD,
|
|
|
|
&pathInfo, sizeof(pathInfo), 0UL);
|
|
|
|
|
|
|
|
if (rc != NO_ERROR)
|
|
|
|
return ConvertOS2Error(rc);
|
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
return NS_OK;
|
2000-05-02 02:21:43 +04:00
|
|
|
}
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
NS_IMETHODIMP
|
2000-05-02 02:21:43 +04:00
|
|
|
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
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
NS_IMETHODIMP
|
2000-05-02 02:21:43 +04:00
|
|
|
nsLocalFile::GetFileSize(PRInt64 *aFileSize)
|
|
|
|
{
|
2006-12-16 17:55:00 +03:00
|
|
|
// Check we are correctly initialized.
|
|
|
|
CHECK_mWorkingPath();
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::GetFileSizeOfLink(PRInt64 *aFileSize)
|
2000-05-02 02:21:43 +04:00
|
|
|
{
|
2005-07-08 20:18:44 +04:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2000-05-02 02:21:43 +04:00
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
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
|
|
|
|
|
|
|
APIRET rc;
|
|
|
|
HFILE hFile;
|
|
|
|
ULONG actionTaken;
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
rc = DosOpen(mWorkingPath.get(),
|
|
|
|
&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;
|
|
|
|
}
|
2005-07-08 20:18:44 +04: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);
|
2005-07-08 20:18:44 +04:00
|
|
|
DosClose(hFile);
|
2000-06-20 18:06:00 +04:00
|
|
|
MakeDirty();
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
if (rc != NO_ERROR)
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-05-02 02:21:43 +04:00
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
return NS_OK;
|
2000-06-20 18:06:00 +04:00
|
|
|
}
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
NS_IMETHODIMP
|
2000-06-20 18:06:00 +04:00
|
|
|
nsLocalFile::GetDiskSpaceAvailable(PRInt64 *aDiskSpaceAvailable)
|
|
|
|
{
|
2006-12-16 17:55:00 +03:00
|
|
|
// Check we are correctly initialized.
|
|
|
|
CHECK_mWorkingPath();
|
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
NS_ENSURE_ARG(aDiskSpaceAvailable);
|
2005-07-08 20:18:44 +04:00
|
|
|
*aDiskSpaceAvailable = 0;
|
|
|
|
|
|
|
|
nsresult rv = Stat();
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
NS_IMETHODIMP
|
2000-05-02 02:21:43 +04:00
|
|
|
nsLocalFile::GetParent(nsIFile * *aParent)
|
|
|
|
{
|
2006-12-16 17:55:00 +03:00
|
|
|
// Check we are correctly initialized.
|
|
|
|
CHECK_mWorkingPath();
|
|
|
|
|
2000-05-02 02:21:43 +04:00
|
|
|
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());
|
2005-07-08 20:18:44 +04:00
|
|
|
// adding this offset check that was removed in bug 241708 fixes mail
|
|
|
|
// directories that aren't relative to/underneath the profile dir.
|
|
|
|
// e.g., on a different drive. Before you remove them, please make
|
|
|
|
// sure local mail directories that aren't underneath the profile dir work.
|
2000-10-06 00:44:11 +04:00
|
|
|
if (offset < 0)
|
2005-07-08 20:18:44 +04:00
|
|
|
return NS_ERROR_FILE_UNRECOGNIZED_PATH;
|
2000-05-02 02:21:43 +04:00
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
if (offset == 1 && parentPath[0] == '\\') {
|
|
|
|
aParent = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (offset > 0)
|
|
|
|
parentPath.Truncate(offset);
|
|
|
|
else
|
|
|
|
parentPath.AssignLiteral("\\\\.");
|
2000-05-02 02:21:43 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsILocalFile> localFile;
|
2005-07-08 20:18:44 +04:00
|
|
|
nsresult rv = NS_NewNativeLocalFile(parentPath, PR_FALSE, 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;
|
|
|
|
}
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
NS_IMETHODIMP
|
2000-05-02 02:21:43 +04:00
|
|
|
nsLocalFile::Exists(PRBool *_retval)
|
|
|
|
{
|
2006-12-16 17:55:00 +03:00
|
|
|
// Check we are correctly initialized.
|
|
|
|
CHECK_mWorkingPath();
|
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
NS_ENSURE_ARG(_retval);
|
2005-07-08 20:18:44 +04:00
|
|
|
*_retval = PR_FALSE;
|
2000-06-20 18:06:00 +04:00
|
|
|
|
|
|
|
MakeDirty();
|
2005-07-08 20:18:44 +04:00
|
|
|
nsresult rv = Stat();
|
2003-06-20 01:53:26 +04:00
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
*_retval = NS_SUCCEEDED(rv);
|
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
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
NS_IMETHODIMP
|
2000-05-02 02:21:43 +04:00
|
|
|
nsLocalFile::IsWritable(PRBool *_retval)
|
|
|
|
{
|
2006-12-16 17:55:00 +03:00
|
|
|
// Check we are correctly initialized.
|
|
|
|
CHECK_mWorkingPath();
|
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
NS_ENSURE_ARG(_retval);
|
|
|
|
*_retval = PR_FALSE;
|
2005-07-08 20:18:44 +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))
|
2005-07-08 20:18:44 +04:00
|
|
|
return rv;
|
2000-06-20 18:06:00 +04:00
|
|
|
|
|
|
|
APIRET rc;
|
|
|
|
FILESTATUS3 pathInfo;
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
// Level 1 info
|
|
|
|
rc = DosQueryPathInfo(mWorkingPath.get(), FIL_STANDARD,
|
|
|
|
&pathInfo, sizeof(pathInfo));
|
|
|
|
|
|
|
|
if (rc != NO_ERROR)
|
2000-06-20 18:06:00 +04:00
|
|
|
{
|
|
|
|
rc = ConvertOS2Error(rc);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
// on OS/2, unlike Windows, directories on writable media
|
|
|
|
// can not be assigned a readonly attribute
|
|
|
|
*_retval = !((pathInfo.attrFile & FILE_READONLY) != 0);
|
2000-06-20 18:06:00 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-05-02 02:21:43 +04:00
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
NS_IMETHODIMP
|
2000-05-02 02:21:43 +04:00
|
|
|
nsLocalFile::IsReadable(PRBool *_retval)
|
|
|
|
{
|
2006-12-16 17:55:00 +03:00
|
|
|
// Check we are correctly initialized.
|
|
|
|
CHECK_mWorkingPath();
|
|
|
|
|
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
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
NS_IMETHODIMP
|
2000-05-02 02:21:43 +04:00
|
|
|
nsLocalFile::IsExecutable(PRBool *_retval)
|
|
|
|
{
|
2006-12-16 17:55:00 +03:00
|
|
|
// Check we are correctly initialized.
|
|
|
|
CHECK_mWorkingPath();
|
|
|
|
|
2000-05-02 02:21:43 +04:00
|
|
|
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;
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
// no need to bother if this isn't a file
|
|
|
|
PRBool isFile;
|
|
|
|
rv = IsFile(&isFile);
|
|
|
|
if (NS_FAILED(rv) || !isFile)
|
|
|
|
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
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
// get the filename, including the leading backslash
|
|
|
|
const char* leaf = (const char*) _mbsrchr((const unsigned char*)path.get(), '\\');
|
|
|
|
if (!leaf)
|
|
|
|
return NS_OK;
|
2000-06-20 18:06:00 +04:00
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
// eliminate trailing dots & spaces in a DBCS-aware manner
|
|
|
|
// XXX shouldn't this have been done when the path was set?
|
|
|
|
|
|
|
|
char* pathEnd = WinPrevChar(0, 0, 0, leaf, strchr(leaf, 0));
|
|
|
|
while (pathEnd > leaf)
|
|
|
|
{
|
|
|
|
if (*pathEnd != ' ' && *pathEnd != '.')
|
|
|
|
break;
|
|
|
|
*pathEnd = 0;
|
|
|
|
pathEnd = WinPrevChar(0, 0, 0, leaf, pathEnd);
|
2000-06-20 18:06:00 +04:00
|
|
|
}
|
2005-07-08 20:18:44 +04:00
|
|
|
|
|
|
|
if (pathEnd == leaf)
|
|
|
|
return NS_OK;
|
|
|
|
|
2007-09-17 00:46:35 +04:00
|
|
|
// get the extension, including the dot, max. of 4 chars for comparison
|
|
|
|
// (copy the extension so that the original filename stays untouched)
|
|
|
|
char ext[5];
|
|
|
|
strncpy(ext, (char*) _mbsrchr((const unsigned char*)leaf, '.'), 4);
|
|
|
|
ext[4] = '\0'; // ensure trailing nullbyte
|
2007-10-26 00:49:37 +04:00
|
|
|
|
2007-03-23 02:01:14 +03:00
|
|
|
// upper-case the extension, then see if it claims to be an executable
|
|
|
|
// WinUpper() cannot be used because it crashes with high memory.
|
|
|
|
// strupr() does not take into account non-ASCII characters but this is
|
|
|
|
// irrelevant for the possible extensions below
|
|
|
|
strupr(ext);
|
|
|
|
if (strcmp(ext, ".EXE") == 0 ||
|
|
|
|
strcmp(ext, ".CMD") == 0 ||
|
|
|
|
strcmp(ext, ".COM") == 0 ||
|
|
|
|
strcmp(ext, ".BAT") == 0)
|
2005-07-08 20:18:44 +04:00
|
|
|
*_retval = PR_TRUE;
|
|
|
|
|
2000-05-02 02:21:43 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
NS_IMETHODIMP
|
2000-05-02 02:21:43 +04:00
|
|
|
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;
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
*_retval = (mFileInfo64.type == PR_FILE_DIRECTORY);
|
2000-05-02 02:21:43 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
NS_IMETHODIMP
|
2000-05-02 02:21:43 +04:00
|
|
|
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;
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
*_retval = (mFileInfo64.type == PR_FILE_FILE);
|
2000-06-20 18:06:00 +04:00
|
|
|
return rv;
|
2000-05-02 02:21:43 +04:00
|
|
|
}
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
NS_IMETHODIMP
|
2000-05-02 02:21:43 +04:00
|
|
|
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
|
|
|
|
|
|
|
APIRET rc;
|
|
|
|
FILESTATUS3 pathInfo;
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
// Level 1 info
|
|
|
|
rc = DosQueryPathInfo(mWorkingPath.get(), FIL_STANDARD,
|
|
|
|
&pathInfo, sizeof(pathInfo));
|
|
|
|
|
|
|
|
if (rc != NO_ERROR)
|
2000-06-20 18:06:00 +04:00
|
|
|
{
|
|
|
|
rc = ConvertOS2Error(rc);
|
|
|
|
return rc;
|
|
|
|
}
|
2000-05-02 02:21:43 +04:00
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
*_retval = ((pathInfo.attrFile & FILE_HIDDEN) != 0);
|
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
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
NS_IMETHODIMP
|
2000-05-02 02:21:43 +04:00
|
|
|
nsLocalFile::IsSymlink(PRBool *_retval)
|
|
|
|
{
|
2006-12-16 17:55:00 +03:00
|
|
|
// Check we are correctly initialized.
|
|
|
|
CHECK_mWorkingPath();
|
|
|
|
|
2003-01-02 00:20:37 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
2005-07-08 20:18:44 +04:00
|
|
|
|
2003-01-02 00:20:37 +03:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
NS_IMETHODIMP
|
2000-05-02 02:21:43 +04:00
|
|
|
nsLocalFile::IsSpecial(PRBool *_retval)
|
|
|
|
{
|
2000-06-20 18:06:00 +04:00
|
|
|
NS_ENSURE_ARG(_retval);
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
// when implemented, IsSpecial will be used for WPS objects
|
|
|
|
*_retval = PR_FALSE;
|
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
|
|
|
|
2002-04-27 09:33:09 +04:00
|
|
|
nsCAutoString inFilePath;
|
|
|
|
inFile->GetNativePath(inFilePath);
|
2005-07-08 20:18:44 +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)
|
|
|
|
{
|
2006-12-16 17:55:00 +03:00
|
|
|
// Check we are correctly initialized.
|
|
|
|
CHECK_mWorkingPath();
|
|
|
|
|
2000-05-02 02:21:43 +04:00
|
|
|
*_retval = PR_FALSE;
|
2005-07-08 20:18:44 +04:00
|
|
|
|
2002-04-27 09:33:09 +04:00
|
|
|
nsCAutoString myFilePath;
|
|
|
|
if ( NS_FAILED(GetNativeTarget(myFilePath)))
|
|
|
|
GetNativePath(myFilePath);
|
2005-07-08 20:18:44 +04:00
|
|
|
|
2002-04-27 09:33:09 +04:00
|
|
|
PRInt32 myFilePathLen = myFilePath.Length();
|
2005-07-08 20:18:44 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2005-07-08 20:18:44 +04:00
|
|
|
|
2000-05-02 02:21:43 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-04-27 09:33:09 +04:00
|
|
|
nsLocalFile::GetNativeTarget(nsACString &_retval)
|
2005-07-08 20:18:44 +04:00
|
|
|
{
|
2006-12-16 17:55:00 +03:00
|
|
|
// Check we are correctly initialized.
|
|
|
|
CHECK_mWorkingPath();
|
|
|
|
|
2003-06-20 01:53:26 +04:00
|
|
|
_retval = mWorkingPath;
|
2000-05-02 02:21:43 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
NS_IMETHODIMP
|
2000-07-13 03:31:31 +04:00
|
|
|
nsLocalFile::GetFollowLinks(PRBool *aFollowLinks)
|
|
|
|
{
|
2005-07-08 20:18:44 +04:00
|
|
|
NS_ENSURE_ARG(aFollowLinks);
|
|
|
|
*aFollowLinks = PR_FALSE;
|
2000-07-13 03:31:31 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2005-07-08 20:18:44 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-07-13 03:31:31 +04:00
|
|
|
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
|
|
|
{
|
2005-07-08 20:18:44 +04:00
|
|
|
NS_ENSURE_ARG(entries);
|
2000-06-20 18:06:00 +04:00
|
|
|
nsresult rv;
|
|
|
|
*entries = nsnull;
|
2000-05-02 02:21:43 +04:00
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
if (mWorkingPath.EqualsLiteral("\\\\.")) {
|
|
|
|
nsDriveEnumerator *drives = new nsDriveEnumerator;
|
|
|
|
if (!drives)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(drives);
|
|
|
|
rv = drives->Init();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_RELEASE(drives);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
*entries = drives;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-06-20 18:06:00 +04:00
|
|
|
PRBool isDir;
|
|
|
|
rv = IsDirectory(&isDir);
|
2005-07-08 20:18:44 +04:00
|
|
|
if (NS_FAILED(rv))
|
2000-05-02 02:21:43 +04:00
|
|
|
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);
|
2005-07-08 20:18:44 +04:00
|
|
|
if (NS_FAILED(rv))
|
2000-06-20 18:06:00 +04:00
|
|
|
{
|
2000-05-02 02:21:43 +04:00
|
|
|
NS_RELEASE(dirEnum);
|
|
|
|
return rv;
|
|
|
|
}
|
2005-07-08 20:18:44 +04:00
|
|
|
|
2000-05-02 02:21:43 +04:00
|
|
|
*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
|
|
|
{
|
2005-07-08 20:18:44 +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()
|
|
|
|
{
|
2005-07-08 20:18:44 +04:00
|
|
|
PRBool isDirectory = PR_FALSE;
|
|
|
|
nsCAutoString path;
|
2001-02-01 00:04:04 +03:00
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
IsDirectory(&isDirectory);
|
|
|
|
if (isDirectory)
|
|
|
|
{
|
|
|
|
GetNativePath(path);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIFile> parent;
|
|
|
|
GetParent(getter_AddRefs(parent));
|
|
|
|
if (parent)
|
|
|
|
parent->GetNativePath(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
HOBJECT hobject = WinQueryObject(path.get());
|
|
|
|
WinSetFocus(HWND_DESKTOP, HWND_DESKTOP);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
2005-07-08 20:18:44 +04:00
|
|
|
WinOpenObject(hobject, OPEN_DEFAULT, TRUE);
|
2001-08-22 08:33:17 +04:00
|
|
|
|
|
|
|
// 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
|
|
|
|
2005-07-08 20:18:44 +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;
|
|
|
|
}
|
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// UCS2 interface
|
|
|
|
//-----------------------------------------------------------------------------
|
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())
|
2005-01-04 22:31:31 +03:00
|
|
|
return InitWithNativePath(EmptyCString());
|
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-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())
|
2005-01-04 22:31:31 +03:00
|
|
|
return SetNativeLeafName(EmptyCString());
|
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())
|
2005-01-04 22:31:31 +03:00
|
|
|
return CopyToNative(newParentDir, EmptyCString());
|
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())
|
2005-01-04 22:31:31 +03:00
|
|
|
return CopyToFollowingLinksNative(newParentDir, EmptyCString());
|
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())
|
2005-01-04 22:31:31 +03:00
|
|
|
return MoveToNative(newParentDir, EmptyCString());
|
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-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;
|
|
|
|
}
|
|
|
|
|
2005-11-18 21:54:19 +03:00
|
|
|
// nsIHashable
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::Equals(nsIHashable* aOther, PRBool *aResult)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIFile> otherfile(do_QueryInterface(aOther));
|
|
|
|
if (!otherfile) {
|
|
|
|
*aResult = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Equals(otherfile, aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::GetHashCode(PRUint32 *aResult)
|
|
|
|
{
|
|
|
|
*aResult = nsCRT::HashCode(mWorkingPath.get());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-04-24 07:47:06 +04:00
|
|
|
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
|
|
|
|
2005-07-08 20:18:44 +04:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsLocalFile <static members>
|
|
|
|
//-----------------------------------------------------------------------------
|
2002-04-27 09:33:09 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
nsLocalFile::GlobalInit()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsLocalFile::GlobalShutdown()
|
|
|
|
{
|
|
|
|
}
|
2005-07-08 20:18:44 +04:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|