public static void saveSettings(string filename) { TricksterTools.Library.Xml.Settings.XmlTricksterRoot XmlRoot = new TricksterTools.Library.Xml.Settings.XmlTricksterRoot(); XmlTools Tools = new XmlTools(); XmlSettings Settings = new XmlSettings(); XmlSettingHungUpTime hungtime = new XmlSettingHungUpTime(); XmlSettingUpdate update = new XmlSettingUpdate(); XmlSettingGameStartUp gamestartup = new XmlSettingGameStartUp(); XmlSettingLogging logging = new XmlSettingLogging(); XmlSettingIcons icons = new XmlSettingIcons(); hungtime.enable = (HungUp.enable) ? "true" : "false"; hungtime.sec = HungUp.sec; update.startup = (Update.startupAutoCehck) ? "true" : "false"; update.checkBeta = (Update.checkBetaVersion) ? "true" : "false"; gamestartup.mode = GameStartUp.mode; logging.enable = (Logging.enable) ? "true" : "false"; logging.Path = Logging.filePath; icons.resourceName = Icons.resourceName; Settings.HungupTime = hungtime; Settings.UpdateCheck = update; Settings.StartUpGame = gamestartup; //Settings.Logging = logging; Settings.Icon = icons; Tools.Settings = Settings; XmlRoot.Tools = Tools; string filepath = ""; if (Path.IsPathRooted(filename)) { filepath = filename; filename = Path.GetFileName(filename); } else { filepath = Path.GetFullPath(Environment.CurrentDirectory + @"\" + filename); } if (!File.Exists(filepath)) { // ファイルがなければ作成 FileStream fs = new FileStream(filepath, FileMode.Create); fs.Close(); } try { System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(TricksterTools.Library.Xml.Settings.XmlTricksterRoot)); FileStream fs = new FileStream(filepath, FileMode.Create); serializer.Serialize(fs, XmlRoot); fs.Close(); } catch (System.Security.SecurityException se) { SimpleLogger.WriteLine(se.Message); //MessageBox.Show("例外エラー:" + Environment.NewLine + "セキュリティエラーです。", "SecurityExceptional error", MessageBoxButtons.OK, MessageBoxIcon.Error); throw se; } catch (System.IO.IOException ioe) { SimpleLogger.WriteLine(ioe.Message); //MessageBox.Show("例外エラー:" + Environment.NewLine + "入出力時にエラーが発生しました。", "IOExceptional error", MessageBoxButtons.OK, MessageBoxIcon.Error); throw ioe; } catch (System.Xml.XmlException xe) { SimpleLogger.WriteLine(xe.Message); //MessageBox.Show("例外エラー:" + Environment.NewLine + "設定読み込みエラー", "XmlExceptional error", MessageBoxButtons.OK, MessageBoxIcon.Error); throw xe; } catch (System.Exception e) { SimpleLogger.WriteLine(e.Message); //MessageBox.Show("例外エラー:" + Environment.NewLine + "原因の特定ができませんでした。", "Exceptional error", MessageBoxButtons.OK, MessageBoxIcon.Error); throw e; } }
public static void saveSettings(string filename) { TricksterTools.Library.Xml.Settings.XmlTricksterRoot XmlRoot = new TricksterTools.Library.Xml.Settings.XmlTricksterRoot(); XmlTools Tools = new XmlTools(); XmlSettings Settings = new XmlSettings(); XmlSettingHungUpTime hungtime = new XmlSettingHungUpTime(); XmlSettingUpdate update = new XmlSettingUpdate(); XmlSettingGameStartUp gamestartup = new XmlSettingGameStartUp(); XmlSettingLogging logging = new XmlSettingLogging(); XmlSettingIcons icons = new XmlSettingIcons(); hungtime.enable = (HungUp.enable) ? "true" : "false"; hungtime.sec = HungUp.sec; update.startup = (Update.startupAutoCehck) ? "true" : "false"; update.checkBeta = (Update.checkBetaVersion) ? "true" : "false"; gamestartup.mode = GameStartUp.mode; logging.enable = (Logging.enable) ? "true" : "false"; logging.Path = Logging.filePath; icons.resourceName = Icons.resourceName; Settings.HungupTime = hungtime; Settings.UpdateCheck = update; Settings.StartUpGame = gamestartup; //Settings.Logging = logging; Settings.Icon = icons; Tools.Settings = Settings; XmlRoot.Tools = Tools; string filepath = ""; if (Path.IsPathRooted(filename)) { filepath = filename; filename = Path.GetFileName(filename); } else { filepath = Path.GetFullPath(Environment.CurrentDirectory + @"\" + filename); } if (!File.Exists(filepath)) { // �t�@�C�����Ȃ���쐬 FileStream fs = new FileStream(filepath, FileMode.Create); fs.Close(); } try { System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(TricksterTools.Library.Xml.Settings.XmlTricksterRoot)); FileStream fs = new FileStream(filepath, FileMode.Create); serializer.Serialize(fs, XmlRoot); fs.Close(); } catch (System.Security.SecurityException se) { SimpleLogger.WriteLine(se.Message); //MessageBox.Show("��O�G���[:" + Environment.NewLine + "�Z�L�����e�B�G���[�ł��B", "SecurityExceptional error", MessageBoxButtons.OK, MessageBoxIcon.Error); throw se; } catch (System.IO.IOException ioe) { SimpleLogger.WriteLine(ioe.Message); //MessageBox.Show("��O�G���[:" + Environment.NewLine + "���o�͎��ɃG���[���������܂����B", "IOExceptional error", MessageBoxButtons.OK, MessageBoxIcon.Error); throw ioe; } catch (System.Xml.XmlException xe) { SimpleLogger.WriteLine(xe.Message); //MessageBox.Show("��O�G���[:" + Environment.NewLine + "�ݒ�ǂݍ��݃G���[", "XmlExceptional error", MessageBoxButtons.OK, MessageBoxIcon.Error); throw xe; } catch (System.Exception e) { SimpleLogger.WriteLine(e.Message); //MessageBox.Show("��O�G���[:" + Environment.NewLine + "�����̓��肪�ł��܂���ł����B", "Exceptional error", MessageBoxButtons.OK, MessageBoxIcon.Error); throw e; } }