/// <summary> /// Handles the export item context item activated event. /// </summary> /// <param name="page">Sender.</param> /// <param name="fileReference">E.</param> private static void OnExportItemRequested(GamePage page, FileReference fileReference) { // TODO: Create a better exporter (EverlookExporter.Export(<>)?) switch (fileReference.GetReferencedFileType()) { case WarcraftFileType.Directory: { /* * using (EverlookDirectoryExportDialog exportDialog = EverlookDirectoryExportDialog.Create(fileReference)) * { * if (exportDialog.Run() == (int)ResponseType.Ok) * { * exportDialog.RunExport(); * } * exportDialog.Destroy(); * } */ break; } case WarcraftFileType.BinaryImage: { using (EverlookImageExportDialog exportDialog = EverlookImageExportDialog.Create(fileReference)) { if (exportDialog.Run() == (int)ResponseType.Ok) { exportDialog.RunExport(); } exportDialog.Destroy(); } break; } } }
/// <summary> /// Initializes a new instance of the <see cref="MP3AudioAsset"/> class. /// </summary> /// <param name="fileReference">The reference to create the asset from.</param> /// <exception cref="ArgumentException">Thrown if the reference is not an MP3 audio file.</exception> /// <exception cref="ArgumentNullException">Thrown if the file data can't be extracted.</exception> public MP3AudioAsset(FileReference fileReference) { if (fileReference == null) { throw new ArgumentNullException(nameof(fileReference)); } if (fileReference.GetReferencedFileType() != WarcraftFileType.MP3Audio) { throw new ArgumentException ( "The provided file reference was not an MP3 audio file.", nameof(fileReference) ); } var fileBytes = fileReference.Extract(); if (fileBytes == null) { throw new ArgumentException("The file data could not be extracted.", nameof(fileReference)); } this.PCMStream = new MP3Stream(new MemoryStream(fileBytes)); this.Channels = ((MP3Stream)this.PCMStream).ChannelCount; this.BitsPerSample = 16; this.SampleRate = ((MP3Stream)this.PCMStream).Frequency; }
/// <summary> /// Handles selection of files in the game explorer, displaying them to the user and routing /// whatever rendering functionality the file needs to the viewport. /// </summary> /// <param name="sender">Sender.</param> /// <param name="e">E.</param> private void OnGameExplorerSelectionChanged(object sender, EventArgs e) { TreeIter selectedIter; this.GameExplorerTreeView.Selection.GetSelected(out selectedIter); FileReference fileReference = this.FiletreeBuilder.NodeStorage.GetItemReferenceFromIter(selectedIter); if (fileReference != null && fileReference.IsFile) { if (string.IsNullOrEmpty(fileReference.FilePath)) { return; } switch (fileReference.GetReferencedFileType()) { case WarcraftFileType.BinaryImage: { BeginLoadingFile(fileReference, DataLoadingRoutines.LoadBinaryImage, DataLoadingRoutines.CreateRenderableBinaryImage, ControlPage.Image); break; } case WarcraftFileType.WorldObjectModel: { BeginLoadingFile(fileReference, DataLoadingRoutines.LoadWorldModel, DataLoadingRoutines.CreateRenderableWorldModel, ControlPage.Model); break; } case WarcraftFileType.WorldObjectModelGroup: { BeginLoadingFile(fileReference, DataLoadingRoutines.LoadWorldModelGroup, DataLoadingRoutines.CreateRenderableWorldModel, ControlPage.Model); break; } case WarcraftFileType.GIFImage: case WarcraftFileType.PNGImage: case WarcraftFileType.JPGImage: { BeginLoadingFile(fileReference, DataLoadingRoutines.LoadBitmapImage, DataLoadingRoutines.CreateRenderableBitmapImage, ControlPage.Image); break; } } } }
/// <summary> /// Handles the export item context item activated event. /// </summary> /// <param name="sender">Sender.</param> /// <param name="e">E.</param> private void OnExportItemContextItemActivated(object sender, EventArgs e) { FileReference fileReference = GetSelectedReference(); if (string.IsNullOrEmpty(fileReference?.FilePath)) { return; } WarcraftFileType fileType = fileReference.GetReferencedFileType(); switch (fileType) { case WarcraftFileType.Directory: { if (fileReference.IsFullyEnumerated) { using (EverlookDirectoryExportDialog exportDialog = EverlookDirectoryExportDialog.Create(fileReference)) { if (exportDialog.Run() == (int)ResponseType.Ok) { exportDialog.RunExport(); } exportDialog.Destroy(); } } else { // TODO: Implement wait message when the directory and its subdirectories have not yet been enumerated. } break; } case WarcraftFileType.BinaryImage: { using (EverlookImageExportDialog exportDialog = EverlookImageExportDialog.Create(fileReference)) { if (exportDialog.Run() == (int)ResponseType.Ok) { exportDialog.RunExport(); } exportDialog.Destroy(); } break; } } }
/// <summary> /// Handles selection of files in the game explorer, displaying them to the user and routing /// whatever rendering functionality the file needs to the viewport. /// </summary> /// <param name="page">The <see cref="GamePage"/> in which the event originated.</param> /// <param name="fileReference">The file reference to load.</param> private async void OnFileLoadRequested(GamePage page, FileReference fileReference) { WarcraftFileType referencedType = fileReference.GetReferencedFileType(); switch (referencedType) { case WarcraftFileType.BinaryImage: { this.FileLoadingCancellationSource.Cancel(); this.FileLoadingCancellationSource = new CancellationTokenSource(); await DisplayRenderableFile ( page, fileReference, DataLoadingRoutines.LoadBinaryImage, DataLoadingRoutines.CreateRenderableBinaryImage, ControlPage.Image, this.FileLoadingCancellationSource.Token ); break; } case WarcraftFileType.WorldObjectModel: { this.FileLoadingCancellationSource.Cancel(); this.FileLoadingCancellationSource = new CancellationTokenSource(); await DisplayRenderableFile ( page, fileReference, DataLoadingRoutines.LoadWorldModel, DataLoadingRoutines.CreateRenderableWorldModel, ControlPage.Model, this.FileLoadingCancellationSource.Token ); break; } case WarcraftFileType.WorldObjectModelGroup: { this.FileLoadingCancellationSource.Cancel(); this.FileLoadingCancellationSource = new CancellationTokenSource(); await DisplayRenderableFile ( page, fileReference, DataLoadingRoutines.LoadWorldModelGroup, DataLoadingRoutines.CreateRenderableWorldModel, ControlPage.Model, this.FileLoadingCancellationSource.Token ); break; } case WarcraftFileType.GIFImage: case WarcraftFileType.PNGImage: case WarcraftFileType.JPGImage: { this.FileLoadingCancellationSource.Cancel(); this.FileLoadingCancellationSource = new CancellationTokenSource(); await DisplayRenderableFile ( page, fileReference, DataLoadingRoutines.LoadBitmapImage, DataLoadingRoutines.CreateRenderableBitmapImage, ControlPage.Image, this.FileLoadingCancellationSource.Token ); break; } case WarcraftFileType.WaveAudio: case WarcraftFileType.MP3Audio: { AudioManager.UnregisterSource(this.GlobalAudio); this.GlobalAudio = AudioSource.CreateNew(); await this.GlobalAudio.SetAudioAsync(fileReference); AudioManager.RegisterSource(this.GlobalAudio); this.GlobalAudio.Play(); break; } } }
/// <summary> /// Handles double-clicking on files in the explorer. /// </summary> /// <param name="o">The sending object.</param> /// <param name="args">Arguments describing the row that was activated.</param> private void OnGameExplorerRowActivated(object o, RowActivatedArgs args) { TreeIter selectedIter; this.GameExplorerTreeView.Selection.GetSelected(out selectedIter); FileReference fileReference = this.FiletreeBuilder.NodeStorage.GetItemReferenceFromIter(selectedIter); if (fileReference == null) { return; } if (fileReference.IsFile) { if (string.IsNullOrEmpty(fileReference.FilePath)) { return; } switch (fileReference.GetReferencedFileType()) { // Warcraft-typed standard files case WarcraftFileType.AddonManifest: case WarcraftFileType.AddonManifestSignature: case WarcraftFileType.ConfigurationFile: case WarcraftFileType.Hashmap: case WarcraftFileType.XML: case WarcraftFileType.INI: case WarcraftFileType.PDF: case WarcraftFileType.HTML: { byte[] fileData = fileReference.Extract(); if (fileData != null) { // create a temporary file and write the data to it. string tempPath = IOPath.GetTempPath() + fileReference.Filename; if (File.Exists(tempPath)) { File.Delete(tempPath); } using (Stream tempStream = File.Open(tempPath, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.Read)) { tempStream.Write(fileData, 0, fileData.Length); tempStream.Flush(); } // Hand off the file to the operating system. System.Diagnostics.Process.Start(tempPath); } break; } } } else { this.GameExplorerTreeView.ExpandRow(this.FiletreeBuilder.NodeStorage.GetPath(selectedIter), false); } }