From: Debayan Sutradhar Date: Sun, 13 Dec 2020 16:06:43 +0530 Subject: Does anyone even look at this? --- Does anyone even look at this? --- --- 'a/.idea/misc.xml' +++ b/.idea/misc.xml @@ -8,7 +8,7 @@ - + \ No newline at end of file --- 'a/src/main/java/com/StreamPi/Util/Platform/Platform.java' +++ b/src/main/java/com/StreamPi/Util/Platform/Platform.java @@ -1,7 +1,7 @@ package com.StreamPi.Util.Platform; public enum Platform { - WINDOWS, LINUX, MAC, ANDROID, IOS, OTHER; + WINDOWS, LINUX, MAC, ANDROID, IOS, LINUX_RPI, UNKNOWN; public static String getUIName(Platform platform) { @@ -9,10 +9,13 @@ public enum Platform { { case WINDOWS: return "Windows"; case LINUX: return "Linux"; + case LINUX_RPI : return "Linux Raspberry Pi"; case MAC: return "MacOS"; case ANDROID: return "Android"; case IOS: return "iOS"; - default: return "Unknown"; + case UNKNOWN: + default: + return "Unknown"; } } } --- 'a/src/main/java/com/StreamPi/Util/Platform/ReleaseStatus.java' +++ b/src/main/java/com/StreamPi/Util/Platform/ReleaseStatus.java @@ -8,5 +8,16 @@ Enum to store the current status of the package com.StreamPi.Util.Platform; public enum ReleaseStatus { - INTERNAL, ALPHA, BETA, STABLE + EA, GA; + + public static String getUIName(ReleaseStatus releaseStatus) + { + switch (releaseStatus) + { + case EA: return "Early Access"; + case GA: return "General Availability"; + default: + return null; + } + } } --- /dev/null +++ b/src/main/java/com/StreamPi/Util/StartAtBoot/SoftwareType.java @@ -0,0 +1,5 @@ +package com.StreamPi.Util.StartAtBoot; + +public enum SoftwareType { + SERVER, CLIENT +} --- /dev/null +++ b/src/main/java/com/StreamPi/Util/StartAtBoot/StartAtBoot.java @@ -0,0 +1,107 @@ +package com.StreamPi.Util.StartAtBoot; + +import com.StreamPi.Util.Exception.MinorException; +import com.StreamPi.Util.Platform.Platform; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; + +public class StartAtBoot { + + SoftwareType softwareType; + Platform platform; + + public StartAtBoot(SoftwareType softwareType, Platform platform) + { + this.softwareType = softwareType; + this.platform = platform; + } + + public void create(File runnerFile) throws MinorException + { + if(platform == Platform.WINDOWS) + createStarterForWindows(runnerFile); + else if(platform == Platform.LINUX || platform == Platform.LINUX_RPI) + createStarterForLinux(runnerFile); + else if(platform == Platform.MAC) + createStarterForMac(runnerFile); + else if(platform == Platform.UNKNOWN) + unknownPlatformException(); + } + + public boolean delete() throws MinorException { + if(platform == Platform.WINDOWS) + return deleteStarterForWindows(); + else if (platform == Platform.LINUX || platform == Platform.LINUX_RPI) + return deleteStarterForLinux(); + else if(platform == Platform.MAC) + unknownPlatformException(); + else if(platform == Platform.UNKNOWN) + unknownPlatformException(); + + return false; + } + + private void createStarterForLinux(File runnerFile) throws MinorException + { + File initFile = new File("/etc/init.d/streampi_starter"+ softwareType); + + try + { + FileWriter fw = new FileWriter(initFile); + BufferedWriter bw = new BufferedWriter(fw); + bw.write("cd "+runnerFile.getParentFile().getCanonicalPath()+"\n" + + "./"+runnerFile.getName()); + bw.close(); + } + catch (Exception e) + { + throw new MinorException(e.getMessage()); + } + } + + private boolean deleteStarterForLinux() + { + return new File("/etc/init.d/streampi_starter"+ softwareType).delete(); + } + + private void createStarterForWindows(File runnerFile) throws MinorException + { + File initFile = new File(System.getenv("APPDATA")+"/Microsoft/Windows/Start Menu/Programs/Startup/streampi_starter"+ softwareType +".bat"); + + try + { + FileWriter fw = new FileWriter(initFile); + BufferedWriter bw = new BufferedWriter(fw); + bw.write("cd "+runnerFile.getParentFile().getCanonicalPath()+"\n" + + runnerFile.getName()); + bw.close(); + } + catch (Exception e) + { + throw new MinorException(e.getMessage()); + } + } + + private boolean deleteStarterForWindows() + { + return new File(System.getenv("APPDATA")+"/Microsoft/Windows/Start Menu/Programs/Startup/streampi_starter"+ softwareType +".bat").delete(); + } + + + private void createStarterForMac(File runnerFile) throws MinorException + { + throw new MinorException("Mac Starter feature is not implemented yet."); + } + + private void deleteStarterForMac() throws MinorException + { + throw new MinorException("Mac Starter feature is not implemented yet."); + } + + private void unknownPlatformException() throws MinorException + { + throw new MinorException("Cannot implemented starter feature. Unknown platform."); + } +} --- 'a/src/main/java/module-info.java' +++ b/src/main/java/module-info.java @@ -9,4 +9,5 @@ module com.StreamPi.Util { exports com.StreamPi.Util.Exception; exports com.StreamPi.Util.Platform; exports com.StreamPi.Util.FormHelper; + exports com.StreamPi.Util.StartAtBoot; } \ No newline at end of file