Пример #1
0
        private static void Convert(string From)
        {
            int    last     = From.LastIndexOfAny(new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar });
            int    dot      = From.LastIndexOf('.');
            string To       = From;
            FType  FileType = WADfile.GetType(File.ReadAllBytes(From));

            //check if file has extension, if so, cut off
            if (dot > last)
            {
                To = From.Substring(0, dot);
            }
            if (FileType == FType.MUS)
            {
                To += ".MID";
            }
            else if (FileType == FType.RAWAUDIO)
            {
                To += ".WAV";
            }

            else
            {
                To += "." + FileType.ToString();
            }
            //very simple check, if the destination is the same as the source, ignoring character case
            if (File.Exists(To) && WADfile.getHash(File.ReadAllBytes(From)) == WADfile.getHash(File.ReadAllBytes(To)))
            {
                Log(ConsoleColor.Yellow, "File would be identical after generating destination name. Not converting");
            }
            else
            {
                Convert(From, To);
            }
        }
Пример #2
0
        /// <summary>
        /// Converts data to its unencoded format
        /// </summary>
        /// <param name="From">Data</param>
        /// <param name="To">destination file (extension added automatically)</param>
        /// <returns>true, if successful</returns>
        public static bool Convert(byte[] From, string To)
        {
            FType FileType = WADfile.GetType(From);

            if (File.Exists(To))
            {
                File.Delete(To);
            }
            switch (FileType)
            {
            //just copy the file for these
            case FType.XM:
            case FType.IT:
            case FType.MID:
            case FType.WAV:
            case FType.MP3:
                Program.Log(ConsoleColor.Green, "Copying DATA -> {0}", FileType);
                File.WriteAllBytes(To + "." + FileType.ToString(), From);
                break;

            case FType.OGG:
                Program.Log(ConsoleColor.Green, "Copying DATA -> {0}", FileType);
                File.WriteAllBytes(To + "." + FileType.ToString(), From);
                break;

            case FType.MUS:
                Program.Log(ConsoleColor.Yellow, "Converting MUS -> MID");
                using (MemoryStream IN = new MemoryStream(From))
                {
                    using (FileStream OUT = File.Create(To + ".MID"))
                    {
                        MUS2MID.Convert(IN, OUT);
                    }
                }
                break;

            case FType.RAWAUDIO:
                SaveAudio(From, To + ".WAV");
                break;

            case FType.VIRTUAL:
                Program.Log(ConsoleColor.Yellow, "Not converting virtual entry");
                return(false);

            default:
                try
                {
                    ToImage(From, To + ".PNG");
                }
                catch
                {
                    return(false);
                }
                break;
            }
            return(true);
        }
Пример #3
0
        private static void Convert(string FromFile)
        {
            Log(Verbosity.Debug, "Converting {0} to auto generated name", FromFile);
            int    last     = FromFile.LastIndexOfAny(new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar });
            int    dot      = FromFile.LastIndexOf('.');
            string To       = FromFile;
            FType  FileType = WADfile.GetDataType(File.ReadAllBytes(FromFile));

            //check if file has extension, if so, cut off
            if (dot > last)
            {
                To = FromFile.Substring(0, dot);
            }
            if (FileType == FType.MUS)
            {
                To += ".MID";
            }
            else if (FileType == FType.RAWAUDIO)
            {
                To += ".WAV";
            }

            else
            {
                To += "." + FileType.ToString();
            }
            //very simple check, if the destination is the same as the source, ignoring character case
            if (File.Exists(To) && WADfile.getHash(File.ReadAllBytes(FromFile)) == WADfile.getHash(File.ReadAllBytes(To)))
            {
                Log(Verbosity.Warn, "File would be identical after generating destination name. Not converting");
            }
            else
            {
                Log(Verbosity.Debug, "Auto-Generated File Name: {0}", To);
                Convert(FromFile, To);
            }
        }
