Ejemplo n.º 1
0
        public void SetupProject(ProjectViewModel projectViewModel)
        {
            if (string.IsNullOrEmpty(InfoFilePath))
            {
                throw new InvalidOperationException("Info file path not specified, use the -info argument");
            }

            Project project = projectViewModel.Project;

            project.InfoFilePath = InfoFilePath;

            if (string.IsNullOrEmpty(SinglePackagePath) &&
                string.IsNullOrEmpty(BankPackagePath) &&
                string.IsNullOrEmpty(StreamPackagePath) &&
                string.IsNullOrEmpty(LooseMediaPackagePath))
            {
                throw new InvalidOperationException("At least one of the output file must be specified (-output, -output_stm, -output_bnk)");
            }

            // -- Filter to keep only the item listed on command line --
            IEnumerable <ContentItemViewModel> sourceItems = projectViewModel.ContentItems;

            if (Banks != null)
            {
                // Filter by bank names
                sourceItems = sourceItems.Where(ci => Banks.Contains(ci.FileName, new StringEqualityComparer(StringComparison.OrdinalIgnoreCase)));
            }

            // -- Collect loose files in included/excluded items --
            HashSet <AK.Wwise.InfoFile.FileDescriptorType> looseMediaFiles = new HashSet <AK.Wwise.InfoFile.FileDescriptorType>();

            if (ExcludedFilesInBanks != null)
            {
                looseMediaFiles.UnionWith(projectViewModel.ContentItems
                                          .Where(ci => ExcludedFilesInBanks.Contains(ci.FileName, new StringEqualityComparer(StringComparison.OrdinalIgnoreCase)))
                                          .SelectMany(ci => ci.ExcludedMemoryFiles));
            }

            if (IncludedFilesInBanks != null)
            {
                looseMediaFiles.UnionWith(projectViewModel.ContentItems
                                          .Where(ci => IncludedFilesInBanks.Contains(ci.FileName, new StringEqualityComparer(StringComparison.OrdinalIgnoreCase)))
                                          .SelectMany(ci => ci.IncludedMemoryFiles));
            }

            if (looseMediaFiles.Count() > 0)
            {
                sourceItems = sourceItems.Concat(looseMediaFiles.Select(i => new ContentItemViewModel(i)));
            }

            if (Languages != null)
            {
                sourceItems = sourceItems.Where(ci => Languages.Contains(ci.Language, new StringEqualityComparer(StringComparison.OrdinalIgnoreCase)));
            }

            // -- Create Packages ---

            // Single package
            if (!string.IsNullOrEmpty(SinglePackagePath))
            {
                Package package = new Package();
                package.Name = SinglePackagePath;
                package.Items.AddRange(sourceItems
                                       .Select(i => new PackageContentItem(i.Id, i.Language, i.FileName)));

                project.ManualPackagingInfo.Packages.Add(package);
            }

            // Bank package
            if (!string.IsNullOrEmpty(BankPackagePath))
            {
                Package package = new Package();
                package.Name = BankPackagePath;
                package.Items.AddRange(sourceItems
                                       .Where(i => i.FileType == FileType.SoundBank)
                                       .Select(i => new PackageContentItem(i.Id, i.Language, i.FileName)
                {
                    InclusionMode = InclusionMode.Bank
                }));

                project.ManualPackagingInfo.Packages.Add(package);
            }

            // Stream package
            if (!string.IsNullOrEmpty(StreamPackagePath))
            {
                Package package = new Package();
                package.Name = StreamPackagePath;
                package.Items.AddRange(sourceItems
                                       .Where(i => i.FileType == FileType.StreamedFile)
                                       .Select(i => new PackageContentItem(i.Id, i.Language, i.FileName)));

                project.ManualPackagingInfo.Packages.Add(package);
            }

            // Loose files package
            if (!string.IsNullOrEmpty(LooseMediaPackagePath))
            {
                Package package = new Package();
                package.Name = LooseMediaPackagePath;
                package.Items.AddRange(sourceItems
                                       .Where(i => i.FileType == FileType.LooseMedia)
                                       .Select(i => new PackageContentItem(i.Id, i.Language, i.FileName)));

                project.ManualPackagingInfo.Packages.Add(package);
            }

            projectViewModel.ManualPackagingInfo.BlockSize = BlockSize;
        }
