forked from j62/ctbrec
1
0
Fork 0

Fix some code smells

This commit is contained in:
0xboobface 2019-12-06 20:20:50 +01:00
parent 00ea43c8b3
commit 26bf26de0a
3 changed files with 41 additions and 17 deletions

View File

@ -0,0 +1,9 @@
package ctbrec;
public class ForkProcessException extends RuntimeException {
public ForkProcessException(Exception e) {
super(e);
}
}

View File

@ -13,21 +13,27 @@ import org.slf4j.LoggerFactory;
public class OS {
private static final transient Logger LOG = LoggerFactory.getLogger(OS.class);
private static final Logger LOG = LoggerFactory.getLogger(OS.class);
public static enum TYPE {
private static final String USER_HOME = "user.home";
private static final String OS_NAME = "os.name";
private static final String CTBREC = "ctbrec";
public enum TYPE {
LINUX,
MAC,
WINDOWS,
OTHER
}
private OS() {}
public static TYPE getOsType() {
if(System.getProperty("os.name").contains("Linux")) {
if(System.getProperty(OS_NAME).contains("Linux")) {
return TYPE.LINUX;
} else if(System.getProperty("os.name").contains("Windows")) {
} else if(System.getProperty(OS_NAME).contains("Windows")) {
return TYPE.WINDOWS;
} else if(System.getProperty("os.name").contains("Mac")) {
} else if(System.getProperty(OS_NAME).contains("Mac")) {
return TYPE.MAC;
} else {
return TYPE.OTHER;
@ -38,26 +44,26 @@ public class OS {
File configDir;
switch (getOsType()) {
case LINUX:
String userHome = System.getProperty("user.home");
configDir = new File(new File(userHome, ".config"), "ctbrec");
String userHome = System.getProperty(USER_HOME);
configDir = new File(new File(userHome, ".config"), CTBREC);
break;
case MAC:
userHome = System.getProperty("user.home");
userHome = System.getProperty(USER_HOME);
configDir = new File(userHome, "Library/Preferences/ctbrec");
break;
case WINDOWS:
String appData = System.getenv("APPDATA");
configDir = new File(appData, "ctbrec");
configDir = new File(appData, CTBREC);
break;
default:
throw new RuntimeException("Unsupported operating system " + System.getProperty("os.name"));
throw new UnsupportedOperatingSystemException("Unsupported operating system " + System.getProperty(OS_NAME));
}
return configDir;
}
public static String[] getBrowserCommand(String...args) {
if(System.getenv("CTBREC_BROWSER") != null) {
String cmd[] = new String[args.length + 1];
String[] cmd = new String[args.length + 1];
cmd[0] = System.getenv("CTBREC_BROWSER");
System.arraycopy(args, 0, cmd, 1, args.length);
return cmd;
@ -86,27 +92,27 @@ public class OS {
System.arraycopy(args, 0, cmd, 2, args.length);
break;
default:
throw new RuntimeException("Unsupported operating system " + System.getProperty("os.name"));
throw new UnsupportedOperatingSystemException("Unsupported operating system " + System.getProperty(OS_NAME));
}
LOG.debug("Browser command: {}", Arrays.toString(cmd));
return cmd;
} catch (URISyntaxException e) {
throw new RuntimeException(e);
throw new ForkProcessException(e);
}
}
public static Settings getDefaultSettings() {
Settings settings = new Settings();
if(getOsType() == TYPE.WINDOWS) {
String userHome = System.getProperty("user.home");
Path path = Paths.get(userHome, "Videos", "ctbrec");
String userHome = System.getProperty(USER_HOME);
Path path = Paths.get(userHome, "Videos", CTBREC);
settings.recordingsDir = path.toString();
String programFiles = System.getenv("ProgramFiles");
programFiles = programFiles != null ? programFiles : "C:\\Program Files";
settings.mediaPlayer = Paths.get(programFiles, "VideoLAN", "VLC", "vlc.exe").toString();
} else if(getOsType() == TYPE.MAC) {
String userHome = System.getProperty("user.home");
settings.recordingsDir = Paths.get(userHome, "Movies", "ctbrec").toString();
String userHome = System.getProperty(USER_HOME);
settings.recordingsDir = Paths.get(userHome, "Movies", CTBREC).toString();
settings.mediaPlayer = "/Applications/VLC.app/Contents/MacOS/VLC";
}
return settings;

View File

@ -0,0 +1,9 @@
package ctbrec;
public class UnsupportedOperatingSystemException extends RuntimeException {
public UnsupportedOperatingSystemException(String msg) {
super(msg);
}
}