private void SetContentItems( IEnumerable <AK.Wwise.InfoFile.FileDescriptorType> fileDescriptors, IEnumerable <FilePackageGenerator.Context.ExternalSourceInfo> externalSources) { _contentItems.Clear(); _contentItems.AddRange(fileDescriptors.SafeSelect(i => new ContentItemViewModel(i))); _contentItems.AddRange(externalSources.SafeSelect(i => new ContentItemViewModel(i))); // Maintain a map of ID to ContentItem try { _contentItemsPerId = _contentItems.ToDictionary(ci => new Tuple <UInt64, string>(ci.Id, ci.Language), ci => ci); } catch (ArgumentException e) { var duplicates = _contentItems.GroupBy(ci => new Tuple <UInt64, string>(ci.Id, ci.Language)) .Where(g => g.Count() > 1); if (duplicates.Any()) { var dup = duplicates.First().First(); throw new InvalidDataException("Could not load the content correctly. Duplicate file identifiers (id) were found while loading SoundBanksInfo.xml. First duplicate found is: " + dup.FileName + " [" + dup.FileType + "]"); } else { throw e; } } if (!UndoManager.Instance.IsBusy) { ManualPackagingInfo.UpdateLanguageList(fileDescriptors.SafeSelect(fd => fd.Language).Distinct()); } }
public ManualPackagingInfoViewModel(ManualPackagingInfo manualPackagingInfo, ProjectViewModel projectViewModel) { _manualPackagingInfo = manualPackagingInfo; RegisterModel(_manualPackagingInfo); _nonePackage = CreatePackageViewModel(new Package() { Name = "None" }); _packages = new UndoableObservableCollection <PackageViewModel, Package>(_manualPackagingInfo.Packages, CreatePackageViewModel); _packages.CollectionChanged += _packages_CollectionChanged; _defaultLanguagePackageIds = new UndoableObservableCollection <LanguagePackageIdsViewModel, LanguagePackageIds>(_manualPackagingInfo.DefaultLanguagePackageIds, CreateLanguagePackageIdsViewModel); // Init Package per ID foreach (PackageViewModel item in _packages) { RegisterPackage(item); } _resultingItemsWorker.DoWork += ResultingItemsWorker_DoWork; _resultingItemsWorker.WorkerSupportsCancellation = true; projectViewModel.PropertyChanged += ProjectViewModel_PropertyChanged; }
private static XElement SaveManualPackaging(ManualPackagingInfo manualPackagingInfo) { return(new XElement("ManualPackagingInfo", new XAttribute("BlockSize", manualPackagingInfo.BlockSize.ToString()), new XAttribute("UnassignedBanksPackageId", manualPackagingInfo.UnassignedBanksPackageId.ToString()), new XAttribute("UnassignedStreamsPackageId", manualPackagingInfo.UnassignedStreamsPackageId.ToString()), new XAttribute("UnassignedExternalsPackageId", manualPackagingInfo.UnassignedExternalsPackageId.ToString()), new XAttribute("UnassignedLooseMediaPackageId", manualPackagingInfo.UnassignedLooseMediaPackageId.ToString()), // Save packages new XElement("Packages", manualPackagingInfo.Packages.Select(p => new XElement("Package", new XAttribute("Id", p.Id), new XAttribute("Name", p.Name), new XElement("Items", p.Items.Select(pci => new XElement("PackageContentItem", new XAttribute("Id", pci.Id.ToString()), new XAttribute("Language", pci.Language), new XAttribute("FileName", pci.FileName), new XAttribute("InclusionMode", pci.InclusionMode.ToString()) ))), new XElement("LayoutItems", p.LayoutItems.Select(pci => new XElement("ContentItemBase", new XAttribute("Id", pci.Id.ToString()), new XAttribute("Language", pci.Language), new XAttribute("FileName", pci.FileName)))) ))), // Save DefaultLanguagePackageIds new XElement("DefaultLanguagePackageIds", manualPackagingInfo.DefaultLanguagePackageIds.Select(dlpi => new XElement("LanguagePackageIds", new XAttribute("Language", dlpi.Language), new XAttribute("BankPackageId", dlpi.BankPackageId.ToString()), new XAttribute("StreamPackageId", dlpi.StreamPackageId.ToString()), new XAttribute("LooseMediaPackageId", dlpi.LooseMediaPackageId.ToString()) ))) )); }
private static void LoadManualPackaging(XElement xParent, ManualPackagingInfo manualPackagingInfo) { XElement xElement = xParent.Element("ManualPackagingInfo"); manualPackagingInfo.BlockSize = uint.Parse(xElement.Attribute("BlockSize").Value); manualPackagingInfo.UnassignedBanksPackageId = new Guid(xElement.Attribute("UnassignedBanksPackageId").Value); manualPackagingInfo.UnassignedStreamsPackageId = new Guid(xElement.Attribute("UnassignedStreamsPackageId").Value); manualPackagingInfo.UnassignedExternalsPackageId = new Guid(xElement.Attribute("UnassignedExternalsPackageId").Value); manualPackagingInfo.UnassignedLooseMediaPackageId = new Guid(xElement.Attribute("UnassignedLooseMediaPackageId").Value); // Load packages XElement xPackages = xElement.Element("Packages"); manualPackagingInfo.Packages.AddRange( xPackages.Elements().Select(p => new Package(new Guid(p.Attribute("Id").Value), p.Element("Items").Elements().Select(i => new PackageContentItem(UInt64.Parse(i.Attribute("Id").Value), i.Attribute("Language").Value, i.Attribute("FileName").Value) { InclusionMode = (InclusionMode)Enum.Parse(typeof(InclusionMode), i.Attribute("InclusionMode").Value) }), p.Element("LayoutItems").Elements().Select(i => new ContentItemBase(UInt64.Parse(i.Attribute("Id").Value), i.Attribute("Language").Value, i.Attribute("FileName").Value)) ) { Name = p.Attribute("Name").Value })); // Load DefaultLanguagePackageIds XElement xDefaultLanguagePackageIds = xElement.Element("DefaultLanguagePackageIds"); manualPackagingInfo.DefaultLanguagePackageIds.AddRange( xDefaultLanguagePackageIds.Elements().Select(e => new LanguagePackageIds(e.Attribute("Language").Value) { BankPackageId = new Guid(e.Attribute("BankPackageId").Value), StreamPackageId = new Guid(e.Attribute("StreamPackageId").Value), LooseMediaPackageId = new Guid(e.Attribute("LooseMediaPackageId").Value), })); }
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()); }