/// <summary> /// Gets a <see cref="Texture2D"/> instance from the cache. If the texture is not already cached, it is /// extracted from the given <see cref="IPackage"/>. If it is cached, the cached version is returned. If no /// texture can be extracted, a fallback texture is returned. /// </summary> /// <param name="texturePath">The path to the texture in the package.</param> /// <param name="package">The package where the texture is stored.</param> /// <param name="wrappingModeS">The wrapping mode to use for the texture on the S axis.</param> /// <param name="wrappingModeT">The wrapping mode to use for the texture on the T axis.</param> /// <returns>A <see cref="Texture2D"/> object.</returns> public Texture2D GetTexture(string texturePath, IPackage package, TextureWrapMode wrappingModeS = TextureWrapMode.Repeat, TextureWrapMode wrappingModeT = TextureWrapMode.Repeat) { ThrowIfDisposed(); if (HasCachedTextureForPath(texturePath)) { return(GetCachedTexture(texturePath)); } try { WarcraftFileType textureType = FileInfoUtilities.GetFileType(texturePath); switch (textureType) { case WarcraftFileType.BinaryImage: { var textureData = package.ExtractFile(texturePath); if (textureData == null) { return(this.FallbackTexture); } BLP texture = new BLP(textureData); return(CreateCachedTexture(texture, texturePath, wrappingModeS, wrappingModeT)); } case WarcraftFileType.BitmapImage: case WarcraftFileType.GIFImage: case WarcraftFileType.IconImage: case WarcraftFileType.PNGImage: case WarcraftFileType.JPGImage: case WarcraftFileType.TargaImage: { using (MemoryStream ms = new MemoryStream(package.ExtractFile(texturePath))) { Bitmap texture = new Bitmap(ms); return(CreateCachedTexture(texture, texturePath)); } } } } catch (InvalidFileSectorTableException fex) { Log.Warn ( $"Failed to load the texture \"{texturePath}\" due to an invalid sector table (\"{fex.Message}\").\nA fallback texture has been loaded instead." ); } return(this.FallbackTexture); }
/// <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> /// Gets a <see cref="Texture2D"/> instance from the cache. If the texture is not already cached, it is /// extracted from the given <see cref="IPackage"/>. If it is cached, the cached version is returned. If no /// texture can be extracted, a fallback texture is returned. /// </summary> /// <param name="texturePath">The path to the texture in the package.</param> /// <param name="package">The package where the texture is stored.</param> /// <param name="wrappingModeS">The wrapping mode to use for the texture on the S axis.</param> /// <param name="wrappingModeT">The wrapping mode to use for the texture on the T axis.</param> /// <returns>A <see cref="Texture2D"/> object.</returns> public Texture2D GetTexture(string texturePath, IPackage package, TextureWrapMode wrappingModeS = TextureWrapMode.Repeat, TextureWrapMode wrappingModeT = TextureWrapMode.Repeat) { ThrowIfDisposed(); if (HasCachedTextureForPath(texturePath)) { return(GetCachedTexture(texturePath)); } WarcraftFileType textureType = FileInfoUtilities.GetFileType(texturePath); switch (textureType) { case WarcraftFileType.BinaryImage: { if (!package.TryExtractFile(texturePath, out var textureData)) { return(this.FallbackTexture); } BLP texture = new BLP(textureData); return(CreateCachedTexture(texture, texturePath, wrappingModeS, wrappingModeT)); } case WarcraftFileType.BitmapImage: case WarcraftFileType.GIFImage: case WarcraftFileType.IconImage: case WarcraftFileType.PNGImage: case WarcraftFileType.JPGImage: case WarcraftFileType.TargaImage: { if (!package.TryExtractFile(texturePath, out var data)) { return(this.FallbackTexture); } using (MemoryStream ms = new MemoryStream(data)) { Bitmap texture = new Bitmap(ms); return(CreateCachedTexture(texture, texturePath)); } } } return(this.FallbackTexture); }
/// <summary> /// This function is used internally by the tree filter to determine which rows are visible and which are not. /// </summary> /// <param name="model">The model of the tree.</param> /// <param name="iter">The iter to determine visibility for.</param> /// <returns>true if the iter should be visible; false otherwise.</returns> private bool TreeModelVisibilityFunc(ITreeModel model, TreeIter iter) { if (!this.IsFiltered) { return(true); } FileNode node = (FileNode)model.GetValue(iter, 0); WarcraftFileType nodeTypes = node.FileType; // If the file types of the node and the filtered types overlap in any way, then it should // be displayed. if ((nodeTypes & this.FilteredFileTypes) != 0) { return(true); } return(false); }
/// <summary> /// Sets the filter of the tree view and asynchronously refilters it. The filter is a set of /// <see cref="WarcraftFileType"/> flags. /// </summary> /// <param name="filteredFileTypes">The file types to filter out.</param> public void SetFilter(WarcraftFileType filteredFileTypes) { _filteredFileTypes = filteredFileTypes; }
/// <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; } } }