mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-26 23:23:33 +00:00
Fix OS/2 breakage. We have an nsLocalFile too.
This commit is contained in:
parent
6efcbdc15e
commit
1ed35daf79
@ -28,18 +28,21 @@
|
|||||||
#include "nsMemory.h"
|
#include "nsMemory.h"
|
||||||
|
|
||||||
#include "nsLocalFileOS2.h"
|
#include "nsLocalFileOS2.h"
|
||||||
#include "nsXPIDLString.h"
|
|
||||||
|
|
||||||
#include "nsISimpleEnumerator.h"
|
#include "nsISimpleEnumerator.h"
|
||||||
#include "nsIComponentManager.h"
|
#include "nsIComponentManager.h"
|
||||||
#include "prtypes.h"
|
#include "prtypes.h"
|
||||||
#include "prio.h"
|
#include "prio.h"
|
||||||
|
|
||||||
#include "prproces.h"
|
#include "nsEscape.h"
|
||||||
|
|
||||||
#include <ctype.h> // needed for toupper
|
#include <ctype.h> // needed for toupper
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "nsXPIDLString.h"
|
||||||
|
#include "prproces.h"
|
||||||
|
|
||||||
|
|
||||||
static unsigned char* PR_CALLBACK
|
static unsigned char* PR_CALLBACK
|
||||||
_mbschr( const unsigned char* stringToSearch, int charToSearchFor);
|
_mbschr( const unsigned char* stringToSearch, int charToSearchFor);
|
||||||
extern unsigned char*
|
extern unsigned char*
|
||||||
@ -2114,55 +2117,110 @@ nsLocalFile::GetDirectoryEntries(nsISimpleEnumerator * *entries)
|
|||||||
|
|
||||||
NS_IMETHODIMP nsLocalFile::GetURL(char * *aURL)
|
NS_IMETHODIMP nsLocalFile::GetURL(char * *aURL)
|
||||||
{
|
{
|
||||||
nsresult rv;
|
NS_ENSURE_ARG_POINTER(aURL);
|
||||||
char* ePath = (char*) nsMemory::Clone(mWorkingPath.get(), strlen(mWorkingPath)+1);
|
*aURL = nsnull;
|
||||||
if (ePath == nsnull)
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
#if defined (XP_WIN) || defined(XP_OS2)
|
|
||||||
// Replace \ with / to convert to an url
|
|
||||||
char* s = ePath;
|
|
||||||
while (*s)
|
|
||||||
{
|
|
||||||
// We need to call IsDBCSLeadByte because
|
|
||||||
// Japanese windows can have 0x5C in the sencond byte
|
|
||||||
// of a Japanese character, for example 0x8F 0x5C is
|
|
||||||
// one Japanese character
|
|
||||||
#ifdef XP_OS2
|
|
||||||
if(::isleadbyte(*s) && *(s+1) != nsnull) {
|
|
||||||
#else
|
|
||||||
if(::IsDBCSLeadByte(*s) && *(s+1) != nsnull) {
|
|
||||||
#endif
|
|
||||||
s++;
|
|
||||||
} else
|
|
||||||
if (*s == '\\')
|
|
||||||
*s = '/';
|
|
||||||
s++;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
// Escape the path with the directory mask
|
|
||||||
nsCAutoString tmp(ePath);
|
|
||||||
tmp.ReplaceChar(":", '|');
|
|
||||||
nsCAutoString escPath("file://");
|
|
||||||
escPath += tmp;
|
|
||||||
// rv = nsURLEscape(ePath,nsIIOService::url_Directory + nsIIOService::url_Forced, escPath);
|
|
||||||
// if (NS_SUCCEEDED(rv)) {
|
|
||||||
PRBool dir;
|
|
||||||
rv = IsDirectory(&dir);
|
|
||||||
if (NS_SUCCEEDED(rv) && dir && escPath[escPath.Length() - 1] != '/') {
|
|
||||||
// make sure we have a trailing slash
|
|
||||||
escPath += "/";
|
|
||||||
}
|
|
||||||
*aURL = escPath.ToNewCString();
|
|
||||||
if (*aURL == nsnull)
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
nsresult rv;
|
||||||
|
char* ePath = nsnull;
|
||||||
|
nsCAutoString escPath;
|
||||||
|
|
||||||
|
rv = GetPath(&ePath);
|
||||||
|
if (NS_SUCCEEDED(rv)) {
|
||||||
|
|
||||||
|
// Replace \ with / to convert to an url
|
||||||
|
char* s = ePath;
|
||||||
|
while (*s)
|
||||||
|
{
|
||||||
|
// We need to call IsDBCSLeadByte because
|
||||||
|
// Japanese windows can have 0x5C in the sencond byte
|
||||||
|
// of a Japanese character, for example 0x8F 0x5C is
|
||||||
|
// one Japanese character
|
||||||
|
#ifdef XP_OS2
|
||||||
|
if(::isleadbyte(*s) && *(s+1) != nsnull)
|
||||||
|
#else
|
||||||
|
if(::IsDBCSLeadByte(*s) && *(s+1) != nsnull)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
s++;
|
||||||
|
}
|
||||||
|
else if (*s == '\\') {
|
||||||
|
*s = '/';
|
||||||
|
}
|
||||||
|
s++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Escape the path with the directory mask
|
||||||
|
rv = nsStdEscape(ePath, esc_Directory+esc_Forced, escPath);
|
||||||
|
if (NS_SUCCEEDED(rv)) {
|
||||||
|
escPath.Insert("file:///", 0);
|
||||||
|
|
||||||
|
PRBool dir;
|
||||||
|
rv = IsDirectory(&dir);
|
||||||
|
NS_ASSERTION(NS_SUCCEEDED(rv), "Cannot tell if this is a directory");
|
||||||
|
if (NS_SUCCEEDED(rv) && dir && escPath[escPath.Length() - 1] != '/') {
|
||||||
|
// make sure we have a trailing slash
|
||||||
|
escPath += "/";
|
||||||
|
}
|
||||||
|
*aURL = nsCRT::strdup((const char *)escPath);
|
||||||
|
rv = *aURL ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CRTFREEIF(ePath);
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsLocalFile::SetURL(const char * aURL)
|
NS_IMETHODIMP nsLocalFile::SetURL(const char * aURL)
|
||||||
{
|
{
|
||||||
return NS_ERROR_NOT_IMPLEMENTED;
|
NS_ENSURE_ARG(aURL);
|
||||||
|
nsresult rv;
|
||||||
|
|
||||||
|
nsXPIDLCString host, directory, fileBaseName, fileExtension;
|
||||||
|
|
||||||
|
rv = ParseURL(aURL, getter_Copies(host), getter_Copies(directory),
|
||||||
|
getter_Copies(fileBaseName), getter_Copies(fileExtension));
|
||||||
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
|
nsCAutoString path;
|
||||||
|
nsCAutoString component;
|
||||||
|
|
||||||
|
if (host)
|
||||||
|
{
|
||||||
|
// We can end up with a host when given: file://C|/ instead of file:///
|
||||||
|
if (strlen((const char *)host) == 2 && ((const char *)host)[1] == '|')
|
||||||
|
{
|
||||||
|
path += host;
|
||||||
|
path.SetCharAt(':', 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (directory)
|
||||||
|
{
|
||||||
|
nsStdEscape(directory, esc_Directory, component);
|
||||||
|
if (!host && component.Length() > 2 && component.CharAt(2) == '|')
|
||||||
|
component.SetCharAt(':', 2);
|
||||||
|
component.ReplaceChar('/', '\\');
|
||||||
|
path += component;
|
||||||
|
}
|
||||||
|
if (fileBaseName)
|
||||||
|
{
|
||||||
|
nsStdEscape(fileBaseName, esc_FileBaseName, component);
|
||||||
|
path += component;
|
||||||
|
}
|
||||||
|
if (fileExtension)
|
||||||
|
{
|
||||||
|
nsStdEscape(fileExtension, esc_FileExtension, component);
|
||||||
|
path += '.';
|
||||||
|
path += component;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsUnescape((char*)path.get());
|
||||||
|
|
||||||
|
// remove leading '\'
|
||||||
|
if (path.CharAt(0) == '\\')
|
||||||
|
path.Cut(0, 1);
|
||||||
|
|
||||||
|
rv = InitWithPath(path);
|
||||||
|
|
||||||
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
@ -139,6 +139,9 @@ private:
|
|||||||
nsresult CopySingleFile(nsIFile *source, nsIFile* dest, const char * newName, PRBool followSymlinks, PRBool move);
|
nsresult CopySingleFile(nsIFile *source, nsIFile* dest, const char * newName, PRBool followSymlinks, PRBool move);
|
||||||
|
|
||||||
nsresult SetModDate(PRInt64 aLastModificationDate, PRBool resolveTerminal);
|
nsresult SetModDate(PRInt64 aLastModificationDate, PRBool resolveTerminal);
|
||||||
|
|
||||||
|
static nsresult ParseURL(const char* inURL, char **outHost, char **outDirectory,
|
||||||
|
char **outFileBaseName, char **outFileExtension);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user