File: download.nsi

package info (click to toggle)
win32-loader 0.10.0
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,664 kB
  • sloc: sh: 460; asm: 345; makefile: 323; ansic: 215
file content (152 lines) | stat: -rw-r--r-- 4,354 bytes parent folder | download
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
; 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/>.

${STDMACROS_DefIfNotDef} IDCANCEL 2
${STDMACROS_DefIfNotDef} IDC_STATIC1 1001
${STDMACROS_DefIfNotDef} IDC_PROGRESS 1004
${STDMACROS_DefIfNotDef} IDC_PROGRESS1 1005
${STDMACROS_DefIfNotDef} IDC_INTROTEXT 1006
${STDMACROS_DefIfNotDef} IDC_SHOWDETAILS 1027

!ifndef NO_SHA256_HELPER
!define SHA256_HELPER_DIR "${BUILD_DIR}/helpers/sha256"
!endif

!define WININET_CANCEL_FLAG $cancel
!define WININET_PROGRESSBAR_CONTROL ${IDC_PROGRESS1}
!define WININET_PROXY $proxy
!define WININET_STATUSTEXT_CONTROL ${IDC_STATIC1}
!define WININET_TEXT_CONNECTING $(connecting)
!define WININET_TEXT_PROGRESS $(progress)
!define WININET_TIMEOUT 10000
!define WININET_USER_AGENT "Mozilla/4.0 (compatible; Win32; ${_PRODUCT_NAME})"

!include include\wininet.nsh
${WININET_Get}

ChangeUI IDD_INSTFILES "${BUILD_DIR}/helpers/instdlg/instdlg.exe"

; Show window controls for reporting progress of download
; Parameter:
;   flag - 0: hide 1: show
Function Download_ShowControls
  Exch $0
!ifdef MUI_INCLUDED
  ${IfNot} ${Silent}
  ${AndIf} $mui.InstFilesPage P<> 0
    ${If} $0 != 0
      StrCpy $0 ${SW_NORMAL}
      SetDetailsView hide
      EnableWindow $mui.InstFilesPage.ShowLogButton 0
    ${Else}
      StrCpy $0 ${SW_HIDE}
      EnableWindow $mui.InstFilesPage.ShowLogButton 1
    ${EndIf}

    Push $1
    GetDlgItem $1 $mui.InstFilesPage ${IDC_STATIC1}
    ${If} $1 P<> 0
      ShowWindow $1 $0
    ${EndIf}
    GetDlgItem $1 $mui.InstFilesPage ${IDC_PROGRESS1}
    ${If} $1 P<> 0
      ShowWindow $1 $0
    ${EndIf}
    Pop $1
  ${EndIf}
!endif ; MUI_INCLUDED

  Push $0
FunctionEnd

Function Download
    System::Store 'S'
    ; Base URL
    Pop $0
    ; Target dir
    Pop $6
    ; Filename
    Pop $2
    ; Allow it to fail?
    Pop $3
    ; Check its sha256sum ?
    Pop $4

    DetailPrint "GET: $0/$2"
    ${If} $4 != "false"
      StrCpy $5 ${CALG_SHA256}
    ${Else}
      StrCpy $5 0
      StrCpy $4 0
    ${EndIf}
    ${WININET_Get} $0 $2 $6 $5 $1
    ${If} $1 != ${ERROR_CANCELLED}
      ${If} $1 != $4
        ${If} $4 == 0
          MessageBox MB_OK|MB_ICONSTOP "$(error): $0/$2 $1"
          ${If} $3 == "false"
            Quit
          ${EndIf}
        ${Else}
          MessageBox MB_OK|MB_ICONSTOP "$(checksum_mismatch)"
          Quit
        ${EndIf}
      ${Else}
        StrCpy $1 "success"
      ${EndIf}
    ${Else}
      Quit
    ${EndIf}

    Push "$1"
    System::Store 'L'
FunctionEnd

Function Get_SHA256_ref
;Line is like:
; d62f7850ef1a0a381c1e856936761ddd678e16dfdab90685de2deaf248f8d655      108 contrib/debian-installer/binary-amd64/Release
;or like;
;8716fec256b2df0b3e7c2f45a90813285b28fe7a72e4925c14d456d40af4caa1  ./netboot/debian-installer/amd64/linux
    ; Url we are looking for
    Pop $0
    ; Release file
    Pop $1
    ClearErrors
    FileOpen $3 $1 r
    IfErrors sha256_done ; Make sure it's readable
  sha256_readline:
    FileRead $3 $4
    IfErrors sha256_endoffile
    StrCpy $5 $4 -1 75 ; space + sha256sum + space-leftpadded size, -1 to get rid of newline
    ; Compare what we want with what we have
    StrCmpS $0 $5 0 sha256_alternativesyntax
    StrCpy $0 $4 64 1 ; Copying the found sha256sum to $0
    Push $0
    Goto sha256_done
  sha256_alternativesyntax:
    StrCpy $5 $4 -1 68 ; sha256sum + spaces and ./, -1 to get rid of newline
    ; Compare what we want with what we have
    StrCmpS $0 $5 0 sha256_readline
    StrCpy $0 $4 64 ; Copying the found sha256sum to $0
    Push $0
    Goto sha256_done
  sha256_endoffile:
    Push "false-sha256"
  sha256_done:
    FileClose $3
FunctionEnd