Sign in to follow this  
Followers 0
Kenkyo

_FTP_ProgressDownload always skip download

7 posts in this topic

I don't know what I'm doing wrong, but _FTP_ProgressDownload don't work for me.

I've tried every place in code, and if it's under first while it stops working in rest of code.

Can someone help me?

#include <FTPEx.au3>
#include <Misc.au3>
#Include <File.au3>
#Include <GuiConstants.au3>
#include <GUIConstantsEx.au3>
#include <FileConstants.au3>
#include <GDIPlus.au3>
#Include <EditConstants.au3>
#include <ProgressConstants.au3>
#include <String.au3>
#include <MsgBoxConstants.au3>
#NoTrayIcon

_GDIPlus_Startup()

$sServer = 'SERVER_ADDRESS'
$sUser = 'USERNAME'
$sPass = 'PASSWORD'

Global $sRemoteFile = "FILE_TO_DOWNLOAD"
Global $sLocalFile = @ScriptDir & "NAME_OF_FILE"
FileDelete($sLocalFile)

Global $Progress2


$Form1 = GUICreate("AwatarMT2 Auto Patch", 300, 500, -1, -1)

$stat = GUICtrlCreateEdit("", 10, 10, 280, 100, BitOR($WS_VSCROLL, $ES_READONLY))
$dpatch = GUICtrlCreateEdit("", 10, 120, 280, 250, BitOR($WS_VSCROLL, $ES_READONLY))
GUICtrlSetData($stat, "AwatarMT2 Auto Patch"&@CRLF&"Sprawdzanie połączenia z serwerem"& @CRLF & GUICtrlRead($stat))
$cancel = GUICtrlCreateButton("Anuluj", 210, 460, 75, 25, 0)
$Progress1 = GUICtrlCreateProgress(10, 390, 280, 20)

$Progress2 = GUICtrlCreateProgress(10, 430, 280, 20)
GUISetState(@SW_SHOW)

Local $hOpen = _FTP_Open('MyFTP Control')
Global $hConn = _FTP_Connect($hOpen, $sServer, $sUser, $sPass, 1)
if $hConn = 0 Then
   GUICtrlSetData($stat, "Błąd połączenia z serwerem aktualizacji."&@CRLF&"Proszę zamknąć patchera i spróbować ponownie"&@CRLF&"za chwilę.")
   MsgBox(48,"Błąd","Błąd połączenia z serwerem aktualizacji")
Else
   GUICtrlSetData($stat, "Pomyślnie połączono z serwerem aktualizacji."&@CRLF&"Rozpoczynam sprawdzanie wersji.")
   Call("Check_version")
EndIf

While 1
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
         _GDIPlus_Shutdown()
         Exit
      Case $cancel
         Exit
   EndSwitch
Wend




func Check_version()
   $hVersion = _FTP_FileOpen($hConn, "version.ini")
   $sVersionCurrent = _HexToString(_FTP_FileRead($hVersion, 10))
   $hFileOpen = FileOpen(@ScriptDir&"/version.ini", $FO_READ)
   $sVersionLocal = FileReadLine($hFileOpen, 1)

   if $hVersion = 0 Then
      GUICtrlSetData($stat, "Plik version.ini nie istnieje na serwerze aktualizacji!"&@CRLF&"Proszę powiadomić pomoc techniczną o problemie."& @CRLF & GUICtrlRead($stat))
      MsgBox(16,"Krytyczny błąd","Brak pliku wersji. Aktualizacja wstrzymana!")
   Elseif $hFileOpen = -1 Then
      GUICtrlSetData($stat, "Plik version.ini nie istnieje!"&@CRLF&"Zostanie on pobrany ponownie."& @CRLF & GUICtrlRead($stat))
   ElseIf StringCompare ($sVersionCurrent, $sVersionLocal) = 0 Then
      GUICtrlSetData($stat,"Klient AwatarMT2 jest aktualny."& @CRLF & GUICtrlRead($stat))
      ;Call("Check_File")
   ElseIf StringCompare ($sVersionCurrent, $sVersionLocal) > 0 Then
      GUICtrlSetData($stat,"Klient AwatarMT2 wymaga aktualizacji." & @CRLF & GUICtrlRead($stat))
     ; Call("Check_File")
     Download_File()
   ElseIf StringCompare ($sVersionCurrent, $sVersionLocal) < 0 Then
      GUICtrlSetData($stat,"O.o NOWSZA WERSJA?" & @CRLF & GUICtrlRead($stat))
      MsgBox(32,"Błąd","Plik version.ini jest niezgodny z najnowszą aktualizacją")
      ;Call("Check_File")
   EndIf
   FileClose($hFileOpen)
   _FTP_FileClose($hVersion)
   return 1
