util

Clone or download

Does anyone even look at this?

Modified Files

M .idea/misc.xml
+1 −1
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<component name="MavenProjectsManager">
<option name="originalFiles">
<option name="originalFiles">
<list>
<list>
<option value="$PROJECT_DIR$/pom.xml" />
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</list>
</option>
</option>
</component>
</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" />
<output url="file://$PROJECT_DIR$/out" />
</component>
</component>
</project>
</project>
package com.StreamPi.Util.Platform;
package com.StreamPi.Util.Platform;
public enum Platform {
public enum Platform {
WINDOWS, LINUX, MAC, ANDROID, IOS, OTHER;
WINDOWS, LINUX, MAC, ANDROID, IOS, LINUX_RPI, UNKNOWN;
public static String getUIName(Platform platform)
public static String getUIName(Platform platform)
{
{
switch (platform)
switch (platform)
{
{
case WINDOWS: return "Windows";
case WINDOWS: return "Windows";
case LINUX: return "Linux";
case LINUX: return "Linux";
case LINUX_RPI : return "Linux Raspberry Pi";
case MAC: return "MacOS";
case MAC: return "MacOS";
case ANDROID: return "Android";
case ANDROID: return "Android";
case IOS: return "iOS";
case IOS: return "iOS";
default: return "Unknown";
case UNKNOWN:
default:
return "Unknown";
}
}
}
}
}
}
/*
/*
ReleaseStatus.java
ReleaseStatus.java
Contributors : Debayan Sutradhar (@dubbadhar)
Contributors : Debayan Sutradhar (@dubbadhar)
Enum to store the current status of the Server Release
Enum to store the current status of the Server Release
*/
*/
package com.StreamPi.Util.Platform;
package com.StreamPi.Util.Platform;
public enum ReleaseStatus {
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;
}
}
}
}
package com.StreamPi.Util.StartAtBoot;
public enum SoftwareType {
SERVER, CLIENT
}
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.");
}
}
module com.StreamPi.Util {
module com.StreamPi.Util {
requires org.kordamp.ikonli.javafx;
requires org.kordamp.ikonli.javafx;
requires org.kordamp.ikonli.fontawesome5;
requires org.kordamp.ikonli.fontawesome5;
requires javafx.base;
requires javafx.base;
requires javafx.controls;
requires javafx.controls;
exports com.StreamPi.Util.Version;
exports com.StreamPi.Util.Version;
exports com.StreamPi.Util.Exception;
exports com.StreamPi.Util.Exception;
exports com.StreamPi.Util.Platform;
exports com.StreamPi.Util.Platform;
exports com.StreamPi.Util.FormHelper;
exports com.StreamPi.Util.FormHelper;
exports com.StreamPi.Util.StartAtBoot;
}
}