Skip to content

Commit

Permalink
Merge pull request #235 from Grabacr07/exp/cef
Browse files Browse the repository at this point in the history
Chromium (CefSharp.Wpf) 版
  • Loading branch information
Grabacr07 authored Aug 21, 2018
2 parents 5938f2e + 8b46abf commit f1b612a
Show file tree
Hide file tree
Showing 51 changed files with 960 additions and 624 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,9 @@ $RECYCLE.BIN/

# Mac crap
.DS_Store

# Visual Studio local files
.vs

# Application Insights Key
*.InstrumentationKey.cs
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,19 @@ MIT ライセンスの下で公開する、オープンソース / フリーソ
* **用途 :** 音量操作
* **ライセンス :** The MIT License (MIT)
* **ライセンス全文 :** [licenses/NETCoreAudioAPIs.txt](licenses/NETCoreAudioAPIs.txt)

### [CefSharp.Wpf](http://cefsharp.github.io/)

* **用途 :** 内蔵 Web ブラウザー
* **ライセンス :** The 3-Clause BSD License
* **ライセンス全文 :** [licenses/CefSharp.txt](licenses/CefSharp.txt)

### [Application Insights](https://azure.microsoft.com/ja-jp/services/application-insights/)

> The MIT License (MIT)
>
> Copyright (c) Microsoft Corporation
* **用途 :** クラッシュ ログ収集
* **ライセンス :** The MIT License (MIT)
* **ライセンス全文 :** [licenses/Application Insights.txt](licenses/Application Insights.txt)
22 changes: 22 additions & 0 deletions licenses/Application Insights.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) Microsoft Corporation

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

30 changes: 30 additions & 0 deletions licenses/CefSharp.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright � 2010-2017 The CefSharp Authors. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
//
// * Neither the name of Google Inc. nor the name Chromium Embedded
// Framework nor the name CefSharp nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4 changes: 2 additions & 2 deletions source/Grabacr07.KanColleViewer/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<applicationSettings>
<Grabacr07.KanColleViewer.Properties.Settings>
<setting name="KanColleUrl" serializeAs="String">
<value>http://www.dmm.com/netgame/social/application/-/detail/=/app_id=854854/</value>
<value>http://www.dmm.com/netgame/social/-/gadgets/=/app_id=854854/</value>
</setting>
<setting name="UIContentHight" serializeAs="String">
<value>333</value>
Expand All @@ -29,7 +29,7 @@
position:fixed;
left:50%;
top:-16px;
margin-left:-450px;
margin-left:-600px;
z-index:1
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

namespace Grabacr07.KanColleViewer
{
partial class Application
{
}
}
114 changes: 114 additions & 0 deletions source/Grabacr07.KanColleViewer/Application.Static.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using CefSharp;
using CefSharp.Wpf;
using Grabacr07.KanColleViewer.Models;
using Grabacr07.KanColleViewer.Models.Cef;
using Grabacr07.KanColleViewer.ViewModels;
using Grabacr07.KanColleWrapper;
using MetroTrilithon.Desktop;
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.DataContracts;

namespace Grabacr07.KanColleViewer
{
partial class Application
{
static Application()
{
AppDomain.CurrentDomain.UnhandledException += (sender, args) => ReportException(sender, args.ExceptionObject as Exception);

TelemetryClient = new TelemetryClient();
TelemetryClient.Context.Session.Id = Guid.NewGuid().ToString();
TelemetryClient.Context.Device.OperatingSystem = Environment.OSVersion.ToString();
TelemetryClient.Context.Component.Version = ProductInfo.VersionString;
#if DEBUG
TelemetryClient.Context.User.Id = Environment.UserName;
#endif
SetInstrumentationKey();
}

public static TelemetryClient TelemetryClient { get; }

public static Application Instance => Current as Application;

static partial void SetInstrumentationKey();

private static void CefInitialize()
{
var cefSettings = new CefSettings()
{
CachePath = CefBridge.CachePath,
};
cefSettings.CefCommandLineArgs.Add("proxy-server", Models.Settings.NetworkSettings.LocalProxySettingsString);
//cefSettings.CefCommandLineArgs.Add("disable-webgl", "1");
CefSharpSettings.SubprocessExitIfParentProcessClosed = true;

Cef.EnableHighDPISupport();
Cef.Initialize(cefSettings);
}

/// <summary>
/// <see cref="ProxyBootstrapper"/> を使用し、<see cref="KanColleProxy"/> を起動することを試みます。
/// 必要に応じて、ユーザーに操作を求めるダイアログを表示します。
/// </summary>
/// <returns><see cref="KanColleProxy"/> の起動に成功した場合は true、それ以外の場合は false。</returns>
private static bool BootstrapProxy()
{
var bootstrapper = new ProxyBootstrapper();
bootstrapper.Try();

if (bootstrapper.Result == ProxyBootstrapResult.Success)
{
return true;
}

var vmodel = new ProxyBootstrapperViewModel(bootstrapper) { Title = ProductInfo.Title, };
var window = new Views.Settings.ProxyBootstrapper { DataContext = vmodel, };
window.ShowDialog();

return vmodel.DialogResult;
}

private static void ReportException(object sender, Exception exception)
{
var now = DateTimeOffset.Now;
var path = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
ProductInfo.Company,
ProductInfo.Product,
"ErrorReports",
$"ErrorReport-{now:yyyyMMdd-HHmmss}-{now.Millisecond:000}.log");

var message = $@"*** Error Report ***
{ProductInfo.Product} ver.{ProductInfo.VersionString}
{DateTimeOffset.Now}
{new SystemEnvironment()}
Sender: {sender.GetType().FullName}
Exception: {exception.GetType().FullName}
{exception}
";
try
{
// ReSharper disable once AssignNullToNotNullAttribute
Directory.CreateDirectory(Path.GetDirectoryName(path));
File.AppendAllText(path, message);

TelemetryClient.TrackException(exception);
TelemetryClient.TrackTrace(message, SeverityLevel.Critical);
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}

Current.Shutdown();
}
}
}
79 changes: 13 additions & 66 deletions source/Grabacr07.KanColleViewer/Application.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using System.Windows;
using CefSharp;
using Grabacr07.KanColleViewer.Composition;
using Grabacr07.KanColleViewer.Models;
using Grabacr07.KanColleViewer.Models.Settings;
Expand Down Expand Up @@ -42,25 +42,20 @@ public enum ApplicationState

