Skip to content

Commit

Permalink
プロジェクト内の整理
Browse files Browse the repository at this point in the history
・Proxy の設定を分割
・WebBrowser に Silent を指定しているとプロキシ認証ダイアログも出なくなるので、Slient に設定するタイミングを CSS 上書きと同じタイミングに変更
・etc...
  • Loading branch information
Grabacr07 committed Jun 24, 2014
1 parent 20df431 commit 256ae05
Show file tree
Hide file tree
Showing 16 changed files with 7,197 additions and 6,630 deletions.
6 changes: 1 addition & 5 deletions Grabacr07.KanColleViewer/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,9 @@ protected override void OnStartup(StartupEventArgs e)
Helper.SetRegistryFeatureBrowserEmulation();

KanColleClient.Current.Proxy.Startup(AppSettings.Default.LocalProxyPort);
KanColleClient.Current.Proxy.UseProxyOnConnect = Settings.Current.EnableProxy;
KanColleClient.Current.Proxy.UseProxyOnSSLConnect = Settings.Current.EnableSSLProxy;
KanColleClient.Current.Proxy.UpstreamProxyHost = Settings.Current.ProxyHost;
KanColleClient.Current.Proxy.UpstreamProxyPort = Settings.Current.ProxyPort;
KanColleClient.Current.Proxy.UpstreamProxySettings = Settings.Current.ProxySettings;

ResourceService.Current.ChangeCulture(Settings.Current.Culture);

ThemeService.Current.Initialize(this, Theme.Dark, Accent.Purple);

ViewModelRoot = new MainWindowViewModel();
Expand Down
27 changes: 27 additions & 0 deletions Grabacr07.KanColleViewer/Composition/IPlugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;

namespace Grabacr07.KanColleViewer.Composition
{
public interface IPlugin
{
/// <summary>
/// プラグインの設定画面を取得します。
/// </summary>
/// <returns></returns>
object GetSettingsView();
}

public interface IPluginMetadata
{
string Name { get; }

[DefaultValue("1.0")]
string Version { get; }

string Author { get; }
}
}
2 changes: 2 additions & 0 deletions Grabacr07.KanColleViewer/KanColleViewer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,15 @@
<Compile Include="Composition\NotifyType.cs" />
<Compile Include="Composition\PluginHost.cs" />
<Compile Include="Models\BrowserZoomFactor.cs" />
<Compile Include="Composition\IPlugin.cs" />
<Compile Include="Models\IZoomFactor.cs" />
<Compile Include="Models\ProductInfo.cs" />
<Compile Include="Models\Data\Xml\XmlFileReader.cs" />
<Compile Include="Models\Data\Xml\XmlFileWriter.cs" />
<Compile Include="Models\Data\Xml\XmlSerializableDictionary.cs" />
<Compile Include="Models\Helper.cs" />
<Compile Include="Models\Mode.cs" />
<Compile Include="Models\ProxySettings.cs" />
<Compile Include="Models\ResourceService.cs" />
<Compile Include="Models\StatusService.cs" />
<Compile Include="Models\Settings.cs" />
Expand Down
99 changes: 84 additions & 15 deletions Grabacr07.KanColleViewer/Models/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using Grabacr07.KanColleViewer.Win32;
using MetroRadiance.Core;
using Microsoft.Win32;

namespace Grabacr07.KanColleViewer.Models
Expand All @@ -21,6 +22,21 @@ static Helper()
IsWindows8OrGreater = (version.Major == 6 && version.Minor >= 2) || version.Major > 6;
}


/// <summary>
/// Windows 8 またはそれ以降のバージョンで動作しているかどうかを確認します。
/// </summary>
public static bool IsWindows8OrGreater { get; private set; }

/// <summary>
/// デザイナーのコンテキストで実行されているかどうかを取得します。
/// </summary>
public static bool IsInDesignMode
{
get { return DesignerProperties.GetIsInDesignMode(new DependencyObject()); }
}


public static string CreateScreenshotFilePath()
{
var filePath = Path.Combine(
Expand All @@ -37,20 +53,6 @@ public static string CreateScreenshotFilePath()
}


/// <summary>
/// Windows 8 またはそれ以降のバージョンで動作しているかどうかを確認します。
/// </summary>
public static bool IsWindows8OrGreater { get; private set; }

/// <summary>
/// デザイナーのコンテキストで実行されているかどうかを取得します。
/// </summary>
public static bool IsInDesignMode
{
get { return DesignerProperties.GetIsInDesignMode(new DependencyObject()); }
}


/// <summary>
/// HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION
/// に WebBrowser コントロールの動作バージョンを設定します。
Expand Down Expand Up @@ -139,5 +141,72 @@ private static bool DeleteInternetCacheCore()

return true;
}


