Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
andanteyk committed Sep 7, 2018
2 parents 59109c8 + 3123eee commit 6dcd433
Show file tree
Hide file tree
Showing 31 changed files with 705 additions and 510 deletions.
31 changes: 7 additions & 24 deletions Browser/Browser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
<AssemblyName>EOBrowser</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<IsWebBootstrapper>false</IsWebBootstrapper>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<CefSharpAnyCpuSupport>true</CefSharpAnyCpuSupport>
<TargetFrameworkProfile />
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
Expand All @@ -27,13 +32,8 @@
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<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 All @@ -44,6 +44,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -53,6 +54,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>1</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net">
Expand Down Expand Up @@ -127,25 +129,6 @@
<Name>BrowserLib</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<COMReference Include="AxSHDocVw">
<Guid>{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}</Guid>
<VersionMajor>1</VersionMajor>
<VersionMinor>1</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>aximp</WrapperTool>
<Isolated>False</Isolated>
</COMReference>
<COMReference Include="SHDocVw">
<Guid>{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}</Guid>
<VersionMajor>1</VersionMajor>
<VersionMinor>1</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>tlbimp</WrapperTool>
<Isolated>False</Isolated>
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.5">
<Visible>False</Visible>
Expand Down
55 changes: 51 additions & 4 deletions Browser/CefOp/RequestHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,70 @@

