Indigo Rose Software

Professional Software Development Tools

 
+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    May 2007
    Location
    Sydney, Australia
    Posts
    1,546

    Progress-Object for File Create (Help???)

    I'm trying to add a Progress-Object to a File Create function (ie. TextFile.WriteFromString) ... but just can't get my head around it???

    (Yeah, I know ... why do I need a progress-bar for a textfile, right? Well, let's just say the textfile may be as big as 99mb which can take over 10 seconds to forge ... so it'd be nice to have a progress-bar)

    Here's my project code thus far. (Can someone help out with how to code the Progress Object for this?):

    Code:
    fSize = Input.GetText("Input1");
    index = ComboBox.GetSelected("ComboBox1");
    	if index == 1 then
     	 mFactor = 1
     		elseif index == 2 then
      		 mFactor = 1024
      			elseif index == 3 then
      	 	 	 mFactor = 1048576
    			end
    
    fSizeOutput = fSize * mFactor
    strValue = " "
    strOutput = String.Repeat(strValue, fSizeOutput);
    fSelect = Dialog.FileBrowse(false, "Save File File", _DesktopFolder, "All Files (*.*)|*.*|", "", "", false, false);
    fPath = Table.Concat(fSelect, "", 1, TABLE_ALL);
    
    TextFile.WriteFromString(fPath, strOutput, false)

  2. #2
    Join Date
    May 2007
    Location
    Sydney, Australia
    Posts
    1,546
    Hey Riz ... you out there?

    What I'm working on here, is kinda like of a copy of your Bloat File Maker which you created in PB a while back. (Forgive my blatant ripoff of your idea ... don't worry, just playing around with it in AMS format ... won't be made public or anything). Anyway, you coded a progress-bar in your PB version of this, so was hoping maybe, you'd have an idea of how to go about coding the progress-bar in Lua???

    Go ahead, call me a dirty little copycat ... I can take it!
    Last edited by mystica; 10-23-2009 at 10:05 PM.

  3. #3
    Join Date
    May 2007
    Location
    Sydney, Australia
    Posts
    1,546
    Hmmm ... still no takers eh?

    Does this mean that everyone has as much trouble as me, when it comes to wrapping their head around coding the Progress-Object for various purposes???

    I've looked at quite a few of the examples of using the Progress-Object to display file-downloads and file-copying, and have managed to tweak the examples for use in my own projects when using it for either of the above two purposes ... but I'm really stumped when it comes to using the Progress-Object to display the progress of a large file being written from string.

    Can someone please confirm for me, whether it's even possible to use the Progress-Object for this particular purpose??? I've attached a basic 'slimmed-down' example .apz file of what I'm doing here ... just to make it easier to follow what I'm trying to achieve.

    Basically, I just need to know how to code the Progress-Bar at the bottom of the application, so it shows to the user that the file being created, is in the process of being written. (The progress-bar becomes necessary when the size of the file being written exceeds 20MB ... as will be apparent if looking at the .apz-example I've attached).

  4. #4
    Join Date
    May 2007
    Location
    Sydney, Australia
    Posts
    1,546
    Geez Louise! Cat got everyone's tongue on this topic??? Starting to feel like a bit of a leper here! C'mon guys, where's the love??? Prr-retty please!
    Last edited by mystica; 10-28-2009 at 01:41 AM.

  5. #5
    Join Date
    Apr 2004
    Location
    Vancouver, Canada
    Posts
    1,790
    You can't, there is no way to measure how long it will take and there is no callback, so there is no way hook it into a progressbar. Just show a label saying Please wait.. file is being saved.

    The only way it could be done is to write the file in junks. That way you could use a progressbar but it will take way way longer to write the file, especially large files.

    Code:
    local index = ComboBox.GetSelected("ComboBox1");
    
    if index == 1 then
    	mFactor = 1
     elseif index == 2 then
      	mFactor = 1024
     elseif index == 3 then
      	mFactor = 1048576
     end
    
    local fSelect = Dialog.FileBrowse(false, "Save File", _SourceFolder, "All Files (*.*)|*.*|", "example-file written from string.dat", "", false, false);
    
    local fSizeOutput = fSize * mFactor
    
    local strValue = " "
    
    Progress.SetRange("Progress1", 0, fSizeOutput)
    
    local file = assert(io.open(fSelect[1], "w"))
    
    for n = 1, fSizeOutput do
    
    	file:write(strValue)
    	Progress.StepIt("Progress1")
    	
    end
    
    file:close()
    
    File.Open(_SourceFolder, "", SW_SHOWNORMAL);
    Dermot

    I am so out of here

  6. #6
    Join Date
    May 2007
    Location
    Sydney, Australia
    Posts
    1,546
    Okay, thanks for that Dermot ... much appreciated.

Posting Permissions

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