论坛首页
论坛首页 开发者论坛 PortableApps开发 win7和xp路径不同,Custom.nsh该怎么写?

win7和xp路径不同,Custom.nsh该怎么写?

讨论关于便携软件开发的技术与问题,包括PAL、NSIS、VMware ThinApp及其他。
wzk999 两把菜刀
两把菜刀

帖子: 25
便携一个上古版本的flashget(1.9.2),遇到一个问题,请教大神。

该软件需要挪移一个下载记录文件(Default.jcd)。
在win7中,该文件在%AppDATA%\FlashGet\DataBase下,在xp中,该文件则在软件本身目录下。
在win7中,用DataBase=%AppDATA%\FlashGet\DataBase。
在xp中,用了[FilesMove]
DataBase\Default.jcd=%PAL:APPDir%\FlashGet。
之所以把初始Default.jcd文件放到DefaultData\DataBase下,是想让DATA下的该文件能通用于win7和xp系统。

查了查以前的帖子,有类似的,但不得要领。
应该需要一个Custom.nsh。在win7中,只执行DataBase=%AppDATA%\FlashGet\DataBase;在xp中,只执行[FilesMove]
DataBase\Default.jcd=%PAL:APPDir%\FlashGet。

请教大神,这Custom.nsh该怎么写?

jooseng 革命同志
革命同志

帖子: 3993
你确定吗? 如果你是程序员你会作如此的设计吗? 可否将有关的安装文件上传给我?

jooseng 革命同志
革命同志

帖子: 3993
如果软件在xp中懂得在本身目录下找Default.jcd,在其他系统中也一样会。试看在win7中将有关文件放入软件目录里,以管理员身份运行。或将软件安装到Program files以外的目录。

wzk999 两把菜刀
两把菜刀

帖子: 25
jooseng 写道:
如果软件在xp中懂得在本身目录下找Default.jcd,在其他系统中也一样会。试看在win7中将有关文件放入软件目录里,以管理员身份运行。或将软件安装到Program files以外的目录。


试了试以管理员身份运行,它仍顽强地去%AppDATA%\FlashGet\DataBase下寻找Default.jcd,若没有该文件,则新建;对软件本身目录下的Default.jcd无视。
对了,系统为64位win7旗舰版。

FlashGet v1.9.2绿色版:
pan.baidu.com/s/17N9_86HlZFk6I7iIDLUKBg

mega.nz/#!o7ZEzQSR!i45HAedJlaC2IHJeK7rxey50aGu7mjqHTQZtb_cx3qg

有劳大神!

jooseng 革命同志
革命同志

帖子: 3993
我假设在%AppDATA%\FlashGet下没有其它子目录或文件。否则多了File move/Directory move, Launcher ini里的运行顺序无法和custom code配合,这种情况下File move/Directory move也必须改为用custom code执行。

Custom.nsh:

你的Custom.nsh必须用英文字体。用中文字体会有无法用眼睛看的到的错误。抄以下代码也一样。


##########
## Define
##########
!define File1 "Default.jcd"
!define File2 "Default.jcd.bak"
!define File3 "Default.bk1"
;如果还有其他文件自己加。

#########
## Macro
#########
!define FileMove::Pre "!insertmacro FileMove::Pre"

!macro FileMove::Pre _File
${If} ${FileExists} "$AppDirectory\FlashGet\${_File}"
Delete "$DataDirectory\DataBase\${_File}"
${Else}
Rename "$DataDirectory\DataBase\${_File}" "$AppDirectory\FlashGet\${_File}"
${EndIf}
!macroend

!define FileMove::Post "!insertmacro FileMove::Post"

!macro FileMove::Post _File
${IfNot} ${FileExists} "$DataDirectory\DataBase"
CreateDirectory "$DataDirectory\DataBase"
${EndIf}
Rename "$AppDirectory\FlashGet\${_File}" "$DataDirectory\DataBase\${_File}"
!macroend

${SegmentFile}

${SegmentPrePrimary}
${If} ${AtMostWinXP}
${FileMove::Pre} "${File1}"
${FileMove::Pre} "${File2}"
${FileMove::Pre} "${File3}"
;如果还有其他文件自己加。
${Else}
StrCpy $0 "$DataDirectory\DataBase"
StrCpy $1 "$AppDATA\FlashGet\DataBase"

;=== Backup Local ===
Rename "$1" "$1.Backup"

;=== Check existent of parent dir of local dir. ===
${IfNot} ${FileExists} "$AppDATA\FlashGet"
CreateDirectory "$AppDATA\FlashGet"
${WriteRuntimeData} DirectoriesMove "RemoveIfEmpty:$AppDATA\FlashGet" true
${EndIf}

