Beispiel #1
0
        public void Test()
        {
            var logger = new LoggerResult();

            var samplesPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..\..\..\samples");
            var files       = Directory.EnumerateFiles(samplesPath, "*.sdscene", SearchOption.AllDirectories);

            foreach (var sceneFile in files)
            {
                logger.HasErrors = false;
                logger.Clear();
                Console.WriteLine($"Checking file {sceneFile}");

                var file = new PackageLoadingAssetFile(sceneFile, Path.GetDirectoryName(sceneFile));

                var context       = new AssetMigrationContext(null, file.ToReference(), file.FilePath.ToWindowsPath(), logger);
                var needMigration = AssetMigration.MigrateAssetIfNeeded(context, file, "Stride");

                foreach (var message in logger.Messages)
                {
                    Console.WriteLine(message);
                }

                Assert.False(logger.HasErrors);

                if (needMigration)
                {
                    var result = Encoding.UTF8.GetString(file.AssetContent);
                    Console.WriteLine(result);

                    // We cannot load the Package here, as the package can use code/scripts that are only available when you actually compile project assmeblies
                }
            }
        }
Beispiel #2
0
        public void TestUpgrade(MyUpgradedAsset asset, bool needMigration)
        {
            var loadingFilePath = new PackageLoadingAssetFile(Path.Combine(DirectoryTestBase, "TestUpgrade\\Asset1.xkobj"), DirectoryTestBase);
            var outputFilePath  = loadingFilePath.FilePath.FullPath;

            AssetFileSerializer.Save(outputFilePath, asset, null);

            var logger  = new LoggerResult();
            var context = new AssetMigrationContext(null, loadingFilePath.ToReference(), loadingFilePath.FilePath.ToWindowsPath(), logger);

            Assert.AreEqual(AssetMigration.MigrateAssetIfNeeded(context, loadingFilePath, "TestPackage"), needMigration);

            if (needMigration)
            {
                using (var fileStream = new FileStream(outputFilePath, FileMode.Truncate))
                    fileStream.Write(loadingFilePath.AssetContent, 0, loadingFilePath.AssetContent.Length);
            }

            Console.WriteLine(File.ReadAllText(outputFilePath).Trim());

            var upgradedAsset = AssetFileSerializer.Load <MyUpgradedAsset>(outputFilePath).Asset;

            AssertUpgrade(upgradedAsset);
        }
        public void TestUpgrade(MyUpgradedAsset asset, bool needMigration)
        {
            var loadingFilePath = new PackageLoadingAssetFile(Path.Combine(DirectoryTestBase, "TestUpgrade\\Asset1.xkobj"), DirectoryTestBase);
            var outputFilePath = loadingFilePath.FilePath.FullPath;
            AssetFileSerializer.Save(outputFilePath, asset);

            var logger = new LoggerResult();
            var context = new AssetMigrationContext(null, loadingFilePath.ToReference(), loadingFilePath.FilePath.ToWindowsPath(), logger);
            Assert.AreEqual(AssetMigration.MigrateAssetIfNeeded(context, loadingFilePath, "TestPackage"), needMigration);

            if (needMigration)
            {
                using (var fileStream = new FileStream(outputFilePath, FileMode.Truncate))
                    fileStream.Write(loadingFilePath.AssetContent, 0, loadingFilePath.AssetContent.Length);
            }

            Console.WriteLine(File.ReadAllText(outputFilePath).Trim());

            var upgradedAsset = AssetFileSerializer.Load<MyUpgradedAsset>(outputFilePath).Asset;
            AssertUpgrade(upgradedAsset);
        }