Make the Migrator build on OS X

This commit is contained in:
ben%bengoodger.com 2004-02-17 03:59:06 +00:00
Родитель 0827082950
Коммит f434315a8b
12 изменённых файлов: 430 добавлений и 62 удалений

Просмотреть файл

@ -60,6 +60,7 @@ REQUIRES = \
unicharutil \ unicharutil \
windowwatcher \ windowwatcher \
dom \ dom \
docshell \
cookie \ cookie \
$(NULL) $(NULL)
@ -83,6 +84,7 @@ CPPSRCS += nsSafariProfileMigrator.cpp \
nsMacIEProfileMigrator.cpp \ nsMacIEProfileMigrator.cpp \
nsOmniWebProfileMigrator.cpp \ nsOmniWebProfileMigrator.cpp \
nsCaminoProfileMigrator.cpp \ nsCaminoProfileMigrator.cpp \
nsICabProfileMigrator.cpp \
$(NULL) $(NULL)
endif endif

Просмотреть файл

@ -0,0 +1,95 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is The Browser Profile Migrator.
*
* The Initial Developer of the Original Code is Ben Goodger.
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ben Goodger <ben@bengoodger.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either 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 ***** */
#include "nsBrowserProfileMigratorUtils.h"
#include "nsCaminoProfileMigrator.h"
#include "nsIObserverService.h"
#include "nsIProfile.h"
#include "nsIProfileInternal.h"
#include "nsIServiceManager.h"
#include "nsISupportsArray.h"
#include "nsISupportsPrimitives.h"
///////////////////////////////////////////////////////////////////////////////
// nsCaminoProfileMigrator
NS_IMPL_ISUPPORTS1(nsCaminoProfileMigrator, nsIBrowserProfileMigrator)
static nsIObserverService* sObserverService = nsnull;
nsCaminoProfileMigrator::nsCaminoProfileMigrator()
{
CallGetService("@mozilla.org/observer-service;1", &sObserverService);
}
nsCaminoProfileMigrator::~nsCaminoProfileMigrator()
{
NS_IF_RELEASE(sObserverService);
}
///////////////////////////////////////////////////////////////////////////////
// nsIBrowserProfileMigrator
NS_IMETHODIMP
nsCaminoProfileMigrator::Migrate(PRUint32 aItems, PRBool aReplace, const PRUnichar* aProfile)
{
nsresult rv = NS_OK;
NOTIFY_OBSERVERS(MIGRATION_STARTED, nsnull);
NOTIFY_OBSERVERS(MIGRATION_ENDED, nsnull);
return rv;
}
NS_IMETHODIMP
nsCaminoProfileMigrator::GetSourceHasMultipleProfiles(PRBool* aResult)
{
*aResult = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP
nsCaminoProfileMigrator::GetSourceProfiles(nsISupportsArray** aResult)
{
*aResult = nsnull;
return NS_OK;
}
///////////////////////////////////////////////////////////////////////////////
// nsCaminoProfileMigrator

Просмотреть файл

@ -0,0 +1,59 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is The Browser Profile Migrator.
*
* The Initial Developer of the Original Code is Ben Goodger.
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ben Goodger <ben@bengoodger.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either 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 ***** */
#ifndef caminoprofilemigrator___h___
#define caminoprofilemigrator___h___
#include "nsIBrowserProfileMigrator.h"
#include "nsISupportsArray.h"
#include "nsString.h"
class nsCaminoProfileMigrator : public nsIBrowserProfileMigrator
{
public:
NS_DECL_NSIBROWSERPROFILEMIGRATOR
NS_DECL_ISUPPORTS
nsCaminoProfileMigrator();
virtual ~nsCaminoProfileMigrator();
protected:
private:
};
#endif

Просмотреть файл

@ -58,11 +58,6 @@
#include "nsReadableUtils.h" #include "nsReadableUtils.h"
#include "prprf.h" #include "prprf.h"
#if defined(XP_MAC) || defined(XP_MACOSX)
#define NEED_TO_FIX_4X_COOKIES 1
#define SECONDS_BETWEEN_1900_AND_1970 2208988800UL
#endif /* XP_MAC */
#define PREF_FILE_HEADER_STRING "# Mozilla User Preferences " #define PREF_FILE_HEADER_STRING "# Mozilla User Preferences "
#if defined(XP_UNIX) && !defined(XP_MACOSX) #if defined(XP_UNIX) && !defined(XP_MACOSX)
@ -333,8 +328,7 @@ nsDogbertProfileMigrator::CopyCookies(PRBool aReplace)
return rv; return rv;
} }
#ifdef NEED_TO_FIX_4X_COOKIES #if NEED_TO_FIX_4X_COOKIES
// XXXben need to rewrite this to downconvert buffers properly, right now this is pretty broken.
nsresult nsresult
nsDogbertProfileMigrator::FixDogbertCookies() nsDogbertProfileMigrator::FixDogbertCookies()
{ {
@ -362,6 +356,9 @@ nsDogbertProfileMigrator::FixDogbertCookies()
nsresult rv = lineInputStream->ReadLine(buffer, &moreData); nsresult rv = lineInputStream->ReadLine(buffer, &moreData);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
if (!moreData)
break;
// skip line if it is a comment or null line // skip line if it is a comment or null line
if (buffer.IsEmpty() || buffer.CharAt(0) == '#' || if (buffer.IsEmpty() || buffer.CharAt(0) == '#' ||
buffer.CharAt(0) == nsCRT::CR || buffer.CharAt(0) == nsCRT::LF) { buffer.CharAt(0) == nsCRT::CR || buffer.CharAt(0) == nsCRT::LF) {
@ -405,9 +402,13 @@ nsDogbertProfileMigrator::FixDogbertCookies()
outBuffer.Append(PRUnichar('\t')); outBuffer.Append(PRUnichar('\t'));
outBuffer.Append(suffix); outBuffer.Append(suffix);
fileOutputStream->Write((const char*)outBuffer.get(), outBuffer.Length(), &written); nsCAutoString convertedBuffer;
convertedBuffer.Assign(NS_ConvertUCS2toUTF8(outBuffer));
fileOutputStream->Write(convertedBuffer.get(), convertedBuffer.Length(), &written);
} }
while (moreData); while (1);
return NS_OK;
} }
#endif // NEED_TO_FIX_4X_COOKIES #endif // NEED_TO_FIX_4X_COOKIES
@ -492,7 +493,7 @@ nsDogbertProfileMigrator::MigrateDogbertBookmarks()
targetBuffer.Append("\r\n"); targetBuffer.Append("\r\n");
outputStream->Write(targetBuffer.get(), targetBuffer.Length(), &bytesWritten); outputStream->Write(targetBuffer.get(), targetBuffer.Length(), &bytesWritten);
} }
while (moreData); while (1);
return NS_OK; return NS_OK;
} }

