예제 #1
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);
        }
예제 #2
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);
        }
예제 #3
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 path to the weapon file to import");
                return(false);
            }

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

            if (writePath.Length == 0)
            {
                cli.Err("Please specify an output path to write the file either inside the iwd file or on disk");
                return(false);
            }

            Model.Weapon weapon;
            if (!File.Exists(weaponPath))
            {
                cli.Err($"Could not find the file {weaponPath}");
                return(false);
            }
            string allText = File.ReadAllText(weaponPath);

            switch (System.IO.Path.GetExtension(weaponPath).ToUpper())
            {
            case ".XML":
                weapon = Model.Weapon.FromXML(allText);
                break;

            case ".JSON":
                weapon = Model.Weapon.FromJSON(allText);
                break;

            default:
                cli.Err($"Unknown format {System.IO.Path.GetExtension(weaponPath)}, will not read it.");
                return(false);
            }

            var finalPath = writePath;
            var contents  = weapon.SerializeToIW();

            if (cli.currentRawFile == null)
            {
                File.WriteAllText(finalPath, contents);
                cli.Log($"Successfully wrote output file to {finalPath}.");
            }
            else
            {
                cli.currentRawFile.GetEntry(writePath).Delete();
                var entry = cli.currentRawFile.CreateEntry(writePath);
                using (var stream = entry.Open())
                {
                    using (StreamWriter writer = new StreamWriter(stream))
                    {
                        writer.Write(contents);
                        cli.Log($"Successfully wrote output file to {cli.currentRawFilePath}. Don't forget to COMMIT to validate the changes.");
                    }
                }
            }

            return(true);
        }
예제 #4
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);
        }