Indigo Rose Software

Professional Software Development Tools

 
+ Reply to Thread
Results 1 to 13 of 13
  1. #1
    Join Date
    Jun 2008
    Posts
    165

    Star Possible bug with Path.parts??

    Hi!
    I think there may be a bug with the path.parts command, could anybody please confirm or deny?

    I have made an automated downloader for MS updates, in a text file I have the name of the update and then a Delimiter, then the download location, on running the app loads this into the listbox, it mostly goes well, but it fails with long names, let me show you the code I am using:

    Code:
    sItems = ListBox.GetCount("ListBox1");
    
    for count = 1, sItems do
    	strItemData = ListBox.GetItemData("ListBox1", count);
    	path_parts = String.SplitPath(strItemData);
    	StatusDlg.Show(0, false);
    	StatusDlg.SetTitle("Downloading Your Files... Please be patient!");
    	StatusDlg.ShowCancelButton(true, "Cancel");
    	StatusDlg.SetMeterRange(0, 65534);
    	HTTP.Download(strItemData, sDloadFold.."\\"..path_parts.Filename..path_parts.Extension, MODE_BINARY, 20, 80, nil, nil, DownloadCallback);
    	StatusDlg.Hide();
    end
    The above code is on click for a button, it works with most download locations, BUT say the location is a long one, such as:
    Code:
    http://www.microsoft.com/downloads/info.aspx?na=41&srcfamilyid=50c334e1-9a67-4b99-a65a-069b79267856&srcdisplaylang=en&u=http%3a%2f%2fdownload.microsoft.com%2fdownload%2f5%2ff%2fd%2f5fdc6240-2127-42b6-8e16-bab6171db233%2fWindowsXP-KB898461-x86-ENU.exe
    it fails to download and I dont know why

    Can somebody check this and tell me why please?

  2. #2
    Join Date
    Apr 2005
    Location
    São Paulo, Brazil
    Posts
    2,539
    Well, String.SplitPath() is for splitting paths into drive, folders, filename, and file extension, not for the splitting of URLs into domain, folder, etc.
    You could use DelimitedStringToTable(), splitting at "%2f", and then show the last element of the table.

    Ulrich
    Last edited by Ulrich; 08-21-2011 at 09:12 PM. Reason: typo

  3. #3
    Join Date
    Jun 2008
    Posts
    165
    Thank you Ulrich for your reply!
    Normally path.parts does work for downloading files as I have a portable downloader that uses the same code to download files, and as I wasnt sure if I was missing something out, I pasted the URL into it to download and it wouldnt which told me I wasnt missing anything!

    I already have a DelimitedString function in Globals, the full code in Globals is:
    Code:
    function DelimitedStringToTable(DelimitedString, Delimiter)
    	tbReturn = {};
    	local strWorking;
    	local nPos = nil;
    	local strData;
    	local nTableIndex = 1;
    	local nDelimiterLength = String.Length(Delimiter);
    	
    	if(nDelimiterLength < 1)then
    		tbReturn[nTableIndex] = DelimitedString;
    		return tbReturn;
    	end
    	
    	strWorking = DelimitedString;
    	nPos = String.Find(strWorking,Delimiter);
    	while(nPos ~= -1)do
    		strData = String.Left(strWorking,nPos-1);
    		tbReturn[nTableIndex] = strData;
    		nTableIndex = nTableIndex + 1;
    		local nLength = String.Length(strWorking);
    		strWorking = String.Right(strWorking,nLength - (nPos + (nDelimiterLength-1)));
    		nPos = String.Find(strWorking,Delimiter);
    	end
    	if(strWorking ~= "")then
    		tbReturn[nTableIndex] = strWorking;
    	end
    	
    	return tbReturn;
    end
    
    function DownloadCallback (nDownloaded, nTotal, TransferRate, SecondLeft, SecondsLeftFormat, Message)
        sDownloaded = String.GetFormattedSize(nDownloaded, FMTSIZE_AUTOMATIC, true);
        sTotal = String.GetFormattedSize(nTotal, FMTSIZE_AUTOMATIC, true);
        local strkbs = string.format("%.0f",TransferRate); --converts to xxxKB/s format
        strKbsRate = "\r\nTransfer Rate: "..strkbs.." KB/Sec";
        StatusDlg.SetTitle("Currenntly Downloading... Please be patient!");
        StatusDlg.ShowCancelButton(true, "Cancel");
        StatusDlg.SetAutoSize(true);
    --    StatusDlg.SetMessage("Downloading File:  "..path_parts.Filename..path_parts.Extension.. "    Downloaded: " .. sDownloaded .. " / " .. sTotal);
        StatusDlg.SetStatusText("Time Left: " .. SecondsLeftFormat.."    Transfer Rate: "..strkbs.." KB/s");
    	StatusDlg.SetMeterPos((nDownloaded / nTotal) * 99);
       if StatusDlg.IsCancelled() then
            StatusDlg.Hide();
            return false;
    end
    end
    I have already posted the On-Click button code, so where would your example need to go, globals or button on-click?

    Thanks again!
    Steevie.

  4. #4
    Join Date
    Apr 2005
    Location
    São Paulo, Brazil
    Posts
    2,539
    I would tackle this a bit differently. See here what I propose:

    Code:
    require("DelimitedStringFunctions");
    
    local sURL = "http://www.microsoft.com/downloads/info.aspx?na=41&srcfamilyid=50c334e1-9a67-4b99-a65a-069b79267856&srcdisplaylang=en&u=http%3a%2f%2fdownload.microsoft.com%2fdownload%2f5%2ff%2fd%2f5fdc6240-2127-42b6-8e16-bab6171db233%2fWindowsXP-KB898461-x86-ENU.exe";
    local sFolder = _TempFolder;
    local sFilename = "";
    
    function DownloadCallback (nDownloaded, nTotal, TransferRate, SecondLeft, SecondsLeftFormat, Message)
        sDownloaded = String.GetFormattedSize(nDownloaded, FMTSIZE_AUTOMATIC, true);
        sTotal = String.GetFormattedSize(nTotal, FMTSIZE_AUTOMATIC, true);
        local strkbs = string.format("%.0f",TransferRate); --converts to xxxKB/s format
        strKbsRate = "\r\nTransfer Rate: "..strkbs.." KB/Sec";
      StatusDlg.SetMessage("Downloading File:  "..sFilename);
        StatusDlg.SetStatusText("Time Left: " .. SecondsLeftFormat.."    Transfer Rate: "..strkbs.." KB/s");
      StatusDlg.SetMeterPos((nDownloaded / nTotal) * 99);
       if StatusDlg.IsCancelled() then
            StatusDlg.Hide();
            return false;
      end
    end
    
    Dialog.Message("Info", "Original URL:\n"..sURL, MB_OK);
    sURL = String.Replace(sURL, "%2f", "/", false);
    Dialog.Message("Info", "New URL:\n"..sURL, MB_OK);
    
    local tSplit = DelimitedStringToTable(sURL, "/");
    if (#tSplit > 0) then
      sFilename = tSplit[#tSplit];
      Dialog.Message("Info", "Now starting download of "..sFilename, MB_OK);
    
      StatusDlg.Show(0, false);
      StatusDlg.SetMeterRange(0, 65534);
      StatusDlg.SetTitle("Currenntly Downloading... Please be patient!");
      StatusDlg.ShowCancelButton(true, "Cancel");
      StatusDlg.SetAutoSize(true);
      HTTP.Download(sURL, sFolder.."\\"..sFilename, MODE_BINARY, 20, 80, nil, nil, DownloadCallback);
      StatusDlg.Hide();
    end
    Take this code and paste it in a new project. Add the DelimitedStringFunctions.lua file to the project and preview. Adapt as required.

    Ulrich
    Last edited by Ulrich; 08-22-2011 at 11:56 AM.

  5. #5
    Join Date
    Jun 2008
    Posts
    165
    Thanks Ulrich, but where do I find the DelimitedStringFunctions.lua file?
    I have done a search in the AMS 7 program directory & sub-directories but this file cannot be found and I cant see an attachment to your post, please could you advise where to get this file please?

    Thanks and sorry for being helpfull!

    Steevie.

  6. #6
    Join Date
    Apr 2005
    Location
    São Paulo, Brazil
    Posts
    2,539
    Please check out the Gallery/Scripts sub folder of your AutoPlay Media Studio installation.

    Ulrich

  7. #7
    Join Date
    Jun 2008
    Posts
    165
    Thanks again Ulrich!
    I found the file & I had a quick look at your example and I am pleased to say it works perfectly thank you very muchly
    I will have a proper play around with the code tomorrow and try to integrate it into my original downloader app!

    Thanks again & sorry for being retarded not finding the file hehe

    Steevie.

  8. #8
    Join Date
    Jun 2008
    Posts
    165
    Hi! I am having problems yet again :-( this was soo simple when I first made this a few years ago!

    My new globals is:
    Code:
    function DelimitedStringToTable(DelimitedString, Delimiter)
    	tbReturn = {};
    	local strWorking;
    	local nPos = nil;
    	local strData;
    	local nTableIndex = 1;
    	local nDelimiterLength = String.Length(Delimiter);
    	
    	if(nDelimiterLength < 1)then
    		tbReturn[nTableIndex] = DelimitedString;
    		return tbReturn;
    	end
    	
    	strWorking = DelimitedString;
    	nPos = String.Find(strWorking,Delimiter);
    	while(nPos ~= -1)do
    		strData = String.Left(strWorking,nPos-1);
    		tbReturn[nTableIndex] = strData;
    		nTableIndex = nTableIndex + 1;
    		local nLength = String.Length(strWorking);
    		strWorking = String.Right(strWorking,nLength - (nPos + (nDelimiterLength-1)));
    		nPos = String.Find(strWorking,Delimiter);
    	end
    	if(strWorking ~= "")then
    		tbReturn[nTableIndex] = strWorking;
    	end
    	
    	return tbReturn;
    end
    
    function DownloadCallback (nDownloaded, nTotal, TransferRate, SecondLeft, SecondsLeftFormat, Message)
        sDownloaded = String.GetFormattedSize(nDownloaded, FMTSIZE_AUTOMATIC, true);
        sTotal = String.GetFormattedSize(nTotal, FMTSIZE_AUTOMATIC, true);
        local strkbs = string.format("%.0f",TransferRate); --converts to xxxKB/s format
        strKbsRate = "\r\nTransfer Rate: "..strkbs.." KB/Sec";
      StatusDlg.SetMessage("Downloading File:  "..sFilename);
        StatusDlg.SetStatusText("Time Left: " .. SecondsLeftFormat.."    Transfer Rate: "..strkbs.." KB/s");
      StatusDlg.SetMeterPos((nDownloaded / nTotal) * 99);
       if StatusDlg.IsCancelled() then
            StatusDlg.Hide();
            return false;
      end
    end
    Button on-click is:
    Code:
    sItems = ListBox.GetCount("ListBox1");
    
    for count = 1, sItems do
    	strItemData = ListBox.GetItemData("ListBox1", count);
    	require("DelimitedStringFunctions");
    	local sURL = strItemData
    	local sFilename = "";
    	local sFolder = sWInXP;
    
    local tSplit = DelimitedStringToTable(sURL, "/");
    if (#tSplit > 0) then
      sFilename = tSplit[#tSplit];
      StatusDlg.Show(0, false);
      StatusDlg.SetMeterRange(0, 65534);
      StatusDlg.SetTitle("Currenntly Downloading... Please be patient!");
      StatusDlg.ShowCancelButton(true, "Cancel");
      StatusDlg.SetAutoSize(true);
      HTTP.Download(sURL, sWinXP.."\\"..sFilename, MODE_BINARY, 20, 80, nil, nil, DownloadCallback);
      StatusDlg.Hide();
    end
    end
    BUT I get the following error on run:

    Error: attempt to concatenate global 'sFilename' (a nil value)
    Why oh WHY cant i ever get things working first time?

  9. #9
    Join Date
    Jun 2007
    Location
    Delphi II
    Posts
    1,534
    StatusDlg.SetMessage("Downloading File: "..sFilename);
    The variable 'sFilename' is not populated or declared anywhere...it's nil just like the error says.
    Action Plugins
    AllOn | Box | Class | Code | Cursor | DXML | Error | Frames | GlobalPaths | Group | INIPlus |KeyBind | KeyLock | MathEx | Menu | Name | Project | Resize | StatusBar
    Download

  10. #10
    Join Date
    Jun 2008
    Posts
    165
    Oh yeah, silly me, I see where I went wrong!
    Thats what ya get with just copying & pasting hehe

  11. #11
    Join Date
    Jun 2008
    Posts
    165
    EDIT #1:

    Being as I cant edit posts, I had to make another post!

    The thing I dont get is that
    Code:
    local tSplit = DelimitedStringToTable(sURL, "/");
    if (#tSplit > 0) then
      sFilename = tSplit[#tSplit];
    works in the example, BUT when I paste it into my project, it dont work!
    It says that sFilename is a nil value, but it shouldnt be as it has data from the sURL so I dont know where I am going wrong with it, not sure if Im just not in the mood to 'get it' as I mostly have to be in the mood to sit down & really get into the coding!

    This project was first started about 2 years ago and it worked then, it was originally started in AMS 7.5, which I went back to the other night but no longer works, I am really sorry, I really am, but I just cannot see why this code is not working :(

  12. #12
    Join Date
    Jun 2008
    Posts
    165
    Quote Originally Posted by SteevieNiteHeat View Post
    EDIT #1:

    Being as I cant edit posts, I had to make another post!

    The thing I dont get is that
    Code:
    local tSplit = DelimitedStringToTable(sURL, "/");
    if (#tSplit > 0) then
      sFilename = tSplit[#tSplit];
    works in the example, BUT when I paste it into my project, it dont work!
    It says that sFilename is a nil value, but it shouldnt be as it has data from the sURL so I dont know where I am going wrong with it, not sure if Im just not in the mood to 'get it' as I mostly have to be in the mood to sit down & really get into the coding!

    This project was first started about 2 years ago and it worked then, it was originally started in AMS 7.5, which I went back to the other night but no longer works, I am really sorry, I really am, but I just cannot see why this code is not working :(

    Sorry for the long bump, but I still havent got anywhere and I really need help to complete my downloader, please can somebody help? :-)

  13. #13
    Join Date
    Apr 2005
    Location
    São Paulo, Brazil
    Posts
    2,539
    This code does not work in AutoPlay Media Studio 7.5 because it uses Lua 5.1 syntax. If you use AMS 7.5, you should place your questions here instead.

    Ulrich

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts