public void ExportShapePathTests(FarmSimulatorVersion version, string shapeFileName)
        {
            var gameMapPath = GamePaths.GetGameMapsPath(version);

            if (!Directory.Exists(gameMapPath))
            {
                var message = $"Game map path not found: \"{version}\".";
                Trace.WriteLine(message);
                Assert.Inconclusive(message);
            }

            var mapPath = Path.Combine(gameMapPath, shapeFileName);

            if (!File.Exists(mapPath))
            {
                var message = $"Map not found \"{version}\": \"{mapPath}\".";
                Trace.WriteLine(message);
                Assert.Inconclusive(message);
            }

            var xmlMapFilePath = mapPath.Replace(GameConstants.SchapesFileExtension, GameConstants.XmlMapFileExtension);
            var mapFile        = MapFile.Load(xmlMapFilePath);
            var shapePaths     = FindShapePath(mapFile)
                                 .OrderBy(v => v.Id)
                                 .ToArray();

            File.WriteAllLines(Path.Combine(Output, version.ToString(), "shapes.path"), shapePaths.Select(v => v.ToString()));
        }
示例#2
0
        /// <summary>
        /// Save error parse shape in directory.
        /// </summary>
        /// <param name="version">Farming simulator version.</param>
        /// <param name="containerVersion">Container version.</param>
        /// <param name="shapeFileName">Shape file name.</param>
        /// <param name="rawShape"><inheritdoc cref="IRawNamedShapeObject"/></param>
        private static void SaveErrorShape(
            FarmSimulatorVersion version,
            short containerVersion,
            string shapeFileName,
            IRawNamedShapeObject rawShape
            )
        {
            var curentPath      = Directory.GetCurrentDirectory();
            var outputPath      = "Output";
            var outputDirectory = Path.Combine(
                curentPath,
                outputPath,
                version.ToString(),
                Path.GetFileName(shapeFileName)
                .Replace(GameConstants.SchapesFileExtension, "")
                );

            if (!Directory.Exists(outputDirectory))
            {
                Directory.CreateDirectory(outputDirectory);
            }

            var fileName = $"({containerVersion})[{rawShape.Id}]_[{rawShape.RawType}]_{FileTools.CleanFileName(rawShape.Name)}.bin";

            File.WriteAllBytes(Path.Combine(outputDirectory, fileName), rawShape.RawData);
        }
示例#3
0
        public void LoadTypedShape <T>(FarmSimulatorVersion version, string shapeFileName, int rawType, Func <BinaryReader, int, T> loadShape)
        {
            var gameMapPath = GamePaths.GetGameMapsPath(version);

            if (!Directory.Exists(gameMapPath))
            {
                var message = $"Game map path not found: \"{version}\".";
                Trace.WriteLine(message);
                Assert.Inconclusive(message);
            }

            var mapPath = Path.Combine(gameMapPath, shapeFileName);

            if (!File.Exists(mapPath))
            {
                var message = $"Map not found \"{version}\": \"{mapPath}\".";
                Trace.WriteLine(message);
                Assert.Inconclusive(message);
            }

            // Clear directory by error shapes
            var errorOutputPath = Path.Combine(OutputErrorShapes, version.ToString(), shapeFileName);

            if (Directory.Exists(errorOutputPath))
            {
                Directory.Delete(errorOutputPath, true);
            }

            var fileContainer = new FileContainer(mapPath);
            var entities      = fileContainer.GetEntities();
            var error         = false;

            fileContainer.ReadRawData(entities)
            .Where(v => v.Entity.Type == rawType)
            .ForEach(
                v =>
            {
                try
                {
                    using var stream = new MemoryStream(v.RawData);
                    using var reader = new EndianBinaryReader(stream, fileContainer.Endian);
                    var shape        = loadShape(reader, fileContainer.Header.Version);
                }
                catch (Exception ex)
                {
                    error            = true;
                    using var stream = new MemoryStream(v.RawData);
                    using var reader = new EndianBinaryReader(stream, fileContainer.Endian);
                    Trace.WriteLine($"Error load shape.");
                    var errorShape2 = new ReverseEngineeringNamedShape1Object(
                        v.Entity.Type,
                        reader,
                        fileContainer.Endian
                        );
                    Save(errorOutputPath, version, errorShape2, v.RawData);
                }
            }
                );

            if (error)
            {
                Assert.Fail();
            }
        }