模仿NSIS SetOverwrite不存在选项“ifNotModified”

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

我的软件有哪些,我不想,如果修改重新安装过程中覆盖了一些用户修改的文件。

我决定使用归档位以表示该目标文件被用户修改或没有。在全新安装的所有相关文件的所有存档位将被设置为OFF。

存档功能:表示该文件是未经修改的,因此可以用最新版本的存档上取代:表示该文件是由用户修改,不应由即使是一个较新版本的安装程序覆盖。

注:如你所知,设计,编辑和保存文件设置存档位ON。

我甚至想给NSIS脚本中使用ROBOCOPY,ROBOCOPY的排除然而参数据我可以看到相关的源文件不是目标文件。我用下面的代码:

    robocopy c:\source c:\target /XA:A

你能好心给的线索来实现这样的功能。

nsis archive robocopy
1个回答
0
投票

我不认为这是可能的File /r做到这一点。

你可以做到这一点,当你手动提取每个文件:

!include LogicLib.nsh

!define /IfNDef FILE_ATTRIBUTE_ARCHIVE 0x20
!define /IfNDef INVALID_FILE_ATTRIBUTES 0xffffffff
!define File_NoArchiveOverwrite "!insertmacro File_NoArchiveOverwrite "
!macro File_NoArchiveOverwrite sourcefile destinationfile
    Push $1
    System::Call 'KERNEL32::GetFileAttributes(ts)i.r1' "${destinationfile}"
    ${IfThen} $1 = ${INVALID_FILE_ATTRIBUTES} ${|} StrCpy $1 0 ${|} ; File does not exist? Make sure "it" has no attributes.
    IntOp $1 $1 & ${FILE_ATTRIBUTE_ARCHIVE}
    ${If} $1 = 0 ; Archive not set?
        SetOverwrite on
        File "/oname=${destinationfile}" "${sourcefile}"
        SetOverwrite lastused
    ${EndIf}
    Pop $1
!macroend


Section "Example preparation"
InitPluginsDir 
StrCpy $InstDir $PluginsDir ; Just a hack for this example

; Prepare some test files for this example:
File "/oname=$InstDir\test1.ini" "${__FILE__}"
SetFileAttributes "$InstDir\test1.ini" ARCHIVE
File "/oname=$InstDir\test2.ini" "${__FILE__}"
SetFileAttributes "$InstDir\test2.ini" NORMAL
SectionEnd

Section "Real code"
SetOutPath $InstDir
#File /r /x "*.ini" c:\myfiles\*.* ; Exclude .ini files because we handle them manually

${File_NoArchiveOverwrite} "${__FILE__}" "$InstDir\test1.ini" ; Not extracted because the dummy test1.ini file has ARCHIVE set
${File_NoArchiveOverwrite} "${__FILE__}" "$InstDir\test2.ini" ; This will overwrite the test2.ini dummy file.
${File_NoArchiveOverwrite} "${__FILE__}" "$InstDir\test3.ini" ; This file does not exist so we will extract a new file

SectionEnd

如果你有太多的文件手动创建${File_NoArchiveOverwrite}调用,那么您可以使用!system调用生成与${File_NoArchiveOverwrite}呼叫.NSH文件的批处理文件(或任何其他脚本或应用程序),然后就可以!include此文件:

Section
SetOutPath $InstDir
!tempfile FILELIST
!system 'generatefilecommands.cmd "${FILELIST}"'
!include "${FILELIST}"
!delfile "${FILELIST}"
!undef FILELIST
SectionEnd

这假定generatefilecommands.cmd是你写一个文件,它可能是这个样子:

@ECHO OFF&SETLOCAL ENABLEEXTENSIONS DISABLEDELAYEDEXPANSION
FOR %%A IN (*.ini) DO (
    ECHO >> "%~1" ${File_NoArchiveOverwrite} "%%~fA" "$InstDir\%%~A"
)
© www.soinside.com 2019 - 2024. All rights reserved.