\r
public class Config\r
{\r
- private readonly string _baseDir = AppDomain.CurrentDomain.BaseDirectory.TrimEnd(Path.DirectorySeparatorChar);\r
- private readonly string _configFileName;\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 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
+ private 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
{\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
InitializeValues();\r
Save();\r
}\r
+ catch (InvalidOperationException ex)\r
+ {\r
+ throw new Exception(FileName + "が壊れています。", ex);\r
+ }\r
ConvertPath(PrependBaseDir);\r
}\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))\r
serializer.Serialize(file, this);\r
}\r
\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
+ 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
+ private string PrependBaseDir(string path) => Path.IsPathRooted(path) ? path : Path.Combine(BaseDir, path);\r
}\r
}
\ No newline at end of file
public static int[] EnemySlot(int id) =>\r
_maxEq != null ? _maxEq.TryGetValue(id, out var slot) ? slot : null : null;\r
\r
+ private const string FileName = "TP.csv";\r
\r
- private static readonly string TpFile =\r
- Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TP.csv");\r
+ private static readonly string TpFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, FileName);\r
\r
private static Dictionary<int, double> _tpSpec;\r
\r
catch (IOException)\r
{\r
}\r
+ catch (Exception ex)\r
+ {\r
+ throw new Exception(FileName + "が壊れています。", ex);\r
+ }\r
}\r
\r
public static double ItemTp(int id) =>\r
labelPresetAkashiTimer.BackColor = ShipLabel.ColumnColors[1];\r
_listForm = new ListForm(_sniffer, _config) {Owner = this};\r
_notificationManager = new NotificationManager(Alarm);\r
- try\r
- {\r
- _config.Load();\r
- }\r
- catch (Exception ex)\r
- {\r
- throw new ConfigFileException("設定ファイルが壊れています。", ex);\r
- }\r
+ _config.Load();\r
_proxyManager = new ProxyManager(_config, this);\r
_errorLog = new ErrorLog(_sniffer);\r
_proxyManager.UpdatePacFile();\r
{\r
Application.Run(new MainForm());\r
}\r
- catch (MainForm.ConfigFileException ex)\r
+ catch (Exception ex)\r
{\r
- MessageBox.Show(ex.Message + "\r\n" +\r
- ex.InnerException?.Message + "\r\n" +\r
- ex.InnerException?.InnerException?.Message, "エラー",\r
- MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+ var inner = ex.InnerException;\r
+ MessageBox.Show(ex.Message +\r
+ (inner == null\r
+ ? ""\r
+ : "\r\n" + inner.Message +\r
+ (inner.InnerException == null\r
+ ? ""\r
+ : "\r\n" + inner.InnerException.Message)),\r
+ "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
}\r
}\r
}\r
\r
public class Status\r
{\r
- private readonly string _baseDir = AppDomain.CurrentDomain.BaseDirectory;\r
- private readonly string _statusFileName;\r
public static bool Restoring { get; set; }\r
public Achievement Achievement { get; set; }\r
public List<MaterialCount> MaterialHistory { get; set; }\r
public QuestCount[] QuestCountList { get; set; }\r
public DateTime QuestLastReset { get; set; }\r
\r
+ private const string FileName = "status.xml";\r
+ private static readonly string StatusFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, FileName);\r
+\r
public Status()\r
{\r
- _statusFileName = Path.Combine(_baseDir, "status.xml");\r
CondRegenTime = double.MinValue;\r
}\r
\r
Restoring = true;\r
var serializer = new XmlSerializer(typeof(Status));\r
Status status;\r
- using (var file = File.OpenText(_statusFileName))\r
+ using (var file = File.OpenText(StatusFile))\r
status = (Status)serializer.Deserialize(file);\r
foreach (var property in GetType().GetProperties())\r
property.SetValue(this, property.GetValue(status, null), null);\r
catch (FileNotFoundException)\r
{\r
}\r
+ catch (InvalidOperationException ex)\r
+ {\r
+ throw new Exception(FileName + "が壊れています。", ex);\r
+ }\r
finally\r
{\r
Restoring = false;\r
public void Save()\r
{\r
var serializer = new XmlSerializer(typeof(Status));\r
- using (var file = File.CreateText(_statusFileName))\r
+ using (var file = File.CreateText(StatusFile))\r
serializer.Serialize(file, this);\r
}\r
}\r