sealed partial class Application : INotifyPropertyChanged, IDisposableHolder
{
static Application()
{
AppDomain.CurrentDomain.UnhandledException += (sender, args) => ReportException(sender, args.ExceptionObject as Exception);
}

private readonly LivetCompositeDisposable compositeDisposable = new LivetCompositeDisposable();
private event PropertyChangedEventHandler propertyChangedInternal;

/// <summary>
/// 現在の <see cref="AppDomain"/> の <see cref="Application"/> オブジェクトを取得します。
/// </summary>
public static Application Instance => Current as Application;
public DirectoryInfo LocalAppData = new DirectoryInfo(
Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
ProductInfo.Company,
ProductInfo.Product));

/// <summary>
/// アプリケーションの現在の状態を示す識別子を取得します。
/// </summary>
public ApplicationState State { get; private set; }


protected override void OnStartup(StartupEventArgs e)
{
this.ChangeState(ApplicationState.Startup);
Expand Down Expand Up @@ -91,8 +86,10 @@ protected override void OnStartup(StartupEventArgs e)
WindowService.Current.AddTo(this).Initialize();
NotifyService.Current.AddTo(this).Initialize();

Helper.SetRegistryFeatureBrowserEmulation();
Helper.SetMMCSSTask();
Helper.DeleteCacheIfRequested();

CefInitialize();

// BootstrapProxy() で Views.Settings.ProxyBootstrapper.Show() が呼ばれるより前に
// Application.MainWindow を設定しておく。これ大事
Expand Down Expand Up @@ -160,6 +157,9 @@ protected override void OnSessionEnding(SessionEndingCancelEventArgs e)

protected override void OnExit(ExitEventArgs e)
{
Cef.Shutdown();


this.ChangeState(ApplicationState.Terminate);
base.OnExit(e);

Expand All @@ -186,59 +186,6 @@ private void ProcessCommandLineParameter(string[] args)
// けど今やることがない
}

/// <summary>
/// <see cref="ProxyBootstrapper"/> を使用し、<see cref="KanColleProxy"/> を起動することを試みます。
/// 必要に応じて、ユーザーに操作を求めるダイアログを表示します。
/// </summary>
/// <returns><see cref="KanColleProxy"/> の起動に成功した場合は true、それ以外の場合は false。</returns>
private static bool BootstrapProxy()
{
var bootstrapper = new ProxyBootstrapper();
bootstrapper.Try();

if (bootstrapper.Result == ProxyBootstrapResult.Success)
{
return true;
}

var vmodel = new ProxyBootstrapperViewModel(bootstrapper) { Title = ProductInfo.Title, };
var window = new Views.Settings.ProxyBootstrapper { DataContext = vmodel, };
window.ShowDialog();

return vmodel.DialogResult;
}

private static void ReportException(object sender, Exception exception)
{
#region const

const string messageFormat = @"
===========================================================
ERROR, date = {0}, sender = {1},
{2}
";
const string path = "error.log";

#endregion

// ToDo: 例外ダイアログ

try
{
var message = string.Format(messageFormat, DateTimeOffset.Now, sender, exception);

Debug.WriteLine(message);
File.AppendAllText(path, message);
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}

// とりあえずもう終了させるしかないもじゃ
// 救えるパターンがあるなら救いたいけど方法わからんもじゃ
Current.Shutdown();
}

#region INotifyPropertyChanged members

Expand Down
Loading

0 comments on commit f1b612a

Please sign in to comment.