Makes the application run independently of the current directory.

This commit is contained in:
Markil3
2021-09-15 10:04:17 -06:00
parent f8be50af9d
commit 4f8b70b2f4
4 changed files with 68 additions and 28 deletions

View File

@@ -18,6 +18,7 @@ import java.net.Socket;
import java.util.Scanner;
import java.util.concurrent.atomic.AtomicBoolean;
import edu.regis.universeplayer.ConfigManager;
import edu.regis.universeplayer.browserCommands.BrowserConstants;
import edu.regis.universeplayer.browserCommands.MessageRunner;
@@ -178,17 +179,7 @@ public class Browser extends MessageRunner
String os = System.getProperty("os.name").toLowerCase();
String arch = System.getProperty("os.arch").toLowerCase();
String args;
File browserDir = new File(System.getProperty("user.dir"), "firefox");
if (!browserDir.isDirectory())
{
browserDir = new File(new File(System.getProperty("user.dir"))
.getParent(), "firefox");
}
File profileDir = new File(System.getProperty("user.dir"), "profile");
if (!profileDir.exists())
{
profileDir.mkdir();
}
File browserDir = ConfigManager.getFirefoxDir();
// args = " -no-remote -profile \"" + profileDir.getAbsolutePath() + "\"";
args = " -no-remote -P Universal";

View File

@@ -20,6 +20,65 @@ public class ConfigManager
private static File dataDir;
private static File commDir;
private static File configDir;
private static File appDir;
private static File firefoxDir;
/**
* Obtains the install directory for the application.
*
* @return The application storage directory.
*/
public static File getAppDir()
{
if (appDir == null)
{
appDir = new File(System.getProperty("java.class" +
".path").split(File.pathSeparator)[0]);
appDir = appDir.getParentFile();
firefoxDir = new File(appDir, "firefox");
if (!firefoxDir.exists())
{
firefoxDir = new File(appDir.getParent(), "firefox");
if (firefoxDir.exists())
{
appDir = appDir.getParentFile();
}
else
{
firefoxDir = new File(System.getProperty("user.dir"),
"firefox");
if (firefoxDir.exists())
{
appDir = new File(System.getProperty("user.dir"));
}
else
{
firefoxDir = new File(firefoxDir.getParentFile().getParent(),
"firefox");
if (firefoxDir.exists())
{
appDir = firefoxDir.getParentFile();
}
}
}
}
}
return appDir;
}
/**
* Obtains the install directory the firefox installation..
*
* @return The firefox storage directory.
*/
public static File getFirefoxDir()
{
if (firefoxDir == null)
{
getAppDir();
}
return firefoxDir;
}
/**
* Obtains the data storage directory for the application, creating it if

View File

@@ -3,6 +3,7 @@ package edu.regis.universeplayer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.net.Socket;
@@ -46,7 +47,6 @@ public class PlayerEnvironment
*/
public static void main(String[] args)
{
logger.info("MAIN FOREVER");
LinkedHashMap<String, Object> ops = new LinkedHashMap<>();
ArrayList<String> params = new ArrayList<>();
parseArgs(args, ops, params);
@@ -466,8 +466,6 @@ public class PlayerEnvironment
}
if (matches > 0)
{
out.printf("%d matches for %s and %s\n", matches,
finalParam, song);
matchMap.put(song, matches);
}
});
@@ -477,15 +475,7 @@ public class PlayerEnvironment
List<Song> songs = matchMap.entrySet().stream().sorted(Map.Entry
.comparingByValue()).filter(entry -> (entry
.getValue() / (float) params.size()) >= 0.65F)
.map(entry -> {
out.printf("%s: %d / %d (%f)\n",
entry.getKey(),
entry.getValue(),
params.size(),
entry.getValue() / (float) params
.size());
return entry.getKey();
})
.map(Map.Entry::getKey)
.collect(Collectors.toList());
Collections.reverse(songs);
out.println("Playing " + songs.toString());

View File

@@ -54,11 +54,11 @@ then
exit 3
fi
chmod +X "\$installDir/firefox/firefox"
rm "/tmp/firefox.tar.bz2"
if [ \$? -ne 0 ]
then
echo "WARNING: Could not clean up firefox!" 1>&2
fi
#rm "/tmp/firefox.tar.bz2"
#if [ \$? -ne 0 ]
#then
# echo "WARNING: Could not clean up firefox!" 1>&2
#fi
cd "\$OLDPWD"
cd "\$installDir/firefox"