namespace Browser.CefOp
{
/// <summary>
/// レスポンスの置換制御を行います。
/// </summary>
public class RequestHandler : DefaultRequestHandler
{
public delegate void RenderProcessTerminatedEventHandler(string message);
public event RenderProcessTerminatedEventHandler RenderProcessTerminated;

bool pixiSettingEnabled;

public RequestHandler(bool pixiSettingEnabled) : base() {

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

/// <summary>
/// レスポンスの置換制御を行います。
/// </summary>
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);
}

/// <summary>
/// 特定の通信をブロックします。
/// </summary>
public override CefReturnValue OnBeforeResourceLoad(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IRequestCallback callback)
{
// ログイン直後に勝手に遷移させられ、ブラウザがホワイトアウトすることがあるためブロックする
if (request.Url.Contains(@"/rt.gsspat.jp/"))
{
return CefReturnValue.Cancel;
}

return base.OnBeforeResourceLoad(browserControl, browser, frame, request, callback);
}

/// <summary>
/// 描画プロセスが何らかの理由で落ちた際の処理を行います。
/// </summary>
public override void OnRenderProcessTerminated(IWebBrowser browserControl, IBrowser browser, CefTerminationStatus status)
{
// note: out of memory (例外コード: 0xe0000008) でクラッシュした場合、このイベントは呼ばれない

string ret = "ブラウザの描画プロセスが";
switch (status)
{
case CefTerminationStatus.AbnormalTermination:
ret += "正常に終了しませんでした。";
break;
case CefTerminationStatus.ProcessWasKilled:
ret += "何者かによって殺害されました。";
break;
case CefTerminationStatus.ProcessCrashed:
ret += "クラッシュしました。";
break;
default:
ret += "謎の死を遂げました。";
break;
}
ret += "再読み込みすると復帰します。";

RenderProcessTerminated(ret);
}
}
}
13 changes: 8 additions & 5 deletions Browser/CefOp/ScreenShotPacket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,24 @@ public class ScreenShotPacket
{
public string ID { get; }
public string DataUrl;
private TaskCompletionSource<Bitmap> taskSource;
public TaskCompletionSource<ScreenShotPacket> TaskSource { get; }

public ScreenShotPacket(TaskCompletionSource<Bitmap> source) : this("ss_" + Guid.NewGuid().ToString("N"), source) { }
public ScreenShotPacket(string id, TaskCompletionSource<Bitmap> source)
public ScreenShotPacket() : this("ss_" + Guid.NewGuid().ToString("N")) { }
public ScreenShotPacket(string id)
{
ID = id;
taskSource = source;
TaskSource = new TaskCompletionSource<ScreenShotPacket>();
}

public void Complete(string dataurl)
{
DataUrl = dataurl;
taskSource.SetResult(ConvertToImage(dataurl));
TaskSource.SetResult(this);
}

public Bitmap GetImage() => ConvertToImage(DataUrl);


public static Bitmap ConvertToImage(string dataurl)
{
if (dataurl == null || !dataurl.StartsWith("data:image/png"))
Expand Down
76 changes: 34 additions & 42 deletions Browser/FormBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,22 +223,28 @@ void InitializeBrowser()
CachePath = BrowserCachePath,
Locale = "ja",
AcceptLanguageList = "ja,en-US,en", // todo: いる?
LogSeverity = LogSeverity.Disable,
LogSeverity = LogSeverity.Error,
LogFile = "BrowserLog.log",
};

if (!Configuration.HardwareAccelerationEnabled)
settings.DisableGpuAcceleration();

settings.CefCommandLineArgs.Add("proxy-server", ProxySettings);
if (Configuration.ForceColorProfile)
settings.CefCommandLineArgs.Add("force-color-profile", "srgb");
CefSharpSettings.SubprocessExitIfParentProcessClosed = true;
Cef.Initialize(settings, false, null);


var requestHandler = new RequestHandler(pixiSettingEnabled: Configuration.PreserveDrawingBuffer);
requestHandler.RenderProcessTerminated += (mes) => AddLog(3, mes);

Browser = new ChromiumWebBrowser(@"about:blank")
{
Dock = DockStyle.None,
Size = SizeAdjuster.Size,
RequestHandler = new RequestHandler(pixiSettingEnabled: Configuration.PreserveDrawingBuffer),
RequestHandler = requestHandler,
MenuHandler = new MenuHandler(),
KeyboardHandler = new KeyboardHandler(),
DragHandler = new DragHandler(),
Expand Down Expand Up @@ -568,67 +574,56 @@ public void ApplyZoom()
/// <summary>
/// スクリーンショットを撮影します。
/// </summary>
private Task<Bitmap> TakeScreenShot()
private async Task<Bitmap> TakeScreenShot()
{
var source = new TaskCompletionSource<Bitmap>();

if (Browser == null || !Browser.IsBrowserInitialized)
return source.Task;


var browser = Browser.GetBrowser();

var KanColleFrame = GetKanColleFrame();

if (KanColleFrame == null)
var kancolleFrame = GetKanColleFrame();
if (kancolleFrame == null)
{
AddLog(3, string.Format("艦これが読み込まれていないため、スクリーンショットを撮ることはできません。"));
System.Media.SystemSounds.Beep.Play();
return source.Task;
return null;
}


var request = new ScreenShotPacket(source);
string script = $@"
Task<ScreenShotPacket> InternalTakeScreenShot()
{
var request = new ScreenShotPacket();

if (Browser == null || !Browser.IsBrowserInitialized)
return request.TaskSource.Task;


string script = $@"
(async function()
{{
await CefSharp.BindObjectAsync('{request.ID}');
var canvas = document.querySelector('canvas');
let canvas = document.querySelector('canvas');
requestAnimationFrame(() =>
{{
var dataurl = canvas.toDataURL('image/png');
let dataurl = canvas.toDataURL('image/png');
{request.ID}.complete(dataurl);
}});
}})();
";

Browser.JavascriptObjectRepository.Register(request.ID, request, true);
KanColleFrame.ExecuteJavaScriptAsync(script);
Browser.JavascriptObjectRepository.Register(request.ID, request, true);
kancolleFrame.ExecuteJavaScriptAsync(script);

return source.Task;
}
return request.TaskSource.Task;
}

var result = await InternalTakeScreenShot();

/// <summary>
/// ブラウザ画面のハードコピーを取得します。
/// TakeScreenShot で SS が撮れない環境 (WebGL && preserveDrawingBuffer=false) で使用します。
/// </summary>
private Task<Bitmap> TakeHardScreenShot()
{
// スタイルシートが適用されていると仮定する
// ごみ掃除
Browser.JavascriptObjectRepository.UnRegister(result.ID);
kancolleFrame.ExecuteJavaScriptAsync($@"delete {result.ID}");

var bmp = new Bitmap(Browser.Width, Browser.Height, PixelFormat.Format24bppRgb);
using (var g = Graphics.FromImage(bmp))
{
g.CopyFromScreen(Browser.PointToScreen(Browser.Location), new Point(0, 0), Browser.Size);
}

// 同期処理でもいいが、TakeScreenShot とシグネチャを合わせるため
return Task.FromResult(bmp);
return result.GetImage();
}



/// <summary>
/// スクリーンショットを撮影し、設定で指定された保存先に保存します。
/// </summary>
Expand All @@ -643,10 +638,7 @@ public async Task SaveScreenShot()
Bitmap image = null;
try
{
if (Configuration.HardwareAccelerationEnabled && !Configuration.PreserveDrawingBuffer)
image = await TakeHardScreenShot();
else
image = await TakeScreenShot();
image = await TakeScreenShot();


if (image == null)
Expand Down
26 changes: 25 additions & 1 deletion Browser/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,31 @@ private static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object s
{
string asmname = args.Name.Split(",".ToCharArray(), 2)[0] + ".dll";
string arch = System.IO.Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, Environment.Is64BitProcess ? "x64" : "x86", asmname);
return System.IO.File.Exists(arch) ? System.Reflection.Assembly.LoadFile(arch) : null;

if (!System.IO.File.Exists(arch))
return null;

try
{
return System.Reflection.Assembly.LoadFile(arch);
}
catch (System.IO.FileNotFoundException)
{
if (MessageBox.Show(
$@"ブラウザコンポーネントがロードできませんでした。動作に必要な
「Microsoft Visual C++ 2015 再頒布可能パッケージ」
がインストールされていないのが原因の可能性があります。
ダウンロードページを開きますか?
(vc_redist.{(Environment.Is64BitProcess ? "x64" : "x86")}.exe をインストールしてください。)",
"CefSharp ロードエラー", MessageBoxButtons.YesNo, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
== DialogResult.Yes)
{
System.Diagnostics.Process.Start(@"https://www.microsoft.com/ja-jp/download/details.aspx?id=53587");
}

// なんにせよ今回は起動できないのであきらめる
throw;
}
}
return null;
}
Expand Down
6 changes: 6 additions & 0 deletions BrowserLib/IBrowserHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,5 +187,11 @@ public class BrowserConfiguration
[DataMember]
public bool PreserveDrawingBuffer { get; set; }

/// <summary>
/// カラープロファイルを sRGB 固定にするか
/// </summary>
[DataMember]
public bool ForceColorProfile { get; set; }

}
}
7 changes: 7 additions & 0 deletions ElectronicObserver/Data/EquipmentDataMaster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,13 @@ public class EquipmentDataMaster : ResponseWrapper, IIdentifiable
public int IconType => (int)RawData.api_type[3];


