From c1ae9a9cc5c9c7b3a9f0179c3a8ca5ddd20bc159 Mon Sep 17 00:00:00 2001 From: Christian Dreier Date: Wed, 18 Dec 2024 21:13:28 +0100 Subject: [PATCH] Change finding out whether the application is a portable instance This fixes issue #58 If the application doesn't run from a usual installation path, it is assumed that it is a portable instance. No extra steps during the installation process needed! Following environment variables are used: - ProgramFiles: usual global path for 64 bits applications - LOCALAPPDATA: usual user local path for applications --- app/main.js | 17 ++++++----------- build/assets/.datadir | 1 - build/deployConfig.js | 1 - build/installer.nsh | 7 ------- 4 files changed, 6 insertions(+), 20 deletions(-) delete mode 100644 build/assets/.datadir delete mode 100644 build/installer.nsh diff --git a/app/main.js b/app/main.js index 8f6efd0..3810271 100644 --- a/app/main.js +++ b/app/main.js @@ -25,9 +25,6 @@ const storage = require("./lib/storageMain") const toc = require("./lib/tocMain") const zoom = require("./lib/zoomMain") -const DATA_DIR_FILE = ".datadir" -const USER_DATA_PLACEHOLDER = "MDVIEW_USER_DATA" - const MIN_WINDOW_WIDTH = 200 // Pixels const MIN_WINDOW_HEIGHT = 50 // Pixels const UPDATE_INTERVAL = 1000 // ms @@ -601,14 +598,12 @@ if (cli.isDevelopment()) { "userData", path.join(path.resolve(args.slice(1).find(arg => !arg.startsWith("-"))), ".data"), ) -} else if (process.platform === "win32") { - const dataPath = fs.readFileSync(path.join(appDir, DATA_DIR_FILE), { encoding: "utf-8" }).trim() - if (dataPath !== USER_DATA_PLACEHOLDER) { - electron.app.setPath( - "userData", - path.isAbsolute(dataPath) ? dataPath : path.join(appDir, ".data"), - ) - } +} else if ( + process.platform === "win32" && + !appDir.startsWith(process.env.ProgramFiles) && + !appDir.startsWith(process.env.LOCALAPPDATA) +) { + electron.app.setPath("userData", path.join(appDir, ".data")) } // If set, ouput only paths and exit diff --git a/build/assets/.datadir b/build/assets/.datadir deleted file mode 100644 index ea26ec2..0000000 --- a/build/assets/.datadir +++ /dev/null @@ -1 +0,0 @@ -.data diff --git a/build/deployConfig.js b/build/deployConfig.js index 1744309..7921c6d 100644 --- a/build/deployConfig.js +++ b/build/deployConfig.js @@ -33,7 +33,6 @@ module.exports = { allowElevation: true, allowToChangeInstallationDirectory: true, createDesktopShortcut: false, - include: "build/installer.nsh", license: "LICENSE", oneClick: false, perMachine: false, diff --git a/build/installer.nsh b/build/installer.nsh deleted file mode 100644 index ce727f9..0000000 --- a/build/installer.nsh +++ /dev/null @@ -1,7 +0,0 @@ -!macro customInstall - Push $0 - FileOpen $0 "$INSTDIR\.datadir" w - FileWrite $0 "MDVIEW_USER_DATA" - FileClose $0 - Pop $0 -!macroend