Added null intent manager check to services/managers and created a LocalUtilities class

This commit is contained in:
Obique
2017-11-19 16:31:53 -06:00
parent 4cd76ae274
commit 016f219e80
3 changed files with 56 additions and 2 deletions

View File

@@ -160,7 +160,9 @@ public abstract class Manager extends Service {
return;
}
children.add(s);
s.setIntentManager(getIntentManager());
IntentManager manager = getIntentManager();
if (manager != null)
s.setIntentManager(manager);
}
}

View File

@@ -74,7 +74,9 @@ public abstract class Service {
* @return TRUE if termination was successful, FALSE otherwise
*/
public boolean terminate() {
IntentManager.getInstance().terminate();
IntentManager im = IntentManager.getInstance();
if (im != null)
im.terminate();
return true;
}

View File

@@ -0,0 +1,50 @@
package com.projectswg.common.utilities;
import java.io.File;
import java.util.concurrent.atomic.AtomicReference;
public class LocalUtilities {
private static final AtomicReference<String> APP_NAME = new AtomicReference<>(".projectswg");
public static void setApplicationName(String name) {
APP_NAME.set(name);
}
public static File getSubApplicationDirectory(String ... names) {
File dir = getApplicationDirectory();
for (String name : names) {
dir = new File(dir, name);
if (!dir.exists())
dir.mkdir();
}
return dir;
}
public static File getApplicationDirectory() {
String home = getHomeDirectory();
if (home == null)
throw new IllegalStateException("Unknown home directory for OS '"+System.getProperty("os.name")+"'");
File dir = new File(home, APP_NAME.get());
if (!dir.exists())
dir.mkdirs();
return dir;
}
private static String getHomeDirectory() {
String os = System.getProperty("os.name").toUpperCase();
if (os.contains("WIN"))
return System.getenv("APPDATA");
if (os.contains("MAC"))
return System.getProperty("user.home") + "/Library/Application Support";
if (os.contains("NUX"))
return System.getProperty("user.home");
return System.getProperty("user.dir");
}
}