internal int[] equippableShipsAtExpansion = new int[0];
/// <summary>
/// 拡張スロットに装備可能な艦船IDのリスト
/// </summary>
public IEnumerable<int> EquippableShipsAtExpansion => equippableShipsAtExpansion;



// 以降自作判定
// note: icontype の扱いについては再考の余地あり
Expand Down
6 changes: 6 additions & 0 deletions ElectronicObserver/Data/KCDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public sealed class KCDatabase
/// </summary>
public IDDictionary<ShipType> ShipTypes { get; private set; }

/// <summary>
/// 艦船グラフィックデータ
/// </summary>
public IDDictionary<ShipGraphicData> ShipGraphics { get; private set; }

/// <summary>
/// 装備のマスターデータ
/// </summary>
Expand Down Expand Up @@ -154,6 +159,7 @@ private KCDatabase()

MasterShips = new IDDictionary<ShipDataMaster>();
ShipTypes = new IDDictionary<ShipType>();
ShipGraphics = new IDDictionary<ShipGraphicData>();
MasterEquipments = new IDDictionary<EquipmentDataMaster>();
EquipmentTypes = new IDDictionary<EquipmentType>();
Ships = new IDDictionary<ShipData>();
Expand Down
Loading

0 comments on commit 6dcd433

Please sign in to comment.