NSIS - 有没有办法写入选择了哪些选项或安装了哪些文件的日志?

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

我有很多需要安装文件的选项 它看起来像这样:

SectionGroup /e "All" SEC0010
SectionGroup "A" SEC0020
    Section "A1"
        SectionIn 1 2
        File /r ".\Path\To\A1.txt"
    SectionEnd
    Section "A2"
        SectionIn 1 2
        File /r ".\Path\To\A2.txt"
    SectionEnd
    Section "A3"
        SectionIn 1 2
        File /r ".\Path\To\A3.txt"
    SectionEnd
SectionGroupEnd
SectionGroup "B" SEC0020
    Section "B1"
        SectionIn 1 2
        File /r ".\Path\To\B1.txt"
    SectionEnd
    Section "B2"
        SectionIn 1 2
        File /r ".\Path\To\B2.txt"
    SectionEnd
    Section "B3"
        SectionIn 1 2
        File /r ".\Path\To\B3.txt"
    SectionEnd
SectionGroupEnd
SectionGroup "C" SEC0030
    Section "C1"
        SectionIn 1 2
        File /r ".\Path\To\C1.txt"
    SectionEnd
    Section "C2"
        SectionIn 1 2
        File /r ".\Path\To\C2.txt"
    SectionEnd
    Section "AC3"
        SectionIn 1 2
        File /r ".\Path\To\C3.txt"
    SectionEnd
SectionGroupEnd
SectionGroupEnd

我想写一个日志,记录安装了哪些文件和/或选择了哪些选项。

理想情况下,它看起来像下面这样:

2023-09-18 12:00:00|All
2023-09-18 12:01:00|C2
2023-09-18 12:02:00|A1, A2, B3, C1, C2
2023-09-18 12:03:00|All

注意:所有文件都安装在同一目录中。


问题

有没有办法知道选择了哪些选项并将其写入文件?

或者,有没有什么方法可以使用 NSIS 之外的东西,比如

.bat
文件,我可以跟踪选择了哪些选项,或者安装了哪些文件?

nsis
1个回答
0
投票

如果您只是想要列表,因为您想记住安装程序下次运行时的配置,请使用 Memento.nsh。

或者只是从 0 开始循环,直到

SectionGetFlags
失败:

!include LogicLib.nsh
!include Sections.nsh

Section
ClearErrors
StrCpy $1 0
loop:
    SectionGetText $1 $2
    SectionGetFlags $1 $3
    IfErrors end
    IntOp $3 $3 & ${SF_SECGRPEND}
    ${If} $2 != ""
    ${AndIf} $3 = 0
        System::Call 'KERNEL32::GetLocalTime(p@r3)'
        System::Call '*$3(&i2.r4,&i2.r5,&i2,&i2.r6,&i2.r7,&i2.r8,&i2.r9)'
        IntFmt $5 "%.2u" $5
        IntFmt $6 "%.2u" $6
        IntFmt $7 "%.2u" $7
        IntFmt $8 "%.2u" $8
        IntFmt $9 "%.2u" $9
        DetailPrint "$4-$5-$6 $7:$8:$9|$2" ; TODO: Write to file
    ${EndIf}
    IntOp $1 $1 + 1
    Goto loop
end:
SectionEnd


Section "Root"
SectionEnd
SectionGroup "G1"
SectionGroup "G1.1"
Section "S1.1"
SectionEnd
Section "S1.2"
SectionEnd
SectionGroupEnd
Section "S1"
SectionEnd
Section "S2"
SectionEnd
SectionGroupEnd
© www.soinside.com 2019 - 2024. All rights reserved.