コミットメタ情報

リビジョン0cdc73ba92c934c363aefadfd6d604f25a5e784c (tree)
日時2018-03-23 22:43:27
作者Kazuhiro Fujieda <fujieda@user...>
コミッターKazuhiro Fujieda

ログメッセージ

status.xmlかTP.csvが壊れていたらエラーを表示する

変更サマリ

差分

--- a/KancolleSniffer/Config.cs
+++ b/KancolleSniffer/Config.cs
@@ -187,9 +187,6 @@ namespace KancolleSniffer
187187
188188 public class Config
189189 {
190- private readonly string _baseDir = AppDomain.CurrentDomain.BaseDirectory.TrimEnd(Path.DirectorySeparatorChar);
191- private readonly string _configFileName;
192-
193190 public Point Location { get; set; } = new Point(int.MinValue, int.MinValue);
194191 public bool TopMost { get; set; }
195192 public bool HideOnMinimized { get; set; }
@@ -229,9 +226,13 @@ namespace KancolleSniffer
229226 public static readonly Dictionary<string, int> NotificationIndex =
230227 NotificationNames.Select((name, i) => new {name, i}).ToDictionary(entry => entry.name, entry => entry.i);
231228
229+
230+ private const string FileName = "config.xml";
231+ private static readonly string BaseDir = AppDomain.CurrentDomain.BaseDirectory;
232+ private static readonly string ConfigFile = Path.Combine(BaseDir, FileName);
233+
232234 public Config()
233235 {
234- _configFileName = Path.Combine(_baseDir, "config.xml");
235236 ConvertPath(PrependBaseDir);
236237 }
237238
@@ -247,7 +248,7 @@ namespace KancolleSniffer
247248 {
248249 var serializer = new XmlSerializer(typeof(Config));
249250 Config config;
250- using (var file = File.OpenText(_configFileName))
251+ using (var file = File.OpenText(ConfigFile))
251252 config = (Config)serializer.Deserialize(file);
252253 foreach (var property in GetType().GetProperties())
253254 property.SetValue(this, property.GetValue(config, null), null);
@@ -281,6 +282,10 @@ namespace KancolleSniffer
281282 InitializeValues();
282283 Save();
283284 }
285+ catch (InvalidOperationException ex)
286+ {
287+ throw new Exception(FileName + "が壊れています。", ex);
288+ }
284289 ConvertPath(PrependBaseDir);
285290 }
286291
@@ -313,7 +318,7 @@ namespace KancolleSniffer
313318 DecomposeNotificationFlags();
314319 ConvertPath(StripBaseDir);
315320 var serializer = new XmlSerializer(typeof(Config));
316- using (var file = File.CreateText(_configFileName))
321+ using (var file = File.CreateText(ConfigFile))
317322 serializer.Serialize(file, this);
318323 }
319324
@@ -334,12 +339,12 @@ namespace KancolleSniffer
334339
335340 private string StripBaseDir(string path)
336341 {
337- if (!path.StartsWith(_baseDir))
342+ if (!path.StartsWith(BaseDir))
338343 return path;
339- path = path.Substring(_baseDir.Length);
344+ path = path.Substring(BaseDir.Length);
340345 return path.TrimStart(Path.DirectorySeparatorChar);
341346 }
342347
343- private string PrependBaseDir(string path) => Path.IsPathRooted(path) ? path : Path.Combine(_baseDir, path);
348+ private string PrependBaseDir(string path) => Path.IsPathRooted(path) ? path : Path.Combine(BaseDir, path);
344349 }
345350 }
\ No newline at end of file
--- a/KancolleSniffer/DataLoader.cs
+++ b/KancolleSniffer/DataLoader.cs
@@ -42,9 +42,9 @@ namespace KancolleSniffer
4242 public static int[] EnemySlot(int id) =>
4343 _maxEq != null ? _maxEq.TryGetValue(id, out var slot) ? slot : null : null;
4444
45+ private const string FileName = "TP.csv";
4546
46- private static readonly string TpFile =
47- Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TP.csv");
47+ private static readonly string TpFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, FileName);
4848
4949 private static Dictionary<int, double> _tpSpec;
5050
@@ -59,6 +59,10 @@ namespace KancolleSniffer
5959 catch (IOException)
6060 {
6161 }
62+ catch (Exception ex)
63+ {
64+ throw new Exception(FileName + "が壊れています。", ex);
65+ }
6266 }
6367
6468 public static double ItemTp(int id) =>
--- a/KancolleSniffer/MainForm.cs
+++ b/KancolleSniffer/MainForm.cs
@@ -79,14 +79,7 @@ namespace KancolleSniffer
7979 labelPresetAkashiTimer.BackColor = ShipLabel.ColumnColors[1];
8080 _listForm = new ListForm(_sniffer, _config) {Owner = this};
8181 _notificationManager = new NotificationManager(Alarm);
82- try
83- {
84- _config.Load();
85- }
86- catch (Exception ex)
87- {
88- throw new ConfigFileException("設定ファイルが壊れています。", ex);
89- }
82+ _config.Load();
9083 _proxyManager = new ProxyManager(_config, this);
9184 _errorLog = new ErrorLog(_sniffer);
9285 _proxyManager.UpdatePacFile();
--- a/KancolleSniffer/Program.cs
+++ b/KancolleSniffer/Program.cs
@@ -30,12 +30,17 @@ namespace KancolleSniffer
3030 {
3131 Application.Run(new MainForm());
3232 }
33- catch (MainForm.ConfigFileException ex)
33+ catch (Exception ex)
3434 {
35- MessageBox.Show(ex.Message + "\r\n" +
36- ex.InnerException?.Message + "\r\n" +
37- ex.InnerException?.InnerException?.Message, "エラー",
38- MessageBoxButtons.OK, MessageBoxIcon.Error);
35+ var inner = ex.InnerException;
36+ MessageBox.Show(ex.Message +
37+ (inner == null
38+ ? ""
39+ : "\r\n" + inner.Message +
40+ (inner.InnerException == null
41+ ? ""
42+ : "\r\n" + inner.InnerException.Message)),
43+ "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error);
3944 }
4045 }
4146 }
--- a/KancolleSniffer/Status.cs
+++ b/KancolleSniffer/Status.cs
@@ -28,8 +28,6 @@ namespace KancolleSniffer
2828
2929 public class Status
3030 {
31- private readonly string _baseDir = AppDomain.CurrentDomain.BaseDirectory;
32- private readonly string _statusFileName;
3331 public static bool Restoring { get; set; }
3432 public Achievement Achievement { get; set; }
3533 public List<MaterialCount> MaterialHistory { get; set; }
@@ -39,9 +37,11 @@ namespace KancolleSniffer
3937 public QuestCount[] QuestCountList { get; set; }
4038 public DateTime QuestLastReset { get; set; }
4139
40+ private const string FileName = "status.xml";
41+ private static readonly string StatusFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, FileName);
42+
4243 public Status()
4344 {
44- _statusFileName = Path.Combine(_baseDir, "status.xml");
4545 CondRegenTime = double.MinValue;
4646 }
4747
@@ -52,7 +52,7 @@ namespace KancolleSniffer
5252 Restoring = true;
5353 var serializer = new XmlSerializer(typeof(Status));
5454 Status status;
55- using (var file = File.OpenText(_statusFileName))
55+ using (var file = File.OpenText(StatusFile))
5656 status = (Status)serializer.Deserialize(file);
5757 foreach (var property in GetType().GetProperties())
5858 property.SetValue(this, property.GetValue(status, null), null);
@@ -60,6 +60,10 @@ namespace KancolleSniffer
6060 catch (FileNotFoundException)
6161 {
6262 }
63+ catch (InvalidOperationException ex)
64+ {
65+ throw new Exception(FileName + "が壊れています。", ex);
66+ }
6367 finally
6468 {
6569 Restoring = false;
@@ -69,7 +73,7 @@ namespace KancolleSniffer
6973 public void Save()
7074 {
7175 var serializer = new XmlSerializer(typeof(Status));
72- using (var file = File.CreateText(_statusFileName))
76+ using (var file = File.CreateText(StatusFile))
7377 serializer.Serialize(file, this);
7478 }
7579 }
旧リポジトリブラウザで表示