Old 1st March 2017, 20:08   #1
Aleksey
Junior Member
 
Join Date: Mar 2017
Posts: 3
Exclamation Wget Nsis

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.
Aleksey is offline   Reply With Quote
Old 1st March 2017, 23:02   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,608
...and wget is not a native Windows tool in your opinion?

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 2nd March 2017, 00:09   #3
Aleksey
Junior Member
 
Join Date: Mar 2017
Posts: 3
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.
Aleksey is offline   Reply With Quote
Old 2nd March 2017, 01:21   #4
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,608
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.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 23rd May 2017, 18:06   #5
Coby
Junior Member
 
Join Date: Feb 2016
Posts: 41
My method of downloading files using wget

PHP Code:
# 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 
$${WM_SETTEXT`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 510905"" 
  
Pop $PATH_Link
  Strcpy 
$1 $PATH_Link
  GetFunctionAddress 
$".onClick.Add.Link"
  
nsDialogs::OnChange /NOUNLOAD $$0

  nsDialogs
::CreateControl /NOUNLOAD BUTTON 0x40000000|0x10000000|0x04000000|0x00000007 0x00000080 259615"Add your url:"  
  
Pop $Lbl.Add.Url 

  
# Add Pack # 

  
nsDialogs::CreateControl /NOUNLOAD EDIT 0x40000000|0x10000000|0x04000000|0x00010000|0x00000080 0 525905"" 
  
Pop $PATH_Pack
  Strcpy 
$1 $PATH_Pack
  GetFunctionAddress 
$".onClick.Add.Pack"
  
nsDialogs::OnChange /NOUNLOAD $$0

  nsDialogs
::CreateControl /NOUNLOAD BUTTON 0x40000000|0x10000000|0x04000000|0x00000007 0x00000080 2209615"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 540805"$DIRSAVEPACK
  
Pop $PATH_Save

  nsDialogs
::CreateControl /NOUNLOAD BUTTON 0x40000000|0x10000000|0x04000000|0x00010000 0 874085"Save"
  
Pop $Btn_Save
  StrCpy 
$1 $Btn_Save
  GetFunctionAddress 
$".onClick.Save.Pack"
  
nsDialogs::onClick /NOUNLOAD $$3

  nsDialogs
::CreateControl /NOUNLOAD BUTTON 0x40000000|0x10000000|0x04000000|0x00000007 0x00000080 2359615"Save your pack:"  
  
Pop $Lbl.Save.Pack 

  
# User

  
nsDialogs::CreateControl /NOUNLOAD EDIT 0x40000000|0x10000000|0x04000000|0x00010000|0x00000080 0 1555344"" Username
  Pop $Path_User
  Strcpy 
$1 $Path_User
  GetFunctionAddress 
$".onClick.User"
  
nsDialogs::OnChange /NOUNLOAD $$3

  nsDialogs
::CreateControl /NOUNLOAD STATIC 0x40000000|0x10000000|0x04000000|0x00000100 0x00000020 255124"User:"
  
Pop $Lbl_User

  nsDialogs
::CreateControl /NOUNLOAD STATIC 0x40000000|0x10000000|0x04000000|0x00000100 0x00000020 5055474""
  
Pop $Lbl_Show_User

 
# Password

  
nsDialogs::CreateControl /NOUNLOAD EDIT 0x40000000|0x10000000|0x04000000|0x00010000|0x00000080 0 1565344"" Password
  Pop $Path_Pass
  Strcpy 
$1 $Path_Pass
  SendMessage $Path_Pass 0x00CC 149 0
  GetFunctionAddress 
$".onClick.Pass"
  
nsDialogs::OnChange /NOUNLOAD $$3

  nsDialogs
::CreateControl /NOUNLOAD STATIC 0x40000000|0x10000000|0x04000000|0x00000100 0x00000020 265124"Password:"
  
Pop $Lbl_Pass

  nsDialogs
::CreateControl /NOUNLOAD STATIC 0x40000000|0x10000000|0x04000000|0x00000100 0x00000020 5065474""
  
Pop $Lbl_Show_Pass

  
# Info #

  
nsDialogs::CreateControl /NOUNLOAD STATIC 0x40000000|0x10000000|0x04000000|0x00000100 0x00000020 275965""
  
Pop $Lbl.ShowStatus1

  nsDialogs
::CreateControl /NOUNLOAD STATIC 0x40000000|0x10000000|0x04000000|0x00000100 0x00000020 282965""
  
Pop $Lbl.ShowStatus2

  nsDialogs
::CreateControl /NOUNLOAD STATIC 0x40000000|0x10000000|0x04000000|0x00000100 0x00000020 289965""
  
Pop $Lbl.ShowStatus3

  SendMessage $Lbl
.ShowStatus3 ${WM_SETTEXT"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"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"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"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"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"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} $== "1"
      
Successfully:

      ${
GetSize"$DIRSAVEPACK" "/M=$3 /S=0K" $$$2
      IfErrors 0 
+2
      StrCpy 
$$1024
      IntCmp 
$0 100 +3 0 +3
       IntCmp 
$0 0 ++2 0
       IntOp 
$0 103 0
      IntOp 
$$10
      IntOp 
$$1024
      StrCpy 
$"$0" "" -1
      IntCmp 
$0 9 ++3 0
       StrCpy 
$"$0" -""
       
Goto +2
       StrCpy 
$"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} $== "1"
      
Successfully1:

      ${
GetSize"$DIRSAVEPACK" "/M=$3 /S=0K" $$$2
      IfErrors 0 
+2
      StrCpy 
$$1024
      IntCmp 
$0 100 +3 0 +3
       IntCmp 
$0 0 ++2 0
       IntOp 
$0 103 0
      IntOp 
$$10
      IntOp 
$$1024
      StrCpy 
$"$0" "" -1
      IntCmp 
$0 9 ++3 0
       StrCpy 
$"$0" -""
       
Goto +2
       StrCpy 
$"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 
$"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 
$"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 
Coby is offline   Reply With Quote
Reply
Go Back   Winamp & SHOUTcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump