mirror of
https://github.com/ProjectSWGCore/pswgcommon.git
synced 2026-01-17 00:04:25 -05:00
Added null intent manager check to services/managers and created a LocalUtilities class
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
50
src/com/projectswg/common/utilities/LocalUtilities.java
Normal file
50
src/com/projectswg/common/utilities/LocalUtilities.java
Normal 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");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user