[Maf] Alternative way of running the maf compressor programs with
nsIProcess
Allister Beharry
ABeharry at infotechcaribbean.com
Mon Dec 13 21:30:13 EST 2004
Hi Chris,
A lot of the problems users are experiencing with maf files
saving/not-saving/only appearing to save, could be diagnosed if there
was a better alternative to the somewhat clumsy way of running the
archive compressor by spawning off an external process using
nsIProcess.run() and just waiting for it to return. I realize that this
method was purely a quick hack to get maf working in a portable way, and
to change the code to call a native XPCOM compressor (which would have
to be written from scratch) is a significant bit of work. In the interim
the following would be an easy way to alert the user of errors during
the maf save process:
1. InfoZip's command-line tools return exit status codes that can be
trapped by nsIProcess.run() and are available in the
nsIProcess.exitValue property. E.g. zip "foo.zip" returns an status code
of 12...nothing to do. Check
http://www.info-zip.org/pub/infozip/FAQ.html down at the bottom for the
complete list of return codes and their meanings. Basically 0 means OK,
anything else means something went awry...either the source file was
missing or the zipped file couldn't be saved or some other bad thing
happened.
2. After you make the call to oProcess.run(true, localProgramArgs,
localProgramArgs.length), test the value oProcess.exitValue. If it's
non-zero then you could say something like obs.notifyObservers(null,
"maf-archiver-failed", oProcess.exitValue).
Testing the exitValue property takes care of the cases where:
a) The maf encoder failed silently and the temp source file wasn't
written...in this case zip will return a non-zero
code since the file to compress just isn't there
b) The zip process itself failed...due to mismatched temp directory
settings or inadequate permissions or something else.
3. When alerting users, you could say if the process failed/succeeded
and tack on the exitValue in the dialog message, so people could report
precisely what error code they got if their file didn't save.
If people on Windows are using invis.vbs then here's an alternative that
will cause the wscript.exe script host to return the status code of the
zip.exe process:
------------------------------------------------------------------------
--------------------------------------------
Option Explicit
Dim wsShell, wsExec, wsExecExitCode
Set wsShell = CreateObject("Wscript.Shell")
Set wsExec = wsShell.Exec("""" & WScript.Arguments(0) & """ """ &
WScript.Arguments(1) & """ """ & WScript.Arguments(2) & """")
Do While wsExec.Status = 0 'Wait unti the process is done executing
WScript.Sleep 10
Loop
wsExecExitCode = wsExec.ExitCode
Set wsExec = Nothing
Set wsShell = Nothing
WScript.Quit wsExecExitCode 'Cause the script engine host to quit with a
defined exit code
------------------------------------------------------------------------
---------------------------------------------
Note: Watch out for any lines that wrap in the above snippet, VB
statements can't span multiple lines
The XPCOM zlib wrapper is on my New Year's Resolutions List...
Allister.
More information about the Maf
mailing list