Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        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()));
        }
Exemplo n.º 3
0
 public static string GetSavesPath(FarmSimulatorVersion version)
 {
     if (!VersionToNameSaveDirectory.ContainsKey(version))
     {
         throw new NotSupportedException();
     }
     return(Path.Combine(MyGamesPath, VersionToNameSaveDirectory[version]));
 }
Exemplo n.º 4
0
 //[DataRow(FarmSimulatorVersion.FarmingSimulator2017, "map01.i3d.shapes")]
 //[DataRow(FarmSimulatorVersion.FarmingSimulator2017, "map02.i3d.shapes")]
 //[DataRow(FarmSimulatorVersion.FarmingSimulator2019, "mapDE.i3d.shapes")]
 //[DataRow(FarmSimulatorVersion.FarmingSimulator2019, "mapUS.i3d.shapes")]
 public void LoadShapeType1Test(FarmSimulatorVersion version, string shapeFileName)
 {
     //if (!SupportVesion.Contains(version))
     //{
     //    var message = $"Currently not supported: \"{version}\".";
     //    Trace.WriteLine(message);
     //    Assert.Inconclusive(message);
     //}
     LoadTypedShape(version, shapeFileName, 1, (reader, version) => new Shape(reader, version));
 }
Exemplo n.º 5
0
        public void GetGameSavePathTest(FarmSimulatorVersion version)
        {
            var path = GamePaths.GetSavesPath(version);

            if (!Directory.Exists(path))
            {
                Assert.Inconclusive($"{FarmSimulatorVersion.FarmingSimulator2019} not exist.");
            }
            Assert.IsTrue(Directory.Exists(path));
        }
Exemplo n.º 6
0
        public static string GetGameMapsPath(FarmSimulatorVersion version)
        {
            var gameDataPath = GetGameDataPath(version);

            if (gameDataPath == null)
            {
                return(null);
            }
            var gameMapsPath = Path.Combine(gameDataPath, GameConstants.MapDirectory);

            return(!Directory.Exists(gameMapsPath) ? null : gameMapsPath);
        }
Exemplo n.º 7
0
        public static string GetCourseplayDirectory(FarmSimulatorVersion version)
        {
            var gameDirectory = GamePaths.GetSavesPath(version);

            if (gameDirectory == null)
            {
                return(null);
            }
            var coursePlayDirectory = Path.Combine(gameDirectory, CourseplayConstants.CourseplayDirectory);

            if (!Directory.Exists(coursePlayDirectory))
            {
                return(null);
            }
            return(coursePlayDirectory);
        }
Exemplo n.º 8
0
        private void Save(
            string errorOutputPath,
            FarmSimulatorVersion version,
            ReverseEngineeringNamedShape1Object errorShape,
            byte[] rawData
            )
        {
            var outputDirectory = Path.Combine(errorOutputPath, errorShape.RawType.ToString(), errorShape.Flag);

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

            var fileName = $"{errorShape.Flag}_[{errorShape.Id}]_{FileTools.CleanFileName(errorShape.Name)}.bin";
            var filePath = Path.Combine(outputDirectory, fileName);

            File.WriteAllBytes(filePath, rawData);
        }
Exemplo n.º 9
0
        public void OpenXmlFileMapTest(FarmSimulatorVersion version, string fileName)
        {
            var mapsPath = GamePaths.GetGameMapsPath(version);

            if (mapsPath == null)
            {
                Assert.Inconclusive("Maps path by \"{0}\" not found.", version);
            }

            var mapFilePath = Path.Combine(mapsPath, fileName);

            if (!File.Exists(mapFilePath))
            {
                Assert.Inconclusive("Map file \"{0}\" by \"{1}\" not found.", fileName, version);
            }

            using (var stream = File.OpenRead(mapFilePath))
            {
                var mapFile = MapFile.Serializer.Deserialize(stream) as MapFile;
                Assert.IsNotNull(mapFile);
            }
        }
Exemplo n.º 10
0
 public static string GetGamePath(FarmSimulatorVersion version)
 {
     return(SteamHelper.GetGameDirectory(VersionToNameGameDirectory[version]));
 }
Exemplo n.º 11
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();
            }
        }
Exemplo n.º 12
0
 public void LoadShapeType3Test(FarmSimulatorVersion version, string shapeFileName)
 {
     LoadTypedShape(version, shapeFileName, 3, (reader, version) => new NavMesh(reader));
 }
Exemplo n.º 13
0
 public void LoadShapeType2Test(FarmSimulatorVersion version, string shapeFileName)
 {
     LoadTypedShape(version, shapeFileName, 2, (reader, version) => new Spline(reader));
 }
Exemplo n.º 14
0
        public void ReadAllShapes(FarmSimulatorVersion version)
        {
            var hasError = false;
            var gamePath = GamePaths.GetGamePath(version);

            if (gamePath == null || !Directory.Exists(gamePath))
            {
                Assert.Inconclusive($"Game path not found: {version}");
            }

            var shapeFiles = Directory.GetFiles(gamePath, $"*{GameConstants.SchapesFileExtension}", SearchOption.AllDirectories);

            shapeFiles
            .AsParallel()
            .WithDegreeOfParallelism(Environment.ProcessorCount)
            .ForEach(
                filePath =>
            {
                try
                {
                    var container = new FileContainer(filePath);
                    var entities  = container.GetEntities();
                    foreach (var valueTuple in container.ReadRawData(entities))
                    {
                        using (var stream = new MemoryStream(valueTuple.RawData))
                        {
                            try
                            {
                                using (var reader = new EndianBinaryReader(stream, container.Endian, true))
                                {
                                    switch (valueTuple.Entity.Type)
                                    {
                                    case 1:
                                        var shape = new Shape(reader, container.Header.Version);
                                        break;

                                    case 2:
                                        var spline = new Spline(reader);
                                        break;

                                    case 3:
                                        var mesh = new NavMesh(reader);
                                        break;
                                    }
                                }
                            }
                            catch
                            {
                                hasError = true;
                                stream.Seek(0, SeekOrigin.Begin);
                                using (var reader = new EndianBinaryReader(stream, container.Endian))
                                {
                                    SaveErrorShape(
                                        version,
                                        container.Header.Version,
                                        filePath,
                                        new RawNamedShapeObject(valueTuple.Entity.Type, reader, container.Endian)
                                        );
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    hasError = true;
                }
            }
                );

            Assert.IsFalse(hasError);
        }
Exemplo n.º 15
0
 public static string GetTestDataPath(FarmSimulatorVersion version)
 {
     return(Path.Combine(TestDataPath, VersionToDictionaryTestData[version]));
 }