diff --git a/trunk/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java b/trunk/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java index 246e86e21..bc1209914 100644 --- a/trunk/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java +++ b/trunk/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java @@ -173,10 +173,10 @@ public class CommandLineArgumentParser { } } if (nextParam.equals("-removefromcontextmenu")) { - ContextMenuTools.addToContextMenu(false); + ContextMenuTools.addToContextMenu(false, true); System.exit(0); } else if (nextParam.equals("-addtocontextmenu")) { - ContextMenuTools.addToContextMenu(true); + ContextMenuTools.addToContextMenu(true, true); System.exit(0); } else if (nextParam.equals("-proxy")) { parseProxy(args); diff --git a/trunk/src/com/jpexs/decompiler/flash/console/ContextMenuTools.java b/trunk/src/com/jpexs/decompiler/flash/console/ContextMenuTools.java index 15aed891f..55e97397d 100644 --- a/trunk/src/com/jpexs/decompiler/flash/console/ContextMenuTools.java +++ b/trunk/src/com/jpexs/decompiler/flash/console/ContextMenuTools.java @@ -27,6 +27,8 @@ import com.sun.jna.platform.win32.Win32Exception; import com.sun.jna.platform.win32.WinReg; import com.sun.jna.platform.win32.WinUser; import java.io.File; +import java.util.logging.Level; +import java.util.logging.Logger; /** * @@ -63,7 +65,7 @@ public class ContextMenuTools { } } - public static boolean addToContextMenu(boolean add) { + public static boolean addToContextMenu(boolean add, boolean fromCommandLine) { if (add == isAddedToContextMenu()) { return true; } @@ -73,15 +75,15 @@ public class ContextMenuTools { if (add) { String exeName = Platform.is64Bit() ? exeName64 : exeName32; - return addToContextMenu(add, exeName); + return addToContextMenu(add, fromCommandLine, exeName); } else { // remove both 32 and 64 bit references - addToContextMenu(add, exeName32); - return addToContextMenu(add, exeName64); + return addToContextMenu(add, fromCommandLine, exeName32) && + addToContextMenu(add, fromCommandLine, exeName64); } } - private static boolean addToContextMenu(boolean add, String exeName) { + private static boolean addToContextMenu(boolean add, boolean fromCommandLine, String exeName) { final String extensions[] = new String[]{"swf", "gfx"}; final WinReg.HKEY REG_CLASSES_HKEY = WinReg.HKEY_LOCAL_MACHINE; @@ -198,16 +200,20 @@ public class ContextMenuTools { } return true; } catch (Exception ex) { - //Updating registry failed, try elevating rights - SHELLEXECUTEINFO sei = new SHELLEXECUTEINFO(); - sei.fMask = 0x00000040; - sei.lpVerb = new WString("runas"); - sei.lpFile = new WString(appDir + exeName); - sei.lpParameters = new WString(add ? "-addtocontextmenu" : "-removefromcontextmenu"); - sei.nShow = WinUser.SW_NORMAL; - Shell32.INSTANCE.ShellExecuteEx(sei); - //Wait till exit - Kernel32.INSTANCE.WaitForSingleObject(sei.hProcess, 1000 * 60 * 60 * 24 /*1 day max*/); + if (!fromCommandLine) { + //Updating registry failed, try elevating rights + SHELLEXECUTEINFO sei = new SHELLEXECUTEINFO(); + sei.fMask = 0x00000040; + sei.lpVerb = new WString("runas"); + sei.lpFile = new WString(appDir + exeName); + sei.lpParameters = new WString(add ? "-addtocontextmenu" : "-removefromcontextmenu"); + sei.nShow = WinUser.SW_NORMAL; + Shell32.INSTANCE.ShellExecuteEx(sei); + //Wait till exit + Kernel32.INSTANCE.WaitForSingleObject(sei.hProcess, 1000 * 60 * 60 * 24 /*1 day max*/); + } else { + Logger.getLogger(ContextMenuTools.class.getName()).log(Level.SEVERE, null, ex); + } } return false; } diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/Main.java b/trunk/src/com/jpexs/decompiler/flash/gui/Main.java index 5a7d8de9b..63bccc0cf 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/Main.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/Main.java @@ -676,7 +676,7 @@ public class Main { if (!offered) { if (Platform.isWindows()) { if ((!ContextMenuTools.isAddedToContextMenu()) && View.showConfirmDialog(null, "Do you want to add FFDec to context menu of SWF files?\n(Can be changed later from main menu)", "Context menu", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) { - ContextMenuTools.addToContextMenu(true); + ContextMenuTools.addToContextMenu(true, false); } } } diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/MainFrameClassicMenu.java b/trunk/src/com/jpexs/decompiler/flash/gui/MainFrameClassicMenu.java index 7330a59d7..6926bc93f 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/MainFrameClassicMenu.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/MainFrameClassicMenu.java @@ -403,7 +403,7 @@ public class MainFrameClassicMenu implements MainFrameMenu, ActionListener { if (miAssociate.isSelected() == ContextMenuTools.isAddedToContextMenu()) { return; } - ContextMenuTools.addToContextMenu(miAssociate.isSelected()); + ContextMenuTools.addToContextMenu(miAssociate.isSelected(), false); //Update checkbox menuitem accordingly (User can cancel rights elevation) new Timer().schedule(new TimerTask() { diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/MainFrameRibbonMenu.java b/trunk/src/com/jpexs/decompiler/flash/gui/MainFrameRibbonMenu.java index 274f538c9..b9f1f6a7f 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/MainFrameRibbonMenu.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/MainFrameRibbonMenu.java @@ -541,7 +541,7 @@ public class MainFrameRibbonMenu implements MainFrameMenu, ActionListener { if (miAssociate.isSelected() == ContextMenuTools.isAddedToContextMenu()) { return; } - ContextMenuTools.addToContextMenu(miAssociate.isSelected()); + ContextMenuTools.addToContextMenu(miAssociate.isSelected(), false); //Update checkbox menuitem accordingly (User can cancel rights elevation) new Timer().schedule(new TimerTask() {