// You should have received a copy of the GNU General Public License\r
// along with this program; if not, see <http://www.gnu.org/licenses/>.\r
\r
+using System;\r
using System.Collections.Generic;\r
using System.Drawing;\r
using System.IO;\r
public LogConfig()\r
{\r
On = true;\r
- OutputDir = Path.GetDirectoryName(Application.ExecutablePath);\r
+ OutputDir = "";\r
MaterialLogInterval = 10;\r
ServerOn = true;\r
Listen = 8008;\r
\r
public class Config\r
{\r
- private readonly string _configFileName =\r
- Path.Combine(Path.GetDirectoryName(Application.ExecutablePath) ?? "", "config.json");\r
+ private readonly string _baseDir = Path.GetDirectoryName(Application.ExecutablePath);\r
+ private readonly string _configFileName;\r
\r
public Point Location { get; set; }\r
public bool TopMost { get; set; }\r
\r
public Config()\r
{\r
+ _configFileName = Path.Combine(_baseDir, "config.json");\r
Location = new Point(int.MinValue, int.MinValue);\r
FlashWindow = ShowBaloonTip = PlaySound = true;\r
MarginShips = 4;\r
AlwaysShowResultRank = false;\r
WithAlvBonus = true;\r
SoundVolume = 100;\r
- var dir = Path.GetDirectoryName(Application.ExecutablePath) ?? "";\r
- MissionSoundFile = Path.Combine(dir, "ensei.mp3");\r
- NDockSoundFile = Path.Combine(dir, "nyuukyo.mp3");\r
- KDockSoundFile = Path.Combine(dir, "kenzou.mp3");\r
- MaxShipsSoundFile = Path.Combine(dir, "kanmusu.mp3");\r
- MaxEquipsSoundFile = Path.Combine(dir, "soubi.mp3");\r
- DamagedShipSoundFile = Path.Combine(dir, "taiha.mp3");\r
- Akashi20MinSoundFile = Path.Combine(dir, "20min.mp3");\r
- AkashiProgressSoundFile = Path.Combine(dir, "syuuri.mp3");\r
- AkashiCompleteSoundFile = Path.Combine(dir, "syuuri2.mp3");\r
- ConditionSoundFile = Path.Combine(dir, "hirou.mp3");\r
- DebugLogFile = Path.Combine(dir, "log.txt");\r
+ MissionSoundFile = "ensei.mp3";\r
+ NDockSoundFile = "nyuukyo.mp3";\r
+ KDockSoundFile = "kenzou.mp3";\r
+ MaxShipsSoundFile = "kanmusu.mp3";\r
+ MaxEquipsSoundFile = "soubi.mp3";\r
+ DamagedShipSoundFile = "taiha.mp3";\r
+ Akashi20MinSoundFile = "20min.mp3";\r
+ AkashiProgressSoundFile = "syuuri.mp3";\r
+ AkashiCompleteSoundFile = "syuuri2.mp3";\r
+ ConditionSoundFile = "hirou.mp3";\r
+ DebugLogFile = "log.txt";\r
Proxy = new ProxyConfig();\r
ShipList = new ShipListConfig();\r
Log = new LogConfig();\r
+ ConvertPath(PrependBaseDir);\r
}\r
\r
public void Load()\r
var config = (Config)DynamicJson.Parse(File.ReadAllText(_configFileName));\r
foreach (var property in GetType().GetProperties())\r
property.SetValue(this, property.GetValue(config, null), null);\r
+ ConvertPath(PrependBaseDir);\r
}\r
catch (FileNotFoundException)\r
{\r
\r
public void Save()\r
{\r
+ ConvertPath(StripBaseDir);\r
File.WriteAllText(_configFileName, DynamicJson.Serialize(this));\r
}\r
+\r
+ private void ConvertPath(Func<string, string> func)\r
+ {\r
+ foreach (var property in GetType().GetProperties())\r
+ {\r
+ if (!property.Name.EndsWith("File"))\r
+ continue;\r
+ property.SetValue(this, func((string)property.GetValue(this)));\r
+ }\r
+ Log.OutputDir = func(Log.OutputDir);\r
+ }\r
+\r
+ private string StripBaseDir(string path)\r
+ {\r
+ if (_baseDir == null)\r
+ return path;\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
+ }\r
+\r
+ private string PrependBaseDir(string path)\r
+ {\r
+ if (_baseDir == null)\r
+ return path;\r
+ if (Path.IsPathRooted(path))\r
+ return path;\r
+ return Path.Combine(_baseDir, path);\r
+ }\r
}\r
}
\ No newline at end of file