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
f625045a
Commit
f625045a
authored
Sep 22, 2021
by
Thomas
Browse files
Fix creation of diff
parent
820a7def
Changes
1
Hide whitespace changes
Inline
Side-by-side
UI/ViewModels/PatchDialogViewModel.cs
View file @
f625045a
...
@@ -27,8 +27,8 @@ namespace pEp.UI.ViewModels
...
@@ -27,8 +27,8 @@ namespace pEp.UI.ViewModels
private
ConfigFile
_SelectedFile
=
null
;
private
ConfigFile
_SelectedFile
=
null
;
private
FlowDocument
_VisibleDiff
=
null
;
private
FlowDocument
_VisibleDiff
=
null
;
private
const
string
FILE_A_PREFIX
=
"---
a
"
;
private
const
string
FILE_A_PREFIX
=
"---
a/
"
;
private
const
string
FILE_B_PREFIX
=
"+++
b
"
;
private
const
string
FILE_B_PREFIX
=
"+++
b/
"
;
#
endregion
#
endregion
...
@@ -330,6 +330,10 @@ namespace pEp.UI.ViewModels
...
@@ -330,6 +330,10 @@ namespace pEp.UI.ViewModels
/// <returns>The diff between the two files.</returns>
/// <returns>The diff between the two files.</returns>
private
string
CreateDiff
(
string
fileNameA
,
string
fileNameB
)
private
string
CreateDiff
(
string
fileNameA
,
string
fileNameB
)
{
{
// Use UNIX file names
fileNameA
=
fileNameA
.
Replace
(
'\\'
,
'/'
);
fileNameB
=
fileNameB
.
Replace
(
'\\'
,
'/'
);
if
(!(
File
.
Exists
(
fileNameA
)
&&
File
.
Exists
(
fileNameB
)))
if
(!(
File
.
Exists
(
fileNameA
)
&&
File
.
Exists
(
fileNameB
)))
{
{
Log
.
ErrorAndFailInDebugMode
(
"CreateDiff: Input file doesn't exist."
);
Log
.
ErrorAndFailInDebugMode
(
"CreateDiff: Input file doesn't exist."
);
...
@@ -412,7 +416,7 @@ namespace pEp.UI.ViewModels
...
@@ -412,7 +416,7 @@ namespace pEp.UI.ViewModels
break
;
break
;
}
}
}
}
index
++
;
index
=
(
index
>=
0
)
?
index
:
0
;
newFileIndex
=
newLines
[
index
].
Position
??
1
;
newFileIndex
=
newLines
[
index
].
Position
??
1
;
oldFileIndex
=
oldLines
[
index
].
Position
??
1
;
oldFileIndex
=
oldLines
[
index
].
Position
??
1
;
}
}
...
@@ -459,7 +463,7 @@ namespace pEp.UI.ViewModels
...
@@ -459,7 +463,7 @@ namespace pEp.UI.ViewModels
return
null
;
return
null
;
}
}
return
diff
.
Insert
(
0
,
$"
{
PatchDialogViewModel
.
FILE_A_PREFIX
}
/
{
fileNameB
}
\n
{
PatchDialogViewModel
.
FILE_B_PREFIX
}
/
{
fileNameB
}
\n"
).
TrimEnd
(
'\n'
);
return
diff
.
Insert
(
0
,
$"
{
PatchDialogViewModel
.
FILE_A_PREFIX
}{
fileNameB
}
\n
{
PatchDialogViewModel
.
FILE_B_PREFIX
}{
fileNameB
}
\n"
).
TrimEnd
(
'\n'
);
}
}
/// <summary>
/// <summary>
...
@@ -534,21 +538,31 @@ namespace pEp.UI.ViewModels
...
@@ -534,21 +538,31 @@ namespace pEp.UI.ViewModels
/// <returns>The root URI</returns>
/// <returns>The root URI</returns>
private
string
GetRootUri
()
private
string
GetRootUri
()
{
{
string
rootUri
=
this
.
ConfigFiles
.
First
()?.
FileName
;
string
firstFileName
=
this
.
ConfigFiles
.
First
()?.
FileName
;
if
(
string
.
IsNullOrEmpty
(
firstFileName
))
{
Log
.
ErrorAndFailInDebugMode
(
"GetRootUri: First file name is empty"
);
return
null
;
}
string
rootUri
=
Directory
.
GetParent
(
firstFileName
).
FullName
.
Replace
(
'\\'
,
'/'
);
foreach
(
ConfigFile
modifiedFile
in
this
.
ConfigFiles
)
foreach
(
ConfigFile
modifiedFile
in
this
.
ConfigFiles
)
{
{
for
(
int
i
=
0
;
i
<
modifiedFile
.
FileName
.
Length
;
i
++)
string
folderName
=
Directory
.
GetParent
(
modifiedFile
.
FileName
).
FullName
.
Replace
(
'\\'
,
'/'
);
int
i
=
0
;
while
((
i
<
folderName
.
Length
)
&&
(
i
<
rootUri
.
Length
))
{
{
if
((
rootUri
.
Length
<=
i
)
||
if
(
folderName
[
i
]
!=
rootUri
[
i
])
(
modifiedFile
.
FileName
[
i
]
==
rootUri
[
i
]))
{
{
continue
;
break
;
}
}
rootUri
=
rootUri
.
Substring
(
0
,
i
);
i
++;
break
;
}
}
rootUri
=
rootUri
.
Substring
(
0
,
i
);
}
}
return
rootUri
;
return
rootUri
;
...
@@ -578,8 +592,8 @@ namespace pEp.UI.ViewModels
...
@@ -578,8 +592,8 @@ namespace pEp.UI.ViewModels
}
}
// Remove root parts of URI
// Remove root parts of URI
diff
=
diff
.
Replace
(
PatchDialogViewModel
.
FILE_A_PREFIX
+
"/"
+
this
.
Dialog
.
Patch
.
Uri
,
PatchDialogViewModel
.
FILE_A_PREFIX
+
"/"
);
diff
=
diff
.
Replace
(
PatchDialogViewModel
.
FILE_A_PREFIX
+
this
.
Dialog
.
Patch
.
Uri
+
"/"
,
PatchDialogViewModel
.
FILE_A_PREFIX
);
diff
=
diff
.
Replace
(
PatchDialogViewModel
.
FILE_B_PREFIX
+
"/"
+
this
.
Dialog
.
Patch
.
Uri
,
PatchDialogViewModel
.
FILE_B_PREFIX
+
"/"
);
diff
=
diff
.
Replace
(
PatchDialogViewModel
.
FILE_B_PREFIX
+
this
.
Dialog
.
Patch
.
Uri
+
"/"
,
PatchDialogViewModel
.
FILE_B_PREFIX
);
return
diff
.
TrimEnd
(
'\n'
);
return
diff
.
TrimEnd
(
'\n'
);
}
}
...
@@ -673,7 +687,7 @@ namespace pEp.UI.ViewModels
...
@@ -673,7 +687,7 @@ namespace pEp.UI.ViewModels
return
document
;
return
document
;
}
}
#
endregion
#
endregion
}
}
}
}
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