Example #1
0
 private static void GenerateManifestUsingApi(string assemblyName, string path)
 {
     var builder = new ManifestBuilder(@"TUTORIAL_ISSUER",
                                       @"..\..\KEY_FILE.xml",
                                       assemblyName,
                                       path);
     builder.CreateAndPublish();
 }
        public void RandomData_ReturnsSimpleManifest()
        {
            var sut = new ManifestBuilder();
            var fixture = new Fixture();
            var fileData = fixture.Create<byte[]>();

            var result = sut.BuildFileManifest(fileData);

            Assert.IsNotNull(result);
            Assert.IsEmpty(result.ItemList);
        }
Example #3
0
        public ModuleManifest GenerateManifest(string assemblyFilePath, string folderPath)
        {
            // build manifest with this settings
            KeysGeneratorProgram.Main(new[] { IssuerPath });

            var manifestBuilder = new ManifestBuilder(IssuerName, IssuerPath,
                                                      assemblyFilePath,
                                                      folderPath, KeyStorage.Nomad,
                                                      string.Empty, Configuration);

            return manifestBuilder.Create();
        }
        public void ZipFile_ReturnsFileList()
        {
            var sut = new ManifestBuilder();
            var fixture = new Fixture();
            var dataList = fixture.CreateMany<ZipEntryData>();
            byte[] zipFileBytes;
            using(ZipFile file = new ZipFile())
            {
                foreach (var data in dataList)
                {
                    string fullFileName = data.Directory + "/" + data.FileName;
                    var entry = file.AddEntry(fullFileName, data.FileData);
                    entry.AccessedTime = data.AccessDateTime;
                    entry.CreationTime = data.CreatedDateTime;
                    entry.ModifiedTime = data.ModifiedDateTime;
                    entry.Attributes = data.FileAttributes;
                }
                using (var stream = new MemoryStream())
                {
                    file.Save(stream);
                    stream.Position = 0;
                    zipFileBytes = TempStreamHelper.ReadAllBytes(stream);
                }
            }

            var result = sut.BuildFileManifest(zipFileBytes);

            Assert.IsNotNull(result);
            Assert.IsNotEmpty(result.ItemList);
            foreach(var data in dataList)
            {
                var entry = result.ItemList.SingleOrDefault(i=>i.FileName == data.FileName && i.Directory == data.Directory);
                Assert.IsNotNull(entry);
                Assert.AreEqual(data.AccessDateTime.ToUniversalTime(), entry.FileAccessedDateTime.ToUniversalTime());
                Assert.AreEqual(data.ModifiedDateTime.ToUniversalTime(), entry.FileModifiedDateTime.ToUniversalTime());
                Assert.AreEqual(data.CreatedDateTime.ToUniversalTime(), entry.FileCreatedDateTime.ToUniversalTime());
                Assert.AreEqual(data.FileAttributes, entry.Attributes);
            }
        }
 protected void SignModule(string name, string path)
 {
     var builder = new ManifestBuilder(IssuerName, IssuerXmlPath, name, path);
     builder.CreateAndPublish();
 }
        private static void GenerateSongPsarcRS1(Stream output, DLCPackageData info, Platform platform)
        {
            var soundBankName = String.Format("Song_{0}", info.Name);

            try
            {
                Stream albumArtStream = null,
                       audioStream = null;

                string albumArtPath;
                if (File.Exists(info.AlbumArtPath)) {
                    albumArtPath = info.AlbumArtPath;
                } else {
                    using (var defaultArtStream = new MemoryStream(Resources.albumart)) {
                        albumArtPath = GeneralExtensions.GetTempFileName(".dds");
                        defaultArtStream.WriteFile(albumArtPath);
                        defaultArtStream.Dispose();
                        TMPFILES_ART.Add(albumArtPath);
                    }
                }

                var ddsfiles = info.ArtFiles;
                if (ddsfiles == null) {
                    ddsfiles = new List<DDSConvertedFile>();
                    ddsfiles.Add(new DDSConvertedFile() { sizeX = 512, sizeY = 512, sourceFile = albumArtPath, destinationFile = GeneralExtensions.GetTempFileName(".dds") });
                    ToDDS(ddsfiles);

                    // Save for reuse
                    info.ArtFiles = ddsfiles;
                }

                albumArtStream = new FileStream(ddsfiles[0].destinationFile, FileMode.Open, FileAccess.Read, FileShare.Read);

                // AUDIO
                var audioFile = info.OggPath;
                if (File.Exists(audioFile))
                    if (platform.IsConsole != audioFile.GetAudioPlatform().IsConsole)
                        audioStream = OggFile.ConvertAudioPlatform(audioFile);
                    else
                        audioStream = File.OpenRead(audioFile);
                else
                    throw new InvalidOperationException(String.Format("Audio file '{0}' not found.", audioFile));

                using (var aggregateGraphStream = new MemoryStream())
                using (var manifestStream = new MemoryStream())
                using (var xblockStream = new MemoryStream())
                using (var soundbankStream = new MemoryStream())
                using (var packageIdStream = new MemoryStream())
                using (var soundStream = OggFile.ConvertOgg(audioStream))
                using (var arrangementFiles = new DisposableCollection<Stream>()) {
                    var manifestBuilder = new ManifestBuilder {
                        AggregateGraph = new AggregateGraph.AggregateGraph {
                            SoundBank = new SoundBank { File = soundBankName + ".bnk" },
                            AlbumArt = new AlbumArt { File = info.AlbumArtPath }
                        }
                    };

                    foreach (var x in info.Arrangements) {
                        //Generate sng file in execution time
                        GenerateSNG(x, platform);

                        manifestBuilder.AggregateGraph.SongFiles.Add(x.SongFile);
                        manifestBuilder.AggregateGraph.SongXMLs.Add(x.SongXml);
                    }
                    manifestBuilder.AggregateGraph.XBlock = new XBlockFile { File = info.Name + ".xblock" };
                    manifestBuilder.AggregateGraph.Write(info.Name, platform.GetPathName(), platform, aggregateGraphStream);
                    aggregateGraphStream.Flush();
                    aggregateGraphStream.Seek(0, SeekOrigin.Begin);

                    {
                        var manifestData = manifestBuilder.GenerateManifest(info.Name, info.Arrangements, info.SongInfo, platform);
                        var writer = new StreamWriter(manifestStream);
                        writer.Write(manifestData);
                        writer.Flush();
                        manifestStream.Seek(0, SeekOrigin.Begin);
                    }

                    GameXblock<Entity>.Generate(info.Name, manifestBuilder.Manifest, manifestBuilder.AggregateGraph, xblockStream);
                    xblockStream.Flush();
                    xblockStream.Seek(0, SeekOrigin.Begin);

                    var soundFileName = SoundBankGenerator.GenerateSoundBank(info.Name, soundStream, soundbankStream, info.Volume, platform);
                    soundbankStream.Flush();
                    soundbankStream.Seek(0, SeekOrigin.Begin);

                    GenerateSongPackageId(packageIdStream, info.Name);

                    var songPsarc = new PSARC.PSARC();
                    songPsarc.AddEntry("PACKAGE_ID", packageIdStream);
                    songPsarc.AddEntry("AggregateGraph.nt", aggregateGraphStream);
                    songPsarc.AddEntry("Manifests/songs.manifest.json", manifestStream);
                    songPsarc.AddEntry(String.Format("Exports/Songs/{0}.xblock", info.Name), xblockStream);
                    songPsarc.AddEntry(String.Format("Audio/{0}/{1}.bnk", platform.GetPathName()[0], soundBankName), soundbankStream);
                    songPsarc.AddEntry(String.Format("Audio/{0}/{1}.ogg", platform.GetPathName()[0], soundFileName), soundStream);
                    songPsarc.AddEntry(String.Format("GRAssets/AlbumArt/{0}.dds", manifestBuilder.AggregateGraph.AlbumArt.Name), albumArtStream);

                    foreach (var x in info.Arrangements) {
                        var xmlFile = File.OpenRead(x.SongXml.File);
                        arrangementFiles.Add(xmlFile);
                        var sngFile = File.OpenRead(x.SongFile.File);
                        arrangementFiles.Add(sngFile);
                        songPsarc.AddEntry(String.Format("GR/Behaviors/Songs/{0}.xml", Path.GetFileNameWithoutExtension(x.SongXml.File)), xmlFile);
                        songPsarc.AddEntry(String.Format("GRExports/{0}/{1}.sng", platform.GetPathName()[1], Path.GetFileNameWithoutExtension(x.SongFile.File)), sngFile);
                    }
                    songPsarc.Write(output, false);
                    output.Flush();
                    output.Seek(0, SeekOrigin.Begin);
                }
            }
            finally
            {
            }
        }
        public void discovers_all_proper_modules_with_manifests_ignores_others_assemblies()
        {
            // make another folder
            string testPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                                           @"IntegrationTests\DirectoryModuleDiscovery2\");

            if (Directory.Exists(testPath))
                Directory.Delete(testPath, true);
            Directory.CreateDirectory(testPath);

            // compile modules into a.dll / b.dll
            var compiler = new ModuleCompiler();
            compiler.OutputDirectory = testPath;

            compiler.OutputName = Path.Combine(testPath, "a.dll");
            compiler.GenerateModuleFromCode(
                @"..\Source\Nomad.Tests\FunctionalTests\Data\SimplestModulePossible1.cs");

            compiler.OutputName = Path.Combine(testPath, "b.dll");
            compiler.GenerateModuleFromCode(
                @"..\Source\Nomad.Tests\FunctionalTests\Data\SimplestModulePossible1.cs");

            // generate manifests
            var builder = new ManifestBuilder(@"TEST_ISSUER", KeyFile, @"a.dll", testPath);
            builder.CreateAndPublish();
            builder = new ManifestBuilder(@"TEST_ISSUER", KeyFile, @"b.dll", testPath);
            builder.CreateAndPublish();

            // add spoiling module (assembly without manifest)
            File.Copy(Path.Combine(testPath, @"a.dll"), Path.Combine(testPath, "c.dll"));

            var expectedModules = new[]
                                      {
                                          new ModuleInfo(Path.Combine(testPath, "a.dll")),
                                          new ModuleInfo(Path.Combine(testPath, "b.dll")),
                                      };

            var discovery = new Nomad.Modules.Discovery.DirectoryModuleDiscovery(testPath,SearchOption.TopDirectoryOnly);

            Assert.That(discovery.GetModules().ToArray(), Is.EquivalentTo(expectedModules),
                        "Discovered modules differ from expected");
        }
        private void PrepareModulesTestDirectories(string testPath, string moduleAPath, string moduleBPath)
        {
            if (Directory.Exists(testPath))
                Directory.Delete(testPath, true);
            Directory.CreateDirectory(testPath);

            // compile modules into a.dll / b.dll
            var compiler = new ModuleCompiler();

            compiler.OutputDirectory = moduleAPath;
            compiler.OutputName = Path.Combine(moduleAPath, "a.dll");
            compiler.GenerateModuleFromCode(
                @"..\Source\Nomad.Tests\FunctionalTests\Data\SimplestModulePossible1.cs");

            compiler.OutputDirectory = moduleBPath;
            compiler.OutputName = Path.Combine(moduleBPath, "b.dll");
            compiler.GenerateModuleFromCode(
                @"..\Source\Nomad.Tests\FunctionalTests\Data\SimplestModulePossible1.cs");

            // generate manifests
            var builder = new ManifestBuilder(@"TEST_ISSUER", KeyFile, @"a.dll", moduleAPath);
            builder.CreateAndPublish();
            builder = new ManifestBuilder(@"TEST_ISSUER", KeyFile, @"b.dll", moduleBPath);
            builder.CreateAndPublish();

            // add spoiling module (assembly without manifest)
            File.Copy(Path.Combine(moduleAPath, @"a.dll"), Path.Combine(testPath, "c.dll"));
        }
