waspy
Posts: 64
Joined: Fri Oct 03, 2008 10:58 am

Displaying error dialog if the file is not found.

Hello guys,
I'd like to do the following:
When user specifies installation directory for the product, I need to check if the directory he's chosen contains a certain file. If it doesn't, I need to display an error dialog and stay on the same page (directory selection). How can I set Advanced Installer to fo this?

Thanks a lot in advance,
Alex
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Displaying error dialog if the file is not found.

Hi Alex,

For what you need you can try this approach:
1) Create a custom action which finds the file by using the path in the APPDIR property.
2) Based on the result of this search, the custom action should set an installer property.
3) Add the custom action as an "UI Custom Action"
4) Set it to run when the "Next" button is pushed on "FolderDlg"
5) Use the property set by the custom action like explained in the Make sure an edit box is not empty how-to

Basically, the property will let the package know if the file was found or not. If it wasn't found, it will trigger another custom action which shows a custom message. Also, the user will not be able to proceed. If you have questions about this, don't hesitate to ask.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
waspy
Posts: 64
Joined: Fri Oct 03, 2008 10:58 am

Re: Displaying error dialog if the file is not found.

Hi Cosmin,
1. It's not very clear which custom action type should I use to set an Installer property. I saw BrowseForFile predifined custom action, but I don't have a clue where to specify parameters for a file I'm looking for and a property to set when it's found or not.
2. When I want to trigger the action when the button in the dialog is pressed I don't see the custom action in the list of available actions...

Would it be possible to send more details or a sample maybe?

Thank you very much for your support,
Alex
waspy
Posts: 64
Joined: Fri Oct 03, 2008 10:58 am

Re: Displaying error dialog if the file is not found.

To be more precise:
I see that BrowseForFile is a different kind of action and won't help me, so I can create a VBS script and link to it via "DoAction" in a button events. Ok, clear, but I still miss the the part of how to pass a search path to the function and set a property based on its execution result. Then I should simply use this property as a condition to NewDialog event.
I would apprecaiate if you could clear just this bit for me...

Thank a lot,
Alex
canhuth
Posts: 241
Joined: Thu Jun 19, 2008 9:03 am

Re: Displaying error dialog if the file is not found.

Hello Alex,

I use something like this:

Code: Select all

var POPUP_BUTTONS_OK                 = 0;
var POPUP_BUTTONS_OK_CANCEL          = 1;
var POPUP_BUTTONS_ABORT_RETRY_IGNORE = 2;
var POPUP_BUTTONS_YES_NO_CANCEL      = 3;
var POPUP_BUTTONS_YES_NO             = 4;
var POPUP_BUTTONS_RETRY_CANCEL       = 5;

var POPUP_ICON_STOP                  = 16;
var POPUP_ICON_QUESTION              = 32;
var POPUP_ICON_EXCLAMATION           = 48;
var POPUP_ICON_INFORMATION           = 64;

var POPUP_RESULT_OK                  = 1;
var POPUP_RESULT_CANCEL              = 2;
var POPUP_RESULT_ABORT               = 3;
var POPUP_RESULT_RETRY               = 4;
var POPUP_RESULT_IGNORE              = 5;
var POPUP_RESULT_YES                 = 6;
var POPUP_RESULT_NO                  = 7;

var POPUP_FLAG_ALWAYS_ON_TOP         = 4096;

var fso   = new ActiveXObject("Scripting.FileSystemObject");
var shell = new ActiveXObject("WScript.Shell");

function checkForXYZFile()
{
	var installationPath = Session.Property("APPDIR");

	if (!fso.fileExists("xyz"))
	{
		// Set property to be used in dialog conditions
		Session.Property("MYAPP_GOTO_PAGE_XYZ") = "x";
	}
	else
	{
		// Unset property to be used in dialog conditions
		Session.Property("MYAPP_GOTO_PAGE_XYZ") = "";

		shell.Popup(
			"ERROR: xyz exists",
			0,
			Session.Property("ProductName") + " Setup",
			POPUP_ICON_STOP + POPUP_FLAG_ALWAYS_ON_TOP)
	}
}
The key bit for you is perhaps the part about setting and unsetting a property in a script via the the "built-in" "Session" object's Property thing.

(What we do instead of showing a popup is to go to an error page. We hope that is more user-friendly for our target audience.)

Also read up on private and public properties to avoid "bugs".



With best regards

Clemens Anhuth
waspy
Posts: 64
Joined: Fri Oct 03, 2008 10:58 am

Re: Displaying error dialog if the file is not found.

Thanks a lot for the help guys,
I was wondering if it's possible to adjust .NET Installer class to do the same. I can use MSIGetproperty() and MSISetProperty() interop methods. The only thing I miss is how to get MSIHandle that these functions require. Any ideas?

Cheers,
Alex
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Displaying error dialog if the file is not found.

Hi Alex,

I'm afraid that .NET Installer class actions cannot access installer properties. This type of custom actions can use only the parameters passed to them.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”