From 4f38ebb85d634ebccd1ad2a9de8a746b54d5591f Mon Sep 17 00:00:00 2001 From: Kuingsmile <96409857+Kuingsmile@users.noreply.github.com> Date: Fri, 4 Jul 2025 17:47:19 +0800 Subject: [PATCH] feat: change default install path and set directory permissions (#39) * feat: change default install path and set directory permissions in installer close #38 * feat: check D: drive existence and fallback to PROGRAMFILES --- scripts/prepare.js | 61 +++++++++++++++++++++--- src-tauri/packages/windows/installer.nsi | 46 +++++++++++++----- 2 files changed, 90 insertions(+), 17 deletions(-) diff --git a/scripts/prepare.js b/scripts/prepare.js index 6fbbdd6..992df51 100644 --- a/scripts/prepare.js +++ b/scripts/prepare.js @@ -81,24 +81,29 @@ const getServiceInfo = exeName => { } } -// SimpleSC.dll -const resolvePlugin = async () => { +const resolvePlugins = async () => { + const pluginDir = path.join(process.env.APPDATA, 'Local/NSIS') + await fs.mkdir(pluginDir, { recursive: true }) + await resolveSimpleServicePlugin(pluginDir) + await resolveAccessControlPlugin(pluginDir) +} + +const resolveSimpleServicePlugin = async pluginDir => { const url = 'https://nsis.sourceforge.io/mediawiki/images/e/ef/NSIS_Simple_Service_Plugin_Unicode_1.30.zip' const TEMP_DIR = path.join(cwd, 'temp') const tempDir = path.join(TEMP_DIR, 'SimpleSC') const tempZip = path.join(tempDir, 'NSIS_Simple_Service_Plugin_Unicode_1.30.zip') const tempDll = path.join(tempDir, 'SimpleSC.dll') - const pluginDir = path.join(process.env.APPDATA, 'Local/NSIS') const pluginPath = path.join(pluginDir, 'SimpleSC.dll') - await fs.mkdir(pluginDir, { recursive: true }) + await fs.mkdir(tempDir, { recursive: true }) if (fs.existsSync(pluginPath)) return + try { if (!fs.existsSync(tempZip)) { await downloadFile(url, tempZip) } const zip = new AdmZip(tempZip) - zip.extractAllTo(tempDir, true) await fsp.cp(tempDll, pluginPath, { recursive: true, force: true }) console.log(`SimpleSC.dll copied to ${pluginPath}`) @@ -107,6 +112,50 @@ const resolvePlugin = async () => { } } +const resolveAccessControlPlugin = async pluginDir => { + const url = 'https://nsis.sourceforge.io/mediawiki/images/4/4a/AccessControl.zip' + const TEMP_DIR = path.join(cwd, 'temp') + const tempDir = path.join(TEMP_DIR, 'AccessControl') + const tempZip = path.join(tempDir, 'AccessControl.zip') + const tempDll = path.join(tempDir, 'Plugins', 'AccessControl.dll') + const pluginPath = path.join(pluginDir, 'Plugins', 'x86-unicode', 'AccessControl.dll') + const pluginPathB = path.join(pluginDir, 'AccessControl.dll') + + await fs.mkdir(tempDir, { recursive: true }) + if (fs.existsSync(pluginPath)) return + + try { + if (!fs.existsSync(tempZip)) { + await downloadFile(url, tempZip) + } + const zip = new AdmZip(tempZip) + zip.extractAllTo(tempDir, true) + + let sourcePath = tempDll + if (!fs.existsSync(sourcePath)) { + const altPaths = [ + path.join(tempDir, 'AccessControl.dll'), + path.join(tempDir, 'Plugins', 'i386-unicode', 'AccessControl.dll') + ] + for (const altPath of altPaths) { + if (fs.existsSync(altPath)) { + sourcePath = altPath + break + } + } + } + if (fs.existsSync(sourcePath)) { + await fsp.cp(sourcePath, pluginPath, { recursive: true, force: true }) + await fsp.cp(sourcePath, pluginPathB, { recursive: true, force: true }) + console.log(`AccessControl.dll copied to ${pluginPath}`) + } else { + console.warn('AccessControl.dll not found in the extracted archive') + } + } finally { + await fsp.rm(tempDir, { recursive: true, force: true }) + } +} + async function resolveSidecar(binInfo) { const { name, targetFile, zipFile, exeFile, downloadURL } = binInfo const binaryDir = path.join(cwd, 'src-tauri', 'binary') @@ -200,7 +249,7 @@ async function main() { ) }) if (isWin) { - await resolvePlugin() + await resolvePlugins() } await resolveService(getServiceInfo('install-openlist-service')) await resolveService(getServiceInfo('openlist-desktop-service')) diff --git a/src-tauri/packages/windows/installer.nsi b/src-tauri/packages/windows/installer.nsi index 0d17770..5ac50ae 100644 --- a/src-tauri/packages/windows/installer.nsi +++ b/src-tauri/packages/windows/installer.nsi @@ -401,17 +401,11 @@ Function .onInit ${If} $INSTDIR == "" ; Set default install location !if "${INSTALLMODE}" == "perMachine" - ${If} ${RunningX64} - !if "${ARCH}" == "x64" - StrCpy $INSTDIR "$PROGRAMFILES64\${PRODUCTNAME}" - !else if "${ARCH}" == "arm64" - StrCpy $INSTDIR "$PROGRAMFILES64\${PRODUCTNAME}" - !else - StrCpy $INSTDIR "$PROGRAMFILES\${PRODUCTNAME}" - !endif - ${Else} - StrCpy $INSTDIR "$PROGRAMFILES\${PRODUCTNAME}" - ${EndIf} + IfFileExists "D:\" 0 +3 + StrCpy $INSTDIR "D:\Program\${PRODUCTNAME}" + Goto instdir_set + StrCpy $INSTDIR "$PROGRAMFILES\${PRODUCTNAME}" + instdir_set: !else if "${INSTALLMODE}" == "currentUser" StrCpy $INSTDIR "$LOCALAPPDATA\${PRODUCTNAME}" !endif @@ -501,6 +495,34 @@ FunctionEnd ${EndIf} !macroend +!macro SetDirectoryPermissions + DetailPrint "Setting permissions for installation directory..." + !if "${INSTALLMODE}" == "currentUser" + AccessControl::GrantOnFile "$INSTDIR" "(S-1-5-32-545)" "FullAccess" + Pop $R0 + ${If} $R0 == "ok" + DetailPrint "Successfully granted permissions to Users group" + ${Else} + DetailPrint "Warning: Failed to set permissions - $R0" + ${EndIf} + !else + AccessControl::GrantOnFile "$INSTDIR" "(S-1-5-32-545)" "FullAccess" + Pop $R0 + ${If} $R0 == "ok" + DetailPrint "Successfully granted permissions to Users group" + ${Else} + DetailPrint "Warning: Failed to set permissions - $R0" + ${EndIf} + AccessControl::GrantOnFile "$INSTDIR" "(S-1-5-11)" "FullAccess" + Pop $R0 + ${If} $R0 == "ok" + DetailPrint "Successfully granted permissions to Authenticated Users" + ${Else} + DetailPrint "Warning: Failed to set permissions for Authenticated Users - $R0" + ${EndIf} + !endif +!macroend + !macro RemoveOpenListService ; Check if the service exists SimpleSC::ExistsService "openlist_desktop_service" @@ -731,6 +753,8 @@ Section Install !insertmacro CheckIfAppIsRunning !insertmacro CheckAllOpenListProcesses + !insertmacro SetDirectoryPermissions + DetailPrint "Cleaning auto-launch registry entries..." StrCpy $R1 "Software\Microsoft\Windows\CurrentVersion\Run"