util

Clone or download

Does anyone even look at this?

Modified Files

M .idea/misc.xml
+1 −1
--- 'a/.idea/misc.xml'
+++ b/.idea/misc.xml
@@ -8,7 +8,7 @@
</list>
</option>
</component>
- <component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="GraalVM 11 20.2.0" project-jdk-type="JavaSDK">
+ <component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="false" project-jdk-name="GraalVM 11 20.2.0 August" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ 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