OSDN Git Service

ログが和暦で出力されることがあるのを直す
authorKazuhiro Fujieda <fujieda@users.osdn.me>
Fri, 10 Nov 2017 13:26:41 +0000 (22:26 +0900)
committerKazuhiro Fujieda <fujieda@users.osdn.me>
Sat, 2 Dec 2017 11:25:06 +0000 (20:25 +0900)
KancolleSniffer/LogServer.cs
KancolleSniffer/Logger.cs
KancolleSniffer/Sniffer.cs

index ffdff0c..007f8ef 100644 (file)
@@ -181,10 +181,18 @@ namespace KancolleSniffer
                     if (!DateTime.TryParseExact(data[0], Logger.DateTimeFormat, CultureInfo.InvariantCulture,\r
                         DateTimeStyles.AssumeLocal, out DateTime date))\r
                     {\r
-                        if (DateTime.TryParse(data[0], CultureInfo.CurrentCulture,\r
+                        // システムが和暦に設定されていて和暦が出力されてしまったケースを救う\r
+                        var wareki = CultureInfo.CreateSpecificCulture("ja-JP");\r
+                        wareki.DateTimeFormat.Calendar = new JapaneseCalendar();\r
+                        if (DateTime.TryParseExact(data[0], Logger.DateTimeFormat, wareki,\r
                             DateTimeStyles.AssumeLocal, out date))\r
                         {\r
-                            data[0] = date.ToString(Logger.DateTimeFormat);\r
+                            data[0] = Logger.FormatDateTime(date);\r
+                        }\r
+                        else if (DateTime.TryParse(data[0], CultureInfo.CurrentCulture,\r
+                            DateTimeStyles.AssumeLocal, out date))\r
+                        {\r
+                            data[0] = Logger.FormatDateTime(date);\r
                         }\r
                         else\r
                         {\r
@@ -229,7 +237,7 @@ namespace KancolleSniffer
 \r
         private static IEnumerable<string> GetCurrentMaterialRecord()\r
         {\r
-            return new[] {DateTime.Now.ToString(Logger.DateTimeFormat)}.\r
+            return new[] {Logger.FormatDateTime(DateTime.Now)}.\r
                 Concat(MaterialHistory.Select(c => c.Now.ToString()));\r
         }\r
 \r
index c5d4e97..dd88a23 100644 (file)
@@ -14,6 +14,7 @@
 \r
 using System;\r
 using System.Collections.Generic;\r
+using System.Globalization;\r
 using System.IO;\r
 using System.Linq;\r
 using System.Text;\r
@@ -66,6 +67,11 @@ namespace KancolleSniffer
             set => _writer = new LogWriter(value).Write;\r
         }\r
 \r
+        public static string FormatDateTime(DateTime date)\r
+        {\r
+            return date.ToString(DateTimeFormat, CultureInfo.InvariantCulture);\r
+        }\r
+\r
         public Logger(ShipInfo ship, ItemInfo item, BattleInfo battle)\r
         {\r
             _shipInfo = ship;\r
@@ -115,7 +121,7 @@ namespace KancolleSniffer
             if ((_logType & LogType.Mission) != 0)\r
             {\r
                 _writer("遠征報告書",\r
-                    string.Join(",", _nowFunc().ToString(DateTimeFormat),\r
+                    string.Join(",", FormatDateTime(_nowFunc()),\r
                         rstr, json.api_quest_name, string.Join(",", material)),\r
                     "日付,結果,遠征,燃料,弾薬,鋼材,ボーキ,開発資材,高速修復材,高速建造材");\r
             }\r
@@ -135,7 +141,7 @@ namespace KancolleSniffer
             if ((_logType & LogType.Achivement) != 0 && json.api_get_eo_rate() && (int)json.api_get_eo_rate != 0)\r
             {\r
                 _writer("戦果",\r
-                    _nowFunc().ToString(DateTimeFormat) + "," + _lastExp + "," + (int)json.api_get_eo_rate,\r
+                    FormatDateTime(_nowFunc()) + "," + _lastExp + "," + (int)json.api_get_eo_rate,\r
                     "日付,経験値,EO");\r
             }\r
             _map = json;\r
@@ -152,11 +158,10 @@ namespace KancolleSniffer
                 if (entry.api_type != 18)\r
                     continue;\r
                 _writer("戦果",\r
-                    _nowFunc().ToString(DateTimeFormat) + "," + _lastExp + "," + (int)entry.api_count,\r
+                    FormatDateTime(_nowFunc()) + "," + _lastExp + "," + (int)entry.api_count,\r
                     "日付,経験値,EO");\r
                 break;\r
             }\r
-\r
         }\r
 \r
         public void InspectBattle(dynamic json)\r
@@ -175,7 +180,7 @@ namespace KancolleSniffer
                     : (int)result.api_get_exmap_rate;\r
                 if (rate != 0)\r
                 {\r
-                    _writer("戦果", _nowFunc().ToString(DateTimeFormat) + "," + _lastExp + "," + rate,\r
+                    _writer("戦果", FormatDateTime(_nowFunc()) + "," + _lastExp + "," + rate,\r
                         "日付,経験値,EO");\r
                 }\r
             }\r
@@ -211,24 +216,24 @@ namespace KancolleSniffer
             }\r
             var fp = _shipInfo.GetFighterPower(BattleInfo.DeckId(_battle));\r
             var fpower = fp[0] == fp[1] ? fp[0].ToString() : fp[0] + "~" + fp[1];\r
-            _writer("海戦・ドロップ報告書", string.Join(",", _nowFunc().ToString(DateTimeFormat),\r
-                result.api_quest_name,\r
-                cell, boss,\r
-                result.api_win_rank,\r
-                BattleFormationName((int)_battle.api_formation[2]),\r
-                FormationName(_battle.api_formation[0]),\r
-                FormationName(_battle.api_formation[1]),\r
-                result.api_enemy_info.api_deck_name,\r
-                dropType, dropName,\r
-                string.Join(",", fships),\r
-                string.Join(",", eships),\r
-                fpower, _battleInfo.EnemyFighterPower.AirCombat + _battleInfo.EnemyFighterPower.UnknownMark,\r
-                AirControlLevelName(_battle)),\r
+            _writer("海戦・ドロップ報告書", string.Join(",", FormatDateTime(_nowFunc()),\r
+                    result.api_quest_name,\r
+                    cell, boss,\r
+                    result.api_win_rank,\r
+                    BattleFormationName((int)_battle.api_formation[2]),\r
+                    FormationName(_battle.api_formation[0]),\r
+                    FormationName(_battle.api_formation[1]),\r
+                    result.api_enemy_info.api_deck_name,\r
+                    dropType, dropName,\r
+                    string.Join(",", fships),\r
+                    string.Join(",", eships),\r
+                    fpower, _battleInfo.EnemyFighterPower.AirCombat + _battleInfo.EnemyFighterPower.UnknownMark,\r
+                    AirControlLevelName(_battle)),\r
                 "日付,海域,マス,ボス,ランク,艦隊行動,味方陣形,敵陣形,敵艦隊,ドロップ艦種,ドロップ艦娘," +\r
                 "味方艦1,味方艦1HP,味方艦2,味方艦2HP,味方艦3,味方艦3HP,味方艦4,味方艦4HP,味方艦5,味方艦5HP,味方艦6,味方艦6HP," +\r
                 "敵艦1,敵艦1HP,敵艦2,敵艦2HP,敵艦3,敵艦3HP,敵艦4,敵艦4HP,敵艦5,敵艦5HP,敵艦6,敵艦6HP," +\r
                 "味方制空値,敵制空値,制空状態"\r
-                );\r
+            );\r
             _map = _battle = null;\r
             _start = false;\r
         }\r
@@ -410,12 +415,13 @@ namespace KancolleSniffer
             {\r
                 if (_lastDate != DateTime.MinValue)\r
                 {\r
-                    _writer("戦果", _lastDate.ToString(DateTimeFormat) + "," + _lastExp + ",0", "日付,経験値,EO");\r
+                    _writer("戦果", FormatDateTime(_lastDate) + "," + _lastExp + ",0", "日付,経験値,EO");\r
                 }\r
-                _writer("戦果", now.ToString(DateTimeFormat) + "," + exp + ",0", "日付,経験値,EO");\r
+                _writer("戦果", FormatDateTime(now) + "," + exp + ",0", "日付,経験値,EO");\r
                 if (isNewMonth)\r
                 {\r
-                    _endOfMonth = new DateTime(now.Year, now.Month, DateTime.DaysInMonth(now.Year, now.Month), 22, 0, 0);\r
+                    _endOfMonth = new DateTime(now.Year, now.Month, DateTime.DaysInMonth(now.Year, now.Month),\r
+                        22, 0, 0);\r
                     if (_endOfMonth.CompareTo(now) <= 0)\r
                     {\r
                         var days = _endOfMonth.Month == 12\r
@@ -440,7 +446,7 @@ namespace KancolleSniffer
                 return;\r
             if (_lastDate != DateTime.MinValue)\r
             {\r
-                _writer("戦果", _lastDate.ToString(DateTimeFormat) + "," + _lastExp + ",0", "日付,経験値,EO");\r
+                _writer("戦果", FormatDateTime(_lastDate) + "," + _lastExp + ",0", "日付,経験値,EO");\r
             }\r
         }\r
 \r
@@ -458,7 +464,7 @@ namespace KancolleSniffer
                 type = spec.TypeName;\r
             }\r
             _writer("開発報告書",\r
-                _nowFunc().ToString(DateTimeFormat) + "," +\r
+                FormatDateTime(_nowFunc()) + "," +\r
                 string.Join(",", name, type,\r
                     values["api_item1"], values["api_item2"], values["api_item3"], values["api_item4"],\r
                     Secretary(), _basic.api_level),\r
@@ -480,7 +486,7 @@ namespace KancolleSniffer
             var ship = _shipInfo.GetSpec((int)kdock.api_created_ship_id);\r
             var avail = ((dynamic[])json).Count(e => (int)e.api_state == 0);\r
             _writer("建造報告書",\r
-                _nowFunc().ToString(DateTimeFormat) + "," +\r
+                FormatDateTime(_nowFunc()) + "," +\r
                 string.Join(",", material.First() >= 1500 ? "大型艦建造" : "通常艦建造",\r
                     ship.Name, ship.ShipTypeName, string.Join(",", material), avail, Secretary(), _basic.api_level),\r
                 "日付,種類,名前,艦種,燃料,弾薬,鋼材,ボーキ,開発資材,空きドック,秘書艦,司令部Lv");\r
@@ -509,7 +515,7 @@ namespace KancolleSniffer
         {\r
             _prevTime = now;\r
             _writer("資材ログ",\r
-                now.ToString(DateTimeFormat) + "," +\r
+                FormatDateTime(now) + "," +\r
                 string.Join(",", _currentMaterial),\r
                 "日付,燃料,弾薬,鋼材,ボーキ,高速建造材,高速修復材,開発資材,改修資材");\r
         }\r
@@ -548,7 +554,7 @@ namespace KancolleSniffer
             if (ships.Length >= 2)\r
                 ship2 = ships[1].Name + "(" + ships[1].Level + ")";\r
             _writer("改修報告書",\r
-                now.ToString(DateTimeFormat) + "," +\r
+                FormatDateTime(now) + "," +\r
                 string.Join(",", name, level, success, certain, useName, useNum,\r
                     diff[(int)Material.Fuel], diff[(int)Material.Bullet], diff[(int)Material.Steal],\r
                     diff[(int)Material.Bouxite],\r
index d61cc0e..382e098 100644 (file)
@@ -14,6 +14,7 @@
 \r
 using System;\r
 using System.Collections.Generic;\r
+using System.Globalization;\r
 using System.Linq;\r
 \r
 namespace KancolleSniffer\r
@@ -652,6 +653,8 @@ namespace KancolleSniffer
         public string ToString(bool finish = false)\r
             => EndTime == DateTime.MinValue\r
                 ? ""\r
-                : finish ? EndTime.ToString(@"dd\ HH\:mm") : $@"{(int)Rest.TotalHours:d2}:{Rest:mm\:ss}";\r
+                : finish\r
+                    ? EndTime.ToString(@"dd\ HH\:mm", CultureInfo.InvariantCulture)\r
+                    : $"{(int)Rest.TotalHours:d2}:" + Rest.ToString(@"mm\:ss", CultureInfo.InvariantCulture);\r
     }\r
 }
\ No newline at end of file