Andromo - Start Making Apps - Free Signup

Announcement

Collapse

New Forum Software

If you're here, you've found the new home for our forums. There will be some bugs to iron out, so thanks for your patience...
See more
See less

http download

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • http download

    is it also possible to

    see what is the downloadspeed on that moment
    when donloading some files thru http

    how do i do that hope it is simple :lol

    thx

  • #2
    you may need to create a 'callback function' during the download

    http download action has a reference to a variable callback called: TransferRate
    so in your callback function you could have something like this as a part of a
    display string

    Code:
    local strkbs = string.format("%.2f",TransferRate); --converts to 2 decimal places
    strKbsRate = " - Transfer Rate: "..strkbs.." KB/Sec";
    hth a little
    Last edited by Eagle; 10-28-2005, 09:54 AM.

    Comment


    • #3
      sorry i am a newby

      where must i put your code can you show me how

      here is the script

      Code:
      -- the correct password "valid"
      real_password = "";
      
      -- prompt the user to enter a password
      user_password = Dialog.PasswordInput("Password", "Please enter the password: ", MB_ICONQUESTION);
      
      -- compare the user's password to the correct password.
      -- If the user supplies the wrong password, exit the program.
      if real_password ~= user_password then
          Application.Exit();
      end-- VARIABLES THAT SHOULD BE CHANGED: THESE ARE THE THINGS YOU SHOULD CHANGE TO MAKE THIS WORK AS YOU WANT IT TO
      sURL = ""; -- where you'll download from
      sDestination = ""; -- Where the files should be 'installed' to
      sZipPassword = ""; -- the password to your zip file (or "" for no password)
      
      -- VARIABLES THAT PROBABLY SHOULDN'T BE CHANGED
      -- HTTP Action Variables
      sDownloadFolder = _TempFolder .. ""; -- temp location to download to
      sDownloadFileName = ""; -- Temp filename to use
      nDownloadMode = MODE_BINARY; -- The download mode to use
      nTimeout = 20; -- The timeout in seconds for your http server
      nPort = 80; -- The port your http server uses
      tProxyData = nil; -- a table of proxy data (nil for none)
      tAuthData = nil; -- A table of http auth data (nil for none)
      
      -- Zip Action Variables
      nZipOverwrite = ZIP_OVERWRITE_ALWAYS; -- How existing files should be handled
      bRecurse = true; -- How zip file recursion should be handled
      bUseInternalFolderStructure = true; -- Whether the folder structure in the zip file should be used when extracting
      tFilesToExtract = {"*.*"} -- A table of files to extract ({"*.*"} to extract everything
      
      
      
      
      -- Callback function for zip action
      function ZipCallback(sDestinationPath, nPercentage, nStatus)
      	Label.SetText("L_Status2", "Installing:");
      	-- Update progress bar if percentage is for entire zip file	
      	if nStatus == ZIP_STATUS_MAJOR then
      		-- Info is for zip file as a whole, update progress
      		Progress.SetCurrentPos("Progress2", nPercentage);
      		UpdateOverallTaskProgress(2, nPercentage);
      		Progress.SetText("Progress2", "Installing (" .. nPercentage .. "%)");
      	end
      	-- No matter what, we want to continue extracting!
      	return true;
      end
      
      
      -- callback function for http.download action
      function HTTPCallback (nBytesRead, nFileSize, nTransferRate, nSecondsLeft, sSecondsLeftFormat, sMessage)
      	-- check if current message is a server status message
      	if sMessage == "" then
      		-- no server message is present, update status
      		Label.SetText("L_Status2", "Downloading:");
      		nPercent = Math.Round((nBytesRead/nFileSize)*100,0);
      		Progress.SetCurrentPos("Progress2", nPercent);
      		Progress.SetText("Progress2", nPercent .. "%");
      		UpdateOverallTaskProgress(1, nPercent);
      	end
      	-- keep the download running!
      	return true;
      end
      
      
      -- Update the overall task progress - called from both above callback functions
      function UpdateOverallTaskProgress (nTaskNumber, nTaskPercentComplete)
      	nTotalTasks = 2;
      	Progress.SetRange("Progress1", 1, 100*nTotalTasks);
      	Progress.SetCurrentPos("Progress1", (nTaskNumber-1)*100 + nTaskPercentComplete);
      end
      
      -- Error checking function (not needed, but it makes error checking easier)
      function CheckError(sOptionalMessage)
      	-- get the last error
      	err = Application.GetLastError();
      	if err ~= 0 then
      	-- last error wasn't 'success', check it out!
      		if sOptionalMessage then
      			-- An optional message was provided, tack it on to the output
      			sTitle = "ERROR (" .. sOptionalMessage .. ")";
      			sMessage = err .. ": " .. _tblErrorMessages[err];
      		else
      			-- No optional message, just output the error
      			sTitle = "ERROR";
      			sMessage = err .. ": " .. _tblErrorMessages[err];
      		end
      	-- output to the user!
      	Dialog.Message(sTitle, sMessage);
      	end
      end
      
      
      
      
      
      
      -- Ensure temp destination folder exists
      Folder.Create(sDownloadFolder);
      CheckError("Folder.Create");
      	
      -- Download the zip file
      HTTP.Download(sURL, sDownloadFolder .. "\\" .. sDownloadFileName, nDownloadMode, nTimeout, nPort, tHTTPAuth, tProxyData, HTTPCallback);
      CheckError("HTTP.Download");
      
      -- Ensure install to directory exists
      Folder.Create(sDestination);
      CheckError("Folder.Create");
      	
      -- Extract the contents of the zip file to the specified folder
      Zip.Extract(sDownloadFolder .. "\\" .. sDownloadFileName, tFilesToExtract, sDestination, bRecurse, bUseInternalFolderStructure, sZipPassword, nZipOverwrite, ZipCallback);
      CheckError("Zip.Extract");
      
      -- Delete the temporarily downloaded file
      File.Delete(sDownloadFolder .. "\\" .. sDownloadFileName, false, false, false, nil);
      CheckError("File.Delete");
      	
      -- Delete the temp download folder
      Folder.Delete(sDownloadFolder);
      CheckError("Folder.Delete");
      	
      -- Clean up output
      Progress.SetText("Progress1", "");
      Progress.SetText("Progress2", "");
      Progress.SetCurrentPos("Progress1", 0);
      Progress.SetCurrentPos("Progress2", 0);
      Label.SetText("L_Status2", "");

      hope it works in this code

      Thx

      CAI

      Comment


      • #4
        Hi, a couple of alternate places in your existing code..thks for posting :yes


        Code:
        -- callback function for http.download action
        function HTTPCallback (nBytesRead, nFileSize, nTransferRate, nSecondsLeft, sSecondsLeftFormat, sMessage)
        	-- check if current message is a server status message
        	if sMessage == "" then
        		-- no server message is present, update status
        		local strkbs = string.format("%.2f",nTransferRate);
        --here perhaps	Label.SetText("L_Status2", "Downloading: ".."  - Transfer Rate: "..strkbs.." kb/s"); 
        		nPercent = Math.Round((nBytesRead/nFileSize)*100,0);
        		Progress.SetCurrentPos("Progress2", nPercent);
        --or here	Progress.SetText("Progress2", nPercent .. "%".."  - Transfer Rate: "..strkbs.." kb/s");
        		UpdateOverallTaskProgress(1, nPercent);
        	end
        	-- keep the download running!
        	return true;
        end
        ..all ya doin is appending it to a current display string (while downloading)
        so just tweak it how you would like it displayed.

        Comment


        • #5
          :o hello i am using this callback right now Its great

          Code:
          HTTP.Download("", "", MODE_BINARY, 20, 80, nil, nil, nameOfCallback);
          -- Callback function for HTTP.Download
          function DownloadCallback (nDownloaded, nTotal, TransferRate, SecondLeft, SecondsLeftFormat, Message)
              -- Convert total and downloaded bytes into formatted strings
              sDownloaded = String.GetFormattedSize(nDownloaded, FMTSIZE_AUTOMATIC, true);
              sTotal = String.GetFormattedSize(nTotal, FMTSIZE_AUTOMATIC, true);
          
              -- Output time left, formatted.
              StatusDlg.SetMessage("Currently downloading file . . . Time Left: " .. SecondsLeftFormat);
              
              -- Output formatted sizes to user through statusdlg status text
              StatusDlg.SetStatusText("Downloaded: " .. sDownloaded .. " / " .. sTotal);
          
              -- Set meter position (fraction downloaded * max meter range)
              StatusDlg.SetMeterPos((nDownloaded / nTotal) * 65534);
          end
          
          
          
          -- Show the StatusDlg
          StatusDlg.Show(0, false);
          
          -- Set statusdlg title and message
          StatusDlg.SetTitle("Downloading . . . ");
          
          -- Set meter range (max range = 65534)
          StatusDlg.SetMeterRange(0, 65534);
          
          -- Download a file from the internet to the user's computer
          -- Uses DownloadCallback() as the callback function
          HTTP.Download("", "", MODE_BINARY, 20, 80, nil, nil, DownloadCallback);
          
          -- Hide the StatusDlg
          StatusDlg.Hide();

          but how can i also set this one in to the other

          so i also see the speed when donloading something

          Code:
          local strkbs = string.format("%.2f",TransferRate); --converts to 2 decimal places
          strKbsRate = " - Transfer Rate: "..strkbs.." KB/Sec";
          don't know where to put this


          who can show me how so everything can be called when downloading

          exp the speed


          thx

          Comment


          • #6
            anybody can help me

            Eagle where are you


            Grtz

            CAI

            Comment


            • #7
              Eagle is\was here, what have you tried yourself

              Comment


              • #8
                Code:
                HTTP.Download("", "", MODE_BINARY, 20, 80, nil, nil, nameOfCallback);
                -- Callback function for HTTP.Download
                function DownloadCallback (nDownloaded, nTotal, TransferRate, SecondLeft, SecondsLeftFormat, Message)
                    -- Convert total and downloaded bytes into formatted strings
                    sDownloaded = String.GetFormattedSize(nDownloaded, FMTSIZE_AUTOMATIC, true);
                    sTotal = String.GetFormattedSize(nTotal, FMTSIZE_AUTOMATIC, true);
                
                    -- Output time left, formatted.
                    local strkbs = string.format("%.2f",TransferRate); --converts to 2 decimal places
                    strKbsRate = "\r\nTransfer Rate: "..strkbs.." KB/Sec";
                    StatusDlg.SetMessage("Currently downloading file . . . Time Left: " .. SecondsLeftFormat..strKbsRate);
                    
                    -- Output formatted sizes to user through statusdlg status text
                    StatusDlg.SetStatusText("Downloaded: " .. sDownloaded .. " / " .. sTotal);
                
                    -- Set meter position (fraction downloaded * max meter range)
                    StatusDlg.SetMeterPos((nDownloaded / nTotal) * 65534);
                end
                
                
                
                -- Show the StatusDlg
                StatusDlg.Show(0, false);
                
                -- Set statusdlg title and message
                StatusDlg.SetTitle("Downloading . . . ");
                
                -- Set meter range (max range = 65534)
                StatusDlg.SetMeterRange(0, 65534);
                
                -- Download a file from the internet to the user's computer
                -- Uses DownloadCallback() as the callback function
                HTTP.Download("", "", MODE_BINARY, 20, 80, nil, nil, DownloadCallback);
                
                -- Hide the StatusDlg
                StatusDlg.Hide();
                Is that what you are looking to do?
                TJ-Tigger
                "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
                "Draco dormiens nunquam titillandus."
                Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

                Comment


                • #9
                  How a table of proxy-parameters must really look for HTTP.Download?

                  Comment


                  • #10
                    It is needed get proxy data from INI-file and use it with HTTP.Download.
                    How is it correct to realize it in the HTTP.Download?

                    Comment


                    • #11
                      Originally posted by TJ_Tigger View Post
                      Code:
                      HTTP.Download("", "", MODE_BINARY, 20, 80, nil, nil, nameOfCallback);
                      -- Callback function for HTTP.Download
                      function DownloadCallback (nDownloaded, nTotal, TransferRate, SecondLeft, SecondsLeftFormat, Message)
                          -- Convert total and downloaded bytes into formatted strings
                          sDownloaded = String.GetFormattedSize(nDownloaded, FMTSIZE_AUTOMATIC, true);
                          sTotal = String.GetFormattedSize(nTotal, FMTSIZE_AUTOMATIC, true);
                      
                          -- Output time left, formatted.
                          local strkbs = string.format("%.2f",TransferRate); --converts to 2 decimal places
                          strKbsRate = "\r\nTransfer Rate: "..strkbs.." KB/Sec";
                          StatusDlg.SetMessage("Currently downloading file . . . Time Left: " .. SecondsLeftFormat..strKbsRate);
                          
                          -- Output formatted sizes to user through statusdlg status text
                          StatusDlg.SetStatusText("Downloaded: " .. sDownloaded .. " / " .. sTotal);
                      
                          -- Set meter position (fraction downloaded * max meter range)
                          StatusDlg.SetMeterPos((nDownloaded / nTotal) * 65534);
                      end
                      
                      
                      
                      -- Show the StatusDlg
                      StatusDlg.Show(0, false);
                      
                      -- Set statusdlg title and message
                      StatusDlg.SetTitle("Downloading . . . ");
                      
                      -- Set meter range (max range = 65534)
                      StatusDlg.SetMeterRange(0, 65534);
                      
                      -- Download a file from the internet to the user's computer
                      -- Uses DownloadCallback() as the callback function
                      HTTP.Download("", "", MODE_BINARY, 20, 80, nil, nil, DownloadCallback);
                      
                      -- Hide the StatusDlg
                      StatusDlg.Hide();
                      Is that what you are looking to do?
                      im gettn an error :'( hehe the error is that strkbs is a nil value .. i wondered if this script can be adjusted te catch all files that are tried to download within the app..?

                      Comment


                      • #12
                        Originally posted by TristanD View Post
                        im gettn an error :'( hehe the error is that strkbs is a nil value .. i wondered if this script can be adjusted te catch all files that are tried to download within the app..?
                        Try this mate:
                        Code:
                        function DownloadCallback (nDownloaded, nTotal, TransferRate, SecondLeft, SecondsLeftFormat, Message)
                            -- Convert total and downloaded bytes into formatted strings
                            sDownloaded = String.GetFormattedSize(nDownloaded, FMTSIZE_AUTOMATIC, true);
                            sTotal = String.GetFormattedSize(nTotal, FMTSIZE_AUTOMATIC, true);
                            local strkbs = string.format("%.0f",TransferRate); --converts to xxx KB/s format
                            strKbsRate = "\r\nTransfer Rate: "..strkbs.." KB/Sec";
                            StatusDlg.SetTitle("Currenntly Downloading... Please be patient!");
                            StatusDlg.SetMessage("Downloading File: "..path_parts.Filename..path_parts.Extension.. "     Downloaded: " .. sDownloaded .. " / " .. sTotal);
                            -- Output formatted sizes to user through statusdlg status text
                            StatusDlg.SetStatusText("Time Left: " .. SecondsLeftFormat.."    Transfer Rate: "..strkbs.." KB/s");
                            -- Set meter position (fraction downloaded * max meter range)
                            StatusDlg.SetMeterPos((nDownloaded / nTotal) * 65534);
                        end
                        This is the code I use and it works quite well, I hope it will help you out too

                        Comment


                        • #13
                          Originally posted by BAZ1301 View Post
                          It is needed get proxy data from INI-file and use it with HTTP.Download.
                          How is it correct to realize it in the HTTP.Download?
                          Code:
                          --[[
                          
                          INIFile should look like this.
                          
                          	[Proxy]
                          	 Username = Anonymous
                          	 Password = Anonymous
                          	 Address = 127.0.0.1
                          
                          ]]--
                          
                          Path = _ProgramFilesFolder.."\\My Program\\Proxy.ini";
                          
                          local Proxy = {};
                          
                          Proxy.PUsername = INIFile.GetValue(Path, "Proxy", "Username");
                          Proxy.PPassword = INIFile.GetValue(Path, "Proxy", "Password");
                          Proxy.PServerAddress = INIFile.GetValue(Path, "Proxy", "Address");
                          
                          --HTTP.Download(x, x, x, x, x, x, Proxy, x);

                          Comment

                          Working...
                          X