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
3c22c064
Commit
3c22c064
authored
Sep 30, 2021
by
Thomas
Browse files
Update the patch model
parent
d0c20197
Changes
7
Hide whitespace changes
Inline
Side-by-side
DPE/Patch.cs
View file @
3c22c064
using
pEp.Extensions
;
using
pEp.Extensions
;
using
System
;
using
System
;
using
System.Collections.Generic
;
namespace
pEp.DPE
namespace
pEp.DPE
{
{
public
class
Patch
public
class
Patch
{
{
public
static
readonly
string
REG_FILE_SCHEME
=
"microsoft.windows.registry
:
"
;
public
static
readonly
string
REG_FILE_SCHEME
=
"
file:///
microsoft.windows.registry"
;
public
enum
RejectReason
public
enum
RejectReason
{
{
...
@@ -16,48 +17,21 @@ namespace pEp.DPE
...
@@ -16,48 +17,21 @@ namespace pEp.DPE
RejectedByUser
RejectedByUser
}
}
public
string
Id
{
get
;
set
;
}
=
Guid
.
NewGuid
().
ToString
();
internal
List
<
PEPIdentity
>
ApplyTo
{
get
;
}
=
new
List
<
PEPIdentity
>();
public
string
Uri
{
get
;
set
;
}
public
string
CommitMessage
{
get
;
set
;
}
public
string
Diff
{
get
;
set
;
}
public
DateTime
CreationDate
{
get
;
set
;
}
=
DateTime
.
UtcNow
;
public
string
CommitMessage
{
get
;
set
;
}
public
string
Diff
{
get
;
set
;
}
public
string
Tag
{
get
;
set
;
}
public
string
Id
{
get
;
set
;
}
=
Guid
.
NewGuid
().
ToString
();
public
DateTime
CreationDate
{
get
;
set
;
}
=
DateTime
.
UtcNow
;
public
Uri
RootPath
{
get
;
set
;
}
public
string
Tag
{
get
;
set
;
}
/// <summary>
/// <summary>
/// Primary constructor.
Needed for de/serialization.
/// Primary constructor.
/// </summary>
/// </summary>
public
Patch
()
public
Patch
()
{
{
}
}
/// <summary>
/// Constructor for a new patch.
/// </summary>
/// <param name="uri">The location to apply the patch to.</param>
/// <param name="diff">The diff to apply.</param>
/// <param name="commitMessage">The commit message for this patch.</param>
/// <param name="tag">The tag for this patch (optional).</param>
public
Patch
(
string
uri
,
string
diff
,
string
commitMessage
,
string
tag
=
null
)
{
this
.
CommitMessage
=
commitMessage
;
this
.
Diff
=
diff
;
this
.
Tag
=
tag
;
this
.
Uri
=
uri
;
}
/// <summary>
/// Constructor for an existing patch
/// </summary>
/// <param name="uri">The location to apply the patch to.</param>
/// <param name="diff">The diff to apply.</param>
/// <param name="commitMessage">The commit message for this patch.</param>
/// <param name="creationDate">The date where this patch was created.</param>
/// <param name="tag">The tag for this patch (optional).</param>
public
Patch
(
string
uri
,
string
diff
,
string
commitMessage
,
DateTime
creationDate
,
string
tag
=
null
)
:
this
(
uri
,
diff
,
commitMessage
,
tag
)
{
this
.
CreationDate
=
creationDate
;
}
/// <summary>
/// <summary>
/// Deserializes a JSON string into a Patch object.
/// Deserializes a JSON string into a Patch object.
/// </summary>
/// </summary>
...
...
UI/Models/PatchDialog.cs
View file @
3c22c064
...
@@ -15,11 +15,6 @@ namespace pEp.UI.Models
...
@@ -15,11 +15,6 @@ namespace pEp.UI.Models
SupportOrRejectPatch
SupportOrRejectPatch
}
}
/// <summary>
/// Gets whether the patch is editable.
/// </summary>
public
bool
IsEditable
{
get
;
}
=
false
;
/// <summary>
/// <summary>
/// Get the patch.
/// Get the patch.
/// </summary>
/// </summary>
...
@@ -35,12 +30,10 @@ namespace pEp.UI.Models
...
@@ -35,12 +30,10 @@ namespace pEp.UI.Models
/// </summary>
/// </summary>
/// <param name="patchAction">The action to perform with this patch.</param>
/// <param name="patchAction">The action to perform with this patch.</param>
/// <param name="patch">The patch to be used in this dialog.</param>
/// <param name="patch">The patch to be used in this dialog.</param>
/// <param name="isEditable">Whether the patch is editable.</param>
public
PatchDialog
(
PatchAction
patchAction
,
Patch
patch
=
null
)
:
base
(
Dialog
.
Type
.
Patch
,
null
)
public
PatchDialog
(
PatchAction
patchAction
,
Patch
patch
=
null
,
bool
isEditable
=
false
)
:
base
(
Dialog
.
Type
.
Patch
,
null
)
{
{
this
.
PatchActionType
=
patchAction
;
this
.
PatchActionType
=
patchAction
;
this
.
Patch
=
patch
;
this
.
Patch
=
patch
??
new
Patch
();
this
.
IsEditable
=
isEditable
;
// Set dialog title
// Set dialog title
switch
(
patchAction
)
switch
(
patchAction
)
...
@@ -66,13 +59,9 @@ namespace pEp.UI.Models
...
@@ -66,13 +59,9 @@ namespace pEp.UI.Models
/// <summary>
/// <summary>
/// Shows a patch dialog.
/// Shows a patch dialog.
/// </summary>
/// </summary>
/// <param name="patchAction">The action to perform with the patch.</param>
public
static
void
ShowNewPatchDialog
()
/// <param name="patch">The patch to manage.</param>
/// <param name="isEditable">Whether the patch can be edited.</param>
public
static
void
ShowDialog
(
PatchDialog
.
PatchAction
patchAction
,
Patch
patch
,
bool
isEditable
=
false
)
{
{
// Open dialog and retrieve result
PatchDialog
patchDialog
=
new
PatchDialog
(
PatchAction
.
NewPatch
);
PatchDialog
patchDialog
=
new
PatchDialog
(
patchAction
,
patch
,
isEditable
);
new
DialogHost
(
patchDialog
).
ShowDialog
();
new
DialogHost
(
patchDialog
).
ShowDialog
();
}
}
}
}
...
...
UI/RibbonCustomizations.cs
View file @
3c22c064
...
@@ -1490,7 +1490,7 @@ namespace pEp
...
@@ -1490,7 +1490,7 @@ namespace pEp
/// </summary>
/// </summary>
public
void
ButtonDPE_Click
(
Office
.
IRibbonControl
control
)
public
void
ButtonDPE_Click
(
Office
.
IRibbonControl
control
)
{
{
PatchDialog
.
Show
Dialog
(
PatchDialog
.
PatchAction
.
NewPatch
,
new
DPE
.
Patch
(),
true
);
PatchDialog
.
Show
New
PatchDialog
(
);
}
}
/// <summary>
/// <summary>
...
...
UI/ViewModels/FormControlPatchViewModel.cs
View file @
3c22c064
...
@@ -141,14 +141,14 @@ namespace pEp.UI.ViewModels
...
@@ -141,14 +141,14 @@ namespace pEp.UI.ViewModels
}
}
/// <summary>
/// <summary>
/// Gets or sets the
URI
of the patch.
/// Gets or sets the
root path
of the patch.
/// </summary>
/// </summary>
public
string
Uri
public
string
RootPath
{
{
get
=>
this
.
patch
?.
Uri
;
get
=>
this
.
patch
?.
RootPath
.
Absolute
Uri
;
set
set
{
{
this
.
patch
.
Uri
=
value
;
this
.
patch
.
RootPath
=
new
Uri
(
value
)
;
this
.
OnPropertyChanged
();
this
.
OnPropertyChanged
();
}
}
}
}
...
...
UI/ViewModels/PatchDialogViewModel.cs
View file @
3c22c064
...
@@ -106,11 +106,6 @@ namespace pEp.UI.ViewModels
...
@@ -106,11 +106,6 @@ namespace pEp.UI.ViewModels
/// </summary>
/// </summary>
public
bool
IsDiffValid
{
get
=>
this
.
_IsDiffValid
;
set
=>
this
.
SetProperty
(
ref
this
.
_IsDiffValid
,
value
);
}
public
bool
IsDiffValid
{
get
=>
this
.
_IsDiffValid
;
set
=>
this
.
SetProperty
(
ref
this
.
_IsDiffValid
,
value
);
}
/// <summary>
/// Gets whether the patch in this dialog is editable.
/// </summary>
public
bool
IsEditable
=>
this
.
Dialog
.
IsEditable
;
/// <summary>
/// <summary>
/// Gets or sets whether the view is currently loading.
/// Gets or sets whether the view is currently loading.
/// </summary>
/// </summary>
...
@@ -272,7 +267,7 @@ namespace pEp.UI.ViewModels
...
@@ -272,7 +267,7 @@ namespace pEp.UI.ViewModels
this
.
Dialog
.
Patch
.
CreationDate
=
DateTime
.
UtcNow
;
this
.
Dialog
.
Patch
.
CreationDate
=
DateTime
.
UtcNow
;
// Get a common root URI of all diff files
// Get a common root URI of all diff files
this
.
Dialog
.
Patch
.
Uri
=
this
.
GetRoot
Uri
();
this
.
Dialog
.
Patch
.
RootPath
=
this
.
GetRoot
Path
();
// Concatenate all diffs from the selected files
// Concatenate all diffs from the selected files
this
.
Dialog
.
Patch
.
Diff
=
this
.
UnifyDiffs
();
this
.
Dialog
.
Patch
.
Diff
=
this
.
UnifyDiffs
();
...
@@ -552,7 +547,7 @@ namespace pEp.UI.ViewModels
...
@@ -552,7 +547,7 @@ namespace pEp.UI.ViewModels
/// Gets a common root URI from all selected files in the dialog.
/// Gets a common root URI from all selected files in the dialog.
/// </summary>
/// </summary>
/// <returns>The root URI</returns>
/// <returns>The root URI</returns>
private
string
GetRoot
Uri
()
private
Uri
GetRoot
Path
()
{
{
string
firstFileName
=
this
.
ConfigFiles
.
First
()?.
FileName
;
string
firstFileName
=
this
.
ConfigFiles
.
First
()?.
FileName
;
if
(
string
.
IsNullOrEmpty
(
firstFileName
))
if
(
string
.
IsNullOrEmpty
(
firstFileName
))
...
@@ -561,16 +556,16 @@ namespace pEp.UI.ViewModels
...
@@ -561,16 +556,16 @@ namespace pEp.UI.ViewModels
return
null
;
return
null
;
}
}
string
root
Uri
=
Directory
.
GetParent
(
firstFileName
).
FullName
.
Replace
(
'\\'
,
'/'
);
string
root
Path
=
Directory
.
GetParent
(
firstFileName
).
FullName
.
Replace
(
'\\'
,
'/'
);
foreach
(
ConfigFile
modifiedFile
in
this
.
ConfigFiles
)
foreach
(
ConfigFile
modifiedFile
in
this
.
ConfigFiles
)
{
{
string
folderName
=
Directory
.
GetParent
(
modifiedFile
.
FileName
).
FullName
.
Replace
(
'\\'
,
'/'
);
string
folderName
=
Directory
.
GetParent
(
modifiedFile
.
FileName
).
FullName
.
Replace
(
'\\'
,
'/'
);
int
i
=
0
;
int
i
=
0
;
while
((
i
<
folderName
.
Length
)
&&
while
((
i
<
folderName
.
Length
)
&&
(
i
<
root
Uri
.
Length
))
(
i
<
root
Path
.
Length
))
{
{
if
(
folderName
[
i
]
!=
root
Uri
[
i
])
if
(
folderName
[
i
]
!=
root
Path
[
i
])
{
{
break
;
break
;
}
}
...
@@ -578,10 +573,10 @@ namespace pEp.UI.ViewModels
...
@@ -578,10 +573,10 @@ namespace pEp.UI.ViewModels
i
++;
i
++;
}
}
root
Uri
=
root
Uri
.
Substring
(
0
,
i
);
root
Path
=
root
Path
.
Substring
(
0
,
i
);
}
}
return
rootUri
;
return
new
Uri
(
rootPath
)
;
}
}
/// <summary>
/// <summary>
...
@@ -608,8 +603,8 @@ namespace pEp.UI.ViewModels
...
@@ -608,8 +603,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
.
RootPath
+
"/"
,
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
.
RootPath
+
"/"
,
PatchDialogViewModel
.
FILE_B_PREFIX
);
return
diff
.
TrimEnd
(
'\n'
);
return
diff
.
TrimEnd
(
'\n'
);
}
}
...
...
UI/Views/FormControlPatchView.xaml
View file @
3c22c064
...
@@ -142,7 +142,7 @@
...
@@ -142,7 +142,7 @@
Background="{Binding Background}"
Background="{Binding Background}"
VerticalAlignment="Center"
VerticalAlignment="Center"
Padding="2"
Padding="2"
Text="{Binding
Uri
}"
Text="{Binding
RootPath
}"
IsReadOnly="True"
IsReadOnly="True"
Margin="5,10,10,10"/>
Margin="5,10,10,10"/>
<Label Grid.Column="0"
<Label Grid.Column="0"
...
...
UI/Views/PatchDialogView.xaml
View file @
3c22c064
...
@@ -122,15 +122,13 @@
...
@@ -122,15 +122,13 @@
Text="{Binding CommitMessage, UpdateSourceTrigger=PropertyChanged}"
Text="{Binding CommitMessage, UpdateSourceTrigger=PropertyChanged}"
IsValidInput="{Binding IsCommitMessageValid}"
IsValidInput="{Binding IsCommitMessageValid}"
Placeholder="Commit message"
Placeholder="Commit message"
Margin="5,10,10,10"
Margin="5,10,10,10" />
Visibility="{Binding IsEditable, Converter={StaticResource BoolToVisibility}}"/>
<ui:TextBoxWithPlaceholder Grid.Column="0"
<ui:TextBoxWithPlaceholder Grid.Column="0"
Grid.ColumnSpan="3"
Grid.ColumnSpan="3"
Grid.Row="3"
Grid.Row="3"
Text="{Binding Tag, UpdateSourceTrigger=PropertyChanged}"
Text="{Binding Tag, UpdateSourceTrigger=PropertyChanged}"
Placeholder="Tag (optional)"
Placeholder="Tag (optional)"
Margin="5,10,10,10"
Margin="5,10,10,10" />
Visibility="{Binding IsEditable, Converter={StaticResource BoolToVisibility}}"/>
<StackPanel Grid.Column="0"
<StackPanel Grid.Column="0"
Grid.ColumnSpan="3"
Grid.ColumnSpan="3"
Grid.Row="4"
Grid.Row="4"
...
...
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