Просмотреть файл

@ -44,6 +44,11 @@
#include "nsNetscapeProfileMigratorBase.h" #include "nsNetscapeProfileMigratorBase.h"
#include "nsString.h" #include "nsString.h"
#if defined(XP_MAC) || defined(XP_MACOSX)
#define NEED_TO_FIX_4X_COOKIES 1
#define SECONDS_BETWEEN_1900_AND_1970 2208988800UL
#endif /* XP_MAC */
class nsIFile; class nsIFile;
class nsDogbertProfileMigrator : public nsNetscapeProfileMigratorBase, class nsDogbertProfileMigrator : public nsNetscapeProfileMigratorBase,

Просмотреть файл

@ -0,0 +1,95 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is The Browser Profile Migrator.
*
* The Initial Developer of the Original Code is Ben Goodger.
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ben Goodger <ben@bengoodger.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either 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 ***** */
#include "nsBrowserProfileMigratorUtils.h"
#include "nsICabProfileMigrator.h"
#include "nsIObserverService.h"
#include "nsIProfile.h"
#include "nsIProfileInternal.h"
#include "nsIServiceManager.h"
#include "nsISupportsArray.h"
#include "nsISupportsPrimitives.h"
///////////////////////////////////////////////////////////////////////////////
// nsICabProfileMigrator
NS_IMPL_ISUPPORTS1(nsICabProfileMigrator, nsIBrowserProfileMigrator)
static nsIObserverService* sObserverService = nsnull;
nsICabProfileMigrator::nsICabProfileMigrator()
{
CallGetService("@mozilla.org/observer-service;1", &sObserverService);
}
nsICabProfileMigrator::~nsICabProfileMigrator()
{
NS_IF_RELEASE(sObserverService);
}
///////////////////////////////////////////////////////////////////////////////
// nsIBrowserProfileMigrator
NS_IMETHODIMP
nsICabProfileMigrator::Migrate(PRUint32 aItems, PRBool aReplace, const PRUnichar* aProfile)
{
nsresult rv = NS_OK;
NOTIFY_OBSERVERS(MIGRATION_STARTED, nsnull);
NOTIFY_OBSERVERS(MIGRATION_ENDED, nsnull);
return rv;
}
NS_IMETHODIMP
nsICabProfileMigrator::GetSourceHasMultipleProfiles(PRBool* aResult)
{
*aResult = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP
nsICabProfileMigrator::GetSourceProfiles(nsISupportsArray** aResult)
{
*aResult = nsnull;
return NS_OK;
}
///////////////////////////////////////////////////////////////////////////////
// nsICabProfileMigrator

Просмотреть файл

@ -0,0 +1,59 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is The Browser Profile Migrator.
*
* The Initial Developer of the Original Code is Ben Goodger.
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ben Goodger <ben@bengoodger.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either 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 ***** */
#ifndef icabprofilemigrator___h___
#define icabprofilemigrator___h___
#include "nsIBrowserProfileMigrator.h"
#include "nsISupportsArray.h"
#include "nsString.h"
class nsICabProfileMigrator : public nsIBrowserProfileMigrator
{
public:
NS_DECL_NSIBROWSERPROFILEMIGRATOR
NS_DECL_ISUPPORTS
nsICabProfileMigrator();
virtual ~nsICabProfileMigrator();
protected:
private:
};
#endif

Просмотреть файл

@ -1824,46 +1824,3 @@ nsIEProfileMigrator::CopyProxyPreferences(nsIPrefBranch* aPrefs)
return NS_OK; return NS_OK;
} }
void ParseOverrideServers(char* aServers, nsIPrefBranch* aBranch)
{
// First check to see if the value is "<local>", if so, set the field to
// "localhost,127.0.0.1"
nsCAutoString override; override = (char*)aServers;
if (override.Equals("<local>")) {
aBranch->SetCharPref("network.proxy.no_proxies_on", "localhost,127.0.0.1");
}
else {
// If it's not, then replace every ";" character with ","
PRInt32 offset = 0, temp = 0;
while (offset != -1) {
offset = override.FindChar(';', offset);
const nsACString& host = Substring(override, temp, offset < 0 ? override.Length() - temp : offset - temp);
if (host.Equals("<local>"))
override.Replace(temp, 7, NS_LITERAL_CSTRING("localhost,127.0.0.1"));
temp = offset + 1;
if (offset != -1)
override.Replace(offset, 1, NS_LITERAL_CSTRING(","));
}
aBranch->SetCharPref("network.proxy.no_proxies_on", override.get());
}
}
void SetProxyPref(const nsACString& aHostPort, const char* aPref,
const char* aPortPref, nsIPrefBranch* aPrefs)
{
nsCAutoString hostPort(aHostPort);
PRInt32 portDelimOffset = hostPort.RFindChar(':');
if (portDelimOffset) {
nsCAutoString host(Substring(hostPort, 0, portDelimOffset));
nsCAutoString port(Substring(hostPort, portDelimOffset + 1, hostPort.Length() - portDelimOffset + 1));
aPrefs->SetCharPref(aPref, host.get());
PRInt32 stringErr;
PRInt32 portValue = port.ToInteger(&stringErr);
aPrefs->SetIntPref(aPortPref, portValue);
}
else {
aPrefs->SetCharPref(aPref, hostPort.get());
}
}

