-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add TLG encoding plugin, Fix #9
- Loading branch information
Showing
21 changed files
with
500 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -254,3 +254,4 @@ paket-files/ | |
/FreeMote.Tests/Res | ||
/FreeMote.Tests/PurifyTest.cs | ||
|
||
/MigrationBackup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?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>{F37472B9-6501-440E-8898-7774304F7FEC}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>FreeMote.Plugins</RootNamespace> | ||
<AssemblyName>FreeMote.Plugins</AssemblyName> | ||
<TargetFrameworkVersion>v4.6</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="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Drawing" /> | ||
<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="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="TlgPlugin.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Dynamitey"> | ||
<Version>2.0.9.136</Version> | ||
</PackageReference> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// 有关程序集的一般信息由以下 | ||
// 控制。更改这些特性值可修改 | ||
// 与程序集关联的信息。 | ||
[assembly: AssemblyTitle("FreeMote.Plugins")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("Project AZUSA")] | ||
[assembly: AssemblyProduct("FreeMote")] | ||
[assembly: AssemblyCopyright("Copyright © Ulysses 2018")] | ||
[assembly: AssemblyTrademark("[email protected]")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// 将 ComVisible 设置为 false 会使此程序集中的类型 | ||
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 | ||
//请将此类型的 ComVisible 特性设置为 true。 | ||
[assembly: ComVisible(false)] | ||
|
||
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID | ||
[assembly: Guid("f37472b9-6501-440e-8898-7774304f7fec")] | ||
|
||
// 程序集的版本信息由下列四个值组成: | ||
// | ||
// 主版本 | ||
// 次版本 | ||
// 生成号 | ||
// 修订号 | ||
// | ||
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 | ||
//通过使用 "*",如下所示: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.*")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
using System; | ||
using System.Drawing; | ||
using System.IO; | ||
using System.Reflection; | ||
using Dynamitey.DynamicObjects; | ||
|
||
namespace FreeMote.Plugins | ||
{ | ||
/// <summary> | ||
/// FreeMote.Tlg | ||
/// <para>Native TLG Plugin</para> | ||
/// </summary> | ||
public static class TlgPlugin | ||
{ | ||
private static bool _isEnabled = true; | ||
|
||
/// <summary> | ||
/// Is plugin enabled | ||
/// </summary> | ||
public static bool IsEnabled | ||
{ | ||
get => IsReady && _isEnabled; | ||
set | ||
{ | ||
if (IsReady) | ||
{ | ||
_isEnabled = value; | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Is plugin loaded | ||
/// </summary> | ||
public static bool IsReady { get; private set; } = false; | ||
private const string PluginPath = "TlgLib.dll"; | ||
private static dynamic TlgNative = null; | ||
//private static dynamic TlgLoader = null; | ||
static TlgPlugin() | ||
{ | ||
IsReady = false; | ||
|
||
if (Environment.OSVersion.Platform == PlatformID.MacOSX || Environment.OSVersion.Platform == PlatformID.Unix) | ||
{ | ||
return; | ||
} | ||
|
||
var path = Path.GetFullPath(PluginPath); | ||
if (!File.Exists(path)) | ||
{ | ||
try | ||
{ | ||
path = Path.Combine( | ||
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? | ||
Environment.CurrentDirectory, PluginPath); | ||
//Console.WriteLine(path); | ||
} | ||
catch (Exception) | ||
{ | ||
// ignored | ||
} | ||
|
||
if (!File.Exists(path)) | ||
{ | ||
return; | ||
} | ||
} | ||
|
||
try | ||
{ | ||
var asm = Assembly.LoadFile(path); | ||
TlgNative = new LateType(asm, "FreeMote.Tlg.TlgNative"); | ||
//TlgLoader = new LateType(asm, "FreeMote.Tlg.TlgLoader"); | ||
if (TlgNative.IsAvailable) | ||
{ | ||
IsReady = true; | ||
} | ||
} | ||
catch (Exception) | ||
{ | ||
return; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Save <see cref="Bitmap"/> as TLG | ||
/// </summary> | ||
/// <param name="bmp"></param> | ||
/// <param name="tlg6">true: save as TLG6; false: save as TLG5</param> | ||
/// <returns></returns> | ||
public static byte[] SaveTlg(Bitmap bmp, bool tlg6 = false) | ||
{ | ||
if (tlg6) | ||
{ | ||
return TlgNative.ToTlg6(bmp); | ||
} | ||
|
||
return TlgNative.ToTlg5(bmp); | ||
} | ||
|
||
/// <summary> | ||
/// Load TLG as <see cref="Bitmap"/> | ||
/// </summary> | ||
/// <param name="tlgBytes"></param> | ||
/// <param name="version">get TLG version [5,6]</param> | ||
/// <returns></returns> | ||
public static Bitmap LoadTlg(byte[] tlgBytes, out int version) | ||
{ | ||
//Impossible to call `TlgNative.ToBitmap(byte[], out int, bool = false)` because dynamic invoke can not call method with ref/out! | ||
Tuple<Bitmap, int> tuple = TlgNative.ToBitmap(tlgBytes); | ||
version = tuple.Item2; | ||
return tuple.Item1; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.