Пример #4
0
        /// <summary>
        /// Main entry point
        /// </summary>
        /// <param name="args">arguments</param>
        private static void Main(string[] args)
        {
#if DEBUG
            MinVerbosity = Verbosity.Debug;
            args         = new string[] {
                "E",
                @"C:\Users\Administrator\Desktop\Games\GZdoom\HellOnEarthStarterPack\hellonearthstarterpack.wad",
                @"C:\Users\Administrator\Desktop\Games\GZdoom\HellOnEarthStarterPack\HellOnEarth"
            };
#endif
            Log(Verbosity.Debug, "Arguments: {0}", string.Join("\t", args));
            WADfile WF;
            if (args.Length < 2)
            {
                Log(Verbosity.Debug, "Interpret as Help Request");
                Help(args.Length == 1 ? args[0].ToUpper()[0] : ' ');
            }
            else if (args.Length == 2)
            {
                if (args[0].ToUpper() == "I")
                {
                    Log(Verbosity.Debug, "Mode I");
                    if (File.Exists(args[1]))
                    {
                        try
                        {
                            WF = new WADfile(args[1]);
                        }
                        catch (Exception ex)
                        {
                            WF = null;
                            Log(Verbosity.Error, "Error parsing WAD file. Message: {0}", ex.Message);
                            return;
                        }
                        Console.WriteLine(WF.Type.ToString());
                        Console.WriteLine("NAME\tFILENAME\tOFFSET\tLENGTH\tTYPE\tHASH");
                        foreach (WADentry e in WF.Entries)
                        {
                            Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}", e.Name, e.SafeName, e.Offset, e.Length, e.DataType, e.Hash);
                        }
                    }
                    else
                    {
                        Log(Verbosity.Error, "File not found");
                    }
                }
                else if (args[0].ToUpper() == "C")
                {
                    Log(Verbosity.Debug, "Mode C");
                    Convert(args[1]);
                }
                else
                {
                    Help(' ');
                }
            }
            else if (args.Length == 3)
            {
                switch (args[0].ToUpper())
                {
                case "A":
                    Log(Verbosity.Debug, "Mode A");
                    if (Directory.Exists(args[2]))
                    {
                        try
                        {
                            WADfile.Assemble(args[1], args[2]);
                            Log(Verbosity.Debug, "Done");
                        }
                        catch (Exception ex)
                        {
                            WF = null;
                            Log(Verbosity.Error, "Error: {0}", ex.Message);
                            return;
                        }
                    }
                    else
                    {
                        Log(Verbosity.Error, "Directory not found: {0}", args[2]);
                    }
                    break;

                case "E":
                    Log(Verbosity.Debug, "Mode E");
                    try
                    {
                        WF = new WADfile(args[1]);
                    }
                    catch (Exception ex)
                    {
                        WF = null;
                        Log(Verbosity.Error, "Error: {0}", ex.Message);
                        return;
                    }
                    if (!Directory.Exists(args[2]))
                    {
                        Log(Verbosity.Log, "Creating Directory: {0}", args[2]);
                        Directory.CreateDirectory(args[2]);
                    }
                    WF.Export(args[2]);
                    Log(Verbosity.Debug, "Done");
                    break;

                case "C":
                    Log(Verbosity.Debug, "Mode C");
                    Convert(args[1], args[2]);
                    break;

                default:
                    Log(Verbosity.Error, "Invalid Operation: {0}", args[0]);
                    break;
                }
            }
            Log(Verbosity.Debug, "#END");
#if DEBUG
            Console.ReadKey(true);
#endif
        }
Пример #5
0
 private static void Convert(string FromFile, string ToFile)
 {
     WADfile.Convert(File.ReadAllBytes(FromFile), ToFile);
 }
Пример #6
0
        /// <summary>
        /// Main entry point
        /// </summary>
        /// <param name="args">arguments</param>
        private static void Main(string[] args)
        {
            WADfile WF;

            if (args.Length < 2)
            {
                Help(args.Length == 1 ? args[0].ToUpper()[0] : ' ');
            }
            else if (args.Length == 2)
            {
                if (args[0].ToUpper() == "I")
                {
                    if (File.Exists(args[1]))
                    {
                        try
                        {
                            WF = new WADfile(args[1]);
                        }
                        catch (Exception ex)
                        {
                            WF = null;
                            Log(ConsoleColor.Red, "Error: {0}", ex.Message);
                            return;
                        }
                        Console.WriteLine(WF.Type.ToString());
                        Console.WriteLine("NAME;FILENAME;OFFSET;LENGTH;TYPE;HASH");
                        foreach (WADentry e in WF.Entries)
                        {
                            Console.WriteLine("{0};{1};{2};{3};{4};{5}", e.Name, e.SafeName, e.Offset, e.Length, e.DataType, e.Hash);
                        }
                    }
                    else
                    {
                        Log(ConsoleColor.Red, "File not found");
                    }
                }
                else if (args[0].ToUpper() == "C")
                {
                    Convert(args[1]);
                }
                else
                {
                    Help(' ');
                }
            }
            else if (args.Length == 3)
            {
                switch (args[0].ToUpper())
                {
                case "A":
                    if (Directory.Exists(args[2]))
                    {
                        try
                        {
                            WADfile.Assemble(args[1], args[2]);
                            Console.WriteLine("Done");
                        }
                        catch (Exception ex)
                        {
                            WF = null;
                            Log(ConsoleColor.Red, "Error: {0}", ex.Message);
                            return;
                        }
                    }
                    else
                    {
                        Log(ConsoleColor.Red, "Directory not found: {0}", args[2]);
                    }
                    break;

                case "E":
                    try
                    {
                        WF = new WADfile(args[1]);
                    }
                    catch (Exception ex)
                    {
                        WF = null;
                        Log(ConsoleColor.Red, "Error: {0}", ex.Message);
                        return;
                    }
                    if (Directory.Exists(args[2]))
                    {
                        WF.Export(args[2]);
                        Console.WriteLine("Done");
                    }
                    else
                    {
                        Log(ConsoleColor.Red, "Directory not found: {0}", args[2]);
                    }
                    break;

                case "C":
                    Convert(args[1], args[2]);
                    break;

                default:
                    Log(ConsoleColor.Red, "Invalid Operation: {0}", args[0]);
                    break;
                }
            }
        }
Пример #7
0
 private static void Convert(string From, string To)
 {
     WADfile.Convert(File.ReadAllBytes(From), To);
 }