Init state of autostart option and handle and all users startup place.

cusax-fix
Damian Minkov 18 years ago
parent 1cedae22fb
commit 7d31f0d498

@ -1,9 +1,10 @@
general=General
autoStartOption=Auto - start MotoGP Impact when computer restarts or reboots.
autoStartOption=Autostart when computer restarts or reboots.
groupChatMessages=Group chat messages in one window.
logHistory=Log chat history
showHistory=Show history
historySize=recent messages in new chats
sendMessagesWith=Send messages with:
enableTypingNotifications=Enable typing notifications
bringWindowToFront=Bring chat window to front
bringWindowToFront=Bring chat window to front
errorPermission=You don't have enough privileges to remove autostart

@ -19,10 +19,17 @@ public class GeneralConfigPluginActivator implements BundleActivator
private static ConfigurationService configService;
protected static BundleContext bundleContext;
private static UIService uiService;
public void start(BundleContext bc) throws Exception
{
bundleContext = bc;
ServiceReference uiServiceRef = bundleContext
.getServiceReference(UIService.class.getName());
uiService = (UIService) bundleContext.getService(uiServiceRef);
ConfigurationManager.loadGuiConfigurations();
@ -57,4 +64,14 @@ public static ConfigurationService getConfigurationService() {
return configService;
}
/**
* Returns the <tt>UIService</tt>.
*
* @return the <tt>UIService</tt>
*/
public static UIService getUIService()
{
return uiService;
}
}

@ -84,6 +84,7 @@ private void initGUI()
mainPanel.add(Box.createVerticalStrut(10));
autoStartCheckBox.setText(
Resources.getString("autoStartOption"));
initAutoStartCheckBox();
autoStartCheckBox.addActionListener(this);
}
{
@ -290,7 +291,6 @@ public void actionPerformed(ActionEvent event)
String appName =
Resources.getApplicationString("applicationName");
ShellLink shortcut = new ShellLink(ShellLink.STARTUP, appName);
shortcut.setLinkType(ShellLink.STARTUP);
shortcut.setUserType(ShellLink.CURRENT_USER);
shortcut.setDescription(
"This starts " + appName + " Application");
@ -299,18 +299,40 @@ public void actionPerformed(ActionEvent event)
shortcut.setShowCommand(ShellLink.MINNOACTIVE);
shortcut.setTargetPath(workingDir + File.separator + "run.exe");
shortcut.setWorkingDirectory(workingDir);
String f1 = shortcut.getcurrentUserLinkPath() +
File.separator + appName + ".lnk";
String f2 = f1.replaceAll(
System.getProperty("user.name"),
"All Users");
if(autoStartCheckBox.isSelected())
{
if(!new File(f1).exists() &&
!new File(f2).exists())
shortcut.save();
}
else
{
// before we can get the filename of the link
// we have to save it
shortcut.save();
boolean isFileDeleted = false;
try {
isFileDeleted = new File(f1).delete();
} catch (Exception e) {}
new File(shortcut.getFileName()).delete();
try {
new File(f2).delete();
} catch (Exception e)
{
if(!isFileDeleted)
GeneralConfigPluginActivator.getUIService().
getPopupDialog().showMessagePopupDialog(
e.getMessage(),
Resources.getString("errorPermission"),
PopupDialog.ERROR_MESSAGE);
// cannot delete no permissions
}
}
} catch (Exception e)
{
logger.error("Cannot create/delete startup shortcut", e);
@ -342,4 +364,35 @@ else if (sourceObject.equals(bringToFrontCheckBox))
bringToFrontCheckBox.isSelected());
}
}
private void initAutoStartCheckBox()
{
try
{
String appName =
Resources.getApplicationString("applicationName");
ShellLink shortcut =
new ShellLink(
ShellLink.STARTUP,
appName);
shortcut.setUserType(ShellLink.CURRENT_USER);
String f1 = shortcut.getcurrentUserLinkPath() +
File.separator + appName + ".lnk";
String f2 = f1.replaceAll(
System.getProperty("user.name"),
"All Users");
if(new File(f1).exists() || new File(f2).exists())
autoStartCheckBox.setSelected(true);
else
autoStartCheckBox.setSelected(false);
} catch (Exception e)
{
logger.error(e);
}
}
}

Loading…
Cancel
Save