File: download.nsi

package info (click to toggle)
win32-loader 0.7.8%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 1,452 kB
  • ctags: 74
  • sloc: ansic: 555; makefile: 241; sh: 61
file content (120 lines) | stat: -rw-r--r-- 3,366 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
; Debian-Installer Loader - Download functions
; 
; Copyright (C) 2007,2008,2009  Robert Millan <rmh@aybabtu.com>
; Copyright (C) 2010,2011       Didier Raboud <odyx@debian.org>
;
; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation, either version 3 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program.  If not, see <http://www.gnu.org/licenses/>.

Function Download
    ; Base URL
    Pop $0
    ; Target dir
    Pop $6
    ; Filename
    Pop $2
    ; Allow it to fail?
    Pop $3
    ; Check its md5sum ?
    Pop $4
    Var /GLOBAL nsisdl_proxy
    ${If} $proxy == ""
      StrCpy $nsisdl_proxy /NOIEPROXY
    ${Else}
      StrCpy $nsisdl_proxy "/PROXY $proxy"
    ${Endif}

    DetailPrint "GET: $0/$2"
    NSISdl::download /TRANSLATE $(nsisdl1) $(nsisdl2) $(nsisdl3) $(nsisdl4) $(nsisdl5) $(nsisdl6) $(nsisdl7) $(nsisdl8) $nsisdl_proxy $0/$2 $6\$2
    Pop $R0
    ${If} $R0 != "success"
      ${If} $R0 != "cancel"
         MessageBox MB_OK|MB_ICONSTOP "$(error): $0/$2 $R0"
      ${EndIf}
      ${If} $3 == "false"
        Quit
      ${Endif}
    ${EndIf}

    ${If} $4 != "false"
      ; $2 goes in the text
      DetailPrint "$(computing_checksum)"
      ; Compute md5sum of downloaded file, put it as $1
      VPatch::GetFileMD5 $6\$2
      Pop $1
      ${If} $4 != $1
       ; MD5 don't match, try sha1sum
       sha1sum::sha1sum $6\$2
       Pop $1
       ${If} $4 != $1
         MessageBox MB_OK|MB_ICONSTOP "$(checksum_mismatch)"
         Quit
       ${EndIf}
      ${EndIf}
      DetailPrint "$4 = $1"
    ${EndIf}

    Push "$R0"
FunctionEnd

Function Get_MD5_ref
;Line is like
;8cb1b6f4bad64a40b636d5f6e3761d0d  ./netboot/debian-installer/amd64/pxelinux.0
    ; Url we are looking for
    Pop $0
    ; MD5SUMS file
    Pop $1
    ClearErrors
    FileOpen $3 $1 r
    IfErrors done ; Make sure it's readable
  readline:
    FileRead $3 $4
    IfErrors endoffile
    StrCpy $5 $4 -1 36 ; md5sum + spaces and ./, -1 to get rid of newline
    ; Compare what we want with what we have
    StrCmpS $0 $5 0 readline
    StrCpy $0 $4 32 ; Copying the found md5sum to $0
    Push $0
    FileClose $3
    Goto done
  endoffile:
    Push "false-md5"
    FileClose $3
  done:
FunctionEnd

Function Get_SHA1_ref
;Line is like:
; dc61910e515a26d252330d311136fa200e4d06fa       94 main/debian-installer/binary-amd64/Release
    ; Url we are looking for
    Pop $0
    ; Release file
    Pop $1
    ClearErrors
    FileOpen $3 $1 r
    IfErrors sha1_done ; Make sure it's readable
  sha1_readline:
    FileRead $3 $4
    IfErrors sha1_endoffile
    StrCpy $5 $4 -1 51 ; space + sha1sum + space-leftpadded size, -1 to get rid of newline
    ; Compare what we want with what we have
    StrCmpS $0 $5 0 sha1_readline
    StrCpy $0 $4 40 1 ; Copying the found sha1sum to $0
    Push $0
    FileClose $3
    Goto sha1_done
  sha1_endoffile:
    Push "false-sha1"
    FileClose $3
  sha1_done:
FunctionEnd