Exemplo n.º 1
0
        private static void ConvertFile(string fileName)
        {
            var reader = new RawReader(fileName);

            RawData file = null;

            try
            {
                file = reader.Read();
            }
            catch (RawReaderException e)
            {
                _hasErrored = true;
                Console.WriteLine("File: {0}", fileName);
                Console.WriteLine(e.Message);
                Console.WriteLine("Reason: {0}", e.InnerException.Message);
                return;
            }

            string data = "";

            switch (file.Type)
            {
            case RawType.UnitData:
                data = UnitDataConverter.GetString((UnitData)file);
                break;

            case RawType.SkillData:
                data = SkillDataConverter.GetString((SkillData)file);
                break;

            case RawType.AffixData:
                data = AffixDataConverter.GetString((AffixData)file);
                break;

            case RawType.MissileData:
                data = MissileDataConverter.GetString((MissileData)file);
                break;

            case RawType.RoomPieceData:
                data = RoomPieceDataConverter.GetString((RoomPieceData)file);
                break;

            case RawType.TriggerableData:
                data = TriggerableDataConverter.GetString((TriggerableData)file);
                break;

            case RawType.UserInterfaceData:
                data = UserInterfaceDataConverter.GetString((UserInterfaceData)file);
                break;
            }

            string outputPath = _outputDir != "" ? Path.Combine(_outputDir, Path.GetFileNameWithoutExtension(fileName) + ".txt") : fileName.Replace(Path.GetExtension(fileName), ".txt");

            File.WriteAllText(outputPath, data);
            Console.WriteLine("Converted {0} into a human readable format", Path.GetFileName(fileName));
        }
Exemplo n.º 2
0
        private static void ConvertFile(string fileName)
        {
            List <string> lines = File.ReadAllLines(fileName).ToList();

            StripBlankLines(ref lines);

            string type = lines[0].TrimStart('[').TrimEnd(']');
            string data = MergeLines(ref lines);

            RawData rawFile = null;

            try
            {
                switch (type)
                {
                case "UNITDATA":
                    rawFile = UnitDataConverter.GetData(data);
                    break;

                case "SKILLS":
                    rawFile = SkillDataConverter.GetData(data);
                    break;

                case "AFFIXES":
                    rawFile = AffixDataConverter.GetData(data);
                    break;

                case "MISSILES":
                    rawFile = MissileDataConverter.GetData(data);
                    break;

                case "ROOMPIECES":
                    rawFile = RoomPieceDataConverter.GetData(data);
                    break;

                case "TRIGGERABLES":
                    rawFile = TriggerableDataConverter.GetData(data);
                    break;

                case "USERINTERFACES":
                    rawFile = UserInterfaceDataConverter.GetData(data);
                    break;

                default:
                    throw new TxtConverterException("Invalid format of " + type);
                }
            }
            catch (TxtConverterException e)
            {
                Console.WriteLine(e.Message);
                return;
            }

            string outputPath = _outputDir != "" ? _outputDir : Path.GetDirectoryName(fileName);

            RawWriter writer = new RawWriter(rawFile);

            writer.Write(outputPath, Path.GetFileNameWithoutExtension(fileName));

            Console.WriteLine("Converted {0} into binary format", Path.GetFileName(fileName));
        }