EndFunc


func Check_File()
   _FTP_DirSetCurrent ( $hConn, "AwatarMT2_Update" )
   $aFile = _FTP_ListToArrayEx($hConn, 0,0,1)
   If $aFile[0][0] = 0 Then
      MsgBox(48,"Błąd","Nieznany błąd. Proszę zrestartować patchera.")
   EndIf

   For $i = 1 To $aFile[0][0]
      If($aFile[$i][2] = 16) Then
         GUICtrlSetData($dpatch, "Otwieranie katalogu "&$aFile[$i][0] & @CRLF & GUICtrlRead($dpatch))
         sleep(100)
         _FTP_DirSetCurrent ( $hConn, $aFile[$i][0] )
         $aDirFile = _FTP_ListToArrayEx($hConn, 0,0,1)
         If $aDirFile[0][0] = 0 Then
            MsgBox(48,"Błąd","Nieznany błąd. Proszę zrestartować patchera.")
         EndIf
         For $b = 1 To $aDirFile[0][0]
            GUICtrlSetData($dpatch, "Sprawdzanie pliku "&$aDirFile[$b][0] & @CRLF & GUICtrlRead($dpatch))
            sleep(100)
         Next
         _FTP_DirSetCurrent ( $hConn, "/AwatarMT2_Update" )

      ElseIf ($aFile[$i][2] = 128) Then
         GUICtrlSetData($dpatch, "Sprawdzanie pliku "&$aFile[$i][0] & @CRLF & GUICtrlRead($dpatch))
         sleep(100)
      EndIf
   Next
   return 1
EndFunc

Func Download_File()
   GUICtrlSetData($stat, _FTP_DirGetCurrent($hConn))
   Global $sFunctionToCall = "_UpdateGUIProgressBar"
   _FTP_ProgressDownload($hConn, $sLocalFile, $sRemoteFile, $sFunctionToCall)
   GUISetState(@SW_SHOW)
   _FTP_DirSetCurrent ( $hConn, "/OTHER DIRECTORY" )
   GUICtrlSetData($stat, _FTP_DirGetCurrent($hConn) & @CRLF & GUICtrlRead($stat))
   return 1
EndFunc

Func _UpdateGUIProgressBar($iPercent)
    GUICtrlSetData($Progress2, $iPercent)
    Return 1 ; Otherwise continue Download
EndFunc   ;==>_UpdateGUIProgressBar

I'm from Poland, so if my english is bad, I can only say sorry.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Func _UpdateProgress($iPercent)

    ProgressSet($iPercent, Int($iPercent) & "%")

    Return 1 ; 1 to continue Download

EndFunc   ;==>_UpdateProgress

You're using GUICtrlSetData, while the help file example shows using ProgressSet and the builtin progress bar for the function. Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

it still doesn't helped me. It's not fault of Progress Bar, just download from FTP doesn't started.

Share this post


Link to post
Share on other sites

You should have mentioned that, seeing as how you're using _FTP_ProgressDownload I assumed the issue was with the progress bar. In your local filename are you writing it like @ScriptDir & "Name_of_file" or @ScriptDir & "Name_of_file"? @ScriptDir doesn't include a trailing backslash, so you have to add one to the file name if you aren't already doing that.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

I've done it. I think that main problem is while loop just under connection to FTP (Line 48) It looks like the main loop stops _FTP_ProgressDownload function. It can't do anything because main loop in line 48 is doing something at the same time. I don't know how to use ProgressDownload with this loop, and when I rewrote script without it, everything works fine. There is no problems. So I think that I must rewrite it without this loop, or find a way to use it, because it stops GUI to close after it did everything.

Share this post


Link to post
Share on other sites

_FTP_ProgressDownload is a blocking function, meaning that the script won't continue until it has finished downloading.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

So Why my loop can stop it? ;)

If _FTP_ProgressDownload is higher than 48 line or inside loop in 48 line it works perfectly, but if I put it lower than this loop it can't do anything.

EDIT: I probably found a reason, Maybe I can't do anything like FTP FileOpen? If I'm Correct then it would not work because of other operation on FTP in the same time

Edited by Kenkyo

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0