Skip to content

Commit

Permalink
Fix #1381 File links containing blanks are broken if non-default view…
Browse files Browse the repository at this point in the history
…er is set

* Fix #1381 File links containing blanks are broken if non-default viewer is set
* Consistently use ProcessBuilder instead of Runtime.exec
  • Loading branch information
stefan-kolb committed May 12, 2016
1 parent 771db07 commit 09dfe61
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ to [sourceforge feature requests](https://sourceforge.net/p/jabref/features/) by
- Fixed [#1365](https://github.com/JabRef/jabref/issues/1365): Default label pattern back to "[auth][year]"
- Fixed [#796](https://github.com/JabRef/jabref/issues/796): Undoing more than one entry at the same time is now working
- Fixed [#1353](https://github.com/JabRef/jabref/issues/1353): Fetch-Preview did not display updated BibTeX-Key after clicking on `Generate Now`
- Fixed [#1381](https://github.com/JabRef/jabref/issues/1381): File links containing blanks are broken if non-default viewer is set

### Removed
- Removed possibility to export entries/databases to an `.sql` file, as the logic cannot easily use the correct escape logic
Expand Down
20 changes: 7 additions & 13 deletions src/main/java/net/sf/jabref/gui/desktop/os/Windows.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,23 @@
import net.sf.jabref.external.ExternalFileTypes;

public class Windows implements NativeDesktop {

private static String DEFAULT_EXECUTABLE_EXTENSION = ".exe";


@Override
public void openFile(String filePath, String fileType) throws IOException {
Optional<ExternalFileType> type = ExternalFileTypes.getInstance().getExternalFileTypeByExt(fileType);

if (type.isPresent() && !type.get().getOpenWithApplication().isEmpty()) {
openFileWithApplication(filePath, type.get().getOpenWithApplication());
} else {
// quote String so explorer handles URL query strings correctly
String quotePath = "\"" + filePath +"\"";
Runtime.getRuntime().exec(new String[] {"explorer.exe", quotePath});
new ProcessBuilder("explorer.exe", quotePath).start();

This comment has been minimized.

Copy link
@Siedlerchr

Siedlerchr May 12, 2016

Member

Did you try opening a URL/Website, too?

This comment has been minimized.

Copy link
@stefan-kolb

stefan-kolb May 12, 2016

Author Member

yeah.

}

}

@Override
public String detectProgramPath(String programName, String directoryName) {

String progFiles = System.getenv("ProgramFiles(x86)");
if (progFiles == null) {
progFiles = System.getenv("ProgramFiles");
Expand All @@ -41,21 +38,18 @@ public String detectProgramPath(String programName, String directoryName) {

@Override
public void openFileWithApplication(String filePath, String application) throws IOException {
Runtime.getRuntime().exec(Paths.get(application) + " " + Paths.get(filePath));
new ProcessBuilder(Paths.get(application).toString(), Paths.get(filePath).toString()).start();
}

@Override
public void openFolderAndSelectFile(String filePath) throws IOException {
String cmd = "explorer.exe";
String arg = "/select,";
String[] commandWithArgs = {cmd, arg, filePath};
//Array variant, because otherwise the Tokenizer, which is internally run, kills the whitespaces in the path
Runtime.getRuntime().exec(commandWithArgs);
new ProcessBuilder("explorer.exe", "/select,", filePath).start();
}

@Override
public void openConsole(String absolutePath) throws IOException {

Runtime.getRuntime().exec("cmd.exe /c start", null, new File(absolutePath));
ProcessBuilder process = new ProcessBuilder("cmd.exe", "/c", "start");
process.directory(new File(absolutePath));
process.start();
}
}

0 comments on commit 09dfe61

Please sign in to comment.