boolean checkApp(MimeType mt) { String appId = mt.getAppId(); AppList appList = MimeTypesList.getAppList(); File d; if (appId == null) { appId = Util.generateId(); d = new File("/"); } else { File exe = new File(appList.getFindPath(appId) + "/" + appList.getExec(appId)); if (exe.isFile()) return true; d = new File(exe.getParent()); while (!d.exists()) d = new File(d.getParent()); } SetAppDialog dlg = new SetAppDialog( App.getFrame(), Local.getString( Local.getString("Select the application to open files of type") + " '" + mt.getLabel() + "'")); Dimension dlgSize = new Dimension(420, 300); dlg.setSize(dlgSize); Dimension frmSize = App.getFrame().getSize(); Point loc = App.getFrame().getLocation(); dlg.setLocation( (frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y); dlg.setDirectory(d); dlg.appPanel.argumentsField.setText("$1"); dlg.setVisible(true); if (dlg.CANCELLED) return false; File f = new File(dlg.appPanel.applicationField.getText()); appList.addOrReplaceApp( appId, f.getParent().replace('\\', '/'), f.getName().replace('\\', '/'), dlg.appPanel.argumentsField.getText()); mt.setApp(appId); /*appList.setFindPath(appId, chooser.getSelectedFile().getParent().replace('\\','/')); appList.setExec(appId, chooser.getSelectedFile().getName().replace('\\','/'));*/ CurrentStorage.get().storeMimeTypesList(); return true; }
void runApp(String fpath) { MimeType mt = MimeTypesList.getMimeTypeForFile(fpath); if (mt.getMimeTypeId().equals("__UNKNOWN")) { mt = addResourceType(fpath); if (mt == null) return; } if (!checkApp(mt)) return; String[] command = MimeTypesList.getAppList().getCommand(mt.getAppId(), fpath); if (command == null) return; /*DEBUG*/ System.out.println("Run: " + command[0]); try { Runtime.getRuntime().exec(command); } catch (Exception ex) { new ExceptionDialog( ex, "Failed to run an external application <br><code>" + command[0] + "</code>", "Check the application path and command line parameters for this resource type " + "(File->Preferences->Resource types)."); } }