public class ProxyConfig\r
{\r
public const int DefaultListenPort = 8080;\r
- public const string AutoConfigUrl = "https://kancollesniffer.osdn.jp/proxy.pac";\r
- public const string AutoConfigUrlWithPort = "https://kancollesniffer.osdn.jp/proxy.php?port=";\r
public bool Auto { get; set; }\r
public int Listen { get; set; }\r
public bool UseUpstream { get; set; }\r
}\r
}\r
\r
+ [Flags]\r
+ public enum ShipCategory\r
+ {\r
+ None = 0,\r
+ // ReSharper disable UnusedMember.Global\r
+ BattleShip = 1 << 0,\r
+\r
+ AircraftCarrier = 1 << 1,\r
+ HeavyCruiser = 1 << 2,\r
+ LightCruiser = 1 << 3,\r
+ Destroyer = 1 << 4,\r
+ Escort = 1 << 5,\r
+ Submarine = 1 << 6,\r
+ Assistant = 1 << 7,\r
+ // ReSharper restore UnusedMember.Global\r
+ All = (1 << 8) - 1\r
+ }\r
+\r
public class ShipListConfig\r
{\r
+ public bool Visible { get; set; }\r
public Point Location { get; set; }\r
public Size Size { get; set; }\r
- public bool ShipType { get; set; }\r
- public ShipListForm.SortOrder SortOrder { get; set; } = ShipListForm.SortOrder.ExpToNext;\r
+ public string Mode { get; set; }\r
+ public ShipCategory ShipCategories { get; set; } = ShipCategory.All;\r
+ public bool ShipType;\r
+ public bool ShowHpInPercent { get; set; }\r
+ public ListForm.SortOrder SortOrder { get; set; } = ListForm.SortOrder.ExpToNext;\r
public List<List<int>> ShipGroup { get; set; }\r
\r
public ShipListConfig()\r
public bool On { get; set; }\r
public string OutputDir { get; set; }\r
public int MaterialLogInterval { get; set; }\r
- public bool ServerOn { get; set; }\r
- public int Listen { get; set; }\r
\r
public LogConfig()\r
{\r
On = true;\r
OutputDir = "";\r
MaterialLogInterval = 10;\r
- ServerOn = true;\r
- Listen = 8008;\r
}\r
}\r
\r
- public class KancolleDbConfig\r
+ public class PushbulletConfig\r
{\r
public bool On { get; set; }\r
public string Token { get; set; } = "";\r
}\r
\r
+ public class PushoverConfig\r
+ {\r
+ public bool On { get; set; }\r
+ public string ApiKey { get; set; } = "";\r
+ public string UserKey { get; set; } = "";\r
+ }\r
+\r
public class SoundConfig\r
{\r
public int Volume { get; set; } = 100;\r
\r
- public string[] Files { get; set; } = {\r
+ public string[] Files =\r
+ {\r
"ensei.mp3",\r
"nyuukyo.mp3",\r
"kenzou.mp3",\r
"20min.mp3",\r
"syuuri.mp3",\r
"syuuri2.mp3",\r
- "hirou.mp3"\r
+ "hirou.mp3",\r
+ "ninmu.mp3"\r
};\r
\r
- public readonly string[] SoundNames =\r
+ public string this[string name]\r
{\r
- "遠征終了", "入渠終了", "建造完了", "艦娘数超過", "装備数超過",\r
- "大破警告", "泊地修理20分経過", "泊地修理進行", "泊地修理完了", "疲労回復"\r
- };\r
+ get => Files[Config.NotificationIndex[name]];\r
+ set => Files[Config.NotificationIndex[name]] = value;\r
+ }\r
\r
- private readonly Dictionary<string, int> _names = new Dictionary<string, int>();\r
+ public void Upgrade()\r
+ {\r
+ var expected = Config.NotificationNames.Length;\r
+ if (Files.Length == expected)\r
+ return;\r
+ Array.Resize(ref Files, expected);\r
+ Files[expected - 1] = "ninmu.mp3";\r
+ }\r
+ }\r
\r
- public SoundConfig()\r
+ [Flags]\r
+ public enum NotificationType\r
+ {\r
+ FlashWindow = 1,\r
+ // ReSharper disable once IdentifierTypo\r
+ ShowBaloonTip = 1 << 1,\r
+ PlaySound = 1 << 2,\r
+ All = (1 << 3) - 1,\r
+ Pushbullet = 1 << 3,\r
+ Push = 1 << 4,\r
+ Repeat = 1 << 5,\r
+ Cont = 1 << 6,\r
+ Preliminary = 1 << 7\r
+ }\r
+\r
+\r
+ public class NotificationSpec\r
+ {\r
+ public string Name { get; set; }\r
+ public NotificationType Flags { get; set; }\r
+ public int RepeatInterval { get; set; }\r
+ public int PreliminaryPeriod { get; set; }\r
+ }\r
+\r
+ public class NotificationConfig\r
+ {\r
+ public NotificationType[] Settings =\r
+ Config.NotificationNames.Select(x => NotificationType.All).ToArray();\r
+\r
+ public int[] RepeatIntervals =\r
+ Config.NotificationNames.Select(x => 0).ToArray();\r
+\r
+ public int[] PreliminaryPeriods =\r
+ Config.NotificationNames.Select(x => 0).ToArray();\r
+\r
+ public NotificationSpec this[string name]\r
{\r
- var idx = 0;\r
- foreach (var name in SoundNames)\r
- _names[name] = idx++;\r
+ get => new NotificationSpec\r
+ {\r
+ Name = name,\r
+ Flags = Settings[Config.NotificationIndex[name]],\r
+ RepeatInterval = RepeatIntervals[Config.NotificationIndex[name]],\r
+ PreliminaryPeriod = PreliminaryPeriods[Config.NotificationIndex[name]]\r
+ };\r
+ set\r
+ {\r
+ Settings[Config.NotificationIndex[name]] = value.Flags;\r
+ RepeatIntervals[Config.NotificationIndex[name]] = value.RepeatInterval;\r
+ PreliminaryPeriods[Config.NotificationIndex[name]] = value.PreliminaryPeriod;\r
+ }\r
}\r
\r
- public string this[string name]\r
+ public void Upgrade()\r
+ {\r
+ UpgradeSettings(ref Settings);\r
+ UpgradeParameterArray(ref RepeatIntervals);\r
+ UpgradeParameterArray(ref PreliminaryPeriods);\r
+ }\r
+\r
+ private void UpgradeSettings(ref NotificationType[] settings)\r
{\r
- get { return Files[_names[name]]; }\r
- set { Files[_names[name]] = value; }\r
+ for (var i = 0; i < settings.Length; i++)\r
+ {\r
+ if ((settings[i] & NotificationType.Pushbullet) != 0)\r
+ settings[i] = settings[i] ^ NotificationType.Pushbullet | NotificationType.Push;\r
+ }\r
+ var expected = Config.NotificationNames.Length;\r
+ if (expected == settings.Length)\r
+ return;\r
+ Array.Resize(ref settings, expected);\r
+ settings[expected - 1] = NotificationType.All;\r
+ }\r
+\r
+ private void UpgradeParameterArray(ref int[] array)\r
+ {\r
+ Array.Resize(ref array, Config.NotificationNames.Length);\r
+ for (var i = 0; i < array.Length; i++)\r
+ {\r
+ if (array[i] < 0)\r
+ array[i] = 0;\r
+ }\r
}\r
}\r
\r
- public class Config\r
+ public class LocationPerMachine\r
{\r
- private readonly string _baseDir = AppDomain.CurrentDomain.BaseDirectory;\r
- private readonly string _configFileName;\r
+ public string MachineName { get; set; }\r
+ public Point Location { get; set; }\r
+ public int Zoom { get; set; } = 100;\r
+ public Point ListLocation { get; set; }\r
+ public Size ListSize { get; set; }\r
+ }\r
+\r
+ [Flags]\r
+ public enum Spoiler\r
+ {\r
+ ResultRank = 1,\r
+ AirBattleResult = 1 << 1,\r
+ BattleResult = 1 << 2,\r
+ NextCell = 1 << 3,\r
+ All = (1 << 4) - 1\r
+ }\r
+\r
+ [Flags]\r
+ public enum TimerKind\r
+ {\r
+ Mission = 1,\r
+ NDock = 1 << 1\r
+ }\r
\r
+ public class Config\r
+ {\r
public Point Location { get; set; } = new Point(int.MinValue, int.MinValue);\r
public bool TopMost { get; set; }\r
public bool HideOnMinimized { get; set; }\r
+ public bool ExitSilently { get; set; }\r
+ public int Zoom { get; set; } = 100;\r
+ public int QuestLines { get; set; } = 6;\r
+ public bool SaveLocationPerMachine { get; set; }\r
+ public List<LocationPerMachine> LocationList { get; set; } = new List<LocationPerMachine>();\r
+ public bool ShowHpInPercent { get; set; }\r
+ public TimerKind ShowEndTime { get; set; }\r
public bool FlashWindow { get; set; } = true;\r
- public bool ShowBaloonTip { get; set; }\r
+ // ReSharper disable once IdentifierTypo\r
+ public bool ShowBaloonTip { get; set; } = true;\r
public bool PlaySound { get; set; } = true;\r
- public int MarginShips { get; set; } = 4;\r
- public int MarginEquips { get; set; } = 10;\r
+ public NotificationType NotificationFlags { get; set; } = NotificationType.All;\r
+ public NotificationConfig Notifications { get; set; } = new NotificationConfig();\r
+ public int MarginShips { get; set; } = 5;\r
+ public int MarginEquips { get; set; } = 5;\r
public List<int> NotifyConditions { get; set; }\r
public List<int> ResetHours { get; set; }\r
public bool AlwaysShowResultRank { get; set; }\r
+ public Spoiler Spoilers { get; set; }\r
public bool UsePresetAkashi { get; set; }\r
+ public bool WarnBadDamageWithDameCon { get; set; }\r
public SoundConfig Sounds { get; set; } = new SoundConfig();\r
public bool DebugLogging { get; set; }\r
public string DebugLogFile { get; set; } = "log.txt";\r
public ProxyConfig Proxy { get; set; } = new ProxyConfig();\r
public ShipListConfig ShipList { get; set; } = new ShipListConfig();\r
public LogConfig Log { get; set; } = new LogConfig();\r
- public KancolleDbConfig KancolleDb { get; set; } = new KancolleDbConfig();\r
+ public PushbulletConfig Pushbullet { get; set; } = new PushbulletConfig();\r
+ public PushoverConfig Pushover { get; set; } = new PushoverConfig();\r
+\r
+ public static readonly string[] NotificationNames =\r
+ {\r
+ "遠征終了", "入渠終了", "建造完了", "艦娘数超過", "装備数超過",\r
+ "大破警告", "泊地修理20分経過", "泊地修理進行", "泊地修理完了", "疲労回復", "任務達成"\r
+ };\r
+\r
+ public static readonly Dictionary<string, int> NotificationIndex =\r
+ NotificationNames.Select((name, i) => new {name, i}).ToDictionary(entry => entry.name, entry => entry.i);\r
+\r
+\r
+ private const string FileName = "config.xml";\r
+ public static readonly string BaseDir = AppDomain.CurrentDomain.BaseDirectory;\r
+ private static readonly string ConfigFile = Path.Combine(BaseDir, FileName);\r
\r
public Config()\r
{\r
- _configFileName = Path.Combine(_baseDir, "config.xml");\r
ConvertPath(PrependBaseDir);\r
}\r
\r
public void InitializeValues()\r
{\r
NotifyConditions = new List<int>(new[] {40, 49});\r
- ResetHours = new List<int>(new int[] {2});\r
+ ResetHours = new List<int>(new[] {2});\r
}\r
\r
public void Load()\r
{\r
var serializer = new XmlSerializer(typeof(Config));\r
Config config;\r
- using (var file = File.OpenText(_configFileName))\r
+ using (var file = File.OpenText(ConfigFile))\r
config = (Config)serializer.Deserialize(file);\r
foreach (var property in GetType().GetProperties())\r
property.SetValue(this, property.GetValue(config, null), null);\r
+ Notifications.Upgrade();\r
+ ComposeNotificationFlags();\r
+ Sounds.Upgrade();\r
+ if (AlwaysShowResultRank)\r
+ {\r
+ Spoilers = Spoiler.All;\r
+ AlwaysShowResultRank = false;\r
+ }\r
+ if (SaveLocationPerMachine)\r
+ {\r
+ foreach (var l in LocationList)\r
+ {\r
+ if (l.MachineName != Environment.MachineName)\r
+ continue;\r
+ Location = l.Location;\r
+ Zoom = l.Zoom;\r
+ ShipList.Location = l.ListLocation;\r
+ ShipList.Size = l.ListSize;\r
+ }\r
+ }\r
}\r
catch (FileNotFoundException)\r
{\r
InitializeValues();\r
- ReadOldConfig();\r
Save();\r
}\r
+ catch (InvalidOperationException ex)\r
+ {\r
+ throw new Exception(FileName + "が壊れています。", ex);\r
+ }\r
ConvertPath(PrependBaseDir);\r
}\r
\r
+ private void ComposeNotificationFlags()\r
+ {\r
+ NotificationFlags = (NotificationFlags & ~NotificationType.All) |\r
+ (FlashWindow ? NotificationType.FlashWindow : 0) |\r
+ (ShowBaloonTip ? NotificationType.ShowBaloonTip : 0) |\r
+ (PlaySound ? NotificationType.PlaySound : 0);\r
+ }\r
+\r
public void Save()\r
{\r
+ if (SaveLocationPerMachine)\r
+ {\r
+ LocationList = LocationList.Where(l => l.MachineName != Environment.MachineName).ToList();\r
+ LocationList.Add(new LocationPerMachine\r
+ {\r
+ MachineName = Environment.MachineName,\r
+ Location = Location,\r
+ Zoom = Zoom,\r
+ ListLocation = ShipList.Location,\r
+ ListSize = ShipList.Size\r
+ });\r
+ }\r
+ else\r
+ {\r
+ LocationList = new List<LocationPerMachine>();\r
+ }\r
+ DecomposeNotificationFlags();\r
ConvertPath(StripBaseDir);\r
var serializer = new XmlSerializer(typeof(Config));\r
- using (var file = File.CreateText(_configFileName))\r
+ using (var file = File.CreateText(ConfigFile + ".tmp"))\r
serializer.Serialize(file, this);\r
+ File.Copy(ConfigFile + ".tmp", ConfigFile, true);\r
+ File.Delete(ConfigFile + ".tmp");\r
+ ConvertPath(PrependBaseDir);\r
+ }\r
+\r
+ private void DecomposeNotificationFlags()\r
+ {\r
+ FlashWindow = (NotificationFlags & NotificationType.FlashWindow) != 0;\r
+ ShowBaloonTip = (NotificationFlags & NotificationType.ShowBaloonTip) != 0;\r
+ PlaySound = (NotificationFlags & NotificationType.PlaySound) != 0;\r
}\r
\r
private void ConvertPath(Func<string, string> func)\r
\r
private string StripBaseDir(string path)\r
{\r
- if (!path.StartsWith(_baseDir))\r
+ if (!path.StartsWith(BaseDir))\r
return path;\r
- path = path.Substring(_baseDir.Length);\r
- return path.StartsWith(Path.DirectorySeparatorChar.ToString()) ? path.Substring(1) : path;\r
+ path = path.Substring(BaseDir.Length);\r
+ return path.TrimStart(Path.DirectorySeparatorChar);\r
}\r
\r
- private string PrependBaseDir(string path) => Path.IsPathRooted(path) ? path : Path.Combine(_baseDir, path);\r
-\r
- private void ReadOldConfig()\r
- {\r
- var old = Path.Combine(_baseDir, "config.json");\r
- dynamic json;\r
- try\r
- {\r
- json = JsonParser.Parse(File.ReadAllText(old));\r
- }\r
- catch (FileNotFoundException)\r
- {\r
- return;\r
- }\r
- Location = new Point((int)json.Location.X, (int)json.Location.Y);\r
- foreach (var property in (from prop in GetType().GetProperties()\r
- let type = prop.PropertyType\r
- where type == typeof(bool) || type == typeof(int) || type == typeof(string)\r
- select prop))\r
- {\r
- if (!json.IsDefined(property.Name))\r
- continue;\r
- var v = json[property.Name];\r
- property.SetValue(this, property.PropertyType == typeof(int) ? (int)v : v);\r
- }\r
- NotifyConditions = new List<int>((int[])json.NotifyConditions);\r
- ResetHours = new List<int>((int[])json.ResetHours);\r
- Sounds.Volume = (int)json.SoundVolume;\r
- var idx = 0;\r
- foreach (var name in new[]\r
- {\r
- "Mission", "NDock", "KDock", "MaxShips", "MaxEquips",\r
- "DamagedShip", "Akashi20Min", "AkashiProgress", "AkashiComplete", "Condition"\r
- })\r
- {\r
- if (json.IsDefined(name + "SoundFile"))\r
- Sounds.Files[idx] = json[name + "SoundFile"];\r
- idx++;\r
- }\r
- Proxy.Auto = json.Proxy.Auto;\r
- Proxy.Listen = (int)json.Proxy.Listen;\r
- Proxy.UseUpstream = json.Proxy.UseUpstream;\r
- Proxy.UpstreamPort = (int)json.Proxy.UpstreamPort;\r
- var sl = json.ShipList;\r
- ShipList.Location = new Point((int)sl.Location.X, (int)sl.Location.Y);\r
- ShipList.Size = new Size((int)sl.Size.Width, (int)sl.Size.Height);\r
- ShipList.ShipType = sl.ShipType;\r
- var sg = (int[][])sl.ShipGroup;\r
- ShipList.ShipGroup = new List<List<int>>();\r
- foreach (var g in sg)\r
- ShipList.ShipGroup.Add(new List<int>(g));\r
- Log.On = json.Log.On;\r
- Log.OutputDir = json.Log.OutputDir;\r
- Log.MaterialLogInterval = (int)json.Log.MaterialLogInterval;\r
- Log.ServerOn = json.Log.ServerOn;\r
- Log.Listen = (int)json.Log.Listen;\r
- }\r
+ private string PrependBaseDir(string path) => Path.IsPathRooted(path) ? path : Path.Combine(BaseDir, path);\r
}\r
}
\ No newline at end of file