mirror of
https://github.com/OpenListTeam/OpenList-Desktop.git
synced 2025-11-25 03:14:56 +08:00
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
This commit is contained in:
@@ -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'))
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user