From 5e8d73928b61541a18aba4e84fe2dbbef4888b23 Mon Sep 17 00:00:00 2001 From: luboslenco Date: Wed, 13 Nov 2019 13:51:17 +0100 Subject: [PATCH] Begin file sys tools --- Sources/arm/App.hx | 2 +- Sources/arm/Plugin.hx | 2 +- Sources/arm/Project.hx | 2 +- Sources/arm/io/ExportArm.hx | 2 +- Sources/arm/io/ImportArm.hx | 2 +- Sources/arm/io/ImportBlend.hx | 2 +- Sources/arm/io/ImportFolder.hx | 33 ++++++++----------------------- Sources/arm/io/ImportMesh.hx | 2 +- Sources/arm/io/ImportPlugin.hx | 23 +++++---------------- Sources/arm/io/ImportTexture.hx | 2 +- Sources/arm/io/Importer.hx | 2 +- Sources/arm/sys/File.hx | 29 +++++++++++++++++++++++++++ Sources/arm/{util => sys}/Path.hx | 20 +++++++++++++++++-- Sources/arm/ui/TabTextures.hx | 2 +- Sources/arm/ui/UIFiles.hx | 2 +- Sources/arm/ui/UIMenu.hx | 2 +- 16 files changed, 72 insertions(+), 57 deletions(-) create mode 100644 Sources/arm/sys/File.hx rename Sources/arm/{util => sys}/Path.hx (90%) diff --git a/Sources/arm/App.hx b/Sources/arm/App.hx index 218fc8dd..b5c0f224 100644 --- a/Sources/arm/App.hx +++ b/Sources/arm/App.hx @@ -18,7 +18,7 @@ import arm.ui.UIMenu; import arm.ui.UIBox; import arm.ui.UIFiles; import arm.io.Importer; -import arm.util.Path; +import arm.sys.Path; import arm.util.RenderUtil; import arm.util.ViewportUtil; import arm.data.MaterialSlot; diff --git a/Sources/arm/Plugin.hx b/Sources/arm/Plugin.hx index 94c97d6b..5dc057f1 100644 --- a/Sources/arm/Plugin.hx +++ b/Sources/arm/Plugin.hx @@ -75,7 +75,7 @@ class ArmBridge { public static var Plugin = arm.Plugin; public static var Project = arm.Project; public static var Res = arm.Res; - public static var Path = arm.util.Path; + public static var Path = arm.sys.Path; public static var NodesMaterial = arm.nodes.NodesMaterial; public static var Material = arm.nodes.Material; public static var Exporter = arm.io.Exporter; diff --git a/Sources/arm/Project.hx b/Sources/arm/Project.hx index e5ca2754..810bc076 100644 --- a/Sources/arm/Project.hx +++ b/Sources/arm/Project.hx @@ -11,7 +11,7 @@ import iron.object.MeshObject; import iron.Scene; import arm.util.RenderUtil; import arm.util.ViewportUtil; -import arm.util.Path; +import arm.sys.Path; import arm.ui.UITrait; import arm.ui.UINodes; import arm.ui.UIFiles; diff --git a/Sources/arm/io/ExportArm.hx b/Sources/arm/io/ExportArm.hx index 250b9845..f41e4a87 100644 --- a/Sources/arm/io/ExportArm.hx +++ b/Sources/arm/io/ExportArm.hx @@ -7,7 +7,7 @@ import iron.system.ArmPack; import arm.ui.UITrait; import arm.ui.UINodes; import arm.util.Lz4; -import arm.util.Path; +import arm.sys.Path; import arm.Project; using StringTools; diff --git a/Sources/arm/io/ImportArm.hx b/Sources/arm/io/ImportArm.hx index 36fe3598..072d0d24 100644 --- a/Sources/arm/io/ImportArm.hx +++ b/Sources/arm/io/ImportArm.hx @@ -15,7 +15,7 @@ import arm.Project; import arm.ui.UITrait; import arm.ui.UINodes; import arm.ui.UIFiles; -import arm.util.Path; +import arm.sys.Path; import arm.util.Lz4; import arm.util.RenderUtil; import arm.util.ViewportUtil; diff --git a/Sources/arm/io/ImportBlend.hx b/Sources/arm/io/ImportBlend.hx index d579f340..4ee9c8b3 100644 --- a/Sources/arm/io/ImportBlend.hx +++ b/Sources/arm/io/ImportBlend.hx @@ -12,7 +12,7 @@ import arm.ui.UITrait; import arm.ui.UINodes; import arm.nodes.NodesMaterial; import arm.nodes.MaterialParser; -import arm.util.Path; +import arm.sys.Path; import arm.util.RenderUtil; import arm.data.MaterialSlot; using StringTools; diff --git a/Sources/arm/io/ImportFolder.hx b/Sources/arm/io/ImportFolder.hx index 1243d18c..86da9538 100644 --- a/Sources/arm/io/ImportFolder.hx +++ b/Sources/arm/io/ImportFolder.hx @@ -1,6 +1,5 @@ package arm.io; -import haxe.io.Bytes; import zui.Nodes; import iron.data.Data; import iron.data.MaterialData; @@ -8,7 +7,8 @@ import arm.ui.UITrait; import arm.ui.UINodes; import arm.util.RenderUtil; import arm.util.MaterialUtil; -import arm.util.Path; +import arm.sys.Path; +import arm.sys.File; import arm.nodes.NodesMaterial; import arm.nodes.MaterialParser; import arm.data.MaterialSlot; @@ -18,22 +18,7 @@ using StringTools; class ImportFolder { public static function run(path:String) { - #if krom_windows - var cmd = "dir /b "; - var sep = "\\"; - #else - var cmd = "ls "; - var sep = "/"; - #end - #if krom_linux - var save = "/tmp"; - #else - var save = Krom.savePath(); - #end - save += sep + "dir.txt"; - Krom.sysCommand(cmd + '"' + path + '"' + ' > ' + '"' + save + '"'); - var str = Bytes.ofData(Krom.loadBlob(save)).toString(); - var files = str.split("\n"); + var files = File.readDirectory(path); var mapbase = ""; var mapopac = ""; var mapnor = ""; @@ -41,16 +26,11 @@ class ImportFolder { var maprough = ""; var mapmet = ""; var mapheight = ""; + // Import maps for (f in files) { - if (f.length == 0) continue; - f = f.rtrim(); if (!Path.isTexture(f)) continue; - - f = path + sep + f; - #if krom_windows - f = f.replace("/", "\\"); - #end + f = path + Path.sep + f; // TODO: handle -albedo @@ -87,6 +67,7 @@ class ImportFolder { if (valid) ImportTexture.run(f); } + // Create material var isScene = UITrait.inst.worktab.position == SpaceScene; if (isScene) { @@ -109,6 +90,7 @@ class ImportFolder { for (n in canvas.nodes) if (n.type == "OUTPUT_MATERIAL_PBR") { nout = n; break; } for (n in canvas.nodes) if (n.name == "RGB") { nodes.removeNode(n, canvas); break; } + // Place nodes var pos = 0; var startY = 100; var nodeH = 164; @@ -182,6 +164,7 @@ class ImportFolder { var l = { id: nodes.getLinkId(canvas.links), from_id: n.id, from_socket: 0, to_id: nout.id, to_socket: 7 }; canvas.links.push(l); } + MaterialParser.parsePaintMaterial(); RenderUtil.makeMaterialPreview(); UITrait.inst.hwnd1.redraws = 2; diff --git a/Sources/arm/io/ImportMesh.hx b/Sources/arm/io/ImportMesh.hx index 72f07432..03c6c2ca 100644 --- a/Sources/arm/io/ImportMesh.hx +++ b/Sources/arm/io/ImportMesh.hx @@ -10,7 +10,7 @@ import iron.Scene; import arm.util.MeshUtil; import arm.util.UVUtil; import arm.util.ViewportUtil; -import arm.util.Path; +import arm.sys.Path; import arm.ui.UITrait; import arm.ui.UIView2D; import arm.ui.UINodes; diff --git a/Sources/arm/io/ImportPlugin.hx b/Sources/arm/io/ImportPlugin.hx index 92b3d05d..52d67eb5 100644 --- a/Sources/arm/io/ImportPlugin.hx +++ b/Sources/arm/io/ImportPlugin.hx @@ -1,8 +1,7 @@ package arm.io; -import iron.data.Data; -import arm.util.Path; -using StringTools; +import arm.sys.Path; +import arm.sys.File; class ImportPlugin { @@ -12,22 +11,10 @@ class ImportPlugin { return; } - #if krom_windows - var sep = "\\"; - var copy = "copy"; - var dataPath = Data.dataPath.replace("/", "\\"); - #else - var sep = "/"; - var copy = "cp"; - var dataPath = Data.dataPath; - #end - - var filename = path.substr(path.lastIndexOf(sep) + 1); - var dest = Krom.getFilesLocation() + sep + dataPath + sep + "plugins" + sep + filename; - - Krom.sysCommand(copy + ' ' + path + ' ' + dest); // Copy to plugin folder + var filename = path.substr(path.lastIndexOf(Path.sep) + 1); + var dstPath = Path.data() + Path.sep + "plugins" + Path.sep + filename; + File.copy(path, dstPath); // Copy to plugin folder arm.ui.BoxPreferences.files = null; // Refresh file list - Log.showMessage("Plugin '" + filename + "' installed."); } } diff --git a/Sources/arm/io/ImportTexture.hx b/Sources/arm/io/ImportTexture.hx index 86409695..62007e22 100644 --- a/Sources/arm/io/ImportTexture.hx +++ b/Sources/arm/io/ImportTexture.hx @@ -3,7 +3,7 @@ package arm.io; import kha.Image; import iron.data.Data; import arm.ui.UITrait; -import arm.util.Path; +import arm.sys.Path; import arm.Project; using StringTools; diff --git a/Sources/arm/io/Importer.hx b/Sources/arm/io/Importer.hx index bc88d37c..94d648c6 100644 --- a/Sources/arm/io/Importer.hx +++ b/Sources/arm/io/Importer.hx @@ -10,7 +10,7 @@ import iron.Scene; import arm.util.MeshUtil; import arm.util.UVUtil; import arm.util.ViewportUtil; -import arm.util.Path; +import arm.sys.Path; import arm.ui.UITrait; import arm.ui.UIView2D; import arm.ui.UINodes; diff --git a/Sources/arm/sys/File.hx b/Sources/arm/sys/File.hx new file mode 100644 index 00000000..ffcaa59c --- /dev/null +++ b/Sources/arm/sys/File.hx @@ -0,0 +1,29 @@ +package arm.sys; + +import haxe.io.Bytes; +using StringTools; + +class File { + + #if krom_windows + static inline var cmd_dir = "dir /b"; + static inline var cmd_copy = "copy"; + #else + static inline var cmd_dir = "ls"; + static inline var cmd_copy = "cp"; + #end + + public static function readDirectory(path:String):Array { + var save = Path.data() + Path.sep + "dir.txt"; + Krom.sysCommand(cmd_dir + ' "' + path + '" > "' + save + '"'); + var str = Bytes.ofData(Krom.loadBlob(save)).toString(); + var ar = str.split("\n"); + var files:Array = []; + for (file in ar) if (file.length > 0) files.push(file.rtrim()); + return files; + } + + public static function copy(srcPath:String, dstPath:String) { + Krom.sysCommand(cmd_copy + ' ' + srcPath + ' ' + dstPath); + } +} diff --git a/Sources/arm/util/Path.hx b/Sources/arm/sys/Path.hx similarity index 90% rename from Sources/arm/util/Path.hx rename to Sources/arm/sys/Path.hx index 1f6399f4..46b83344 100644 --- a/Sources/arm/util/Path.hx +++ b/Sources/arm/sys/Path.hx @@ -1,15 +1,31 @@ -package arm.util; +package arm.sys; +import iron.data.Data; using StringTools; class Path { + #if krom_windows + public static inline var sep = "\\"; + #else + public static inline var sep = "/"; + #end + public static var meshFormats = ["obj", "fbx", "stl", "blend"]; public static var textureFormats = ["jpg", "jpeg", "png", "tga", "bmp", "psd", "gif", "hdr"]; public static var meshImporters = new Map(Void->Void)->Void>(); public static var textureImporters = new Map(kha.Image->Void)->Void>(); + public static function data():String { + #if krom_windows + var path = Data.dataPath.replace("/", "\\"); + #else + var path = Data.dataPath; + #end + return Krom.getFilesLocation() + Path.sep + path; + } + public static function toRelative(from:String, to:String):String { from = haxe.io.Path.normalize(from); to = haxe.io.Path.normalize(to); @@ -134,7 +150,7 @@ class Path { public static function shortPath(s:String):String { var cmd = 'for %I in ("' + s + '") do echo %~sI'; - var save = Krom.getFilesLocation() + "\\data\\tmp.txt"; + var save = data() + sep + "tmp.txt"; Krom.sysCommand(cmd + ' > "' + save + '"'); return haxe.io.Bytes.ofData(Krom.loadBlob(save)).toString().rtrim(); } diff --git a/Sources/arm/ui/TabTextures.hx b/Sources/arm/ui/TabTextures.hx index e5156478..71596cf0 100644 --- a/Sources/arm/ui/TabTextures.hx +++ b/Sources/arm/ui/TabTextures.hx @@ -5,7 +5,7 @@ import iron.data.Data; import iron.system.Time; import iron.system.Input; import arm.io.Importer; -import arm.util.Path; +import arm.sys.Path; using StringTools; class TabTextures { diff --git a/Sources/arm/ui/UIFiles.hx b/Sources/arm/ui/UIFiles.hx index 38b99399..55cc540b 100644 --- a/Sources/arm/ui/UIFiles.hx +++ b/Sources/arm/ui/UIFiles.hx @@ -3,7 +3,7 @@ package arm.ui; import zui.Zui; import zui.Id; import iron.system.Input; -import arm.util.Path; +import arm.sys.Path; using StringTools; class UIFiles { diff --git a/Sources/arm/ui/UIMenu.hx b/Sources/arm/ui/UIMenu.hx index 96d43332..dfb5f030 100644 --- a/Sources/arm/ui/UIMenu.hx +++ b/Sources/arm/ui/UIMenu.hx @@ -8,7 +8,7 @@ import iron.system.Input; import iron.data.Data; import arm.util.ViewportUtil; import arm.util.BuildMacros; -import arm.util.Path; +import arm.sys.Path; using StringTools; class UIMenu {