util

Clone or download

Modified Files

M pom.xml
+1 −0
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<modelVersion>4.0.0</modelVersion>
<groupId>com.stream-pi</groupId>
<groupId>com.stream-pi</groupId>
<artifactId>util</artifactId>
<artifactId>util</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>1.0.0-SNAPSHOT</version>
<url>https://stream-pi.com/</url>
<url>https://stream-pi.com/</url>
<build>
<build>
<plugins>
<plugins>
<plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<version>3.1.0</version>
<executions>
<executions>
<execution>
<execution>
<id>test-jar</id>
<id>test-jar</id>
<phase>package</phase>
<phase>package</phase>
<goals>
<goals>
<goal>test-jar</goal>
<goal>test-jar</goal>
</goals>
</goals>
</execution>
</execution>
</executions>
</executions>
</plugin>
</plugin>
<plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>3.8.1</version>
<configuration>
<configuration>
<release>11</release>
<release>11</release>
</configuration>
</configuration>
</plugin>
</plugin>
</plugins>
</plugins>
</build>
</build>
<properties>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>11</maven.compiler.release>
<maven.compiler.release>11</maven.compiler.release>
<IkonliVersion>11.5.0</IkonliVersion>
<IkonliVersion>11.5.0</IkonliVersion>
<IkonliFA5PackVersion>11.5.0</IkonliFA5PackVersion>
<IkonliFA5PackVersion>11.5.0</IkonliFA5PackVersion>
<JavaFXVersion>16-ea+6</JavaFXVersion>
<JavaFXVersion>16-ea+6</JavaFXVersion>
</properties>
</properties>
<dependencies>
<dependencies>
<dependency>
<dependency>
<groupId>org.kordamp.ikonli</groupId>
<groupId>org.kordamp.ikonli</groupId>
<artifactId>ikonli-fontawesome5-pack</artifactId>
<artifactId>ikonli-fontawesome5-pack</artifactId>
<version>${IkonliFA5PackVersion}</version>
<version>${IkonliFA5PackVersion}</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>org.openjfx</groupId>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<artifactId>javafx-controls</artifactId>
<version>${JavaFXVersion}</version>
<version>${JavaFXVersion}</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>org.openjfx</groupId>
<groupId>org.openjfx</groupId>
<artifactId>javafx-base</artifactId>
<artifactId>javafx-base</artifactId>
<version>${JavaFXVersion}</version>
<version>${JavaFXVersion}</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>org.kordamp.ikonli</groupId>
<groupId>org.kordamp.ikonli</groupId>
<artifactId>ikonli-javafx</artifactId>
<artifactId>ikonli-javafx</artifactId>
<version>${IkonliVersion}</version>
<version>${IkonliVersion}</version>
</dependency>
</dependency>
</dependencies>
</dependencies>
</project>
</project>
package com.stream_pi.util.comms;
package com.stream_pi.util.comms;
import java.io.Serializable;
import java.io.Serializable;
public class Message implements Serializable
public class Message implements Serializable
{
{
private final String header;
private final String header;
private String[] stringArrValue;
private String[] stringArrValue;
private String stringValue;
private String stringValue;
private byte[] byteArrValue;
private Byte[] byteArrValue;
public Message(String header)
public Message(String header)
{
{
this.header = header;
this.header = header;
}
}
public void setByteArrValue(byte[] byteArrValue)
public void setByteArrValue(Byte[] byteArrValue)
{
{
this.byteArrValue = byteArrValue;
this.byteArrValue = byteArrValue;
}
}
public void setStringArrValue(String... stringArrValue)
public void setStringArrValue(String... stringArrValue)
{
{
this.stringArrValue = stringArrValue;
this.stringArrValue = stringArrValue;
}
}
public void setStringValue(String stringValue)
public void setStringValue(String stringValue)
{
{
this.stringValue = stringValue;
this.stringValue = stringValue;
}
}
public String getHeader()
public String getHeader()
{
{
return header;
return header;
}
}
public byte[] getByteArrValue()
public Byte[] getByteArrValue()
{
{
return byteArrValue;
return byteArrValue;
}
}
public String[] getStringArrValue()
public String[] getStringArrValue()
{
{
return stringArrValue;
return stringArrValue;
}
}
public String getStringValue()
public String getStringValue()
{
{
return stringValue;
return stringValue;
}
}
}
}
/*
/*
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
This program is free software: you can redistribute it and/or modify
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
(at your option) any later version.
This program is distributed in the hope that it will be useful,
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
GNU General Public License for more details.
Originally Written by : Debayan Sutradhar (rnayabed)
Originally Written by : Debayan Sutradhar (rnayabed)
*/
*/
package com.stream_pi.util.startatboot;
package com.stream_pi.util.startatboot;
import com.stream_pi.util.platform.Platform;
import com.stream_pi.util.platform.Platform;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.MinorException;
import java.io.BufferedWriter;
import java.io.BufferedWriter;
import java.io.File;
import java.io.File;
import java.io.FileWriter;
import java.io.FileWriter;
public class StartAtBoot {
public class StartAtBoot {
SoftwareType softwareType;
SoftwareType softwareType;
Platform platform;
Platform platform;
public StartAtBoot(SoftwareType softwareType, Platform platform)
public StartAtBoot(SoftwareType softwareType, Platform platform)
{
{
this.softwareType = softwareType;
this.softwareType = softwareType;
this.platform = platform;
this.platform = platform;
}
}
public void create(File runnerFile) throws MinorException
public void create(File runnerFile) throws MinorException
{
{
if(platform == Platform.WINDOWS)
if(platform == Platform.WINDOWS)
createStarterForWindows(runnerFile);
createStarterForWindows(runnerFile);
else if(platform == Platform.LINUX || platform == Platform.LINUX_RPI)
else if(platform == Platform.LINUX || platform == Platform.LINUX_RPI)
createStarterForLinux(runnerFile);
createStarterForLinux(runnerFile, true);
else if(platform == Platform.MAC)
createStarterForMac(runnerFile);
else if(platform == Platform.UNKNOWN)
unknownPlatformException();
}
public void create(File runnerFile, boolean isXMode) throws MinorException
{
if(platform == Platform.WINDOWS)
createStarterForWindows(runnerFile);
else if(platform == Platform.LINUX || platform == Platform.LINUX_RPI)
createStarterForLinux(runnerFile, isXMode);
else if(platform == Platform.MAC)
else if(platform == Platform.MAC)
createStarterForMac(runnerFile);
createStarterForMac(runnerFile);
else if(platform == Platform.UNKNOWN)
else if(platform == Platform.UNKNOWN)
unknownPlatformException();
unknownPlatformException();
}
}
public boolean delete() throws MinorException {
public boolean delete() throws MinorException {
if(platform == Platform.WINDOWS)
if(platform == Platform.WINDOWS)
return deleteStarterForWindows();
return deleteStarterForWindows();
else if (platform == Platform.LINUX || platform == Platform.LINUX_RPI)
else if (platform == Platform.LINUX || platform == Platform.LINUX_RPI)
return deleteStarterForLinux();
return deleteStarterForLinux();
else if(platform == Platform.MAC)
else if(platform == Platform.MAC)
deleteStarterForMac();
deleteStarterForMac();
else if(platform == Platform.UNKNOWN)
else if(platform == Platform.UNKNOWN)
unknownPlatformException();
unknownPlatformException();
return false;
return false;
}
}
private void createStarterForLinux(File runnerFile) throws MinorException
private void createStarterForLinux(File runnerFile, boolean isXMode) throws MinorException
{
{
try
try
{
{
String sysDDirectoryPath = System.getProperty("user.home")+"/.local/share/systemd/user/";
String sysDDirectoryPath = System.getProperty("user.home")+"/.local/share/systemd/user/";
File sysDDirectoryFile = new File(sysDDirectoryPath);
File sysDDirectoryFile = new File(sysDDirectoryPath);
if(!sysDDirectoryFile.exists())
if(!sysDDirectoryFile.exists())
sysDDirectoryFile.mkdirs();
sysDDirectoryFile.mkdirs();
File sysDServiceFile = new File(sysDDirectoryPath+"stream-pi-"+ softwareType+".service");
File sysDServiceFile = new File(sysDDirectoryPath+"stream-pi-"+ softwareType+".service");
FileWriter fw = new FileWriter(sysDServiceFile);
FileWriter fw = new FileWriter(sysDServiceFile);
BufferedWriter bw = new BufferedWriter(fw);
BufferedWriter bw = new BufferedWriter(fw);
bw.write("[Unit]\n" +
"Description=Stream-Pi "+softwareType+"\n" +
if(isXMode)
"[Service]\n" +
{
"Type=oneshot\n" +
bw.write("[Unit]\n" +
"WorkingDirectory="+runnerFile.getAbsoluteFile().getParent()+"\n" +
"Description=Stream-Pi "+softwareType+"\n" +
"ExecStart="+runnerFile.getAbsoluteFile().getParent()+"/"+runnerFile.getName()+"\n" +
"[Service]\n" +
"[Install]\n" +
"Type=simple\n" +
"WantedBy=default.target\n");
"Environment=\"DISPLAY=:0\"\n" +
"WorkingDirectory="+runnerFile.getAbsoluteFile().getParent()+"\n" +
"ExecStart="+runnerFile.getAbsoluteFile().getParent()+"/"+runnerFile.getName()+"\n" +
"[Install]\n" +
"WantedBy=default.target\n");
}
else
{
bw.write("[Unit]\n" +
"Description=Stream-Pi "+softwareType+"\n" +
"[Service]\n" +
"Type=oneshot\n" +
"WorkingDirectory="+runnerFile.getAbsoluteFile().getParent()+"\n" +
"ExecStart="+runnerFile.getAbsoluteFile().getParent()+"/"+runnerFile.getName()+"\n" +
"[Install]\n" +
"WantedBy=default.target\n");
}
bw.close();
bw.close();
Runtime.getRuntime().exec("systemctl --user daemon-reload");
Runtime.getRuntime().exec("systemctl --user daemon-reload");
Runtime.getRuntime().exec("systemctl --user enable stream-pi-"+softwareType+".service");
Runtime.getRuntime().exec("systemctl --user enable stream-pi-"+softwareType+".service");
}
}
catch (Exception e)
catch (Exception e)
{
{
e.printStackTrace();
e.printStackTrace();
throw new MinorException("Unable to set start at boot",e.getMessage());
throw new MinorException("Unable to set start at boot",e.getMessage());
}
}
}
}
private boolean deleteStarterForLinux() throws MinorException
private boolean deleteStarterForLinux() throws MinorException
{
{
try
try
{
{
boolean f1 = new File(System.getProperty("user.home")+"/.local/share/systemd/user/stream-pi-"+
boolean f1 = new File(System.getProperty("user.home")+"/.local/share/systemd/user/stream-pi-"+
softwareType+".service").delete();
softwareType+".service").delete();
Runtime.getRuntime().exec("systemctl --user daemon-reload");
Runtime.getRuntime().exec("systemctl --user daemon-reload");
return f1;
return f1;
}
}
catch (Exception e)
catch (Exception e)
{
{
e.printStackTrace();
e.printStackTrace();
throw new MinorException("Unable to unset start at boot",e.getMessage());
throw new MinorException("Unable to unset start at boot",e.getMessage());
}
}
}
}
private void createStarterForWindows(File runnerFile) throws MinorException
private void createStarterForWindows(File runnerFile) throws MinorException
{
{
File initFile = new File(System.getenv("APPDATA")+"/Microsoft/Windows/Start Menu/Programs/Startup/streampi_starter_"+ softwareType +".bat");
File initFile = new File(System.getenv("APPDATA")+"/Microsoft/Windows/Start Menu/Programs/Startup/streampi_starter_"+ softwareType +".bat");
try
try
{
{
FileWriter fw = new FileWriter(initFile);
FileWriter fw = new FileWriter(initFile);
BufferedWriter bw = new BufferedWriter(fw);
BufferedWriter bw = new BufferedWriter(fw);
bw.write("cd "+runnerFile.getAbsoluteFile().getParent()+"\n" +
bw.write("cd "+runnerFile.getAbsoluteFile().getParent()+"\n" +
runnerFile.getName());
runnerFile.getName());
bw.close();
bw.close();
}
}
catch (Exception e)
catch (Exception e)
{
{
throw new MinorException(e.getMessage());
throw new MinorException(e.getMessage());
}
}
}
}
private boolean deleteStarterForWindows()
private boolean deleteStarterForWindows()
{
{
return new File(System.getenv("APPDATA")+"/Microsoft/Windows/Start Menu/Programs/Startup/streampi_starter_"+ softwareType +".bat").delete();
return new File(System.getenv("APPDATA")+"/Microsoft/Windows/Start Menu/Programs/Startup/streampi_starter_"+ softwareType +".bat").delete();
}
}
private void createStarterForMac(File runnerFile) throws MinorException
private void createStarterForMac(File runnerFile) throws MinorException
{
{
throw new MinorException("Mac Starter feature is not implemented yet.");
throw new MinorException("Mac Starter feature is not implemented yet.");
}
}
private void deleteStarterForMac() throws MinorException
private void deleteStarterForMac() throws MinorException
{
{
throw new MinorException("Mac Starter feature is not implemented yet.");
throw new MinorException("Mac Starter feature is not implemented yet.");
}
}
private void unknownPlatformException() throws MinorException
private void unknownPlatformException() throws MinorException
{
{
throw new MinorException("Cannot implemented starter feature. Unknown platform.");
throw new MinorException("Cannot implemented starter feature. Unknown platform.");
}
}
}
}