tags:

views:

152

answers:

3

I have several apps that I work on and like to distribute to friends that require Microsoft Provided .dlls and or frameworks. Specifically, XNA. I'm tired of getting emails back from them saying "It crashed" when in reality, all that's happened is they don't have XNA (or .NET 3.5, or whatever) installed. However, Main can't catch these errors because the .exe loads them before main is even executed.

So, my question is, how would I go about creating a launcher that could check for things like .NET 3.5, XNA, etc. and display a nice error message ("This application requires XNA 3.0, download it here!") instead of looking like it crashed?

UPDATE: I should have specified that I want to do this without using an installer. I have a boiler plate WIX installer that allows me to check for dependencies, but sometimes I just want to upload a zip for people to play around with.

+1  A: 

You could create a setup project (which compiles to an MSI installer) for your application. In the configuration of this installer, you can set prerequisites such as .NET Framework vX.X. I am not absolutely sure about XNA, but I would assume that this can be listed as a prerequisite as well.

Jørn Schou-Rode
What if they uninstall the framework later, but your app is still installed? As far as I know, the .NET framework uninstaller doesn't check whether there are apps that depend on it.
Nathan
@Nathan: What would happen to the apps on your machine if you uninstalled the .NET framework right now? On my machine a LOT of things would probably break. I don't think that's something your app should have to deal with.
Andy West
@Andy: I wish that apps didn't have to deal with it. However, the question here is dealing with exactly this type of problem (which I have also experienced). It is not all that unusual for people to uninstall an older version of the framework after a new one has been installed. At the very least, it would be useful to have a diagnostic in your program to check which versions are available when an error occurs.
Nathan
+1  A: 

This is done most easily during installation. Include the Microsoft XNA Framework Redistributable with your installation package.

You can use the MsiQueryProductState function to determine if the framework is already installed.

Or you could check the registry for:

[HKEY_LOCAL_MACHINE\Software\Microsoft\XNA\Framework\v3.1]
Installed=1

(This check could alternatively be performed in a launcher application.)

Here's an article about distributing your game with a section on detecting and installing prerequisites.

Andy West
+4  A: 

To do this without an installer, you might want to create a "launcher" script that does little more than call the "real" entry point after performing any dependency checks up front.

Since missing dependencies appear to be a very common source of pain for you, it's probably advisable to write the launcher in something that goes out of its way to have no dependencies that aren't already on a bare Windows installation, such as an AutoIt script packaged as an executable.

Const $AppTitle = 'Whizzy Game'
Const $MB_ICONERROR = 16

If RegRead('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5', 'Install') <> 1 Then
    MsgBox($MB_ICONERROR, $AppTitle, 'The .NET Framework runtime v3.5 is required to run.')
    Exit 1
EndIf

If RegRead('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\XNA\Framework\v3.1', 'Installed') <> 1 Then
    MsgBox($MB_ICONERROR, $AppTitle, 'The XNA Framework runtime v3.1 is required to run.')
    Exit 1
EndIf

Exit RunWait('WhizzySoftware.WhizzyGame.EntryPoint.exe')
Jeffrey Hantin
Looks like a good alternative. Can you give me an example of an AutoIt script that would check for, say, .NET 3.5?
Jeff