コード例 #1
0
 //--------------------------------------------------------------------------
 //終了
 //--------------------------------------------------------------------------
 private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     var iniFileName = Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), gApplicationIniFileName);
     if (Directory.Exists(Path.GetDirectoryName(iniFileName)) == false)
     {
         Directory.CreateDirectory(Path.GetDirectoryName(iniFileName));
     }
     //タスクがなければセーブチェックなし
     bool bSave = (gTaskList.Count == 0) ? false : true;
     //既存セーブファイルがあれば
     if (bSave == true && gFileName != "")
     {
         var saveTempFileName = Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), gSaveTempFileName);
         gTaskList.Save(saveTempFileName);
         var sr1 = new StreamReader(saveTempFileName, Encoding.GetEncoding(OptionData.GetInstance().Code));
         var sr2 = new StreamReader(gFileName, Encoding.GetEncoding(OptionData.GetInstance().Code));
         //変更がなければセーブチェックなし
         if (sr1.ReadToEnd() == sr2.ReadToEnd())
         {
             bSave = false;
         }
         sr1.Close();
         sr2.Close();
         File.Delete(saveTempFileName);
     }
     //セーブチェック
     if (bSave)
     {
         DialogResult result = MessageBox.Show("セーブしますか?", "確認", MessageBoxButtons.YesNoCancel);
         if (result == DialogResult.Cancel)
         {
             e.Cancel = true;
             return;
         }
         if (result == DialogResult.Yes)
         {
             if (gFileName == "")
             {
                 saveFileDialog1.ShowDialog();
             }
             else
             {
                 gTaskList.Save(gFileName);
             }
         }
     }
     //セーブ
     using (var ms = new FileStream(iniFileName, FileMode.Create))
     {
         using (var xw = XmlWriter.Create(ms, new XmlWriterSettings { Indent = true }))
         {
             var serializer = new DataContractSerializer(typeof(IniData));
             var iniData = new IniData();
             iniData.FileName = gFileName;
             serializer.WriteObject(xw, iniData);
         }
     }
 }
コード例 #2
0
 public void 初期化データ()
 {
     IniData ini = new IniData();
     Assert.True(ini != null);
 }