/*
Create Version.Txt from JExpress Control File
This example shows
1. how to create a panel which does *not* interact with the user
2. how to extract information from the installer's property list
3. it inherits from StatusPanel instead of WizardPanel to maintain a
consistent look between non-interactive panels.
Important Note:
1. This panel should not really be used because JExpress installers
already create the version info in the JExpress subdirectory of
your installation directory. This class is strictly as a simple
example of how to create a custom class.
Copyright (C) 1998-2012 DeNova
Last modified: 2012-01-12
*/
import java.io.File;
import java.io.FileOutputStream;
import com.denova.ui.UserNotices;
import com.denova.util.PropertyList;
import com.denova.JExpress.Installer.CustomInstaller;
import com.denova.JExpress.Installer.CustomUninstaller;
import com.denova.JExpress.Installer.InstallPropertyNames;
import com.denova.JExpress.Installer.StatusPanel;
public class VersionPanel extends StatusPanel
implements InstallPropertyNames {
private String progressLabel = CustomInstaller.getLocalizedString("UpdatingVersion");
public VersionPanel(PropertyList properties)
{
super (properties);
updateProgressBarLabel(progressLabel);
}
/**
* Enter the panel.
*
* Do not call this method; only the wizard should call it.
*/
public void enter()
{
// let them know what's happening
updateProgressBarLabel(progressLabel);
// we don't actually want to interact with the user
// this panel simply copies key information from jex.control
// to a text file in the installation directory
String applicationDirectory =
getPropertyList (). getProperty ( ApplicationDirectory, "" );
// only do this after we know where the installation directory is
if ( applicationDirectory != null ) {
// let's create a local property list that holds just the info we want
PropertyList list = new PropertyList();
// get the following properties from the control file
// and if any of the properties don't exist, then default them to blank fields
list. setProperty ( PackageName,
getPropertyList ().getProperty ( PackageName, "" ) );
list. setProperty ( WebSite,
getPropertyList ().getProperty( WebSite, "" ) );
list. setProperty ( PackageCopyright,
getPropertyList ().getProperty( PackageCopyright, "" ) );
list. setProperty ( PackageVersion,
getPropertyList ().getProperty( PackageVersion, "" ) );
// save the information to a text file
File f = new File ( applicationDirectory, VersionFilename );
try {
FileOutputStream o = new FileOutputStream ( f );
// save the property list
list. save ( o, "Version" );
// close the output stream
o. close ();
}
catch ( Exception e ) {
// if anything goes wrong, let the user know
UserNotices un = new UserNotices();
un.noteError ( "Unable to save the version information" );
}
// append the appropriate commands to the uninstaller
CustomUninstaller customUninstaller = new CustomUninstaller ();
File versionFile = new File ( applicationDirectory, VersionFilename );
customUninstaller. deleteFile ( versionFile. getPath () );
customUninstaller. append ( applicationDirectory );
}
// we don't want any user interaction
// so move them to the next panel automatically
showNextPanel ();
}
static final String VersionFilename = "version.txt";
} // VersionPanel