Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
andanteyk committed Aug 28, 2018
2 parents 59d7a4c + 45a2f3f commit 59109c8
Show file tree
Hide file tree
Showing 68 changed files with 3,669 additions and 3,603 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,5 @@ packages/
/ElectronicObserver/Record
/ElectronicObserver/ErrorReport
/ElectronicObserver/BattleLog
/ElectronicObserver/BrowserCache
/ElectronicObserver/ScreenShot
6 changes: 3 additions & 3 deletions Browser/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
</startup>
</configuration>
</configuration>
39 changes: 33 additions & 6 deletions Browser/Browser.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\CefSharp.WinForms.65.0.1\build\CefSharp.WinForms.props" Condition="Exists('..\packages\CefSharp.WinForms.65.0.1\build\CefSharp.WinForms.props')" />
<Import Project="..\packages\CefSharp.Common.65.0.1\build\CefSharp.Common.props" Condition="Exists('..\packages\CefSharp.Common.65.0.1\build\CefSharp.Common.props')" />
<Import Project="..\packages\cef.redist.x86.3.3325.1758\build\cef.redist.x86.props" Condition="Exists('..\packages\cef.redist.x86.3.3325.1758\build\cef.redist.x86.props')" />
<Import Project="..\packages\cef.redist.x64.3.3325.1758\build\cef.redist.x64.props" Condition="Exists('..\packages\cef.redist.x64.3.3325.1758\build\cef.redist.x64.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand All @@ -9,7 +13,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Browser</RootNamespace>
<AssemblyName>EOBrowser</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
Expand All @@ -26,6 +30,10 @@
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<CefSharpAnyCpuSupport>true</CefSharpAnyCpuSupport>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down Expand Up @@ -53,8 +61,8 @@
<Reference Include="Microsoft.mshtml, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="Nekoxy">
<HintPath>..\packages\Nekoxy.1.5.1.19\lib\net45\Nekoxy.dll</HintPath>
<Reference Include="Nekoxy, Version=1.5.3.21, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Nekoxy.1.5.3.21\lib\net45\Nekoxy.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -67,11 +75,17 @@
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="TrotiNet">
<HintPath>..\packages\Nekoxy.1.5.1.19\lib\net45\TrotiNet.dll</HintPath>
<Reference Include="TrotiNet, Version=0.8.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Nekoxy.1.5.3.21\lib\net45\TrotiNet.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="CefOp\DragHandler.cs" />
<Compile Include="CefOp\KeyboardHandler.cs" />
<Compile Include="CefOp\MenuHandler.cs" />
<Compile Include="CefOp\RequestHandler.cs" />
<Compile Include="CefOp\ResponseFilterPixiSetting.cs" />
<Compile Include="CefOp\ScreenShotPacket.cs" />
<Compile Include="FormBrowser.cs">
<SubType>Form</SubType>
</Compile>
Expand Down Expand Up @@ -150,6 +164,19 @@
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>このプロジェクトは、このコンピューター上にない NuGet パッケージを参照しています。それらのパッケージをダウンロードするには、[NuGet パッケージの復元] を使用します。詳細については、http://go.microsoft.com/fwlink/?LinkID=322105 を参照してください。見つからないファイルは {0} です。</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\cef.redist.x64.3.3325.1758\build\cef.redist.x64.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\cef.redist.x64.3.3325.1758\build\cef.redist.x64.props'))" />
<Error Condition="!Exists('..\packages\cef.redist.x86.3.3325.1758\build\cef.redist.x86.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\cef.redist.x86.3.3325.1758\build\cef.redist.x86.props'))" />
<Error Condition="!Exists('..\packages\CefSharp.Common.65.0.1\build\CefSharp.Common.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\CefSharp.Common.65.0.1\build\CefSharp.Common.props'))" />
<Error Condition="!Exists('..\packages\CefSharp.Common.65.0.1\build\CefSharp.Common.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\CefSharp.Common.65.0.1\build\CefSharp.Common.targets'))" />
<Error Condition="!Exists('..\packages\CefSharp.WinForms.65.0.1\build\CefSharp.WinForms.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\CefSharp.WinForms.65.0.1\build\CefSharp.WinForms.props'))" />
<Error Condition="!Exists('..\packages\CefSharp.WinForms.65.0.1\build\CefSharp.WinForms.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\CefSharp.WinForms.65.0.1\build\CefSharp.WinForms.targets'))" />
</Target>
<Import Project="..\packages\CefSharp.Common.65.0.1\build\CefSharp.Common.targets" Condition="Exists('..\packages\CefSharp.Common.65.0.1\build\CefSharp.Common.targets')" />
<Import Project="..\packages\CefSharp.WinForms.65.0.1\build\CefSharp.WinForms.targets" Condition="Exists('..\packages\CefSharp.WinForms.65.0.1\build\CefSharp.WinForms.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
26 changes: 26 additions & 0 deletions Browser/CefOp/DragHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using CefSharp;
using CefSharp.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Browser.CefOp
{
/// <summary>
/// (たぶん)ドラッグ&ドロップを無効化します。
/// </summary>
public class DragHandler : IDragHandler
{
public bool OnDragEnter(IWebBrowser browserControl, IBrowser browser, IDragData dragData, DragOperationsMask mask)
{
return true;
}

public void OnDraggableRegionsChanged(IWebBrowser browserControl, IBrowser browser, IList<DraggableRegion> regions)
{
// nop?
}
}
}
143 changes: 143 additions & 0 deletions Browser/CefOp/KeyboardHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
using CefSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Browser.CefOp
{
/// <summary>
/// キーボード入力を下層のフォームに伝えます?
/// </summary>
/// <remarks>CefSharp.WinForms.Example.Handlers</remarks>
public class KeyboardHandler : IKeyboardHandler
{
public bool OnPreKeyEvent(IWebBrowser browserControl, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey, ref bool isKeyboardShortcut)
{
const int WM_SYSKEYDOWN = 0x104;
const int WM_KEYDOWN = 0x100;
const int WM_KEYUP = 0x101;
const int WM_SYSKEYUP = 0x105;
const int WM_CHAR = 0x102;
const int WM_SYSCHAR = 0x106;
const int VK_TAB = 0x9;
const int VK_LEFT = 0x25;
const int VK_UP = 0x26;
const int VK_RIGHT = 0x27;
const int VK_DOWN = 0x28;

isKeyboardShortcut = false;

// Don't deal with TABs by default:
//: Are there any additional ones we need to be careful of?
// i.e. Escape, Return, etc...?
if (windowsKeyCode == VK_TAB || windowsKeyCode == VK_LEFT || windowsKeyCode == VK_UP || windowsKeyCode == VK_DOWN || windowsKeyCode == VK_RIGHT)
{
return false;
}

var result = false;

var control = browserControl as Control;
var msgType = 0;
switch (type)
{
case KeyType.RawKeyDown:
if (isSystemKey)
{
msgType = WM_SYSKEYDOWN;
}
else
{
msgType = WM_KEYDOWN;
}
break;
case KeyType.KeyUp:
if (isSystemKey)
{
msgType = WM_SYSKEYUP;
}
else
{
msgType = WM_KEYUP;
}
break;
case KeyType.Char:
if (isSystemKey)
{
msgType = WM_SYSCHAR;
}
else
{
msgType = WM_CHAR;
}
break;
default:
// abort?
break;
}


// We have to adapt from CEF's UI thread message loop to our fronting WinForm control here.
// So, we have to make some calls that Application.Run usually ends up handling for us:
var state = PreProcessControlState.MessageNotNeeded;

// We can't use BeginInvoke here, because we need the results for the return value
// and isKeyboardShortcut. In theory this shouldn't deadlock, because
// atm this is the only synchronous operation between the two threads.
control.Invoke(new Action(() =>
{
var msg = new Message
{
HWnd = control.Handle,
Msg = msgType,
WParam = new IntPtr(windowsKeyCode),
LParam = new IntPtr(nativeKeyCode)
};

// First comes Application.AddMessageFilter related processing:
// 99.9% of the time in WinForms this doesn't do anything interesting.
var processed = Application.FilterMessage(ref msg);
if (processed)
{
state = PreProcessControlState.MessageProcessed;
}
else
{
// Next we see if our control (or one of its parents)
// wants first crack at the message via several possible Control methods.
// This includes things like Mnemonics/Accelerators/Menu Shortcuts/etc...
state = control.PreProcessControlMessage(ref msg);
}
}));

if (state == PreProcessControlState.MessageNeeded)
{
//: Determine how to track MessageNeeded for OnKeyEvent.
isKeyboardShortcut = true;
}
else if (state == PreProcessControlState.MessageProcessed)
{
// Most of the interesting cases get processed by PreProcessControlMessage.
result = true;
}

//Debug.WriteLine("OnPreKeyEvent: KeyType: {0} 0x{1:X} Modifiers: {2}", type, windowsKeyCode, modifiers);
//Debug.WriteLine("OnPreKeyEvent PreProcessControlState: {0}", state);

return result;
}

public bool OnKeyEvent(IWebBrowser browserControl, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey)
{
var result = false;
//Debug.WriteLine("OnKeyEvent: KeyType: {0} 0x{1:X} Modifiers: {2}", type, windowsKeyCode, modifiers);
//: Handle MessageNeeded cases here somehow.
return result;
}


}
}
41 changes: 41 additions & 0 deletions Browser/CefOp/MenuHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using CefSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Browser.CefOp
{
/// <summary>
/// コンテキストメニューを無効化します。
/// </summary>
public class MenuHandler : IContextMenuHandler
{
public MenuHandler()
{
}


public void OnBeforeContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model)
{
model.Clear();
}

public bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags)
{
return false;
}

