Request: Hooks for file saving/loading

BlitzMax Forums/BlitzMax Module Tweaks/Request: Hooks for file saving/loading

ImaginaryHuman(Posted 2006) [#1]
BRL could you possible add a hook in each of the image loaders/savers so that `SAVEPROGRESS` `LOADPROGRESS` or `PROGRESS` events are generated while the image is being loaded or saved, so us programmers can then create an appropriate progress indicator? I realize this would mean the loader/saver would have to be paused while the hooks are run.


Hotcakes(Posted 2006) [#2]
Good idea.


Byteemoz(Posted 2006) [#3]
It's maybe better to use a StreamWrapper instead of altering the image loaders:

Link: ProgressStream

This should work with all load and save functions that accept a stream as source.
-- Byteemoz


ImaginaryHuman(Posted 2006) [#4]
No idea how to do that, and nor do most people. An event would be easier.


Yan(Posted 2006) [#5]
No idea how to do that, and nor do most people
There's an article included with BMax which explains how to do this. It's labelled as 'advanced', but it's really pretty simple...
"BlitzMax tutorials and articles>Writing custom stream handlers"

You could just use the code Byteemoz has linked to, of course. ;o)


Byteemoz(Posted 2006) [#6]
An event would be easier.

Then replace the Progress() method in TProgressStream with
	Method Progress()
		EmitEvent CreateEvent(EVENT_STREAMPROGRESS, _stream, 0, 0, _readcount, _writecount, ProgressContext)
	EndMethod
and define the EVENT_STREAMPROGRESS constant. The event then contains:
EventSource() = the stream
EventX() = read bytes
EventY() = written bytes
EventData() = progress context (optional)

-- Byteemoz