import std.stdio; import std.range; import std.algorithm; import std.path; import std.file; import dfuse.fuse; import cm3d2; void main(string[] args) { if (args.length < 2) { help(args[0]); return; } switch (args[1]) { case "help": case "-h": case "--help": help(args[0]); break; case "menu-to-sdl": ubyte[] data = stdin.byChunk(4096).joiner.array; writeln(Menu.fromMenu(data).toSDL()); break; case "sdl-to-menu": throw new Exception("Not implemented yet"); case "mount-arc": string arcPath; string mountpoint; if (args.length < 4 || !(arcPath = args[2]).isValidPath || !(mountpoint = args[3]).isValidPath) { goto case "help"; } mountArc(arcPath, mountpoint); break; default: writeln("Unknown option '" ~ args[1] ~ "'"); writeln(); goto case "help"; } } void help(string toolPath) { writeln("usage: " ~ toolPath ~ " [--help] []"); writeln(); void showCommandUsage(string command, string description) { writeln(" " ~ toolPath ~ " " ~ command); writeln(" " ~ description); } showCommandUsage("menu-to-sdl", "Convert .menu (from stdin) to SDL (stdout)"); showCommandUsage("sdl-to-menu", "Convert SDL (from stdin) to .menu (stdout)"); writeln(); showCommandUsage("mount-arc ", "FUSE mount arc file(s) on mountpoint"); writeln(); writeln("Reads input from stdin and writes output to stdout."); } void mountArc(string arcPath, string mountpoint) { if (!arcPath.exists) { writeln("Error: .arc path doesn't exist."); return; } if (!mountpoint.exists || !mountpoint.isDir) { writeln("Error: mountpoint doesn't exist or isn't a directory."); return; } string[] arcFiles; if (arcPath.isDir) { arcFiles ~= arcPath.dirEntries("*.arc", SpanMode.shallow).map!(e => e.name).array; } else { arcFiles ~= arcPath; } if (arcFiles.length == 0) { writeln("Error: no .arc file(s) selected!"); return; } auto fuse = new Fuse("cm3d2tool-arcfs", true, true); fuse.mount(new ArcFileSystem(arcFiles), mountpoint, ["ro", "noexec"]); }