mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-23 01:21:40 +00:00
* Begin scripting work * More scripting work * Finalize scripting system * Begin implementing script events * Finalize script system Co-authored-by: Banks T <btrout.dhrs@gmail.com>
49 lines
1.2 KiB
Java
49 lines
1.2 KiB
Java
package com.chameleonvision.util;
|
|
|
|
import java.io.File;
|
|
import java.net.URISyntaxException;
|
|
|
|
public class ProgramDirectoryUtilities
|
|
{
|
|
private static String getJarName()
|
|
{
|
|
return new File(ProgramDirectoryUtilities.class.getProtectionDomain()
|
|
.getCodeSource()
|
|
.getLocation()
|
|
.getPath())
|
|
.getName();
|
|
}
|
|
|
|
private static boolean runningFromJAR()
|
|
{
|
|
String jarName = getJarName();
|
|
return jarName.contains(".jar");
|
|
}
|
|
|
|
public static String getProgramDirectory()
|
|
{
|
|
if (runningFromJAR())
|
|
{
|
|
if (Platform.isRaspberryPi()) {
|
|
return "/boot/chameleon-vision";
|
|
}
|
|
return getCurrentJARDirectory();
|
|
} else
|
|
{
|
|
return System.getProperty("user.dir");
|
|
}
|
|
}
|
|
|
|
private static String getCurrentJARDirectory()
|
|
{
|
|
try
|
|
{
|
|
return new File(ProgramDirectoryUtilities.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()).getParent();
|
|
} catch (URISyntaxException exception)
|
|
{
|
|
exception.printStackTrace();
|
|
}
|
|
|
|
return null;
|
|
}
|
|
} |