PDA

View Full Version : Progress-Object for File Create (Help???)



mystica
10-23-2009, 12:12 PM
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?):


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)

mystica
10-23-2009, 10:56 PM
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! :p

mystica
10-24-2009, 09:32 PM
Hmmm ... still no takers eh? :huh

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??? :D

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).

mystica
10-28-2009, 02:39 AM
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!

Dermot
10-28-2009, 02:52 AM
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.


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);

mystica
10-28-2009, 02:56 AM
Okay, thanks for that Dermot ... much appreciated.