;=== Restore Portable ===
CreateDirectory "$1"
CopyFiles /SILENT "$0\*.*" "$1"
${EndIf}
!macroend

${SegmentPostPrimary}
${If} ${AtMostWinXP}
${FileMove::Post} "${File1}"
${FileMove::Post} "${File2}"
${FileMove::Post} "${File3}"
;如果还有其他文件自己加。
${Else}
StrCpy $0 "$DataDirectory\DataBase"
StrCpy $1 "$AppDATA\FlashGet\DataBase"

RMDir "$1"
RMDir /r "$0"
CreateDirectory "$0"
CopyFiles /SILENT "$1\*.*" "$0"
RMDir /r "$1"

;=== If the parent directory we put the directory in locally didn't exist before, delete it if it's empty. ===
${ReadRuntimeData} $2 DirectoriesMove "RemoveIfEmpty:$AppDATA\FlashGet"
${If} $2 == true
RMDir "$AppDATA\FlashGet"
${EndIf}

;=== Restore Local ===
Rename "$1.Backup" "$1"
${EndIf}
!macroend

wzk999 两把菜刀
两把菜刀

帖子: 25
jooseng 写道:
我假设在%AppDATA%\FlashGet下没有其它子目录或文件。否则多了File move/Directory move, Launcher ini里的运行顺序无法和custom code配合,这种情况下File move/Directory move也必须改为用custom code执行。

Custom.nsh:

你的Custom.nsh必须用英文字体。用中文字体会有无法用眼睛看的到的错误。抄以下代码也一样。


##########
## Define
##########
!define File1 "Default.jcd"
!define File2 "Default.jcd.bak"
!define File3 "Default.bk1"
;如果还有其他文件自己加。

#########
## Macro
#########
!define FileMove::Pre "!insertmacro FileMove::Pre"

!macro FileMove::Pre _File
${If} ${FileExists} "$AppDirectory\FlashGet\${_File}"
Delete "$DataDirectory\DataBase\${_File}"
${Else}
Rename "$DataDirectory\DataBase\${_File}" "$AppDirectory\FlashGet\${_File}"
${EndIf}
!macroend

!define FileMove::Post "!insertmacro FileMove::Post"

!macro FileMove::Post _File
${IfNot} ${FileExists} "$DataDirectory\DataBase"
CreateDirectory "$DataDirectory\DataBase"
${EndIf}
Rename "$AppDirectory\FlashGet\${_File}" "$DataDirectory\DataBase\${_File}"
!macroend

${SegmentFile}

${SegmentPrePrimary}
${If} ${AtMostWinXP}
${FileMove::Pre} "${File1}"
${FileMove::Pre} "${File2}"
${FileMove::Pre} "${File3}"
;如果还有其他文件自己加。
${Else}
StrCpy $0 "$DataDirectory\DataBase"
StrCpy $1 "$AppDATA\FlashGet\DataBase"

;=== Backup Local ===
Rename "$1" "$1.Backup"

;=== Check existent of parent dir of local dir. ===
${IfNot} ${FileExists} "$AppDATA\FlashGet"
CreateDirectory "$AppDATA\FlashGet"
${WriteRuntimeData} DirectoriesMove "RemoveIfEmpty:$AppDATA\FlashGet" true
${EndIf}

;=== Restore Portable ===
CreateDirectory "$1"
CopyFiles /SILENT "$0\*.*" "$1"
${EndIf}
!macroend

${SegmentPostPrimary}
${If} ${AtMostWinXP}
${FileMove::Post} "${File1}"
${FileMove::Post} "${File2}"
${FileMove::Post} "${File3}"
;如果还有其他文件自己加。
${Else}
StrCpy $0 "$DataDirectory\DataBase"
StrCpy $1 "$AppDATA\FlashGet\DataBase"

RMDir "$1"
RMDir /r "$0"
CreateDirectory "$0"
CopyFiles /SILENT "$1\*.*" "$0"
RMDir /r "$1"

;=== If the parent directory we put the directory in locally didn't exist before, delete it if it's empty. ===
${ReadRuntimeData} $2 DirectoriesMove "RemoveIfEmpty:$AppDATA\FlashGet"
${If} $2 == true
RMDir "$AppDATA\FlashGet"
${EndIf}

;=== Restore Local ===
Rename "$1.Backup" "$1"
${EndIf}
!macroend


完美搞定^_^
非常感谢大神!


回到 PortableApps开发