diff --git a/chrome/content/zotero/preferences/preferences_advanced.js b/chrome/content/zotero/preferences/preferences_advanced.js
index 71d09c17d..0a246bc95 100644
--- a/chrome/content/zotero/preferences/preferences_advanced.js
+++ b/chrome/content/zotero/preferences/preferences_advanced.js
@@ -298,6 +298,12 @@ Zotero_Preferences.Advanced = {
var currentDir = Zotero.DataDirectory.dir;
var defaultDataDir = Zotero.DataDirectory.defaultDir;
+ if (Zotero.forceDataDir) {
+ document.getElementById('command-line-data-dir-path').textContent = currentDir;
+ document.getElementById('command-line-data-dir').hidden = false;
+ document.getElementById('data-dir').hidden = true;
+ }
+
// Change "Use profile directory" label to home directory location unless using profile dir
if (useDataDir || currentDir == defaultDataDir) {
document.getElementById('default-data-dir').setAttribute(
diff --git a/chrome/content/zotero/preferences/preferences_advanced.xul b/chrome/content/zotero/preferences/preferences_advanced.xul
index 3f014e517..e77706daa 100644
--- a/chrome/content/zotero/preferences/preferences_advanced.xul
+++ b/chrome/content/zotero/preferences/preferences_advanced.xul
@@ -184,6 +184,11 @@
+
+
+
+
+
diff --git a/chrome/content/zotero/xpcom/dataDirectory.js b/chrome/content/zotero/xpcom/dataDirectory.js
index a6015d4e7..960cd62d7 100644
--- a/chrome/content/zotero/xpcom/dataDirectory.js
+++ b/chrome/content/zotero/xpcom/dataDirectory.js
@@ -54,7 +54,37 @@ Zotero.DataDirectory = {
init: Zotero.Promise.coroutine(function* () {
var dataDir;
var dbFilename = this.getDatabaseFilename();
- if (Zotero.Prefs.get('useDataDir')) {
+ // Handle directory specified on command line
+ if (Zotero.forceDataDir) {
+ let dir = Zotero.forceDataDir;
+ // Profile subdirectory
+ if (dir == 'profile') {
+ dataDir = OS.Path.join(Zotero.Profile.dir, this.legacyDirName);
+ }
+ // Absolute path
+ else {
+ // Ignore non-absolute paths
+ if ("winIsAbsolute" in OS.Path) {
+ if (!OS.Path.winIsAbsolute(dir)) {
+ dir = false;
+ }
+ }
+ else if (!dir.startsWith('/')) {
+ dir = false;
+ }
+ if (!dir) {
+ throw `-datadir requires an absolute path or 'profile' ('${Zotero.forceDataDir}' given)`;
+ }
+
+ // Require parent directory to exist
+ if (!(yield OS.File.exists(OS.Path.dirname(dir)))) {
+ throw `Parent directory of -datadir ${dir} not found`;
+ }
+
+ dataDir = dir;
+ }
+ }
+ else if (Zotero.Prefs.get('useDataDir')) {
let prefVal = Zotero.Prefs.get('dataDir');
// Convert old persistent descriptor pref to string path and clear obsolete lastDataDir pref
//
@@ -660,6 +690,10 @@ Zotero.DataDirectory = {
return false;
}
+ if (Zotero.forceDataDir) {
+ return false;
+ }
+
// Legacy default or set to legacy default from other program (Standalone/Z4Fx) to share data
if (!Zotero.Prefs.get('useDataDir') || this.isLegacy(currentDir)) {
return true;
diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js
index 1f38ea1a8..73876628f 100644
--- a/chrome/content/zotero/xpcom/zotero.js
+++ b/chrome/content/zotero/xpcom/zotero.js
@@ -180,6 +180,8 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js");
'skipBundledFiles'
];
opts.filter(opt => options[opt]).forEach(opt => this[opt] = true);
+
+ this.forceDataDir = options.forceDataDir;
}
this.mainThread = Services.tm.mainThread;
@@ -378,16 +380,18 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js");
}
if (!Zotero.isConnector) {
- yield Zotero.DataDirectory.checkForLostLegacy();
- if (this.restarting) {
- return;
- }
-
- yield Zotero.DataDirectory.checkForMigration(
- dataDir, Zotero.DataDirectory.defaultDir
- );
- if (this.skipLoading) {
- return;
+ if (!this.forceDataDir) {
+ yield Zotero.DataDirectory.checkForLostLegacy();
+ if (this.restarting) {
+ return;
+ }
+
+ yield Zotero.DataDirectory.checkForMigration(
+ dataDir, Zotero.DataDirectory.defaultDir
+ );
+ if (this.skipLoading) {
+ return;
+ }
}
// Make sure data directory isn't in Dropbox, etc.
diff --git a/chrome/locale/en-US/zotero/preferences.dtd b/chrome/locale/en-US/zotero/preferences.dtd
index df2367956..2a5e310e3 100644
--- a/chrome/locale/en-US/zotero/preferences.dtd
+++ b/chrome/locale/en-US/zotero/preferences.dtd
@@ -193,6 +193,7 @@
+
diff --git a/chrome/skin/default/zotero/preferences.css b/chrome/skin/default/zotero/preferences.css
index b95549576..d6065a78e 100644
--- a/chrome/skin/default/zotero/preferences.css
+++ b/chrome/skin/default/zotero/preferences.css
@@ -289,3 +289,17 @@ treechildren::-moz-tree-checkbox(checked){
in your extension or elsewhere. */
list-style-image: url("chrome://global/skin/checkbox/cbox-check.gif");
}
+
+/* Advanced pane */
+#command-line-data-dir description {
+ font-size: 12px;
+ cursor: text;
+ -moz-user-select: text;
+}
+
+#command-line-data-dir label {
+ font-size: 11px;
+ font-style: italic;
+ padding-top: .4em;
+ padding-bottom: .4em;
+}
diff --git a/components/zotero-service.js b/components/zotero-service.js
index c38a6a9ab..8ecef0c4e 100644
--- a/components/zotero-service.js
+++ b/components/zotero-service.js
@@ -503,6 +503,8 @@ ZoteroCommandLineHandler.prototype = {
zInitOptions.forceDebugLog = 1;
}
+ zInitOptions.forceDataDir = cmdLine.handleFlagWithParam("datadir", false);
+
// handler to open Zotero pane at startup in Zotero for Firefox
if (!isStandalone() && cmdLine.handleFlag("ZoteroPaneOpen", false)) {
zInitOptions.openPane = true;