2019-11-23 11:55:20 -05:00
|
|
|
package com.chameleonvision.util;
|
2019-11-19 12:43:38 -05:00
|
|
|
|
|
|
|
|
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())
|
|
|
|
|
{
|
|
|
|
|
return getCurrentJARDirectory();
|
|
|
|
|
} else
|
|
|
|
|
{
|
2019-11-21 05:32:19 -05:00
|
|
|
return System.getProperty("user.dir");
|
|
|
|
|
// return getCurrentProjectDirectory();
|
2019-11-19 12:43:38 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static String getCurrentProjectDirectory()
|
|
|
|
|
{
|
|
|
|
|
return new File("").getAbsolutePath();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static String getCurrentJARDirectory()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return new File(ProgramDirectoryUtilities.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()).getParent();
|
|
|
|
|
} catch (URISyntaxException exception)
|
|
|
|
|
{
|
|
|
|
|
exception.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|