Просмотреть файл

@ -26,7 +26,7 @@
#define _NS_INIPARSER_H_ #define _NS_INIPARSER_H_
#include <stdio.h> #include <stdio.h>
#include <malloc.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <locale.h> #include <locale.h>

Просмотреть файл

@ -69,6 +69,19 @@
static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID); static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
#define MIGRATION_BUNDLE "chrome://browser/locale/migration/migration.properties" #define MIGRATION_BUNDLE "chrome://browser/locale/migration/migration.properties"
#ifdef XP_WIN
#define OPERA_PREFERENCES_FOLDER_NAME NS_LITERAL_STRING("Opera")
#define OPERA_PREFERENCES_FILE_NAME NS_LITERAL_STRING("opera6.ini")
#define OPERA_HISTORY_FILE_NAME NS_LITERAL_STRING("global.dat")
#define OPERA_BOOKMARKS_FILE_NAME NS_LITERAL_STRING("opera6.adr")
#elif defined(XP_MACOSX)
#define OPERA_PREFERENCES_FOLDER_NAME NS_LITERAL_STRING("Opera 6 Preferences")
#define OPERA_PREFERENCES_FILE_NAME NS_LITERAL_STRING("Opera 6 Preferences")
#define OPERA_HISTORY_FILE_NAME NS_LITERAL_STRING("Opera Global History")
#define OPERA_BOOKMARKS_FILE_NAME NS_LITERAL_STRING("Bookmarks")
#endif
#define OPERA_COOKIES_FILE_NAME NS_LITERAL_STRING("cookies4.dat")
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// nsBrowserProfileMigrator // nsBrowserProfileMigrator
@ -112,12 +125,14 @@ nsOperaProfileMigrator::GetSourceHasMultipleProfiles(PRBool* aResult)
nsCOMPtr<nsISupportsArray> profiles; nsCOMPtr<nsISupportsArray> profiles;
GetSourceProfiles(getter_AddRefs(profiles)); GetSourceProfiles(getter_AddRefs(profiles));
#ifndef XP_MACOSX
if (profiles) { if (profiles) {
PRUint32 count; PRUint32 count;
profiles->Count(&count); profiles->Count(&count);
*aResult = count > 1; *aResult = count > 1;
} }
else else
#endif
*aResult = PR_FALSE; *aResult = PR_FALSE;
return NS_OK; return NS_OK;
@ -132,10 +147,11 @@ nsOperaProfileMigrator::GetSourceProfiles(nsISupportsArray** aResult)
nsCOMPtr<nsIProperties> fileLocator(do_GetService("@mozilla.org/file/directory_service;1")); nsCOMPtr<nsIProperties> fileLocator(do_GetService("@mozilla.org/file/directory_service;1"));
nsCOMPtr<nsILocalFile> file; nsCOMPtr<nsILocalFile> file;
#ifdef XP_WIN
fileLocator->Get(NS_WIN_APPDATA_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(file)); fileLocator->Get(NS_WIN_APPDATA_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(file));
// Opera profile lives under %APP_DATA%\Opera\<operaver>\profile // Opera profile lives under %APP_DATA%\Opera\<operaver>\profile
file->Append(NS_LITERAL_STRING("Opera")); file->Append(NS_LITERAL_STRING(OPERA_PREFERENCES_FOLDER_NAME));
nsCOMPtr<nsISimpleEnumerator> e; nsCOMPtr<nsISimpleEnumerator> e;
file->GetDirectoryEntries(getter_AddRefs(e)); file->GetDirectoryEntries(getter_AddRefs(e));
@ -158,6 +174,21 @@ nsOperaProfileMigrator::GetSourceProfiles(nsISupportsArray** aResult)
e->HasMoreElements(&hasMore); e->HasMoreElements(&hasMore);
} }
#elif defined (XP_MACOSX)
fileLocator->Get(NS_MAC_USER_LIB_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(file));
file->Append(NS_LITERAL_STRING("Preferences"));
file->Append(OPERA_PREFERENCES_FOLDER_NAME);
PRBool exists;
file->Exists(&exists);
if (exists) {
nsCOMPtr<nsISupportsString> string(do_CreateInstance("@mozilla.org/supports-string;1"));
string->SetData(OPERA_PREFERENCES_FOLDER_NAME);
mProfiles->AppendElement(string);
}
#endif
} }
*aResult = mProfiles; *aResult = mProfiles;
@ -252,7 +283,7 @@ nsOperaProfileMigrator::CopyPreferences(PRBool aReplace)
{ {
nsCOMPtr<nsIFile> operaPrefs; nsCOMPtr<nsIFile> operaPrefs;
mOperaProfile->Clone(getter_AddRefs(operaPrefs)); mOperaProfile->Clone(getter_AddRefs(operaPrefs));
operaPrefs->Append(NS_LITERAL_STRING("opera6.ini")); operaPrefs->Append(OPERA_PREFERENCES_FILE_NAME);
nsCAutoString path; nsCAutoString path;
operaPrefs->GetNativePath(path); operaPrefs->GetNativePath(path);
@ -307,6 +338,8 @@ nsOperaProfileMigrator::CopyPreferences(PRBool aReplace)
valStr = val; valStr = val;
transform->boolValue = valStr.ToInteger(&strerr) != 0; transform->boolValue = valStr.ToInteger(&strerr) != 0;
break; break;
default:
break;
} }
transform->prefHasValue = PR_TRUE; transform->prefHasValue = PR_TRUE;
transform->prefSetterFunc(transform, branch); transform->prefSetterFunc(transform, branch);
@ -456,7 +489,7 @@ nsOperaProfileMigrator::CopyCookies(PRBool aReplace)
mOperaProfile->Clone(getter_AddRefs(temp)); mOperaProfile->Clone(getter_AddRefs(temp));
nsCOMPtr<nsILocalFile> historyFile(do_QueryInterface(temp)); nsCOMPtr<nsILocalFile> historyFile(do_QueryInterface(temp));
historyFile->Append(NS_LITERAL_STRING("cookies4.dat")); historyFile->Append(OPERA_COOKIES_FILE_NAME);
nsCOMPtr<nsIInputStream> fileStream; nsCOMPtr<nsIInputStream> fileStream;
NS_NewLocalFileInputStream(getter_AddRefs(fileStream), historyFile); NS_NewLocalFileInputStream(getter_AddRefs(fileStream), historyFile);
@ -757,8 +790,7 @@ nsOperaProfileMigrator::CopyHistory(PRBool aReplace)
nsCOMPtr<nsIFile> temp; nsCOMPtr<nsIFile> temp;
mOperaProfile->Clone(getter_AddRefs(temp)); mOperaProfile->Clone(getter_AddRefs(temp));
nsCOMPtr<nsILocalFile> historyFile(do_QueryInterface(temp)); nsCOMPtr<nsILocalFile> historyFile(do_QueryInterface(temp));
historyFile->Append(OPERA_HISTORY_FILE_NAME);
historyFile->Append(NS_LITERAL_STRING("global.dat"));
nsCOMPtr<nsIInputStream> fileStream; nsCOMPtr<nsIInputStream> fileStream;
NS_NewLocalFileInputStream(getter_AddRefs(fileStream), historyFile); NS_NewLocalFileInputStream(getter_AddRefs(fileStream), historyFile);
@ -815,7 +847,7 @@ nsOperaProfileMigrator::CopyBookmarks(PRBool aReplace)
// Find Opera Bookmarks // Find Opera Bookmarks
nsCOMPtr<nsIFile> operaBookmarks; nsCOMPtr<nsIFile> operaBookmarks;
mOperaProfile->Clone(getter_AddRefs(operaBookmarks)); mOperaProfile->Clone(getter_AddRefs(operaBookmarks));
operaBookmarks->Append(NS_LITERAL_STRING("opera6.adr")); operaBookmarks->Append(OPERA_BOOKMARKS_FILE_NAME);
nsCOMPtr<nsIInputStream> fileInputStream; nsCOMPtr<nsIInputStream> fileInputStream;
NS_NewLocalFileInputStream(getter_AddRefs(fileInputStream), operaBookmarks); NS_NewLocalFileInputStream(getter_AddRefs(fileInputStream), operaBookmarks);
@ -844,7 +876,9 @@ nsOperaProfileMigrator::CopyBookmarks(PRBool aReplace)
else else
parentFolder = root; parentFolder = root;
#ifdef XP_WIN
CopySmartKeywords(bms, bundle, parentFolder); CopySmartKeywords(bms, bundle, parentFolder);
#endif
nsCOMPtr<nsIRDFResource> toolbar; nsCOMPtr<nsIRDFResource> toolbar;
bms->GetBookmarksToolbarFolder(getter_AddRefs(toolbar)); bms->GetBookmarksToolbarFolder(getter_AddRefs(toolbar));
@ -855,6 +889,7 @@ nsOperaProfileMigrator::CopyBookmarks(PRBool aReplace)
return ParseBookmarksFolder(lineInputStream, parentFolder, toolbar, bms); return ParseBookmarksFolder(lineInputStream, parentFolder, toolbar, bms);
} }
#ifdef XP_WIN
nsresult nsresult
nsOperaProfileMigrator::CopySmartKeywords(nsIBookmarksService* aBMS, nsOperaProfileMigrator::CopySmartKeywords(nsIBookmarksService* aBMS,
nsIStringBundle* aBundle, nsIStringBundle* aBundle,
@ -958,6 +993,7 @@ nsOperaProfileMigrator::CopySmartKeywords(nsIBookmarksService* aBMS,
return rv; return rv;
} }
#endif
void void
nsOperaProfileMigrator::ClearToolbarFolder(nsIBookmarksService* aBookmarksService, nsIRDFResource* aToolbarFolder) nsOperaProfileMigrator::ClearToolbarFolder(nsIBookmarksService* aBookmarksService, nsIRDFResource* aToolbarFolder)
@ -1133,14 +1169,64 @@ nsOperaProfileMigrator::GetOperaProfile(const PRUnichar* aProfile, nsILocalFile*
{ {
nsCOMPtr<nsIProperties> fileLocator(do_GetService("@mozilla.org/file/directory_service;1")); nsCOMPtr<nsIProperties> fileLocator(do_GetService("@mozilla.org/file/directory_service;1"));
nsCOMPtr<nsILocalFile> file; nsCOMPtr<nsILocalFile> file;
#ifdef XP_WIN
fileLocator->Get(NS_WIN_APPDATA_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(file)); fileLocator->Get(NS_WIN_APPDATA_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(file));
// Opera profile lives under %APP_DATA%\Opera\<operaver>\profile // Opera profile lives under %APP_DATA%\Opera\<operaver>\profile
file->Append(NS_LITERAL_STRING("Opera")); file->Append(OPERA_PREFERENCES_FOLDER_NAME);
file->Append(nsDependentString(aProfile)); file->Append(nsDependentString(aProfile));
file->Append(NS_LITERAL_STRING("profile")); file->Append(NS_LITERAL_STRING("profile"));
#elif defined (XP_MACOSX)
fileLocator->Get(NS_MAC_USER_LIB_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(file));
file->Append(NS_LITERAL_STRING("Preferences"));
file->Append(OPERA_PREFERENCES_FOLDER_NAME);
#endif
*aFile = file; *aFile = file;
NS_ADDREF(*aFile); NS_ADDREF(*aFile);
} }
void SetProxyPref(const nsACString& aHostPort, const char* aPref,
const char* aPortPref, nsIPrefBranch* aPrefs)
{
nsCAutoString hostPort(aHostPort);
PRInt32 portDelimOffset = hostPort.RFindChar(':');
if (portDelimOffset) {
nsCAutoString host(Substring(hostPort, 0, portDelimOffset));
nsCAutoString port(Substring(hostPort, portDelimOffset + 1, hostPort.Length() - portDelimOffset + 1));
aPrefs->SetCharPref(aPref, host.get());
PRInt32 stringErr;
PRInt32 portValue = port.ToInteger(&stringErr);
aPrefs->SetIntPref(aPortPref, portValue);
}
else {
aPrefs->SetCharPref(aPref, hostPort.get());
}
}
void ParseOverrideServers(char* aServers, nsIPrefBranch* aBranch)
{
// First check to see if the value is "<local>", if so, set the field to
// "localhost,127.0.0.1"
nsCAutoString override; override = (char*)aServers;
if (override.Equals("<local>")) {
aBranch->SetCharPref("network.proxy.no_proxies_on", "localhost,127.0.0.1");
}
else {
// If it's not, then replace every ";" character with ","
PRInt32 offset = 0, temp = 0;
while (offset != -1) {
offset = override.FindChar(';', offset);
const nsACString& host = Substring(override, temp, offset < 0 ? override.Length() - temp : offset - temp);
if (host.Equals("<local>"))
override.Replace(temp, 7, NS_LITERAL_CSTRING("localhost,127.0.0.1"));
temp = offset + 1;
if (offset != -1)
override.Replace(offset, 1, NS_LITERAL_CSTRING(","));
}
aBranch->SetCharPref("network.proxy.no_proxies_on", override.get());
}
}

Просмотреть файл

@ -106,9 +106,11 @@ protected:
nsIRDFResource* aFolder, nsIRDFResource* aFolder,
nsIRDFResource* aToolbar, nsIRDFResource* aToolbar,
nsIBookmarksService* aBMS); nsIBookmarksService* aBMS);
#ifdef XP_WIN
nsresult CopySmartKeywords(nsIBookmarksService* aBMS, nsresult CopySmartKeywords(nsIBookmarksService* aBMS,
nsIStringBundle* aBundle, nsIStringBundle* aBundle,
nsIRDFResource* aParentFolder); nsIRDFResource* aParentFolder);
#endif
void GetOperaProfile(const PRUnichar* aProfile, nsILocalFile** aFile); void GetOperaProfile(const PRUnichar* aProfile, nsILocalFile** aFile);

