Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Windows
pEp for Outlook
Commits
11a334a6
Commit
11a334a6
authored
Sep 17, 2021
by
Thomas
Browse files
Do not accept empty patches (no modifications)
parent
d155fc28
Changes
1
Hide whitespace changes
Inline
Side-by-side
UI/ViewModels/PatchDialogViewModel.cs
View file @
11a334a6
...
@@ -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
openCod
eProcess
=
new
Process
using
(
Process
modifyFil
eProcess
=
Process
.
Start
(
new
Process
StartInfo
{
{
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
)
{
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment