Skip to content

Commit

Permalink
Preview plugins (WoW-Tools#30)
Browse files Browse the repository at this point in the history
* Tested implement previev plugin systems.

Signed-off-by: Konctantin <gawrilyako@gmail.com>

* Additional functional for view plugins

Signed-off-by: Konctantin <gawrilyako@gmail.com>

* fix

Signed-off-by: Konctantin <gawrilyako@gmail.com>

* Reimplement plugin system:
 * Use metadata composition

Signed-off-by: Konctantin <gawrilyako@gmail.com>

* fix

Signed-off-by: Konctantin <gawrilyako@gmail.com>

* Fixed hex preview

Signed-off-by: Konctantin <gawrilyako@gmail.com>

* Fix

Signed-off-by: Konctantin <gawrilyako@gmail.com>

* fix

Signed-off-by: Konctantin <gawrilyako@gmail.com>

* Add more extensions for unknown file analizer.

Signed-off-by: Konctantin <gawrilyako@gmail.com>

* Fixed typo

Signed-off-by: Konctantin <gawrilyako@gmail.com>

* fix

Signed-off-by: Konctantin <gawrilyako@gmail.com>

* fix

Signed-off-by: Konstantin <gawrilyako@gmail.com>

* add listfile path

Signed-off-by: Konctantin <gawrilyako@gmail.com>

* upd

Signed-off-by: Konstantin <gawrilyako@gmail.com>

* fix

Signed-off-by: Konstantin <gawrilyako@gmail.com>

* fix

Signed-off-by: Konstantin <gawrilyako@gmail.com>
  • Loading branch information
Konctantin authored and billy1arm committed Feb 24, 2021
1 parent 34b7b2d commit 282e013
Show file tree
Hide file tree
Showing 28 changed files with 1,157 additions and 185 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -4,3 +4,4 @@
[Bb]in
[Oo]bj
*.user
packages/*
91 changes: 91 additions & 0 deletions CASCExplorer.ViewPlugin/CASCExplorer.ViewPlugin.csproj
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{63C32AC8-2EE2-4DB7-99C5-84FD815AADC3}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CASCExplorer.ViewPlugin</RootNamespace>
<AssemblyName>CASCExplorer.ViewPlugin</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Be.Windows.Forms.HexBox, Version=1.6.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Be.Windows.Forms.HexBox.1.6.1\lib\net40\Be.Windows.Forms.HexBox.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Previews\BlpView.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Previews\BlpView.Designer.cs">
<DependentUpon>BlpView.cs</DependentUpon>
</Compile>
<Compile Include="Previews\HexView.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Previews\HexView.Designer.cs">
<DependentUpon>HexView.cs</DependentUpon>
</Compile>
<Compile Include="IPreview.cs" />
<Compile Include="Previews\TextView.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Previews\TextView.Designer.cs">
<DependentUpon>TextView.cs</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Previews\BlpView.resx">
<DependentUpon>BlpView.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Previews\HexView.resx">
<DependentUpon>HexView.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Previews\TextView.resx">
<DependentUpon>TextView.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SereniaBLPLib\SereniaBLPLib\SereniaBLPLib.csproj">
<Project>{4ed9f877-a9bb-470f-b35c-694147472080}</Project>
<Name>SereniaBLPLib</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
15 changes: 15 additions & 0 deletions CASCExplorer.ViewPlugin/IPreview.cs
@@ -0,0 +1,15 @@
using System.IO;
using System.Windows.Forms;

namespace CASCExplorer.ViewPlugin
{
public interface IExtensions
{
string[] Extensions { get; }
}

public interface IPreview
{
Control Show(Stream stream, string fileName);
}
}
124 changes: 124 additions & 0 deletions CASCExplorer.ViewPlugin/Previews/BlpView.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 75 additions & 0 deletions CASCExplorer.ViewPlugin/Previews/BlpView.cs
@@ -0,0 +1,75 @@
using System.Windows.Forms;
using CASCExplorer.ViewPlugin;
using System.IO;
using SereniaBLPLib;
using System.ComponentModel.Composition;
using System.Linq;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;

namespace CASCExplorer.DefaultViews.Previews
{
[Export(typeof(IPreview))]
[ExportMetadata("Extensions", new string[] { ".blp" })]
public partial class BlpView : UserControl, IPreview
{
List<Bitmap> m_mips = new List<Bitmap>();
string m_fileName;

public BlpView()
{
InitializeComponent();
}

public Control Show(Stream stream, string fileName)
{
m_fileName = fileName;
m_mips.Clear();
try
{
using (var blp = new BlpFile(stream))
{
for (int i = 0; i < blp.MipMapCount; ++i)
{
var bmp = blp.GetBitmap(i);
if (bmp.Width > 0 && bmp.Height > 0)
{
m_mips.Add(bmp);
}
}
}
}
catch// (System.Exception ex)
{
//MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

cbMipIndex.Items.Clear();
cbMipIndex.Items.AddRange(Enumerable.Range(0, m_mips.Count).Select(m => m.ToString()).ToArray());
if (cbMipIndex.Items.Count > 0)
cbMipIndex.SelectedIndex = 0;
return this;
}

private void cbMipIndex_SelectedIndexChanged(object sender, System.EventArgs e)
{
pictureBox1.Image = m_mips[cbMipIndex.SelectedIndex];
}

private void bSave_Click(object sender, System.EventArgs e)
{
saveFileDialog1.FileName = Path.GetFileNameWithoutExtension(m_fileName);
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
var format = ImageFormat.Bmp;
switch (saveFileDialog1.FilterIndex)
{
case 2: format = ImageFormat.Jpeg; break;
case 3: format = ImageFormat.Png; break;
}
pictureBox1.Image.Save(saveFileDialog1.FileName, format);
}
}
}
}

0 comments on commit 282e013

Please sign in to comment.