Skip to content

Commit

Permalink
Merge branch 'release/0.1.9'
Browse files Browse the repository at this point in the history
  • Loading branch information
KodamaSakuno committed Apr 1, 2016
2 parents 05c922a + f6a357f commit 4782812
Show file tree
Hide file tree
Showing 213 changed files with 4,642 additions and 1,026 deletions.
68 changes: 68 additions & 0 deletions HeavenlyWind.Base/ExtraStringResourceExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Markup;

namespace Sakuno.KanColle.Amatsukaze
{
public class ExtraStringResourceExtension : MarkupExtension
{
ExtraStringResourceType r_Type;
string r_IDPath;
string r_OriginalTextPath;

public string StringFormat { get; set; }

public ExtraStringResourceExtension(ExtraStringResourceType rpType, string rpIDPath, string rpOriginalTextPath)
{
r_Type = rpType;
r_IDPath = rpIDPath;
r_OriginalTextPath = rpOriginalTextPath;
}

public override object ProvideValue(IServiceProvider rpServiceProvider)
{
var rResult = new MultiBinding() { Mode = BindingMode.OneWay, Converter = Converter.Instance, ConverterParameter = r_Type, StringFormat = StringFormat };
rResult.Bindings.Add(new Binding(r_IDPath));
rResult.Bindings.Add(new Binding(r_OriginalTextPath));
rResult.Bindings.Add(new Binding(nameof(StringResources.Instance.Extra)) { Source = StringResources.Instance });

return rResult.ProvideValue(rpServiceProvider);
}

class Converter : IMultiValueConverter
{
public static Converter Instance { get; } = new Converter();

public object Convert(object[] rpValues, Type rpTargetType, object rpParameter, CultureInfo rpCulture)
{
if (rpValues[0] == DependencyProperty.UnsetValue || rpValues[1] == DependencyProperty.UnsetValue)
return string.Empty;

var rType = (ExtraStringResourceType)rpParameter;
var rID = (int)rpValues[0];
var rOriginalText = rpValues[1];
var rESR = (ExtraStringResources)rpValues[2];

if (rESR == null)
return rOriginalText;

var rTranslations = rESR.GetTranslations(rType);
if (rTranslations == null)
return rOriginalText;

string rTranslatedText;
if (!rTranslations.TryGetValue(rID, out rTranslatedText))
return rOriginalText;

return rTranslatedText;
}

public object[] ConvertBack(object rpValue, Type[] rpTargetTypes, object rpParameter, CultureInfo rpCulture)
{
throw new NotImplementedException();
}
}
}
}
1 change: 1 addition & 0 deletions HeavenlyWind.Base/ExtraStringResourceType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public enum ExtraStringResourceType
{
Ship,
ShipType,
AbyssalShip,
Equipment,
Item,
Expedition,
Expand Down
71 changes: 58 additions & 13 deletions HeavenlyWind.Base/ExtraStringResources.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,75 @@
using System.Collections.Generic;
using Sakuno.Collections;
using System;
using System.Collections.Generic;

namespace Sakuno.KanColle.Amatsukaze
{
public class ExtraStringResources : ModelBase
{
public Dictionary<int, string> Ships { get; internal set; }
public Dictionary<int, string> ShipTypes { get; internal set; }
public Dictionary<int, string> Equipment { get; internal set; }
public Dictionary<int, string> Items { get; internal set; }
public Dictionary<int, string> Expeditions { get; internal set; }
public Dictionary<int, string> Quests { get; internal set; }
public Dictionary<int, string> Areas { get; internal set; }
public Dictionary<int, string> Maps { get; internal set; }
public Dictionary<int, string> ShipLocking { get; internal set; }
public HybridDictionary<int, string> Ships { get; internal set; }
public HybridDictionary<int, string> ShipTypes { get; internal set; }
public HybridDictionary<int, string> AbyssalShip { get; internal set; }
public HybridDictionary<int, string> Equipment { get; internal set; }
public HybridDictionary<int, string> Items { get; internal set; }
public HybridDictionary<int, string> Expeditions { get; internal set; }
public HybridDictionary<int, string> Quests { get; internal set; }
public HybridDictionary<int, string> Areas { get; internal set; }
public HybridDictionary<int, string> Maps { get; internal set; }
public HybridDictionary<int, string> ShipLocking { get; internal set; }

internal ExtraStringResources() { }

string GetName(Dictionary<int, string> rpDictionary, int rpID)
public HybridDictionary<int, string> GetTranslations(ExtraStringResourceType rpType)
{
string rResult = null;
rpDictionary?.TryGetValue(rpID, out rResult);
switch (rpType)
{
case ExtraStringResourceType.Ship:
return Ships;

case ExtraStringResourceType.ShipType:
return ShipTypes;

case ExtraStringResourceType.AbyssalShip:
return AbyssalShip;

case ExtraStringResourceType.Equipment:
return Equipment;

case ExtraStringResourceType.Item:
return Items;

case ExtraStringResourceType.Expedition:
return Expeditions;

case ExtraStringResourceType.Quest:
return Quests;

case ExtraStringResourceType.Area:
return Areas;

case ExtraStringResourceType.Map:
return Maps;

case ExtraStringResourceType.ShipLocking:
return ShipLocking;

default: throw new ArgumentException(nameof(rpType));
}
}

string GetName(IDictionary<int, string> rpDictionary, int rpID)
{
if (rpDictionary == null)
return null;

string rResult;
rpDictionary.TryGetValue(rpID, out rResult);
return rResult;
}

public string GetShipName(int rpID) => GetName(Ships, rpID);
public string GetShipTypeName(int rpID) => GetName(ShipTypes, rpID);
public string GetAbyssalShip(int rpID) => GetName(AbyssalShip, rpID);
public string GetEquipmentName(int rpID) => GetName(Equipment, rpID);
public string GetItemName(int rpID) => GetName(Items, rpID);
public string GetExpeditionName(int rpID) => GetName(Expeditions, rpID);
Expand Down
9 changes: 8 additions & 1 deletion HeavenlyWind.Base/HeavenlyWind.Base.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
<HintPath>..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="PresentationCore" />
Expand Down Expand Up @@ -69,6 +69,7 @@
<Compile Include="CollapsedIfZeroExtension.cs" />
<Compile Include="EnumerationExtension.cs" />
<Compile Include="EnumToStringResourceExtension.cs" />
<Compile Include="ExtraStringResourceExtension.cs" />
<Compile Include="ExtraStringResources.cs" />
<Compile Include="ExtraStringResourceInfo.cs" />
<Compile Include="ExtraStringResourceType.cs" />
Expand All @@ -85,13 +86,18 @@
<Compile Include="Models\Preferences\BrowserPreference.cs" />
<Compile Include="Models\Preferences\CachePreference.cs" />
<Compile Include="Models\Preferences\FlashPreference.cs" />
<Compile Include="Models\Preferences\GamePreference.cs" />
<Compile Include="Models\Preferences\LayoutPreference.cs" />
<Compile Include="Models\Preferences\NetworkPreference.cs" />
<Compile Include="Models\Preferences\NotificationPreference.cs" />
<Compile Include="Models\Preferences\ScreenshotPreference.cs" />
<Compile Include="Models\Preferences\UpdatePreference.cs" />
<Compile Include="Models\Preferences\UpstreamProxyPreference.cs" />
<Compile Include="Models\Preferences\WindowPreference.cs" />
<Compile Include="Models\Preferences\WindowsPreference.cs" />
<Compile Include="Models\ScreenshotImageFormat.cs" />
<Compile Include="Models\UpdateChannel.cs" />
<Compile Include="Models\UpdateNotificationMode.cs" />
<Compile Include="MultiplyExtension.cs" />
<Compile Include="Preference.cs" />
<Compile Include="Preference.Data.cs" />
Expand All @@ -101,6 +107,7 @@
<Compile Include="StringResourceExtension.cs" />
<Compile Include="StringResources.cs" />
<Compile Include="StringResources.Items.cs" />
<Compile Include="ViewInfoAttribute.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Library\Sakuno.Base\Sakuno.Base.csproj">
Expand Down
26 changes: 26 additions & 0 deletions HeavenlyWind.Base/Logger.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
using System;
using System.Collections.Concurrent;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;

namespace Sakuno.KanColle.Amatsukaze
{
public class Logger
{
static Tuple<string, Regex> r_ExceptionLogFilenameRegex;

static Logger Instance { get; } = new Logger();

StreamWriter r_Writer;
Expand Down Expand Up @@ -64,5 +68,27 @@ void WriteCore(LoggingLevel rpLevel, string rpContent)
}

public static void Write(LoggingLevel rpLevel, string rpContent) => Task.Run(() => Instance.WriteCore(rpLevel, rpContent));

public static string GetNewExceptionLogFilename()
{
var rCurrentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var rExceptionLogDirectory = new DirectoryInfo(Path.Combine(rCurrentDirectory, "Logs", "Exceptions"));
if (!rExceptionLogDirectory.Exists)
rExceptionLogDirectory.Create();

var rPrefix = DateTime.Now.ToString("yyMMdd");
Regex rRegex;
if (r_ExceptionLogFilenameRegex != null && r_ExceptionLogFilenameRegex.Item1 == rPrefix)
rRegex = r_ExceptionLogFilenameRegex.Item2;
else
r_ExceptionLogFilenameRegex = Tuple.Create(rPrefix, rRegex = new Regex(rPrefix + @"_(\d+)\.log$", RegexOptions.IgnoreCase));

var rIndex = 0;
var rSavedLogs = rExceptionLogDirectory.GetFiles(rPrefix + "_*.log");
if (rSavedLogs.Any())
rIndex = rSavedLogs.Max(r => int.Parse(rRegex.Match(r.FullName).Groups["Index"].Value));

return Path.Combine(rExceptionLogDirectory.FullName, $"{rPrefix}_{rIndex + 1}.log");
}
}
}
10 changes: 10 additions & 0 deletions HeavenlyWind.Base/Models/Preferences/GamePreference.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Newtonsoft.Json;

namespace Sakuno.KanColle.Amatsukaze.Models.Preferences
{
public class GamePreference
{
[JsonProperty("main_los_formula")]
public int MainFleetLoSFormula { get; set; } = 3;
}
}
3 changes: 3 additions & 0 deletions HeavenlyWind.Base/Models/Preferences/NetworkPreference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ public class NetworkPreference
[JsonProperty("enableforssl")]
public bool EnableForSSL { get; set; } = false;

[JsonProperty("allowremoterequests")]
public bool AllowRequestsFromOtherDevices { get; set; } = false;

[JsonProperty("upstreamproxy")]
public UpstreamProxyPreference UpstreamProxy { get; set; } = new UpstreamProxyPreference();
}
Expand Down
19 changes: 19 additions & 0 deletions HeavenlyWind.Base/Models/Preferences/NotificationPreference.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Newtonsoft.Json;

namespace Sakuno.KanColle.Amatsukaze.Models.Preferences
{
public class NotificationPreference
{
[JsonProperty("expedition")]
public bool Expedition { get; set; } = true;

[JsonProperty("repair")]
public bool Repair { get; set; } = true;

[JsonProperty("construction")]
public bool Construction { get; set; } = true;

[JsonProperty("heavily_damaged")]
public bool HeavilyDamagedWarning { get; set; } = true;
}
}
13 changes: 13 additions & 0 deletions HeavenlyWind.Base/Models/Preferences/UpdatePreference.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Newtonsoft.Json;

namespace Sakuno.KanColle.Amatsukaze.Models.Preferences
{
public class UpdatePreference
{
[JsonProperty("notification")]
public UpdateNotificationMode NotificationMode { get; set; } = UpdateNotificationMode.AlwaysShow;

[JsonProperty("channel")]
public UpdateChannel UpdateChannel { get; set; } = UpdateChannel.Release;
}
}
19 changes: 6 additions & 13 deletions HeavenlyWind.Base/Models/Preferences/WindowPreference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,20 @@ namespace Sakuno.KanColle.Amatsukaze.Models.Preferences
{
public class WindowPreference
{
public string Name { get; }
[JsonProperty("name")]
public string Name { get; set; }

[JsonProperty("state")]
public WindowState State { get; set; }

[JsonProperty("left")]
public double Left { get; set; }
public int Left { get; set; }
[JsonProperty("top")]
public double Top { get; set; }
public int Top { get; set; }

[JsonProperty("width")]
public double Width { get; set; }
public int Width { get; set; }
[JsonProperty("height")]
public double Height { get; set; }

[JsonProperty("topmost")]
public bool TopMost { get; set; }

public WindowPreference(string rpName)
{
Name = rpName;
}
public int Height { get; set; }
}
}
Loading

0 comments on commit 4782812

Please sign in to comment.