util
Clone or download
Modified Files
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 static final long SerialVersionUID = 2004200019671976L;
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;
private int intValue;
private int intValue;
private int[] intArrValue;
private int[] intArrValue;
private double doubleValue;
private double doubleValue;
private double[] doubleArrValue;
private double[] doubleArrValue;
public Message(String header)
public Message(String header)
{
{
this.header = header;
this.header = header;
}
}
public void setDoubleArrValue(double... doubleArrValue)
public void setDoubleArrValue(double... doubleArrValue)
{
{
this.doubleArrValue = doubleArrValue;
this.doubleArrValue = doubleArrValue;
}
}
public double[] getDoubleArrValue()
public double[] getDoubleArrValue()
{
{
return doubleArrValue;
return doubleArrValue;
}
}
public void setDoubleValue(double doubleValue)
public void setDoubleValue(double doubleValue)
{
{
this.doubleValue = doubleValue;
this.doubleValue = doubleValue;
}
}
public double getDoubleValue()
public double getDoubleValue()
{
{
return doubleValue;
return doubleValue;
}
}
public void setIntArrValue(int... intArrValue)
public void setIntArrValue(int... intArrValue)
{
{
this.intArrValue = intArrValue;
this.intArrValue = intArrValue;
}
}
public int[] getIntArrValue()
public int[] getIntArrValue()
{
{
return intArrValue;
return intArrValue;
}
}
public void setIntValue(int intValue)
public void setIntValue(int intValue)
{
{
this.intValue = intValue;
this.intValue = intValue;
}
}
public int getIntValue()
public int getIntValue()
{
{
return intValue;
return intValue;
}
}
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 com.stream_pi.util.platform.PlatformType;
import com.stream_pi.util.platform.PlatformType;
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 {
PlatformType softwareType;
PlatformType softwareType;
Platform platform;
Platform platform;
public StartAtBoot(PlatformType softwareType, Platform platform)
public StartAtBoot(PlatformType 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
{
{
create(runnerFile, true);
create(runnerFile, true);
}
}
public void create(File runnerFile, boolean isXMode) throws MinorException
public void create(File runnerFile, boolean isXMode) throws MinorException
{
{
if(platform == Platform.WINDOWS)
if(platform == Platform.WINDOWS)
createStarterForWindows(runnerFile);
createStarterForWindows(runnerFile);
else if(platform == Platform.LINUX)
else if(platform == Platform.LINUX)
createStarterForLinux(runnerFile, isXMode);
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)
else if (platform == Platform.LINUX)
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, boolean isXMode) 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);
if(isXMode)
if(isXMode)
{
{
bw.write("[Unit]\n" +
bw.write("[Unit]\n" +
"Description=Stream-Pi "+softwareType+"\n" +
"Description=Stream-Pi "+softwareType+"\n" +
"[Service]\n" +
"[Service]\n" +
"Type=simple\n" +
"Type=simple\n" +
"Environment=\"DISPLAY=:0\"\n" +
"Environment=\"DISPLAY=:0\"\n" +
"WorkingDirectory=\""+runnerFile.getAbsoluteFile().getParent()+"\"\n" +
"ExecStart=/usr/bin/env \""+runnerFile.getAbsoluteFile().getParent()+"/"+runnerFile.getName()+"\"\n" +
"ExecStart="+runnerFile.getAbsoluteFile().getParent()+"/"+runnerFile.getName()+"\n" +
"[Install]\n" +
"[Install]\n" +
"WantedBy=default.target\n");
"WantedBy=default.target\n");
}
}
else
else
{
{
bw.write("[Unit]\n" +
bw.write("[Unit]\n" +
"Description=Stream-Pi "+softwareType+"\n" +
"Description=Stream-Pi "+softwareType+"\n" +
"[Service]\n" +
"[Service]\n" +
"Type=oneshot\n" +
"Type=oneshot\n" +
"WorkingDirectory=\""+runnerFile.getAbsoluteFile().getParent()+"\"\n" +
"ExecStart=/usr/bin/env \""+runnerFile.getAbsoluteFile().getParent()+"/"+runnerFile.getName()+"\"\n" +
"ExecStart="+runnerFile.getAbsoluteFile().getParent()+"/"+runnerFile.getName()+"\n" +
"[Install]\n" +
"[Install]\n" +
"WantedBy=default.target\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
{
{
try
try
{
{
File initFile = new File(System.getenv("APPDATA")+"/stream_pi_starter_batch_"+ softwareType +".bat");
File initFile = new File(System.getenv("APPDATA")+"/stream_pi_starter_batch_"+ softwareType +".bat");
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()+"\"\r\n" +
bw.write("cd \""+runnerFile.getAbsoluteFile().getParent()+"\"\r\n" +
"start \"\" \""+runnerFile.getName()+"\"");
"start \"\" \""+runnerFile.getName()+"\"");
bw.close();
bw.close();
File vbsStarterFile = new File(System.getenv("APPDATA")+"/Microsoft/Windows/Start Menu/Programs/Startup/stream_pi_starter_"+ softwareType +".vbs");
File vbsStarterFile = new File(System.getenv("APPDATA")+"/Microsoft/Windows/Start Menu/Programs/Startup/stream_pi_starter_"+ softwareType +".vbs");
fw = new FileWriter(vbsStarterFile);
fw = new FileWriter(vbsStarterFile);
bw = new BufferedWriter(fw);
bw = new BufferedWriter(fw);
bw.write("Set WshShell = CreateObject(\"WScript.Shell\") \r\n" +
bw.write("Set WshShell = CreateObject(\"WScript.Shell\") \r\n" +
"WshShell.Run chr(34) & \""+initFile.getAbsolutePath()+"\" & Chr(34), 0\r\n" +
"WshShell.Run chr(34) & \""+initFile.getAbsolutePath()+"\" & Chr(34), 0\r\n" +
"Set WshShell = Nothing");
"Set WshShell = Nothing");
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()
{
{
boolean f1 = new File(System.getenv("APPDATA")+"/Microsoft/Windows/Start Menu/Programs/Startup/stream_pi_starter_"+ softwareType +".vbs").delete();
boolean f1 = new File(System.getenv("APPDATA")+"/Microsoft/Windows/Start Menu/Programs/Startup/stream_pi_starter_"+ softwareType +".vbs").delete();
boolean f2 = new File(System.getenv("APPDATA")+"/stream_pi_starter_batch_"+ softwareType +".bat").delete();
boolean f2 = new File(System.getenv("APPDATA")+"/stream_pi_starter_batch_"+ softwareType +".bat").delete();
return f1 && f2;
return f1 && f2;
}
}
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.");
}
}
}
}