Deprecated-Unsupported/Java Peojects/Bookshelf/src/Opener.java

76 lines
2.6 KiB
Java

public class Opener {
private Process pb; // Process runner
private String slash = "";
private int useWindows, toggle = 0;
public void setSlash() {
if (System.getProperty("os.name").contains("Windows")) {
slash = "\\";
int dontUseWin = getWinSetting();
if (dontUseWin == 1)
useWindows = 0;
else
useWindows = 1;
} else {
slash = "/";
}
}
public void setWinSetting() {
if (toggle == 0)
toggle = 1;
else if (toggle == 1)
toggle = 0;
}
public int getWinSetting() { return toggle; }
public void fileOpener(String filePth) {
if (filePth.toLowerCase().contains(".epub"))
openEpub(filePth);
else if (filePth.toLowerCase().contains(".pdf"))
openPdf(filePth);
else
System.out.println("Something happened and the file culdn't be loaded.\n" +
"You either didn't select a file or the type isn't understood by this program.\n" +
"Or, something entirely unforseen happened....");
}
public void openEpub(String filePth) {
setSlash();
System.out.println("Opening EPUB : " + "'file:" + filePth + "'");
if (useWindows == 0) {
try {
ProcessBuilder pb = new ProcessBuilder("java", "-jar", "resources" + slash + "jars" + slash +
"EpubViewer.jar", filePth);
Process p = pb.start();
} catch(Throwable cpErr) {
System.out.println("Launch Error:\n" + cpErr);
}
} else { windows(filePth); }
}
public void openPdf(String filePth) {
setSlash();
System.out.println("Opening PDF : " + "'file:" + filePth + "'");
if (useWindows == 0) {
try {
ProcessBuilder pb = new ProcessBuilder("java", "-jar", "resources" + slash + "jars" + slash +
"PdfViewer.jar", filePth );
Process p = pb.start();
} catch(Throwable cpErr) {
System.out.println("Launch Error:\n" + cpErr);
}
} else { windows(filePth); }
}
public void windows(String filePth) {
try {
ProcessBuilder pb = new ProcessBuilder("resources/bin/SumatraPDF.exe", filePth);
Process p = pb.start();
} catch(Throwable cpErr) {
System.out.println("Launch Error:\n" + cpErr);
}
}
}