예제 #1
0
        public override bool Execute(CommandLineInterface cli, string arguments, out string remainder)
        {
            if (arguments.Length == 0)
            {
                cli.Log($"We are currently in {Directory.GetCurrentDirectory()}");
                remainder = arguments;
            }
            else
            {
                var newPath = CommandLineInterface.GetFirstString(arguments, out remainder);

                try
                {
                    Directory.SetCurrentDirectory(newPath);
                    cli.Log($"We are now in {Directory.GetCurrentDirectory()}");
                }
                catch (System.IO.DirectoryNotFoundException)
                {
                    cli.Err($"The directory or a part of the directory {newPath} could not be found.");
                    return(false);
                }
            }
            return(true);
        }
예제 #2
0
        public override bool Execute(CommandLineInterface cli, string arguments, out string remainder)
        {
            if (cli.currentRawFile == null)
            {
                cli.Warn("No iwd file was loaded! Nothing was unloaded.");
            }

            cli.currentRawFile?.Dispose();
            cli.currentRawFile = null;

            cli.Log($"Unloaded iwd file {cli.currentRawFilePath}");

            cli.currentRawFilePath = null;

            remainder = arguments;

            return(true);
        }
예제 #3
0
        public override bool Execute(CommandLineInterface cli, string arguments, out string remainder)
        {
            if (cli.currentRawFile == null)
            {
                cli.Warn("No iwd file was loaded! Nothing to commit.");
                remainder = string.Empty;
                return(false);
            }
            else
            {
                cli.currentRawFile.Dispose();
                cli.currentRawFile = ZipFile.Open(cli.currentRawFilePath, ZipArchiveMode.Update);
                cli.Log($"Committed all changes to iwd file {cli.currentRawFilePath}");
            }

            remainder = arguments;

            return(true);
        }
예제 #4
0
        public override bool Execute(CommandLineInterface cli, string arguments, out string remainder)
        {
            string rawFilePath = CommandLineInterface.GetFirstString(arguments, out remainder);

            if (rawFilePath.Length == 0)
            {
                cli.Err("Please specify a path to load.");
                return(false);
            }

            try
            {
                cli.currentRawFile     = ZipFile.Open(rawFilePath, ZipArchiveMode.Update);
                cli.currentRawFilePath = rawFilePath;
                cli.Log($"Successfully opened {rawFilePath} for import/export operations");
            }
            catch (System.IO.IOException e)
            {
                cli.Err(e.ToString());
                return(false);
            }

            return(true);
        }
예제 #5
0
        public override bool Execute(CommandLineInterface cli, string arguments, out string remainder)
        {
            string weaponPath = CommandLineInterface.GetFirstString(arguments, out remainder);

            if (weaponPath.Length == 0)
            {
                cli.Err("Please specify a weapon path to export");
                return(false);
            }

            string format = CommandLineInterface.GetFirstString(remainder, out remainder);

            if (format.Length == 0)
            {
                cli.Err("Please specify a format for the exported file, either XML or JSON");
                return(false);
            }

            /*
             * if (arguments.Length <= secondMarker + 1)
             * {
             *  cli.Err("Please supply a valid format for the exported file");
             *  remainder = string.Empty;
             *  return false;
             * }
             *
             * remainder = arguments.Substring(secondMarker + 2);
             */


            Model.Weapon weapon;
            string       allText;

            if (cli.currentRawFile != null)
            {
                var entry = cli.currentRawFile.GetEntry(weaponPath);
                if (entry == null)
                {
                    cli.Err($"Could not find the file {weaponPath} in loaded iwd file");
                    return(false);
                }
                else
                {
                    using (var stream = cli.currentRawFile.GetEntry(weaponPath).Open())
                    {
                        using (StreamReader reader = new StreamReader(stream))
                        {
                            allText = reader.ReadToEnd();
                        }
                    }
                }
            }
            else
            {
                if (!File.Exists(weaponPath))
                {
                    cli.Err($"Could not find the file {weaponPath}");
                    return(false);
                }

                if (System.IO.Path.GetExtension(weaponPath).Length > 0)
                {
                    cli.Err($"Wrong format for file {System.IO.Path.GetFileName(weaponPath)}");
                    return(false);
                }

                allText = File.ReadAllText(weaponPath);
            }


            weapon = Model.Weapon.FromIW(allText, cli.Warn);
            cli.Log($"Successfully loaded {System.IO.Path.GetFileName(weaponPath)}");

            var    finalPath = System.IO.Path.GetFileName(weaponPath) + "." + format;
            string output;

            switch (format.ToUpper())
            {
            case "XML":
                output = weapon.SerializeToXML();
                break;

            case "JSON":
                output = weapon.SerializeToJSON();
                break;

            default:
                cli.Err($"No valid output format given for {System.IO.Path.GetFileName(weaponPath)} ({format}), will not write anything to disk.");
                return(false);
            }

            File.WriteAllText(finalPath, output);

            cli.Log($"Successfully wrote output file to {finalPath}");
            return(true);
        }