Beispiel #1
0
 private string BuildInputFormat()
 {
     if (InputFormat != null)
     {
         return($"-f {InputFormat.ToString()} ");
     }
     else
     {
         return(string.Empty);
     }
 }
Beispiel #2
0
        private static bool AutoDetectFormat(ref List <string> fileList)
        {
            // detect what types of file formats are found
            bool foundMBIN = false;
            bool foundEXML = false;

            foreach (var file in fileList)
            {
                DetectFormat(file, ref foundMBIN, ref foundEXML);
            }

            // TODO: this should be handled better
            if (!foundMBIN && !foundEXML)
            {
                if ((fileList.Count == 1) && File.Exists(fileList[0]))
                {
                    using (var fIn = new FileStream(fileList[0], FileMode.Open)) {
                        // possibly MBIN? check for a valid header
                        using (var mbin = new MBINFile(fIn, true)) foundMBIN = (mbin.Load() && mbin.Header.IsValid);
                        if (!foundMBIN)     // possibly EXML? check for a valid xml tag
                        {
                            var xmlTag = "<?xml version=\"1.0\" encoding=\"utf-8\"?>".ToLower();
                            var bytes  = new byte[xmlTag.Length];
                            // TODO: handle potential leading whitespace?
                            if (fIn.Read(bytes, 0, xmlTag.Length) == xmlTag.Length)
                            {
                                var txt = System.Text.Encoding.ASCII.GetString(bytes).ToLower();
                                foundEXML = (txt == xmlTag);
                            }
                        }
                    }
                }
            }

            if (foundMBIN && foundEXML)
            {
                const string msg = "Unable to automatically determine the --input-format type.";
                if (Quiet)
                {
                    return(CommandLine.ShowError(msg) == (int)ErrorCode.Success);
                }
                CommandLine.ShowWarning(msg);
                Console.Out.WriteLine("Both MBIN and EXML file types were detected!\n");
                InputFormat = Utils.PromptInputFormat();
                Console.WriteLine();
            }
            else if (foundMBIN)
            {
                if (!StreamToConsole)
                {
                    Logger.LogInfo("Auto-Detected --input-format=MBIN");
                }
                InputFormat = FormatType.MBIN;
            }
            else if (foundEXML)
            {
                if (!StreamToConsole)
                {
                    Logger.LogInfo("Auto-Detected --input-format=EXML");
                }
                InputFormat = FormatType.EXML;
            }
            else
            {
                CommandLine.ShowError("No valid files found!");
                return(false);
            }

            OutputFormat = (InputFormat == FormatType.MBIN) ? FormatType.EXML : FormatType.MBIN;
            Logger.LogMessage("INFO", $"--input-format={InputFormat} --output-format={OutputFormat}");

            // exclude any files that don't match InputFormat
            for (int i = fileList.Count - 1; i >= 0; i--)
            {
                var ext = Path.GetExtension(fileList[i]).ToUpper();
                if (ext == ".PC")
                {
                    ext = Path.GetExtension(Path.ChangeExtension(fileList[i], null)).ToUpper();
                }
                if (ext.Substring(1) != InputFormat.ToString())
                {
                    fileList.RemoveAt(i);
                }
            }

            return(true);
        }