Tweak existing data directory detection
Fixes some issues after f2163b3433
This commit is contained in:
parent
71524d9087
commit
bc3386ff9d
1 changed files with 34 additions and 33 deletions
|
@ -1080,46 +1080,47 @@ Components.utils.import("resource://gre/modules/osfile.jsm");
|
||||||
if(defProfile) {
|
if(defProfile) {
|
||||||
// get Zotero directory
|
// get Zotero directory
|
||||||
let profileDir = defProfile[0].path;
|
let profileDir = defProfile[0].path;
|
||||||
let zoteroDir = OS.Path.join(profileDir, ZOTERO_CONFIG.ID);
|
Zotero.debug("Found default profile at " + profileDir);
|
||||||
|
|
||||||
// if Zotero directory exists in default profile for alternative app, use it
|
// copy prefs
|
||||||
if (Zotero.File.pathToFile(zoteroDir).exists()) {
|
let prefsFile = OS.Path.join(profileDir, "prefs.js");
|
||||||
let multipleProfiles = defProfile[1];
|
if (Zotero.File.pathToFile(prefsFile).exists()) {
|
||||||
|
// build sandbox
|
||||||
|
var sandbox = new Components.utils.Sandbox("http://www.example.com/");
|
||||||
|
Components.utils.evalInSandbox(
|
||||||
|
"var prefs = {};"+
|
||||||
|
"function user_pref(key, val) {"+
|
||||||
|
"prefs[key] = val;"+
|
||||||
|
"}"
|
||||||
|
, sandbox);
|
||||||
|
|
||||||
// copy prefs
|
// remove comments
|
||||||
let prefsFile = OS.Path.join(profileDir, "prefs.js");
|
var prefsJs = Zotero.File.getContents(prefsFile);
|
||||||
if (Zotero.File.pathToFile(prefsFile).exists()) {
|
prefsJs = prefsJs.replace(/^#[^\r\n]*$/mg, "");
|
||||||
// build sandbox
|
|
||||||
var sandbox = new Components.utils.Sandbox("http://www.example.com/");
|
// evaluate
|
||||||
Components.utils.evalInSandbox(
|
Components.utils.evalInSandbox(prefsJs, sandbox);
|
||||||
"var prefs = {};"+
|
var prefs = sandbox.prefs;
|
||||||
"function user_pref(key, val) {"+
|
for(var key in prefs) {
|
||||||
"prefs[key] = val;"+
|
if(key.substr(0, ZOTERO_CONFIG.PREF_BRANCH.length) === ZOTERO_CONFIG.PREF_BRANCH
|
||||||
"}"
|
&& key !== "extensions.zotero.firstRun2") {
|
||||||
, sandbox);
|
Zotero.Prefs.set(key.substr(ZOTERO_CONFIG.PREF_BRANCH.length), prefs[key]);
|
||||||
|
|
||||||
// remove comments
|
|
||||||
var prefsJs = Zotero.File.getContents(prefsFile);
|
|
||||||
prefsJs = prefsJs.replace(/^#[^\r\n]*$/mg, "");
|
|
||||||
|
|
||||||
// evaluate
|
|
||||||
Components.utils.evalInSandbox(prefsJs, sandbox);
|
|
||||||
var prefs = sandbox.prefs;
|
|
||||||
for(var key in prefs) {
|
|
||||||
if(key.substr(0, ZOTERO_CONFIG.PREF_BRANCH.length) === ZOTERO_CONFIG.PREF_BRANCH
|
|
||||||
&& key !== "extensions.zotero.firstRun2") {
|
|
||||||
Zotero.Prefs.set(key.substr(ZOTERO_CONFIG.PREF_BRANCH.length), prefs[key]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// also set data dir if no custom data dir is now defined
|
// If data directory setting was transferred, use that
|
||||||
if(!Zotero.Prefs.get("useDataDir")) {
|
if (Zotero.Prefs.get('useDataDir')) {
|
||||||
this.setDataDirectory(zoteroDir);
|
return this.getZoteroDirectory();
|
||||||
}
|
}
|
||||||
|
|
||||||
file = Zotero.File.pathToFile(zoteroDir);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If a custom data directory isn't now defined and there's a data directory in the
|
||||||
|
// default profile for the alternative app, use that
|
||||||
|
let zoteroDir = OS.Path.join(profileDir, ZOTERO_CONFIG.ID);
|
||||||
|
if (!Zotero.Prefs.get("useDataDir") && Zotero.File.pathToFile(profileDir).exists()) {
|
||||||
|
this.setDataDirectory(zoteroDir);
|
||||||
|
}
|
||||||
|
file = Zotero.File.pathToFile(zoteroDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
Zotero.File.createDirectoryIfMissing(file);
|
Zotero.File.createDirectoryIfMissing(file);
|
||||||
|
|
Loading…
Reference in a new issue