/// <summary> /// アプリケーション設定を設定ファイルに書き出す /// </summary> public void SaveSettings() { MailSetting = new MailSettings() { // アカウント情報 m_fromName = AccountInfo.fromName, m_mailAddress = AccountInfo.mailAddress, m_userName = AccountInfo.userName, m_passWord = Encrypt(AccountInfo.passWord), // 接続情報 m_smtpServer = AccountInfo.smtpServer, m_popServer = AccountInfo.popServer, m_smtpPortNo = AccountInfo.smtpPortNumber, m_popPortNo = AccountInfo.popPortNumber, m_apopFlag = AccountInfo.apopFlag, m_deleteMail = AccountInfo.deleteMail, m_popBeforeSMTP = AccountInfo.popBeforeSMTP, m_popOverSSL = AccountInfo.popOverSSL, m_smtpAuth = AccountInfo.smtpAuth, // 自動受信設定 m_autoMailFlag = AccountInfo.autoMailFlag, m_getMailInterval = AccountInfo.getMailInterval, // 通知設定 m_popSoundFlag = AccountInfo.popSoundFlag, m_popSoundName = AccountInfo.popSoundName, m_bodyIEShow = AccountInfo.bodyIEShow, m_minimizeTaskTray = AccountInfo.minimizeTaskTray, // ウィンドウ設定 m_windowLeft = this.Left, m_windowTop = this.Top, m_windowWidth = this.Width, m_windowHeight = this.Height, m_windowStat = this.WindowState }; System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(MailSettings)); using (var fs = new FileStream(Application.StartupPath + @"\AkaneMail.xml", FileMode.Create)) { serializer.Serialize(fs, MailSetting); } }
/// <summary> /// 設定ファイルからアプリケーション設定を読み出す /// </summary> public void LoadSettings() { // 環境設定保存クラスを作成する MailSetting = new MailSettings(); // アカウント情報(初期値)を設定する AccountInfo.fromName = ""; AccountInfo.mailAddress = ""; AccountInfo.userName = ""; AccountInfo.passWord = ""; AccountInfo.smtpServer = ""; AccountInfo.popServer = ""; AccountInfo.popPortNumber = 110; AccountInfo.smtpPortNumber = 25; AccountInfo.apopFlag = false; AccountInfo.deleteMail = false; AccountInfo.popBeforeSMTP = false; AccountInfo.popOverSSL = false; AccountInfo.smtpAuth = false; AccountInfo.autoMailFlag = false; AccountInfo.getMailInterval = 10; AccountInfo.popSoundName = ""; AccountInfo.bodyIEShow = false; AccountInfo.minimizeTaskTray = false; // 環境設定ファイルが存在する場合は環境設定情報を読み込んでアカウント情報に設定する if (File.Exists(Application.StartupPath + @"\AkaneMail.xml")) { var serializer = new System.Xml.Serialization.XmlSerializer(typeof(MailSettings)); using (var fs = new FileStream(Application.StartupPath + @"\AkaneMail.xml", FileMode.Open)) { MailSetting = (MailSettings)serializer.Deserialize(fs); } // アカウント情報 AccountInfo.fromName = MailSetting.m_fromName; AccountInfo.mailAddress = MailSetting.m_mailAddress; AccountInfo.userName = MailSetting.m_userName; AccountInfo.passWord = Decrypt(MailSetting.m_passWord); // 接続情報 AccountInfo.smtpServer = MailSetting.m_smtpServer; AccountInfo.popServer = MailSetting.m_popServer; AccountInfo.smtpPortNumber = MailSetting.m_smtpPortNo; AccountInfo.popPortNumber = MailSetting.m_popPortNo; AccountInfo.apopFlag = MailSetting.m_apopFlag; AccountInfo.deleteMail = MailSetting.m_deleteMail; AccountInfo.popBeforeSMTP = MailSetting.m_popBeforeSMTP; AccountInfo.popOverSSL = MailSetting.m_popOverSSL; AccountInfo.smtpAuth = MailSetting.m_smtpAuth; // 自動受信設定 AccountInfo.autoMailFlag = MailSetting.m_autoMailFlag; AccountInfo.getMailInterval = MailSetting.m_getMailInterval; // 通知設定 AccountInfo.popSoundFlag = MailSetting.m_popSoundFlag; AccountInfo.popSoundName = MailSetting.m_popSoundName; AccountInfo.bodyIEShow = MailSetting.m_bodyIEShow; AccountInfo.minimizeTaskTray = MailSetting.m_minimizeTaskTray; // 画面の表示が通常のとき if (MailSetting.m_windowStat == FormWindowState.Normal) { // 過去のバージョンから環境設定ファイルを流用した初期起動以外はこの中に入る if (MailSetting.m_windowLeft != 0 && MailSetting.m_windowTop != 0 && MailSetting.m_windowWidth != 0 && MailSetting.m_windowHeight != 0) { this.Left = MailSetting.m_windowLeft; this.Top = MailSetting.m_windowTop; this.Width = MailSetting.m_windowWidth; this.Height = MailSetting.m_windowHeight; } } this.WindowState = MailSetting.m_windowStat; } }