Hello, I need your help with downloading files.
I need to save cookies and then using it download my file. Like this by wget:
--save cookies
wget --no-check-certificate --save-cookies /tmp/cookies.txt --post-data 'email=my-email&password=mypassword' https://mysite/auth/signIn
--download usins saved cookes
wget --no-check-certificate --content-disposition --load-cookies /tmp/cookies.txt --post-data 'type=win64' https://mysite/download -O /tmp/file_win64.zip
Inetc plugin can't do that. Can you give me any tips?
I need to download it by using native windows tools.
Wget Nsis
5 posts
...and wget is not a native Windows tool in your opinion?
wget is not a native Windows tool. Am i wrong?
I have solved my problem by getting wget for windows inside my installer and using it to get files.
I have solved my problem by getting wget for windows inside my installer and using it to get files.
A native tool is (IMHO) a .EXE that uses the normal WinAPI excluding unix tools that have been "ported" to Cygwin. wget is not shipped as a part of Windows of course but it is a native program.
My method of downloading files using wget
# DETAILS #
Name "Wget Downloader"
OutFile "Wget Downloader.exe"
InstallDir "$TEMP\Wget Downloader"
# COMPRESS #
SetCompressor /SOLID /FINAL lzma
# ELEVATED #
RequestExecutionLevel 'User'
# RUNTIME SWITCHES #
ShowInstDetails Show
AutoCloseWindow true
# INCLUDE #
!include "MUI.nsh"
!include "WinCore.nsh"
!include "nsDialogs.nsh"
!include "FileFunc.nsh"
!include "LogicLib.nsh"
!include "WinMessages.nsh"
!include "x64.nsh"
# STYLE #
BrandingText /TRIMRIGHT " "
# PAGE #
Page custom "PageWelcomeShow" ""
Page 'InstFiles'
# LANGUAGE #
!insertmacro MUI_LANGUAGE "English"
# INIT #
Function ".onInit"
FunctionEnd
# WELCOME #
Function "PageWelcomeShow"
var /GLOBAL DIALOG
var /GLOBAL Lbl.Add.Url
var /GLOBAL PATH_Link
var /GLOBAL Lbl.Add.Pack
var /GLOBAL PATH_Pack
var /GLOBAL Lbl.Save.Pack
var /GLOBAL PATH_Save
var /GLOBAL Btn_Save
var /GLOBAL Lbl.ShowStatus1
var /GLOBAL Lbl.ShowStatus2
var /GLOBAL Lbl.ShowStatus3
var /GLOBAL Path_User
var /GLOBAL Lbl_User
var /GLOBAL Lbl_Show_User
var /GLOBAL Path_Pass
var /GLOBAL Lbl_Pass
var /GLOBAL Lbl_Show_Pass
var /GLOBAL DIRSAVEPACK
var /GLOBAL COMPUTERNAME
GetDlgItem $0 $HWNDPARENT 1
EnableWindow $0 0
SendMessage $0 ${WM_SETTEXT} 0 `STR:Download`
nsDialogs::Create /NOUNLOAD 1044
Pop $DIALOG
${If} $DIALOG == error
Abort
${EndIf}
# Add Url #
nsDialogs::CreateControl /NOUNLOAD EDIT 0x40000000|0x10000000|0x04000000|0x00010000|0x00000080 0 5% 10% 90% 5% ""
Pop $PATH_Link
Strcpy $1 $PATH_Link
GetFunctionAddress $0 ".onClick.Add.Link"
nsDialogs::OnChange /NOUNLOAD $1 $0
nsDialogs::CreateControl /NOUNLOAD BUTTON 0x40000000|0x10000000|0x04000000|0x00000007 0x00000080 2% 5% 96% 15% "Add your url:"
Pop $Lbl.Add.Url
# Add Pack #
nsDialogs::CreateControl /NOUNLOAD EDIT 0x40000000|0x10000000|0x04000000|0x00010000|0x00000080 0 5% 25% 90% 5% ""
Pop $PATH_Pack
Strcpy $1 $PATH_Pack
GetFunctionAddress $0 ".onClick.Add.Pack"
nsDialogs::OnChange /NOUNLOAD $1 $0
nsDialogs::CreateControl /NOUNLOAD BUTTON 0x40000000|0x10000000|0x04000000|0x00000007 0x00000080 2% 20% 96% 15% "Add your pack:"
Pop $Lbl.Add.Pack
# Save Pack #
System::Call "advapi32::GetUserName(t .r0, *i ${NSIS_MAX_STRLEN} r1) i.r2"
StrCpy $COMPUTERNAME "$0"
Strcpy $DIRSAVEPACK "C:\Users\$COMPUTERNAME\Downloads"
nsDialogs::CreateControl /NOUNLOAD EDIT 0x40000000|0x10000000|0x04000000|0x00010000|0x00000080 0 5% 40% 80% 5% "$DIRSAVEPACK"
Pop $PATH_Save
nsDialogs::CreateControl /NOUNLOAD BUTTON 0x40000000|0x10000000|0x04000000|0x00010000 0 87% 40% 8% 5% "Save"
Pop $Btn_Save
StrCpy $1 $Btn_Save
GetFunctionAddress $3 ".onClick.Save.Pack"
nsDialogs::onClick /NOUNLOAD $1 $3
nsDialogs::CreateControl /NOUNLOAD BUTTON 0x40000000|0x10000000|0x04000000|0x00000007 0x00000080 2% 35% 96% 15% "Save your pack:"
Pop $Lbl.Save.Pack
# User
nsDialogs::CreateControl /NOUNLOAD EDIT 0x40000000|0x10000000|0x04000000|0x00010000|0x00000080 0 15% 55% 34% 4% "" ; Username
Pop $Path_User
Strcpy $1 $Path_User
GetFunctionAddress $3 ".onClick.User"
nsDialogs::OnChange /NOUNLOAD $1 $3
nsDialogs::CreateControl /NOUNLOAD STATIC 0x40000000|0x10000000|0x04000000|0x00000100 0x00000020 2% 55% 12% 4% "User:"
Pop $Lbl_User
nsDialogs::CreateControl /NOUNLOAD STATIC 0x40000000|0x10000000|0x04000000|0x00000100 0x00000020 50% 55% 47% 4% ""
Pop $Lbl_Show_User
# Password
nsDialogs::CreateControl /NOUNLOAD EDIT 0x40000000|0x10000000|0x04000000|0x00010000|0x00000080 0 15% 65% 34% 4% "" ; Password
Pop $Path_Pass
Strcpy $1 $Path_Pass
SendMessage $Path_Pass 0x00CC 149 0
GetFunctionAddress $3 ".onClick.Pass"
nsDialogs::OnChange /NOUNLOAD $1 $3
nsDialogs::CreateControl /NOUNLOAD STATIC 0x40000000|0x10000000|0x04000000|0x00000100 0x00000020 2% 65% 12% 4% "Password:"
Pop $Lbl_Pass
nsDialogs::CreateControl /NOUNLOAD STATIC 0x40000000|0x10000000|0x04000000|0x00000100 0x00000020 50% 65% 47% 4% ""
Pop $Lbl_Show_Pass
# Info #
nsDialogs::CreateControl /NOUNLOAD STATIC 0x40000000|0x10000000|0x04000000|0x00000100 0x00000020 2% 75% 96% 5% ""
Pop $Lbl.ShowStatus1
nsDialogs::CreateControl /NOUNLOAD STATIC 0x40000000|0x10000000|0x04000000|0x00000100 0x00000020 2% 82% 96% 5% ""
Pop $Lbl.ShowStatus2
nsDialogs::CreateControl /NOUNLOAD STATIC 0x40000000|0x10000000|0x04000000|0x00000100 0x00000020 2% 89% 96% 5% ""
Pop $Lbl.ShowStatus3
SendMessage $Lbl.ShowStatus3 ${WM_SETTEXT} 0 "STR:Save Location: $DIRSAVEPACK"
nsDialogs::Show
FunctionEnd
# Link #
Function ".onClick.Add.Link"
var /GLOBAL LINK
${NSD_GetText} $PATH_LINK $0
StrCpy $LINK "$0"
${If} $LINK != ""
SendMessage $Lbl.ShowStatus1 ${WM_SETTEXT} 0 "STR:Link: $LINK"
${EndIf}
FunctionEnd
# Package #
Function ".onClick.Add.Pack"
var /GLOBAL PACK
${NSD_GetText} $PATH_PACK $0
StrCpy $PACK "$0"
${If} $PACK != ""
SendMessage $Lbl.ShowStatus2 ${WM_SETTEXT} 0 "STR:Package: $PACK"
GetDlgItem $0 $HWNDPARENT 1
EnableWindow $0 1
${EndIf}
FunctionEnd
# Save #
Function ".onClick.Save.Pack"
nsDialogs::SelectFolderDialog /NOUNLOAD "Save file:" "C:\Users\$COMPUTERNAME\Downloads"
Pop $0
StrCpy $DIRSAVEPACK $0
${NSD_SetText} $PATH_Save $DIRSAVEPACK
${If} $DIRSAVEPACK != ""
SendMessage $Lbl.ShowStatus3 ${WM_SETTEXT} 0 "STR:Save Location: $DIRSAVEPACK"
${EndIf}
FunctionEnd
# User Name #
Function ".onClick.User"
var /Global USERNAME
Pop $Path_User
${NSD_GetText} $Path_User $0
StrCpy $USERNAME "$0"
SendMessage $Lbl_Show_User ${WM_SETTEXT} 0 "STR:$USERNAME"
FunctionEnd
# Password #
Function ".onClick.Pass"
var /Global PASSWORD
Pop $Path_Pass
${NSD_GetText} $Path_Pass $0
StrCpy $PASSWORD "$0"
SendMessage $Lbl_Show_Pass ${WM_SETTEXT} 0 "STR:$PASSWORD"
FunctionEnd
# Download #
!define fileDownload "!insertmacro fileDownload"
!macro fileDownload Url FileName UserName Password
Push ${Url}
Push ${FileName}
Push ${UserName}
Push ${Password}
Call fileDownload
!macroend
Function fileDownload
Pop $1
Pop $2
Pop $3
Pop $4
DetailPrint "Link: $4"
DetailPrint "Package: $3"
DetailPrint "User Name: $1"
DetailPrint "Password: $2"
DetailPrint "Save Location: $DIRSAVEPACK"
DetailPrint "Downloading $3 ... Please wait few moments ..."
${If} ${RunningX64}
nsExec::ExecToStack /NOUNLOAD '"$EXEDIR\Bin\wget64.exe" --continue --show-progress --no-check-certificate "$4" -O "$DIRSAVEPACK\$3" --user=$2 --password=$1'
Pop $0
Pop $1
IfFileExists "$DIRSAVEPACK\$3" "Successfully" "Failed"
StrCmp $0 1 "Successfully" "Failed"
${If} $0 == "1"
Successfully:
${GetSize} "$DIRSAVEPACK" "/M=$3 /S=0K" $0 $1 $2
IfErrors 0 +2
StrCpy $0 $0 * 1024
IntCmp $0 100 +3 0 +3
IntCmp $0 0 +2 +2 0
IntOp $0 103 + 0
IntOp $0 $0 * 10
IntOp $0 $0 / 1024
StrCpy $1 "$0" "" -1
IntCmp $0 9 +3 +3 0
StrCpy $0 "$0" -1 ""
Goto +2
StrCpy $0 "0"
DetailPrint "Your file $3 was sucessfully download! ($0.$1 MiB)"
Abort
${Else}
Failed:
DetailPrint "Your file $3 was failed download!"
Abort
${EndIf}
${Else}
nsExec::ExecToStack /NOUNLOAD '"$EXEDIR\Bin\wget.exe" --continue --show-progress --no-check-certificate "$4" -O "$DIRSAVEPACK\$3" --user=$2 --password=$1'
Pop $0
Pop $1
IfFileExists "$DIRSAVEPACK\$3" "Successfully1" "Failed1"
StrCmp $0 1 "Successfully1" "Failed1"
${If} $0 == "1"
Successfully1:
${GetSize} "$DIRSAVEPACK" "/M=$3 /S=0K" $0 $1 $2
IfErrors 0 +2
StrCpy $0 $0 * 1024
IntCmp $0 100 +3 0 +3
IntCmp $0 0 +2 +2 0
IntOp $0 103 + 0
IntOp $0 $0 * 10
IntOp $0 $0 / 1024
StrCpy $1 "$0" "" -1
IntCmp $0 9 +3 +3 0
StrCpy $0 "$0" -1 ""
Goto +2
StrCpy $0 "0"
DetailPrint "Your file $3 was sucessfully download! ($0.$1 MiB)"
Abort
${Else}
Failed1:
DetailPrint "Your file $3 was failed download!"
Abort
${EndIf}
${EndIf}
Pop $0
FunctionEnd
# Section #
Section "MAIN" SEC01
DetailPrint `Check if installed required app ...`
IfFileExists "$EXEDIR\Bin\Wget.exe" "NSIS.Detect.Required.App" "NSIS.Download.Required.App"
NSIS.Download.Required.App:
DetailPrint `Downloading wget ...`
CreateDirectory "$EXEDIR\Bin"
${If} ${RunningX64}
inetc::get "https://eternallybored.org/misc/wget/current/wget64.exe" "$EXEDIR\Bin\wget64.exe" /END
Pop $0
StrCmp $0 "OK" +3
MessageBox MB_OK|MB_ICONEXCLAMATION "$0.Error Downloading!"
Goto Cancelled
${Else}
inetc::get "https://eternallybored.org/misc/wget/current/wget.exe" "$EXEDIR\Bin\wget.exe" /END
Pop $0
StrCmp $0 "OK" +3
MessageBox MB_OK|MB_ICONEXCLAMATION "$0.Error Downloading!"
Goto Cancelled
${EndIf}
NSIS.Detect.Required.App:
DetailPrint `Required app is installed...`
CreateDirectory "$DIRSAVEPACK"
${fileDownload} "$LINK" "$PACK" "$USERNAME" "$PASSWORD"
Cancelled:
SetAutoClose true
SectionEnd
# End #
Function ".onGUIEnd"
FunctionEnd