public void OnContextMenuDismissed(IWebBrowser browserControl, IBrowser browser, IFrame frame)
{
// nop
}

public bool RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback)
{
return false;
}
}
}
30 changes: 30 additions & 0 deletions Browser/CefOp/RequestHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using CefSharp;
using CefSharp.Handler;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Browser.CefOp
{
/// <summary>
/// レスポンスの置換制御を行います。
/// </summary>
public class RequestHandler : DefaultRequestHandler
{
bool pixiSettingEnabled;

public RequestHandler(bool pixiSettingEnabled) : base() {
this.pixiSettingEnabled = pixiSettingEnabled;
}

public override IResponseFilter GetResourceResponseFilter(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response)
{
if (pixiSettingEnabled && request.Url.Contains(@"/kcs2/index.php"))
return new ResponseFilterPixiSetting();

return base.GetResourceResponseFilter(browserControl, browser, frame, request, response);
}
}
}
50 changes: 50 additions & 0 deletions Browser/CefOp/ResponseFilterPixiSetting.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using CefSharp;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Browser.CefOp
{
/// <summary>
/// スクリーンショット撮影に必要なデータを挿入します。
/// </summary>
public class ResponseFilterPixiSetting : IResponseFilter
{
public bool InitFilter() => true;

public FilterStatus Filter(Stream dataIn, out long dataInRead, Stream dataOut, out long dataOutWritten)
{
if (dataIn == null)
{
dataInRead = 0;
dataOutWritten = 0;
return FilterStatus.Done;
}

using (var reader = new StreamReader(dataIn))
{
string raw = reader.ReadToEnd();

// note: preserveDrawingBuffer = true 設定時に動作が重くなる可能性がある
// が、 false だとスクリーンショットがハードコピー(Graphics.CopyFromScreen 等)でしか取れなくなる
// 描画直後に保存処理(toDataUrl)を行うと false でも撮れるらしいが、外部からの操作でそれができるかは不明
string replaced = raw.Replace(
@"/pixi.js""></script>",
@"/pixi.js""></script><script>PIXI.settings.RENDER_OPTIONS.preserveDrawingBuffer=true;</script>");

var bytes = Encoding.UTF8.GetBytes(replaced);
dataOut.Write(bytes, 0, bytes.Length);

dataInRead = dataIn.Length;
dataOutWritten = Math.Min(bytes.Length, dataOut.Length);
}

return FilterStatus.Done;
}

public void Dispose() { }
}
}
Loading

0 comments on commit 59109c8

Please sign in to comment.