public static LuaStream GetResourceAsset(String path, String resName) { LuaStream ls = new LuaStream(); ls.SetStream(Defines.GetResourceAsset(path, resName)); return(ls); }
/** * This function gets resource based on defines.lua config * @param path root path to search. * @param resName resource name to search * @return LuaStream of resource */ public static LuaStream GetResource(String path, String resName) { //String scriptsRoot = LuaEngine.getInstance().GetScriptsRoot(); int primaryLoad = LuaEngine.Instance.GetPrimaryLoad(); switch (primaryLoad) { case LuaEngine.EXTERNAL_DATA: { LuaStream ls = new LuaStream(); ls.SetStream(Defines.GetResourceSdAsset(path + "/", resName)); return(ls); } case LuaEngine.INTERNAL_DATA: case LuaEngine.RESOURCE_DATA: { LuaStream ls = new LuaStream(); ls.SetStream(Defines.GetResourceAsset(path + "/", resName)); return(ls); } default: { LuaStream ls = new LuaStream(); ls.SetStream(Defines.GetResourceAsset(path + "/", resName)); return(ls); } } }
public void Initialize(Lua.lua_State L) { DrawableParser = LGDrawableParser.Instance; DimensionParser = LGDimensionParser.Instance; ColorParser = LGColorParser.Instance; StringParser = LGStringParser.Instance; List <String> lst = new List <String>(); lst.Add("ld"); MatchStringsStart.Add(lst); lst = new List <String>(); lst.Add("sw"); MatchStringsStart.Add(lst); lst = new List <String>(); lst.Add("w"); MatchStringsStart.Add(lst); lst = new List <String>(); lst.Add("h"); MatchStringsStart.Add(lst); lst = new List <String>(); lst.Add("small"); lst.Add("normal"); lst.Add("large"); lst.Add("xlarge"); MatchStringsStart.Add(lst); lst = new List <String>(); lst.Add("port"); lst.Add("land"); MatchStringsStart.Add(lst); lst = new List <String>(); lst.Add("ldpi"); lst.Add("mdpi"); lst.Add("hdpi"); lst.Add("xhdpi"); lst.Add("nodpi"); MatchStringsStart.Add(lst); lst = new List <String>(); lst.Add("v"); MatchStringsStart.Add(lst); lst = new List <String>(); MatchStringsEnd.Add(lst); lst = new List <String>(); lst.Add("dp"); MatchStringsEnd.Add(lst); lst = new List <String>(); lst.Add("dp"); MatchStringsEnd.Add(lst); lst = new List <String>(); lst.Add("dp"); MatchStringsEnd.Add(lst); lst = new List <String>(); MatchStringsEnd.Add(lst); lst = new List <String>(); MatchStringsEnd.Add(lst); lst = new List <String>(); MatchStringsEnd.Add(lst); lst = new List <String>(); switch (LuaEngine.Instance.GetPrimaryLoad()) { case LuaEngine.EXTERNAL_DATA: { #if NETFX_CORE StorageFolder internalScriptsFolder = null; /*String[] scriptRootArr = scriptsRoot.Split('/'); * foreach (String scriptRootPart in scriptRootArr)*/ String uiRoot = LuaEngine.Instance.GetUIRoot().Replace("/", "\\"); internalScriptsFolder = Package.Current.InstalledLocation.GetFolderAsync(uiRoot).AsTask().Synchronize(); IReadOnlyList <StorageFile> files = internalScriptsFolder.GetFilesAsync().AsTask().Synchronize(); String rootPath = ApplicationData.Current.LocalFolder.Path; StorageFolder rootFolder = ApplicationData.Current.LocalFolder; StorageFolder scriptsFolder = null; if (LuaEngine.Instance.GetForceLoad() > 0) { try { StorageFolder sf = rootFolder.GetFolderAsync(uiRoot).AsTask().Synchronize(); sf.DeleteAsync().AsTask().Synchronize(); } catch { } scriptsFolder = rootFolder.CreateFolderAsync(uiRoot, CreationCollisionOption.ReplaceExisting).AsTask().Synchronize(); } else { scriptsFolder = rootFolder.CreateFolderAsync(uiRoot, CreationCollisionOption.OpenIfExists).AsTask().Synchronize(); } foreach (StorageFile fileSF in files) { String file = fileSF.Name; Stream sr = Defines.GetResourceAsset(uiRoot + "/", file); StorageFile toWrite = scriptsFolder.CreateFileAsync(file, CreationCollisionOption.ReplaceExisting).AsTask().Synchronize(); var toWriteStream = toWrite.OpenTransactedWriteAsync().AsTask().Synchronize(); byte[] buffer = new byte[1024]; int length = 0; while ((length = sr.Read(buffer, 0, buffer.Length)) > 0) { toWriteStream.Stream.WriteAsync(buffer.AsBuffer()).AsTask().Synchronize(); } toWriteStream.CommitAsync().AsTask().Synchronize(); toWriteStream.Dispose(); } #endif } break; case LuaEngine.INTERNAL_DATA: case LuaEngine.RESOURCE_DATA: { } break; } ParseValues(L); DrawableParser.Initialize(L); }