resources import with path - step 1 for better resource/different DPI management; is possible after import with path is fixed in DMD on windows

This commit is contained in:
Vadim Lopatin 2017-08-31 11:43:57 +03:00
parent a1aeaefb07
commit 03a87383eb
1 changed files with 13 additions and 3 deletions

View File

@ -112,9 +112,11 @@ immutable string EMBEDDED_RESOURCE_PREFIX = "@embedded@/";
struct EmbeddedResource { struct EmbeddedResource {
immutable string name; immutable string name;
immutable ubyte[] data; immutable ubyte[] data;
this(immutable string name, immutable ubyte[] data) { immutable string dir;
this(immutable string name, immutable ubyte[] data, immutable string dir = null) {
this.name = name; this.name = name;
this.data = data; this.data = data;
this.dir = dir;
} }
} }
@ -169,7 +171,13 @@ __gshared EmbeddedResourceList embeddedResourceList;
//immutable string test_res = import("res/background.xml"); //immutable string test_res = import("res/background.xml");
// Unfortunately, import with full pathes does not work on Windows // Unfortunately, import with full pathes does not work on Windows
//version = USE_FULL_PATH_FOR_RESOURCES; version = USE_FULL_PATH_FOR_RESOURCES;
string resDirName(string fullname) {
immutable string step0 = fullname.dirName;
immutable string step1 = step0.startsWith("res/") ? step0[4 .. $] : step0;
return step1 == "." ? null : step1;
}
EmbeddedResource[] embedResource(string resourceName)() { EmbeddedResource[] embedResource(string resourceName)() {
static if (resourceName.startsWith("#")) { static if (resourceName.startsWith("#")) {
@ -182,8 +190,10 @@ EmbeddedResource[] embedResource(string resourceName)() {
} }
static if (name.length > 0) { static if (name.length > 0) {
immutable ubyte[] data = cast(immutable ubyte[])import(name); immutable ubyte[] data = cast(immutable ubyte[])import(name);
immutable string resname = baseName(name);
immutable string resdir = resDirName(name);
static if (data.length > 0) static if (data.length > 0)
return [EmbeddedResource(name, data)]; return [EmbeddedResource(resname, data, resdir)];
else else
return []; return [];
} else } else