2016-02-15 89 views
0

我寫下面的代碼來讀取一個文本文件,其中包含服務器的url和預計算的md5總和的update.zip文件。該文件被命名爲TEMP.TXT文本文件的內容如下NSISdl ::下載不起作用

http://10.212.8.230:8080/update.zip 
daf6de1b3d8fa32f276e26566311515f 

我讀的文本文件,並保存在%PATH變量中的URL字符串。我的問題是,當我通過這個$路徑NSISdl ::下載然後它給我錯誤在運行時間像'北大'的東西。但是當我通過相同的網址硬編碼(手動沒有讀取文件,然後它的作品)。與MD5總和相同的情況。我從temp.txt文件讀取它並存儲在一個變量中,當我競選字符串時,即使字符串相同,它也顯示我不相同。但是,當我給它硬編碼,然後它可以工作。

有誰能告訴我爲什麼會發生這種情況,我犯了錯誤。我盡我所能,但我無法修復它。如何從文本文件中讀取它,並將其從服務器下載下載?

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 $0 "$INSTDIR\temp\temp.txt" r ;reading file 
    FileRead $0 $1 
    StrCpy $path $1;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 $0 $1 
    StrCpy $downloaded_md5 $1;storing md5 string 
    md5dll::GetMD5File "$INSTDIR\temp\update.zip" 
    Pop $0 
    StrCpy $local_md5 $0 

    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 

回答

1

Fileread讀取直到讀取換行符或空字節爲止。結果字符串中包含回車符/左行字符,因此您需要修剪字符串。

請參閱。

你的代碼應該是這樣的:

!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 $0 "$INSTDIR\temp\temp.txt" r ;reading file 
    FileRead $0 $1 
    ${StrTrimNewLines} $path $1 ;storing url in $path and removing newline 
[....] 

您閱讀MD5SUM時需要做同樣的操作。

+0

謝謝!現在工作正常。 –

+0

好。請注意並接受答案。 :) –

+0

做同樣的問題,如果你覺得這是一個有效的問題 –