Ejemplo n.º 2
0
        void ResultingItemsWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            if (_resultingItemsWorker.CancellationPending)
            {
                return;
            }

            ReferenceManager referenceManager = new ReferenceManager();
            Dictionary <PackageViewModel, PackageResultingItems> newItems =
                _packages.ToDictionary(p => p, p => new PackageResultingItems(p, referenceManager));

            ProjectViewModel project = ProjectViewModel.Current;

            // First clear all packages and copy the included items and their associated streams
            foreach (PackageViewModel package in Packages)
            {
                // Copy the manually added items
                newItems[package].AddRange(
                    package.Items
                    .Where(i => i.ContentItem != null)  // Skip missing references
                    .Where(i => i.CanIncludeExplicitly)
                    .Select(i => new ContentItemViewModelReference()
                {
                    ContentItem = i.ContentItem, IsExplicit = true
                }));

                // Copy implicit items
                newItems[package].AddRange(
                    package.Items
                    .Where(i => i.ContentItem != null)
                    .SelectMany(i => i.ImplicitItems)
                    .Where(i => i != null && !referenceManager.HasExplicitReferencesToPackage(i, package))
                    .Select(i => new ContentItemViewModelReference()
                {
                    ContentItem = i, IsExplicit = false
                }));

                if (_resultingItemsWorker.CancellationPending)
                {
                    return;
                }
            }

            // Add unassigned bank items per language
            foreach (LanguagePackageIdsViewModel lpivm in DefaultLanguagePackageIds)
            {
                if (lpivm.BankPackage != _nonePackage)
                {
                    var noRef = project.ContentItems.Where(ci =>
                                                           ci.FileType == FileType.SoundBank &&
                                                           ci.Language == lpivm.Language &&
                                                           referenceManager.GetReferences(ci) == null);

                    newItems[lpivm.BankPackage].AddRange(noRef.Select(i => new ContentItemViewModelReference()
                    {
                        ContentItem = i, IsExplicit = false
                    }));
                }
                if (lpivm.StreamPackage != _nonePackage)
                {
                    var noRef = project.ContentItems.Where(ci =>
                                                           ci.FileType == FileType.StreamedFile &&
                                                           ci.Language == lpivm.Language &&
                                                           referenceManager.GetReferences(ci) == null);

                    newItems[lpivm.StreamPackage].AddRange(noRef.Select(i => new ContentItemViewModelReference()
                    {
                        ContentItem = i, IsExplicit = false
                    }));
                }
                if (lpivm.LooseMediaPackage != _nonePackage)
                {
                    var noRef = project.ContentItems.Where(ci =>
                                                           ci.FileType == FileType.LooseMedia &&
                                                           ci.Language == lpivm.Language &&
                                                           referenceManager.GetReferences(ci) == null);

                    newItems[lpivm.LooseMediaPackage].AddRange(noRef.Select(i => new ContentItemViewModelReference()
                    {
                        ContentItem = i, IsExplicit = false
                    }));
                }

                if (_resultingItemsWorker.CancellationPending)
                {
                    return;
                }
            }

            // Add unassigned bank items
            if (UnassignedBanksPackage != _nonePackage)
            {
                var noRef = project.ContentItems.Where(ci => ci.FileType == FileType.SoundBank && referenceManager.GetReferences(ci) == null);

                newItems[UnassignedBanksPackage].AddRange(noRef.Select(i => new ContentItemViewModelReference()
                {
                    ContentItem = i, IsExplicit = false
                }));
            }

            if (_resultingItemsWorker.CancellationPending)
            {
                return;
            }

            // Add unassigned stream items
            if (UnassignedStreamsPackage != _nonePackage)
            {
                var noRef = project.ContentItems.Where(ci => ci.FileType == FileType.StreamedFile && referenceManager.GetReferences(ci) == null);

                newItems[UnassignedStreamsPackage].AddRange(noRef.Select(i => new ContentItemViewModelReference()
                {
                    ContentItem = i, IsExplicit = false
                }));
            }

            if (_resultingItemsWorker.CancellationPending)
            {
                return;
            }

            // Add unassigned externals items
            if (UnassignedExternalsPackage != _nonePackage)
            {
                var noRef = project.ContentItems.Where(ci => ci.FileType == FileType.ExternalSource && referenceManager.GetReferences(ci) == null);

                newItems[UnassignedExternalsPackage].AddRange(noRef.Select(i => new ContentItemViewModelReference()
                {
                    ContentItem = i, IsExplicit = false
                }));
            }

            // Add unassigned loose media items
            if (UnassignedLooseMediaPackage != _nonePackage)
            {
                var noRef = project.ContentItems.Where(ci => ci.FileType == FileType.LooseMedia && referenceManager.GetReferences(ci) == null);

                newItems[UnassignedLooseMediaPackage].AddRange(noRef.Select(i => new ContentItemViewModelReference()
                {
                    ContentItem = i, IsExplicit = false
                }));
            }

            if (_resultingItemsWorker.CancellationPending)
            {
                return;
            }

            // Finally add/remove the items
            if (MainViewModel.Instance.Application.IsGenerateMode)
            {
                PushResultingItems(newItems);
            }
            else
            {
                // Switch thread when running in background
                Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
                                                           (Action) delegate
                {
                    using (new AutoCursor(Cursors.Wait))
                    {
                        PushResultingItems(newItems);
                    }
                });
            }
        }