NSISdl::download 不工作
NSISdl::download is not working
我写了下面的代码来读取一个文本文件,其中包含服务器 url 和预先计算的 update.zip 文件的 md5 和。文件命名为temp.txt 文本文件内容如下
http://10.212.8.230:8080/update.zip
daf6de1b3d8fa32f276e26566311515f
我读取文本文件并将 url 字符串保存在 %path 变量中。我的问题是,当我将此 $path 传递给 NSISdl::download 时,它会在 运行 时给我错误,例如 'PKU' 之类的。但是当我通过相同的 url 硬编码时(手动而不从文件读取然后它工作)。与 MD5 和相同的情况。我从 temp.txt 文件中读取它并存储在一个变量中,当我 campare 字符串时它显示我不一样,即使字符串相同。但是当我给它硬编码时它就可以工作了。
谁能告诉我为什么会这样,我哪里做错了。我尽我所能,但我无法修复它。如何从文本文件中读取并传递给服务器下载???
var path;variable to save download url downloaded from temp.txt file
var downloaded_md5;variable to save md5 sum of update.zip downloaded from temp.txt file
var local_md5;used to store md5 sum of update.zip after downloading the update.zip
Section
FileOpen [=12=] "$INSTDIR\temp\temp.txt" r ;reading file
FileRead [=12=]
StrCpy $path ;storing url in $path
NSISdl::download "$path" "$INSTDIR\temp\update.zip";passing $path to download
Pop $R0 ;Get the return value
StrCmp $R0 "success" ExtractFiles
DetailPrint "Update downloading failed"
MessageBox MB_OK "Update downloading failed: $R0"
Quit
ExtractFiles:
FileRead [=12=]
StrCpy $downloaded_md5 ;storing md5 string
md5dll::GetMD5File "$INSTDIR\temp\update.zip"
Pop [=12=]
StrCpy $local_md5 [=12=]
StrCmp $downloaded_md5 $local_md5 same notsame
same:
MessageBox MB_OK "MD5 is same"
goto End
notsame:
MessageBox MB_OK "MD5 is not same"
goto End
End:
Quit
SectionEnd
Fileread 读取直到读取到换行符或空字节。结果字符串中包含回车 return /lew 行字符,因此您需要 trim 字符串。
你的代码应该是这样的:
!include "StrFunc.nsh"
${StrTrimNewLines}
var path;variable to save download url downloaded from temp.txt file
var downloaded_md5;variable to save md5 sum of update.zip downloaded from temp.txt file
var local_md5;used to store md5 sum of update.zip after downloading the update.zip
Section
FileOpen [=10=] "$INSTDIR\temp\temp.txt" r ;reading file
FileRead [=10=]
${StrTrimNewLines} $path ;storing url in $path and removing newline
[....]
读取MD5sum时需要做同样的操作
我写了下面的代码来读取一个文本文件,其中包含服务器 url 和预先计算的 update.zip 文件的 md5 和。文件命名为temp.txt 文本文件内容如下
http://10.212.8.230:8080/update.zip
daf6de1b3d8fa32f276e26566311515f
我读取文本文件并将 url 字符串保存在 %path 变量中。我的问题是,当我将此 $path 传递给 NSISdl::download 时,它会在 运行 时给我错误,例如 'PKU' 之类的。但是当我通过相同的 url 硬编码时(手动而不从文件读取然后它工作)。与 MD5 和相同的情况。我从 temp.txt 文件中读取它并存储在一个变量中,当我 campare 字符串时它显示我不一样,即使字符串相同。但是当我给它硬编码时它就可以工作了。
谁能告诉我为什么会这样,我哪里做错了。我尽我所能,但我无法修复它。如何从文本文件中读取并传递给服务器下载???
var path;variable to save download url downloaded from temp.txt file
var downloaded_md5;variable to save md5 sum of update.zip downloaded from temp.txt file
var local_md5;used to store md5 sum of update.zip after downloading the update.zip
Section
FileOpen [=12=] "$INSTDIR\temp\temp.txt" r ;reading file
FileRead [=12=]
StrCpy $path ;storing url in $path
NSISdl::download "$path" "$INSTDIR\temp\update.zip";passing $path to download
Pop $R0 ;Get the return value
StrCmp $R0 "success" ExtractFiles
DetailPrint "Update downloading failed"
MessageBox MB_OK "Update downloading failed: $R0"
Quit
ExtractFiles:
FileRead [=12=]
StrCpy $downloaded_md5 ;storing md5 string
md5dll::GetMD5File "$INSTDIR\temp\update.zip"
Pop [=12=]
StrCpy $local_md5 [=12=]
StrCmp $downloaded_md5 $local_md5 same notsame
same:
MessageBox MB_OK "MD5 is same"
goto End
notsame:
MessageBox MB_OK "MD5 is not same"
goto End
End:
Quit
SectionEnd
Fileread 读取直到读取到换行符或空字节。结果字符串中包含回车 return /lew 行字符,因此您需要 trim 字符串。
你的代码应该是这样的:
!include "StrFunc.nsh"
${StrTrimNewLines}
var path;variable to save download url downloaded from temp.txt file
var downloaded_md5;variable to save md5 sum of update.zip downloaded from temp.txt file
var local_md5;used to store md5 sum of update.zip after downloading the update.zip
Section
FileOpen [=10=] "$INSTDIR\temp\temp.txt" r ;reading file
FileRead [=10=]
${StrTrimNewLines} $path ;storing url in $path and removing newline
[....]
读取MD5sum时需要做同样的操作