public void LoadContentItems() { using (new AutoCursor(Cursors.Wait)) { string infoPath = InfoFilePathResolved; if (System.IO.File.Exists(infoPath)) { AK.Wwise.InfoFile.SoundBanksInfo soundBankInfo = null; try { soundBankInfo = AK.Wwise.InfoFile.InfoFileHelpers.LoadInfoFile(infoPath); } catch (Exception e) { if (e.Message.Contains("xsd")) { MainViewModel.Instance.Application.ShowMessage( string.Format(Properties.Resources.CouldNotFindXmlSchema, e.Message), Severity.Error); } else { string message = string.Empty; Exception current = e; while (current != null) { message += current.Message + " "; current = current.InnerException; } MainViewModel.Instance.Application.ShowMessage( string.Format(Properties.Resources.CouldNotLoadInfoFile, message), Severity.Error); } } if (soundBankInfo != null) { try { BasePlatform = soundBankInfo.BasePlatform; _sourceFilesRoot = soundBankInfo.RootPaths.SourceFilesRoot; _soundBanksRoot = soundBankInfo.RootPaths.SoundBanksRoot; _externalSourcesOutputRoot = soundBankInfo.RootPaths.ExternalSourcesOutputRoot; IEnumerable <AK.Wwise.InfoFile.FileDescriptorType> fileDescriptors = soundBankInfo.SoundBanks.SoundBank.Cast <AK.Wwise.InfoFile.FileDescriptorType>() .Concat(soundBankInfo.StreamedFiles.File.Cast <AK.Wwise.InfoFile.FileDescriptorType>() .Union(soundBankInfo.MediaFilesNotInAnyBank.File.Cast <AK.Wwise.InfoFile.FileDescriptorType>())); List <FilePackageGenerator.Context.ExternalSourceInfo> externalSources = new List <FilePackageGenerator.Context.ExternalSourceInfo>(); // Load External Sources if (File.Exists(soundBankInfo.RootPaths.ExternalSourcesInputFile)) { XElement root = XElement.Load(soundBankInfo.RootPaths.ExternalSourcesInputFile); IEnumerable <XElement> sources = root.Elements("Source"); foreach (XElement source in sources) { FilePackageGenerator.Context.ExternalSourceInfo info = new FilePackageGenerator.Context.ExternalSourceInfo(); string sourcePath = source.Attribute("Path").Value; string destinationPath = string.Empty; XAttribute destination = source.Attribute("Destination"); if (destination != null) { destinationPath = Path.Combine(_externalSourcesOutputRoot, destination.Value); } else { destinationPath = Path.Combine(_externalSourcesOutputRoot, sourcePath); destinationPath = FilePackager.Base.Extensions.PathCanonicalize(destinationPath); } destinationPath = Path.ChangeExtension(destinationPath, ".wem"); info.Path = destinationPath; string name = FilePackager.Base.Extensions.PathRelativePathTo(_externalSourcesOutputRoot, true, destinationPath, false); info.Name = FilePackager.Base.Extensions.PathCanonicalize(name); externalSources.Add(info); } } SetContentItems(fileDescriptors, externalSources); } catch (Exception e) { MainViewModel.Instance.Application.ShowMessage( string.Format(Properties.Resources.GenericError, e.Message), Severity.Error); } } } else { if (!string.IsNullOrEmpty(infoPath)) { MainViewModel.Instance.Application.ShowMessage( string.Format(Properties.Resources.CouldNotFindInfoFile, infoPath), Severity.Error); } SetContentItems(null, null); } } // Clear the reference manager ManualPackagingInfo.Packages.ForEach(p => p.ResultingItems.RemoveAll()); ReferenceManager.Clear(); ManualPackagingInfo.InvalidateResultingItems(); ManualPackagingInfo.Packages.SelectMany(p => p.Items).ForEach(i => i.OnIsMissingChanged()); ManualPackagingInfo.Packages.SelectMany(p => p.LayoutItems).ForEach(i => i.OnIsMissingChanged()); ManualPackagingInfo.Packages.ForEach(p => p.OnMissingItemsChanged()); }
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); } }); } }