Example #9
0
        /// <summary>
        ///     Wrapps the generating manifest with values that should be provided. Provides access to <paramref name="configuration"/>.
        /// </summary>
        /// <param name="modulePath"></param>
        /// <param name="keyLocation"></param>
        /// <param name="configuration"></param>
        /// <returns></returns>
        public string GenerateManifestForModule(string modulePath, string keyLocation,
            ManifestBuilderConfiguration configuration)
        {
            string directory = Path.GetFullPath(Path.GetDirectoryName(modulePath));
            var builder = new ManifestBuilder("TEST_ISSUER_COMPILER",
                                              keyLocation,
                                              Path.GetFileName(modulePath), directory, KeyStorage.Nomad, string.Empty,
                                              configuration);
            builder.CreateAndPublish();

            return modulePath + ModuleManifest.ManifestFileNameSuffix;
        }
 private void SignUsedModules()
 {
     var builder = new ManifestBuilder(IssuerName, IssuerXmlPath,
                                       @"SimplestModulePossible1.dll", @"Modules\Simple\");
     builder.CreateAndPublish();
     builder = new ManifestBuilder(IssuerName, IssuerXmlPath, @"SimplestModulePossible2.dll",
                                   @"Modules\Simple\");
     builder.CreateAndPublish();
 }
Example #11
0
 private static string AddManifestFile()
 {
     // generate manifest for SimplestModulePossible file
     var builder = new ManifestBuilder(IssuerName, IssuerXmlPath,
                                       @"SimplestModulePossible1.dll",
                                       @"Modules\Simple");
     _manifest = builder.CreateAndPublish();
     return @"Modules\Simple\SimplestModulePossible1.dll" +
            ModuleManifest.ManifestFileNameSuffix;
 }
        private static void BuildModule()
        {
            // some remarkable constancies, we are using sample module from psake build
            const string issuerName = @"TEST_ISSUER";
            const string issuerXmlPath = @"TEST_XML_KEY_FILE.xml";
            const string assemblyName = @"Modules\Simple\SimplestModulePossible1.dll";

            // get the key file
            KeysGeneratorProgram.Main(new[] { Path.Combine(FolderPath, issuerXmlPath) });

            // get the assembly file into test folder
            File.Copy(assemblyName, Path.Combine(FolderPath, Path.GetFileName(assemblyName)),true);

            // NOTE: we are using here default builder configuration for simplicity of the test
            var manifestBuilder = new ManifestBuilder(issuerName,
                                                      Path.Combine(FolderPath, issuerXmlPath),
                                                      Path.GetFileName(assemblyName), FolderPath, KeyStorage.Nomad,
                                                      string.Empty, ManifestBuilderConfiguration.Default);

            manifestBuilder.CreateAndPublish();
        }
        private void GetNodeTags( TreeNode parent, ManifestBuilder builder )
        {
            foreach ( TreeNode child in parent.Nodes )
             {
            GetNodeTags( child, builder );
             }

             if ( parent.Tag is RecipeSlotInfo )
             {
            RecipeSlotInfo info = parent.Tag as RecipeSlotInfo;
            builder.AddSlotInfo( info );
             }
        }
        private void BuildManifest()
        {
            theListView.Items.Clear();

             ManifestBuilder manifest = new ManifestBuilder();
             GetNodeTags( theTreeView.Nodes[ 0 ], manifest );

             IList<ManifestItem> items = new List<ManifestItem>();
             foreach ( KeyValuePair<long, int> pair in manifest.Items )
             {
            items.Add( new ManifestItem { Item = Db.GetItemName( pair.Key ), Count = pair.Value, } );
             }

             foreach ( ManifestItem item in items.OrderBy( i => i.Item ) )
             {
            ListViewItem viewItem = theListView.Items.Add( item.Item );
            viewItem.SubItems.Add( item.Count.ToString() );
             }

             items.Clear();
             foreach ( KeyValuePair<long, int> pair in manifest.Components )
             {
            items.Add( new ManifestItem { Item = Db.GetItemName( pair.Key ), Count = pair.Value, } );
             }

             foreach ( ManifestItem item in items.OrderBy( i => i.Item ) )
             {
            ListViewItem viewItem = theListView.Items.Add( item.Item );
            viewItem.SubItems.Add( item.Count.ToString() );
            viewItem.BackColor = Color.LightPink;
             }
        }