/// <summary>
/// 指定した文字列を暗号化します。
/// </summary>
/// <param name="source">暗号化する文字列。</param>
/// <param name="password">暗号化に使用するパスワード。</param>
/// <returns>暗号化された文字列。</returns>
public static string EncryptString(string source, string password)
{
using (var rijndael = new RijndaelManaged())
{
byte[] key, iv;
GenerateKeyFromPassword(password, rijndael.KeySize, out key, rijndael.BlockSize, out iv);
rijndael.Key = key;
rijndael.IV = iv;

using (var encryptor = rijndael.CreateEncryptor())
{
var strBytes = Encoding.UTF8.GetBytes(source);
var encBytes = encryptor.TransformFinalBlock(strBytes, 0, strBytes.Length);
return Convert.ToBase64String(encBytes);
}
}
}

/// <summary>
/// 指定された文字列を複合化します。
/// </summary>
/// <param name="source">暗号化された文字列。</param>
/// <param name="password">暗号化に使用したパスワード。</param>
/// <returns>復号化された文字列。</returns>
public static string DecryptString(string source, string password)
{
try
{
using (var rijndael = new RijndaelManaged())
{
byte[] key, iv;
GenerateKeyFromPassword(password, rijndael.KeySize, out key, rijndael.BlockSize, out iv);
rijndael.Key = key;
rijndael.IV = iv;

using (var decryptor = rijndael.CreateDecryptor())
{
var strBytes = Convert.FromBase64String(source);
var decBytes = decryptor.TransformFinalBlock(strBytes, 0, strBytes.Length);
return Encoding.UTF8.GetString(decBytes);
}
}
}
catch (Exception ex)
{
Debug.WriteLine(ex);
return null;
}
}

private static void GenerateKeyFromPassword(string password, int keySize, out byte[] key, int blockSize, out byte[] iv)
{
var salt = Encoding.UTF8.GetBytes("C98534F6-7286-4BED-83A6-10FD5052ABA6");
using (var deriveBytes = new Rfc2898DeriveBytes(password, salt) { IterationCount = 1000 })
{
key = deriveBytes.GetBytes(keySize / 8);
iv = deriveBytes.GetBytes(blockSize / 8);
}
}
}
}
161 changes: 161 additions & 0 deletions Grabacr07.KanColleViewer/Models/ProxySettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Xml.Serialization;
using Grabacr07.KanColleWrapper;
using Livet;

namespace Grabacr07.KanColleViewer.Models
{
[Serializable]
public class ProxySettings : NotificationObject, IProxySettings
{
#region IsEnabled 変更通知プロパティ

private bool _IsEnabled;

public bool IsEnabled
{
get { return this._IsEnabled; }
set
{
if (this._IsEnabled != value)
{
this._IsEnabled = value;
this.RaisePropertyChanged();
}
}
}

#endregion

#region IsEnabledOnSSL 変更通知プロパティ

private bool _IsEnabledOnSSL;

public bool IsEnabledOnSSL
{
get { return this._IsEnabledOnSSL; }
set
{
if (this._IsEnabledOnSSL != value)
{
this._IsEnabledOnSSL = value;
this.RaisePropertyChanged();
}
}
}

#endregion

#region Host 変更通知プロパティ

private string _Host;

[XmlElement(ElementName = "ProxyHost")]
public string Host
{
get { return this._Host; }
set
{
if (this._Host != value)
{
this._Host = value;
this.RaisePropertyChanged();
}
}
}

#endregion

#region Port 変更通知プロパティ

private ushort _Port;

public ushort Port
{
get { return this._Port; }
set
{
if (this._Port != value)
{
this._Port = value;
this.RaisePropertyChanged();
}
}
}

#endregion

#region IsAuthRequired 変更通知プロパティ

private bool _IsAuthRequired;

public bool IsAuthRequired
{
get { return this._IsAuthRequired; }
set
{
if (this._IsAuthRequired != value)
{
this._IsAuthRequired = value;
this.RaisePropertyChanged();
}
}
}

#endregion

#region Username 変更通知プロパティ

private string _Username;

public string Username
{
get { return this._Username; }
set
{
if (this._Username != value)
{
this._Username = value;
this.RaisePropertyChanged();
}
}
}

#endregion

#region Password 変更通知プロパティ

private const string passwordForEncryption = "4629A16F-C815-4307-B367-9C16FAC0A52F";

[XmlIgnore]
public string Password
{
get { return Helper.DecryptString(this.ProtectedPassword, passwordForEncryption); }
set { this.ProtectedPassword = Helper.EncryptString(value, passwordForEncryption); }
}

#endregion

#region ProtectedPassword 変更通知プロパティ

private string _ProtectedPassword;

public string ProtectedPassword
{
get { return this._ProtectedPassword; }
set
{
if (this._ProtectedPassword != value)
{
this._ProtectedPassword = value;
this.RaisePropertyChanged();
}
}
}

#endregion
}
}
Loading

0 comments on commit 256ae05

Please sign in to comment.