I'm not sure if you've seen this yet, but a while back someone made a program called
IFI Loader Reloaded which I think does about what you're doing. The source code is included (
here), and that should help you; you could also contact the guy who made it.
Good Luck.