Просмотреть файл

@ -184,10 +184,17 @@ nsSeamonkeyProfileMigrator::GetProfileDataFromSeamonkeyRegistry(nsISupportsArray
// Find the Seamonkey Registry // Find the Seamonkey Registry
nsCOMPtr<nsIProperties> fileLocator(do_GetService("@mozilla.org/file/directory_service;1")); nsCOMPtr<nsIProperties> fileLocator(do_GetService("@mozilla.org/file/directory_service;1"));
nsCOMPtr<nsILocalFile> seamonkeyRegistry; nsCOMPtr<nsILocalFile> seamonkeyRegistry;
#ifdef XP_WIN
fileLocator->Get(NS_WIN_APPDATA_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(seamonkeyRegistry)); fileLocator->Get(NS_WIN_APPDATA_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(seamonkeyRegistry));
seamonkeyRegistry->Append(NS_LITERAL_STRING("Mozilla")); seamonkeyRegistry->Append(NS_LITERAL_STRING("Mozilla"));
seamonkeyRegistry->Append(NS_LITERAL_STRING("registry.dat")); seamonkeyRegistry->Append(NS_LITERAL_STRING("registry.dat"));
#elif defined(XP_MACOSX)
fileLocator->Get(NS_MAC_USER_LIB_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(seamonkeyRegistry));
seamonkeyRegistry->Append(NS_LITERAL_STRING("Mozilla"));
seamonkeyRegistry->Append(NS_LITERAL_STRING("Application Registry"));
#endif
// Open It // Open It
nsCOMPtr<nsIRegistry> reg(do_CreateInstance("@mozilla.org/registry;1")); nsCOMPtr<nsIRegistry> reg(do_CreateInstance("@mozilla.org/registry;1"));