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

@@ -1,99 +0,0 @@
package edu.regis.universeplayer;
import net.harawata.appdirs.AppDirsFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
public class ConfigManager
{
/**
* The port the player will listen for connecting instances on.
*/
public static final int PORT = 3001;
private static final Logger logger = LoggerFactory
.getLogger(ConfigManager.class);
private static File dataDir;
private static File commDir;
private static File configDir;
/**
* Obtains the data storage directory for the application, creating it if
* needed.
*
* @return The data storage directory.
*/
public static File getDataDir()
{
if (dataDir == null)
{
dataDir = new File(AppDirsFactory.getInstance()
.getUserDataDir("universalmusic", null, null, true));
if (!dataDir.exists())
{
if (!dataDir.mkdir())
{
logger.error("Could not create data directory {}", dataDir);
}
}
}
return dataDir;
}
/**
* Obtains the configuration directory for the application, creating it if
* needed.
*
* @return The configuration directory.
*/
public static File getConfigDir()
{
if (configDir == null)
{
configDir = new File(AppDirsFactory.getInstance()
.getUserConfigDir("universalmusic", null, null, true));
if (!configDir.exists())
{
if (!configDir.mkdir())
{
logger.error("Could not create configuration directory {}", configDir);
}
}
}
return configDir;
}
/**
* Obtains the directory for memory mapped files
*
* @return The communications storage directory.
*/
public static File getCommDir()
{
if (commDir == null)
{
commDir = new File(AppDirsFactory.getInstance()
.getSharedDir("universalmusic", null, null), "comm");
if (!commDir.getParentFile().exists())
{
if (!commDir.getParentFile().mkdir())
{
logger.error("Could not create shared directory {}", commDir
.getParent());
}
}
if (!commDir.exists())
{
if (!commDir.mkdir())
{
logger.error("Could not create data directory {}", commDir);
}
}
}
return commDir;
}
}

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());