예제 #1
0
 private void CheckIfProjectChanged()
 {
     // Serialize the current project in memory to later compare it
     MemoryStream streamCurrent = new MemoryStream();
     BinaryFormatter bFormatterCurrent = new BinaryFormatter();
     bFormatterCurrent.Serialize(streamCurrent, Project);
     // Get the old project to compare it with the current project
     if (File.Exists("LastProjectPath.plcfg"))
     {
         String proj = File.ReadAllText("LastProjectPath.plcfg").Trim();
         if (File.Exists(proj))
         {
             Stream streamOld = File.Open(proj, FileMode.Open);
             // First, just compare the lengh. If they are different, the project has obviously changed
             if (streamCurrent.Length != streamOld.Length)
             {
                 streamCurrent.Close();
                 streamOld.Close();
                 SaveClosingForm closeForm = new SaveClosingForm(this.Text);
                 closeForm.ShowDialog();
                 if (closeForm.Sauvegarder)
                     SaveProject();
             }
             else
             {
                 using (PLUtils utils = new PLUtils())
                 {
                     byte[] byteCurrent = utils.ReadToEnd(streamCurrent);
                     byte[] byteOld = utils.ReadToEnd(streamOld);
                     streamCurrent.Close();
                     streamOld.Close();
                     if (!byteCurrent.SequenceEqual(byteOld))
                     {
                         SaveClosingForm closeForm = new SaveClosingForm(this.Text);
                         closeForm.ShowDialog();
                         if (closeForm.Sauvegarder)
                             SaveProject();
                     }
                 }
             }
         }
     }
 }
예제 #2
0
 private void PeventListEditor_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (!SaveCalled)
     {
         SaveClosingForm closeForm = new SaveClosingForm(this.Name);
         closeForm.ShowDialog();
         if (closeForm.Sauvegarder)
             Save();
     }
 }
예제 #3
0
 private void MainFormPixelLion_FormClosing(object sender, FormClosingEventArgs e)
 {
     MemoryStream streamCurrent = new MemoryStream();
     BinaryFormatter bFormatterCurrent = new BinaryFormatter();
     bFormatterCurrent.Serialize(streamCurrent, CurrentMap);
     if (File.Exists(LastOpenedMapFile))
     {
         Stream streamOld = File.Open(LastOpenedMapFile, FileMode.Open);
         if (streamCurrent.Length != streamOld.Length)
         {
             SaveClosingForm closeForm = new SaveClosingForm(this.Text);
             closeForm.ShowDialog();
             streamCurrent.Close();
             streamOld.Close();
             if (closeForm.Sauvegarder)
             {
                 SaveMap();
                 SaveProject();
             }
         }
         else
         {
             using (PLUtils utils = new PLUtils())
             {
                 byte[] byteCurrent = utils.ReadToEnd(streamCurrent);
                 byte[] byteOld = utils.ReadToEnd(streamOld);
                 streamCurrent.Close();
                 streamOld.Close();
                 if (!byteCurrent.SequenceEqual(byteOld))
                 {
                     SaveClosingForm closeForm = new SaveClosingForm(this.Text);
                     closeForm.ShowDialog();
                     if (closeForm.Sauvegarder)
                     {
                         SaveMap();
                         SaveProject();
                     }
                 }
             }
         }
     }
     else
         CheckIfProjectChanged();
 }