diff --git a/.gitignore b/.gitignore index de5cb7700..f4a91a690 100644 --- a/.gitignore +++ b/.gitignore @@ -145,3 +145,9 @@ $RECYCLE.BIN/ # Mac crap .DS_Store + +# Visual Studio local files +.vs + +# Application Insights Key +*.InstrumentationKey.cs diff --git a/README.md b/README.md index 445238d5d..0573634d6 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/licenses/Application Insights.txt b/licenses/Application Insights.txt new file mode 100644 index 000000000..a39f344e6 --- /dev/null +++ b/licenses/Application Insights.txt @@ -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. + diff --git a/licenses/CefSharp.txt b/licenses/CefSharp.txt new file mode 100644 index 000000000..4e8c9e27e --- /dev/null +++ b/licenses/CefSharp.txt @@ -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. diff --git a/source/Grabacr07.KanColleViewer/App.config b/source/Grabacr07.KanColleViewer/App.config index df211966c..347f51c2f 100644 --- a/source/Grabacr07.KanColleViewer/App.config +++ b/source/Grabacr07.KanColleViewer/App.config @@ -11,7 +11,7 @@ - http://www.dmm.com/netgame/social/application/-/detail/=/app_id=854854/ + http://www.dmm.com/netgame/social/-/gadgets/=/app_id=854854/ 333 @@ -29,7 +29,7 @@ position:fixed; left:50%; top:-16px; - margin-left:-450px; + margin-left:-600px; z-index:1 } diff --git a/source/Grabacr07.KanColleViewer/Application.InstrumentationKey.cs b/source/Grabacr07.KanColleViewer/Application.InstrumentationKey.cs new file mode 100644 index 000000000..085caf242 --- /dev/null +++ b/source/Grabacr07.KanColleViewer/Application.InstrumentationKey.cs @@ -0,0 +1,7 @@ + +namespace Grabacr07.KanColleViewer +{ + partial class Application + { + } +} diff --git a/source/Grabacr07.KanColleViewer/Application.Static.cs b/source/Grabacr07.KanColleViewer/Application.Static.cs new file mode 100644 index 000000000..55c0a3487 --- /dev/null +++ b/source/Grabacr07.KanColleViewer/Application.Static.cs @@ -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); + } + + /// + /// を使用し、 を起動することを試みます。 + /// 必要に応じて、ユーザーに操作を求めるダイアログを表示します。 + /// + /// の起動に成功した場合は true、それ以外の場合は false。 + 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(); + } + } +} diff --git a/source/Grabacr07.KanColleViewer/Application.xaml.cs b/source/Grabacr07.KanColleViewer/Application.xaml.cs index f763630aa..906f85117 100644 --- a/source/Grabacr07.KanColleViewer/Application.xaml.cs +++ b/source/Grabacr07.KanColleViewer/Application.xaml.cs @@ -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; @@ -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; - /// - /// 現在の オブジェクトを取得します。 - /// - public static Application Instance => Current as Application; + public DirectoryInfo LocalAppData = new DirectoryInfo( + Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), + ProductInfo.Company, + ProductInfo.Product)); /// /// アプリケーションの現在の状態を示す識別子を取得します。 /// public ApplicationState State { get; private set; } - protected override void OnStartup(StartupEventArgs e) { this.ChangeState(ApplicationState.Startup); @@ -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 を設定しておく。これ大事 @@ -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); @@ -186,59 +186,6 @@ private void ProcessCommandLineParameter(string[] args) // けど今やることがない } - /// - /// を使用し、 を起動することを試みます。 - /// 必要に応じて、ユーザーに操作を求めるダイアログを表示します。 - /// - /// の起動に成功した場合は true、それ以外の場合は false。 - 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 diff --git a/source/Grabacr07.KanColleViewer/KanColleViewer.csproj b/source/Grabacr07.KanColleViewer/KanColleViewer.csproj index bbb75e1c6..5c914f986 100644 --- a/source/Grabacr07.KanColleViewer/KanColleViewer.csproj +++ b/source/Grabacr07.KanColleViewer/KanColleViewer.csproj @@ -1,5 +1,9 @@  + + + + Debug @@ -26,41 +30,39 @@ true 12.0.50716.0 + + - - AnyCPU + + Assets\app.ico + + true - full - false bin\Debug\ TRACE;DEBUG;BETA - prompt - 4 - false + full + x86 false + prompt + MinimumRecommendedRules.ruleset - - AnyCPU - pdbonly - true + bin\Release\ TRACE + true + pdbonly + x86 prompt - 4 - false - - - Assets\app.ico + MinimumRecommendedRules.ruleset - - bin\Release %28beta%29\ + + bin\x86\Release %28beta%29\ TRACE;BETA true pdbonly - AnyCPU + x86 prompt MinimumRecommendedRules.ruleset - false @@ -74,6 +76,9 @@ ..\packages\log4net.2.0.3\lib\net40-full\log4net.dll True + + ..\packages\Microsoft.ApplicationInsights.2.7.2\lib\net46\Microsoft.ApplicationInsights.dll + False ..\..\assemblies\Microsoft.Expression.Drawing.dll @@ -92,7 +97,11 @@ + + ..\packages\System.Diagnostics.DiagnosticSource.4.5.0\lib\net46\System.Diagnostics.DiagnosticSource.dll + + ..\packages\Rx-Core.2.2.5\lib\net45\System.Reactive.Core.dll @@ -148,6 +157,11 @@ + + + + + @@ -343,6 +357,7 @@ StatusBar.xaml + @@ -517,6 +532,14 @@ Application.xaml Code + + Application.xaml + Code + + + Application.xaml + Code + @@ -632,28 +655,21 @@ Always - - - {3050F1C5-98B5-11CF-BB82-00AA00BDCE0B} - 4 - 0 - 0 - tlbimp - False - True - - - {EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B} - 1 - 1 - 0 - tlbimp - False - True - - + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + + +