Commit 11a334a6 authored by Thomas's avatar Thomas
Browse files

Do not accept empty patches (no modifications)

parent d155fc28
...@@ -9,6 +9,7 @@ using System.Collections.ObjectModel; ...@@ -9,6 +9,7 @@ using System.Collections.ObjectModel;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Windows;
using System.Windows.Documents; using System.Windows.Documents;
using System.Windows.Media; using System.Windows.Media;
...@@ -366,8 +367,7 @@ namespace pEp.UI.ViewModels ...@@ -366,8 +367,7 @@ namespace pEp.UI.ViewModels
* => The modified part. * => The modified part.
* => Three unchanged lines (if available) after the modified part. * => Three unchanged lines (if available) after the modified part.
*/ */
string diff = $"{ PatchDialogViewModel.FILE_A_PREFIX }/{ fileNameB }\n{ PatchDialogViewModel.FILE_B_PREFIX }/{ fileNameB }\n"; string diff = null;
SideBySideDiffModel sideBySideDiffModel = SideBySideDiffBuilder.Diff(fileA, fileB); SideBySideDiffModel sideBySideDiffModel = SideBySideDiffBuilder.Diff(fileA, fileB);
List<DiffPiece> newLines = sideBySideDiffModel.NewText.Lines; List<DiffPiece> newLines = sideBySideDiffModel.NewText.Lines;
List<DiffPiece> oldLines = sideBySideDiffModel.OldText.Lines; List<DiffPiece> oldLines = sideBySideDiffModel.OldText.Lines;
...@@ -443,7 +443,12 @@ namespace pEp.UI.ViewModels ...@@ -443,7 +443,12 @@ namespace pEp.UI.ViewModels
} }
} }
return diff.TrimEnd('\n'); if (string.IsNullOrEmpty(diff))
{
return null;
}
return diff.Insert(0, $"{ PatchDialogViewModel.FILE_A_PREFIX }/{ fileNameB }\n{ PatchDialogViewModel.FILE_B_PREFIX }/{ fileNameB }\n").TrimEnd('\n');
} }
/// <summary> /// <summary>
...@@ -472,28 +477,35 @@ namespace pEp.UI.ViewModels ...@@ -472,28 +477,35 @@ namespace pEp.UI.ViewModels
File.Copy(fileName, originalFileName, true); File.Copy(fileName, originalFileName, true);
} }
// Open temp file in VS Code for the user to edit // Open temp file in Notepad for the user to edit
Process openCodeProcess = new Process using (Process modifyFileProcess = Process.Start(new ProcessStartInfo
{ {
StartInfo = new ProcessStartInfo FileName = "Notepad.exe",
{ Arguments = fileName,
FileName = "code", UseShellExecute = false,
Arguments = fileName, CreateNoWindow = true
UseShellExecute = true, }))
CreateNoWindow = true {
} modifyFileProcess.WaitForExit();
}; }
openCodeProcess.Start();
openCodeProcess.WaitForExit(); // If changes were made, add or update file, otherwise show notification
if (this.CreateDiff(originalFileName, fileName) is string diff)
{
this.ConfigFiles.Remove(this.ConfigFiles.Where(f => (f.FileName?.Equals(fileName) == true) && f.TempFileName?.Equals(tempFileName) == true).FirstOrDefault());
this.ConfigFiles.Add(new ConfigFile(fileName, tempFileName, diff));
// Select the created diff in the UI
this.SelectedFile = this.ConfigFiles.Last();
}
else
{
MessageBox.Show("No changes were made. Ignoring selected file.");
}
string diff = this.CreateDiff(originalFileName, fileName); // Always update the respective files
this.ConfigFiles.Remove(this.ConfigFiles.Where(f => (f.FileName?.Equals(fileName) == true) && f.TempFileName?.Equals(tempFileName) == true).FirstOrDefault());
this.ConfigFiles.Add(new ConfigFile(fileName, tempFileName, diff));
File.Copy(fileName, tempFileName, true); File.Copy(fileName, tempFileName, true);
File.Copy(originalFileName, fileName, true); File.Copy(originalFileName, fileName, true);
// Select the created diff in the UI
this.SelectedFile = this.ConfigFiles.Last();
} }
catch (Exception ex) catch (Exception ex)
{ {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment