local ____lualib = require("lualib_bundle") local __TS__ArrayForEach = ____lualib.__TS__ArrayForEach local __TS__StringEndsWith = ____lualib.__TS__StringEndsWith local __TS__SourceMapTraceBack = ____lualib.__TS__SourceMapTraceBack __TS__SourceMapTraceBack(debug.getinfo(1).short_src, {["7"] = 1,["8"] = 1,["9"] = 3,["10"] = 3,["11"] = 4,["12"] = 4,["19"] = 20,["20"] = 21,["21"] = 21,["22"] = 21,["23"] = 21,["24"] = 23,["25"] = 24,["26"] = 23,["27"] = 27,["28"] = 28,["29"] = 29,["31"] = 31,["32"] = 31,["33"] = 31,["34"] = 32,["35"] = 32,["36"] = 32,["37"] = 32,["38"] = 33,["39"] = 33,["40"] = 33,["41"] = 33,["42"] = 31,["43"] = 31,["44"] = 35,["45"] = 27,["46"] = 38,["47"] = 39,["48"] = 40,["49"] = 41,["50"] = 41,["51"] = 41,["52"] = 42,["53"] = 46,["54"] = 47,["55"] = 48,["56"] = 49,["57"] = 50,["58"] = 51,["60"] = 41,["61"] = 41,["62"] = 54,["63"] = 38,["64"] = 57,["65"] = 58,["66"] = 59,["68"] = 61,["70"] = 57,["71"] = 67,["72"] = 68,["73"] = 69,["74"] = 70,["75"] = 71,["76"] = 72,["78"] = 74,["80"] = 67,["81"] = 78,["82"] = 20}); local ____exports = {} local ____FileUtils = require("FileUtils") local FileUtils = ____FileUtils.FileUtils local ____XmlUtils = require("XmlUtils") local XmlUtils = ____XmlUtils.XmlUtils local ____base64Codec = require("base64Codec") local decode = ____base64Codec.decode --- Craete Image Importer -- Runs the "UpdateContent" command which makes MA3 generate XML file for each image in the image library. -- Then resolves which XML belongs to which image file. -- -- @param pluginId an id used as a sub-folder name inside the image library -- @returns An Importer that can be used to import images by their original file name. function ____exports.ImageLibraryUtils(self, pluginId, log) local imageLibraryPath = FileUtils:path( GetPath(Enums.PathType.ImageLibrary), pluginId ) local function getImageFileName(self, originalFileName) return (pluginId .. "_") .. originalFileName end local function writeImageFiles(self, images) if not FileUtils:exists(imageLibraryPath) then FileUtils:makeDir(imageLibraryPath) end __TS__ArrayForEach( images, function(____, image) local path = FileUtils:path( imageLibraryPath, getImageFileName(nil, image.fileName) ) FileUtils:writeBinaryFile( path, decode(image.imageBase64) ) end ) Cmd("UpdateContent image \"Images\"") end local function indexLibraryFile(self) local files = FileUtils:getDirectoryContent(imageLibraryPath) local xmlFileNameByImageFileName = {} __TS__ArrayForEach( files, function(____, file) if __TS__StringEndsWith(file.name, ".png.xml") then local content = FileUtils:readFile(file.fullPath) local presetsXmlNode = XmlUtils:parseXml(content) local root = presetsXmlNode[2] local userImageNode = root[1] local imageFileName = userImageNode.xarg.FileName xmlFileNameByImageFileName[imageFileName] = file.name end end ) return xmlFileNameByImageFileName end local function deleteAllImages(self) if FileUtils:exists(imageLibraryPath) and FileUtils:isDir(imageLibraryPath) then FileUtils:removeDirectory(imageLibraryPath) else log:warn("deleteAllImages: The plugin's Image library folder was aobut to be deleted, but it didn't exist. Folder path = " .. imageLibraryPath) end end local function importImages(self, images) local xmlFileNameByImageFileName = indexLibraryFile(nil) for ____, image in ipairs(images) do local xmlFileName = xmlFileNameByImageFileName[getImageFileName(nil, image.imageFileName)] if xmlFileName == nil then error((("Import " .. image.imageFileName) .. " failed. a corresponding XML file was not found under ") .. imageLibraryPath) end Cmd(((((("Import Image \"Images\"." .. tostring(image.targetIndex)) .. " /File \"") .. xmlFileName) .. "\" /Path \"") .. imageLibraryPath) .. "\" /nc") end end return {deleteAllImages = deleteAllImages, imageLibraryPath = imageLibraryPath, importImages = importImages, writeImageFiles = writeImageFiles} end return ____exports