Make system directories more consistent
This commit is contained in:
@@ -44,6 +44,8 @@ class System {
|
|||||||
public static var numDisplays (get, null):Int;
|
public static var numDisplays (get, null):Int;
|
||||||
public static var userDirectory (get, null):String;
|
public static var userDirectory (get, null):String;
|
||||||
|
|
||||||
|
@:noCompletion private static var __directories = new Map<SystemDirectory, String> ();
|
||||||
|
|
||||||
|
|
||||||
#if (js && html5)
|
#if (js && html5)
|
||||||
@:keep @:expose("lime.embed")
|
@:keep @:expose("lime.embed")
|
||||||
@@ -240,6 +242,89 @@ class System {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static function __getDirectory (type:SystemDirectory):String {
|
||||||
|
|
||||||
|
#if (lime_cffi && !macro)
|
||||||
|
|
||||||
|
if (__directories.exists (type)) {
|
||||||
|
|
||||||
|
return __directories.get (type);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
var path:String;
|
||||||
|
|
||||||
|
if (type == APPLICATION_STORAGE) {
|
||||||
|
|
||||||
|
var company = "MyCompany";
|
||||||
|
var file = "MyApplication";
|
||||||
|
|
||||||
|
if (Application.current != null && Application.current.config != null) {
|
||||||
|
|
||||||
|
if (Application.current.config.company != null) {
|
||||||
|
|
||||||
|
company = Application.current.config.company;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Application.current.config.file != null) {
|
||||||
|
|
||||||
|
file = Application.current.config.file;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
path = lime_system_get_directory (type, company, file);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
path = lime_system_get_directory (type, null, null);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#if windows
|
||||||
|
var seperator = "\\";
|
||||||
|
#else
|
||||||
|
var seperator = "/";
|
||||||
|
#end
|
||||||
|
|
||||||
|
if (path != null && path.length > 0 && !StringTools.endsWith (path, seperator)) {
|
||||||
|
|
||||||
|
path += seperator;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
__directories.set (type, path);
|
||||||
|
return path;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#elseif flash
|
||||||
|
|
||||||
|
if (type != FONTS && Capabilities.playerType == "Desktop") {
|
||||||
|
|
||||||
|
var propertyName = switch (type) {
|
||||||
|
|
||||||
|
case APPLICATION: "applicationDirectory";
|
||||||
|
case APPLICATION_STORAGE: "applicationStorageDirectory";
|
||||||
|
case DESKTOP: "desktopDirectory";
|
||||||
|
case DOCUMENTS: "documentsDirectory";
|
||||||
|
default: "userDirectory";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return Reflect.getProperty (Type.resolveClass ("flash.filesystem.File"), propertyName).nativePath;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#end
|
||||||
|
|
||||||
|
return null;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Get & Set Methods
|
// Get & Set Methods
|
||||||
@@ -271,114 +356,35 @@ class System {
|
|||||||
|
|
||||||
private static function get_applicationDirectory ():String {
|
private static function get_applicationDirectory ():String {
|
||||||
|
|
||||||
#if (lime_cffi && !macro)
|
return __getDirectory (APPLICATION);
|
||||||
return lime_system_get_directory (SystemDirectory.APPLICATION, null, null);
|
|
||||||
#elseif flash
|
|
||||||
if (Capabilities.playerType == "Desktop") {
|
|
||||||
|
|
||||||
return Reflect.getProperty (Type.resolveClass ("flash.filesystem.File"), "applicationDirectory").nativePath;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
return null;
|
|
||||||
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
return null;
|
|
||||||
#end
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static function get_applicationStorageDirectory ():String {
|
private static function get_applicationStorageDirectory ():String {
|
||||||
|
|
||||||
var company = "MyCompany";
|
return __getDirectory (APPLICATION_STORAGE);
|
||||||
var file = "MyApplication";
|
|
||||||
|
|
||||||
if (Application.current != null && Application.current.config != null) {
|
|
||||||
|
|
||||||
if (Application.current.config.company != null) {
|
|
||||||
|
|
||||||
company = Application.current.config.company;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Application.current.config.file != null) {
|
|
||||||
|
|
||||||
file = Application.current.config.file;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#if (lime_cffi && !macro)
|
|
||||||
return lime_system_get_directory (SystemDirectory.APPLICATION_STORAGE, company, file);
|
|
||||||
#elseif flash
|
|
||||||
if (Capabilities.playerType == "Desktop") {
|
|
||||||
|
|
||||||
return Reflect.getProperty (Type.resolveClass ("flash.filesystem.File"), "applicationStorageDirectory").nativePath;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
return null;
|
|
||||||
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
return null;
|
|
||||||
#end
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static function get_desktopDirectory ():String {
|
private static function get_desktopDirectory ():String {
|
||||||
|
|
||||||
#if (lime_cffi && !macro)
|
return __getDirectory (DESKTOP);
|
||||||
return lime_system_get_directory (SystemDirectory.DESKTOP, null, null);
|
|
||||||
#elseif flash
|
|
||||||
if (Capabilities.playerType == "Desktop") {
|
|
||||||
|
|
||||||
return Reflect.getProperty (Type.resolveClass ("flash.filesystem.File"), "desktopDirectory").nativePath;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
return null;
|
|
||||||
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
return null;
|
|
||||||
#end
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static function get_documentsDirectory ():String {
|
private static function get_documentsDirectory ():String {
|
||||||
|
|
||||||
#if (lime_cffi && !macro)
|
return __getDirectory (DOCUMENTS);
|
||||||
return lime_system_get_directory (SystemDirectory.DOCUMENTS, null, null);
|
|
||||||
#elseif flash
|
|
||||||
if (Capabilities.playerType == "Desktop") {
|
|
||||||
|
|
||||||
return Reflect.getProperty (Type.resolveClass ("flash.filesystem.File"), "documentsDirectory").nativePath;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
return null;
|
|
||||||
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
return null;
|
|
||||||
#end
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static function get_fontsDirectory ():String {
|
private static function get_fontsDirectory ():String {
|
||||||
|
|
||||||
#if (lime_cffi && !macro)
|
return __getDirectory (FONTS);
|
||||||
return lime_system_get_directory (SystemDirectory.FONTS, null, null);
|
|
||||||
#else
|
|
||||||
return null;
|
|
||||||
#end
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -396,21 +402,7 @@ class System {
|
|||||||
|
|
||||||
private static function get_userDirectory ():String {
|
private static function get_userDirectory ():String {
|
||||||
|
|
||||||
#if (lime_cffi && !macro)
|
return __getDirectory (USER);
|
||||||
return lime_system_get_directory (SystemDirectory.USER, null, null);
|
|
||||||
#elseif flash
|
|
||||||
if (Capabilities.playerType == "Desktop") {
|
|
||||||
|
|
||||||
return Reflect.getProperty (Type.resolveClass ("flash.filesystem.File"), "userDirectory").nativePath;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
return null;
|
|
||||||
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
return null;
|
|
||||||
#end
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user