Nsis 搜索文件夹以及所有驱动器上的部分目录

问题描述 投票:0回答:1

我有这个非常小众的问题,

我是 Corsa 改装者,我根据游戏中已有的汽车制作附加组件。我无法提供所有文件,因为它可能会给人们提供他们尚未购买的 dlc。 (不希望被起诉)

所以我需要在某人的计算机上找到特定的汽车文件夹,然后复制其中的所有文件并安装更多文件。我的问题;我无法自动化查找过程。有些放在 C:\ 上,有些放在 D:\ 上,等等

我目前的手动方法,这有效,但我收到了很多关于它的负面反馈:

!include "nsDialogs.nsh"
!include "LogicLib.nsh"

Name "Vismonger mod installation"
Outfile "Toyota Supra MKIV Tuned LHD.exe"
InstallDir "C:\Program Files (x86)\Steam\steamapps\common\assettocorsa\content\cars\ks_toyota_supra_mkiv_tuned_lhd" ;most probable $INSTDIR
RequestExecutionLevel admin
XPStyle on

Icon "D:\Downloads\assetto autos\installer\data\upgrade.ico" ;path to icon

Var Dialog
Var SOURCE_DIR

Page components
Page custom nsDialogsPage
Page directory
Page instfiles

Function nsDialogsPage
    nsDialogs::Create 1018
    Pop $Dialog
    
    ;make them select the folder themselves
    nsDialogs::SelectFolderDialog "Please select the 'ks_toyota_supra_mkiv_tuned' folder in assetto corsa's game files" "C:\Program Files (x86)\Steam\steamapps\common\assettocorsa\content\cars"
    Pop $SOURCE_DIR ;$SOURCE_DIR is now the wanted directory
    ${If} $Dialog == error
        Abort
    ${EndIf}
FunctionEnd

Section "Toyota Supra MKIV Tuned LHD" SEC01
    ; Copy files from the selected source directory to the destination directory
    SetOutPath $INSTDIR
    CopyFiles "$SOURCE_DIR\*.*" $INSTDIR
    
    ; Copy specific files from my fixed location and install to the destination directory
    SetOutPath $INSTDIR
    File /r "D:\Downloads\assetto autos\installer\data\ks_toyota_supra_mkiv_tuned_lhd\*.*"
SectionEnd

我在一百万个论坛的帮助下尝试了这一点,只是为了在尝试将其实现到我的安装代码中之前找到并向我提供正确驱动器上的目录:

!include LogicLib.nsh
!include FileFunc.nsh

Name "SearchDirectoryExample"
OutFile "SearchDirectoryExample.exe"
RequestExecutionLevel user

Section "Search Directory" SEC01

  InitPluginsDir

  StrCpy $0 0 ; Drive index
  System::Call 'KERNEL32::GetLogicalDrives() i.r1'
  loop:
    IntOp $2 $1 & 1
    StrCmp $2 0 next
      System::Call 'KERNEL32::GetVolumeInformation(t " $0:\") i .r3 t .r4 i .r5 i .r6 .r7'
      StrCmp $3 "" next
      ; Check if the directory exists on this drive
      IfFileExists "$0:\Program Files (x86)\Steam\steamapps\common\assettocorsa\content\cars\ks_toyota_supra_mkiv_tuned\*" 0 found
        found:
          DetailPrint "Found directory on drive $0:"
          DetailPrint "$0:\Program Files (x86)\Steam\steamapps\common\assettocorsa\content\cars\ks_toyota_supra_mkiv_tuned"
          MessageBox MB_OK "Found directory on drive $0:`n$0:\Program Files (x86)\Steam\steamapps\common\assettocorsa\content\cars\ks_toyota_supra_mkiv_tuned"
          Goto done
  next:
    IntOp $0 $0 + 1
    IntOp $1 $1 >> 1
    StrCmp $0 26 loop

  done:

SectionEnd

但这似乎没有任何作用。

我真的是一个新手,我只知道 python 和 nsis。我已经搜索了几个小时,但找不到任何与我的问题相关或我可能感兴趣的内容。我想要我的旧代码,但手动目录选择更改为工作自动目录选择。 (这是我最初的想法。)。

installation directory nsis file-copying
1个回答
0
投票

枚举驱动器盘符:

!include LogicLib.nsh
Section

StrCpy $0 0 ; Drive index
System::Call 'KERNEL32::GetLogicalDrives()i.r1'
loop:
  ${If} $1 & 1
    IntOp $2 $0 + 65
    System::Call 'USER32::wsprintf(t.r2, t "%c", ir2)?c'
    System::Call 'KERNEL32::GetDriveType(t "$2:\")i.r4'
    DetailPrint "Drive letter $2 is valid and is of type $4"

    ${If} $4 <> 1 ; Skip DRIVE_NO_ROOT_DIR
    ${AndIf} $4 <> 5 ; Skip DRIVE_CDROM
      StrCpy $3 ":\Program Files (x86)" ; Default
      ; Use the correct program files path if possible (optional)
      StrCpy $4 $ProgramFiles32 2 1 ; Extract substring so we can check if it is a drive or a network share
      ${IfThen} $4 == ":\" ${|} StrCpy $3 $ProgramFiles32 "" 1 ${|}

      StrCpy $2 "$2$3"
      DetailPrint "The file might be somewhere inside $2\..."
    ${EndIf}
  ${EndIf}
  ${If} $0 < 26
    IntOp $0 $0 + 1
    IntOp $1 $1 >> 1
    Goto loop
  ${EndIf}

SectionEnd

如果您想在驱动器中的所有文件夹中搜索,请在递归函数中使用

FindFirst
FindNext
FindClose
(可能太慢)。

© www.soinside.com 2019 - 2024. All rights reserved.