Skip to content
This repository was archived by the owner on Jan 28, 2021. It is now read-only.

Commit ba838ce

Browse files
authored
Merge pull request #13 from XElementDev/20160607_-_AdminPrivileges
20160607_-_AdminPrivileges
2 parents a8bd341 + c169265 commit ba838ce

File tree

205 files changed

+95339
-7644
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

205 files changed

+95339
-7644
lines changed

DataTypes/IApplicationInfo.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@ public interface IApplicationInfo
88

99
IDefinitionInfo DefinitionInfo { get; }
1010

11+
// TODO: Use guid as folder name
1112
string FolderName { get; }
1213

1314
Guid Id { get; }
1415

16+
// TODO: Extend this: Use also "Herausgeber" field to identify installed application
1517
/// <summary>
1618
/// A regex that matches the name that is displayed in the installed applications list.
1719
/// </summary>
1820
string TechnicalNameMatcher { get; }
21+
22+
// TODO: Add publish year for better sorting
23+
24+
// TODO: Add series name (like "Battlefield") for better sorting (by grouping)
1925
}
2026
}

Logic/Logic.Implementation/Execution/Link/FileLink.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,39 @@
11
using System.IO;
2-
using XElement.CloudSyncHelper.DataTypes;
32

4-
namespace XElement.CloudSyncHelper.Logic.Execution
3+
namespace XElement.CloudSyncHelper.Logic.Execution.Link
54
{
65
#region not unit-tested
76
internal class FileLink : LinkBase, ILinkInt
87
{
9-
public FileLink( IApplicationInfo appInfo,
10-
IFileLinkInfo fileLinkInfo,
11-
PathVariablesDTO pathVariablesDTO )
12-
: base( appInfo, fileLinkInfo, pathVariablesDTO ) { }
8+
public FileLink( LinkParametersDTO parametersDTO,
9+
DependenciesDTO dependenciesDTO )
10+
: base( parametersDTO, dependenciesDTO ) { }
11+
1312

1413
protected override FileSystemInfo /*LinkBase.*/FileSystemInfo
1514
{
1615
get { return new FileInfo( this.LinkPath ); }
1716
}
1817

18+
1919
public override bool /*LinkBase.*/IsInCloud
2020
{
2121
get { return File.Exists( this.TargetPath ); }
2222
}
2323

24-
protected override string /*LinkBase.*/MkLinkParams { get { return string.Empty; } }
24+
25+
protected override MkLink.Type /*LinkBase.*/MkLinkType
26+
{
27+
get { return MkLink.Type.FILE_LINK; }
28+
}
29+
2530

2631
protected override void /*LinkBase.*/MoveToCloud_CopyStuff()
2732
{
2833
File.Copy( this.LinkPath, this.TargetPath );
2934
}
3035

36+
3137
public override void /*LinkBase.*/Undo()
3238
{
3339
if ( File.Exists( this.LinkPath ) )

Logic/Logic.Implementation/Execution/Link/FolderLink.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
using System;
22
using System.IO;
3-
using XElement.CloudSyncHelper.DataTypes;
43

5-
namespace XElement.CloudSyncHelper.Logic.Execution
4+
namespace XElement.CloudSyncHelper.Logic.Execution.Link
65
{
76
#region not unit-tested
87
internal class FolderLink : LinkBase, ILinkInt
98
{
10-
public FolderLink( IApplicationInfo appInfo,
11-
IFolderLinkInfo folderLinkInfo,
12-
PathVariablesDTO pathVariablesDTO )
13-
: base( appInfo, folderLinkInfo, pathVariablesDTO ) { }
9+
public FolderLink( LinkParametersDTO parametersDTO,
10+
DependenciesDTO dependenciesDTO )
11+
: base( parametersDTO, dependenciesDTO ) { }
12+
1413

1514
private void AbstractSourceDestLinker( Func<string, string[]> sourcePathsGetter,
1615
string source,
@@ -27,6 +26,7 @@ private void AbstractSourceDestLinker( Func<string, string[]> sourcePathsGetter,
2726
}
2827
}
2928

29+
3030
// Copy all levels
3131
private void CopyFilesRecursively( string source, string destination )
3232
{
@@ -39,23 +39,31 @@ private void CopyFilesRecursively( string source, string destination )
3939
( s, d ) => this.CopyFilesRecursively( s, d ) );
4040
}
4141

42+
4243
protected override FileSystemInfo /*LinkBase.*/FileSystemInfo
4344
{
4445
get { return new DirectoryInfo( this.LinkPath ); }
4546
}
4647

48+
4749
public override bool /*LinkBase.*/IsInCloud
4850
{
4951
get { return Directory.Exists( this.TargetPath ); }
5052
}
5153

52-
protected override string /*LinkBase.*/MkLinkParams { get { return "/D"; } }
54+
55+
protected override MkLink.Type /*LinkBase.*/MkLinkType
56+
{
57+
get { return MkLink.Type.DIRECTORY_LINK; }
58+
}
59+
5360

5461
protected override void /*LinkBase.*/MoveToCloud_CopyStuff()
5562
{
5663
this.CopyFilesRecursively( this.LinkPath, this.TargetPath );
5764
}
5865

66+
5967
// Copy only one level
6068
private void ShallowCopyFiles( string source, string destination )
6169
{
@@ -65,6 +73,7 @@ private void ShallowCopyFiles( string source, string destination )
6573
( s, d ) => File.Copy( s, d ) );
6674
}
6775

76+
6877
public override void /*LinkBase.*/Undo()
6978
{
7079
if ( Directory.Exists( this.LinkPath ) )

Logic/Logic.Implementation/Execution/Link/GameLogic.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System.IO;
22
using XElement.CloudSyncHelper.DataTypes;
33

4-
namespace XElement.CloudSyncHelper.Logic.Execution
4+
namespace XElement.CloudSyncHelper.Logic.Execution.Link
55
{
66
#region not unit-tested
77
internal class GameLogic : IApplicationLogic

Logic/Logic.Implementation/Execution/Link/IApplicationLogic.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace XElement.CloudSyncHelper.Logic.Execution
1+
namespace XElement.CloudSyncHelper.Logic.Execution.Link
22
{
33
internal interface IApplicationLogic
44
{

Logic/Logic.Implementation/Execution/Link/ILinkInt.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using XElement.DesignPatterns.BehavioralPatterns.Command;
22

3-
namespace XElement.CloudSyncHelper.Logic.Execution
3+
namespace XElement.CloudSyncHelper.Logic.Execution.Link
44
{
55
internal interface ILinkInt : IDoUndoCommand, ILink
66
{

Logic/Logic.Implementation/Execution/Link/LinkBase.cs

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,46 @@
11
using System;
2-
using System.Diagnostics;
32
using System.IO;
43
using XElement.CloudSyncHelper.DataTypes;
54

6-
namespace XElement.CloudSyncHelper.Logic.Execution
5+
namespace XElement.CloudSyncHelper.Logic.Execution.Link
76
{
87
#region not unit-tested
98
internal abstract class LinkBase : ILinkInt
109
{
11-
public LinkBase( IApplicationInfo appInfo,
12-
ILinkInfo linkInfo,
13-
PathVariablesDTO pathVariablesDTO )
10+
public LinkBase( LinkParametersDTO parametersDTO,
11+
DependenciesDTO dependenciesDTO )
1412
{
15-
this._linkInfo = linkInfo;
16-
this._pathVariablesDTO = pathVariablesDTO;
13+
this._mkLinkExecutorFactory = dependenciesDTO.MkLinkExecutorFactory;
14+
15+
this._linkInfo = parametersDTO.LinkInfo;
16+
this._pathVariablesDTO = parametersDTO.PathVariablesDTO;
1717
this._symLinkHelper = new SymbolicLinkHelper();
1818

19-
Initialize( appInfo );
19+
Initialize( parametersDTO.ApplicationInfo );
2020
}
2121

22+
2223
private void CreatePathToDestinationTarget()
2324
{
2425
Directory.CreateDirectory( this.PathToDestinationTarget );
2526
}
2627

28+
2729
public void /*ILink.*/Do()
2830
{
2931
this.CreatePathToDestinationTarget();
3032
this.Undo();
31-
this.ExecuteCmd();
32-
}
3333

34-
private void ExecuteCmd()
35-
{
36-
var mkLink = this.GetCmdCommand();
37-
var process = new Process();
38-
process.StartInfo.FileName = "cmd.exe";
39-
process.StartInfo.Arguments = "/c " + mkLink;
40-
process.StartInfo.CreateNoWindow = true;
41-
process.StartInfo.UseShellExecute = false;
42-
process.StartInfo.Verb = "runas";
43-
process.Start();
44-
45-
process.WaitForExit();
34+
var mkLinkParams = new MkLink.ParametersDTO
35+
{
36+
Link = this.LinkPath,
37+
Target = this.TargetPath,
38+
Type = this.MkLinkType
39+
};
40+
this._mkLinkExecutorFactory.Get( mkLinkParams ).Execute();
4641
}
4742

43+
4844
private bool DoesSymbolicLinkPointToExpectedPath
4945
{
5046
get
@@ -54,13 +50,9 @@ private bool DoesSymbolicLinkPointToExpectedPath
5450
}
5551
}
5652

53+
5754
protected abstract FileSystemInfo FileSystemInfo { get; }
5855

59-
private string GetCmdCommand()
60-
{
61-
return String.Format( "MKLINK {0} \"{1}\" \"{2}\"", this.MkLinkParams,
62-
this.LinkPath, this.TargetPath );
63-
}
6456

6557
private void Initialize( IApplicationInfo programInfo )
6658
{
@@ -74,8 +66,10 @@ private void Initialize( IApplicationInfo programInfo )
7466
}
7567
}
7668

69+
7770
public abstract bool /*ILink.*/IsInCloud { get; }
7871

72+
7973
public bool /*ILink.*/IsLinked
8074
{
8175
get
@@ -85,6 +79,7 @@ public bool /*ILink.*/IsLinked
8579
}
8680
}
8781

82+
8883
private bool IsSymbolicLink
8984
{
9085
get
@@ -94,6 +89,7 @@ private bool IsSymbolicLink
9489
}
9590
}
9691

92+
9793
public string /*ILink.*/LinkPath
9894
{
9995
get
@@ -104,16 +100,20 @@ public string /*ILink.*/LinkPath
104100
}
105101
}
106102

107-
protected abstract string MkLinkParams { get; }
103+
104+
protected abstract MkLink.Type MkLinkType { get; }
105+
108106

109107
public void /*ILink.*/MoveToCloud()
110108
{
111109
Directory.CreateDirectory( this.PathToCloudUserFolder );
112110
this.MoveToCloud_CopyStuff();
113111
}
114112

113+
115114
protected abstract void MoveToCloud_CopyStuff();
116115

116+
117117
private string PathToDestinationTarget
118118
{
119119
get
@@ -123,6 +123,7 @@ private string PathToDestinationTarget
123123
}
124124
}
125125

126+
126127
private string PathToCloudUserFolder
127128
{
128129
get
@@ -135,6 +136,7 @@ private string PathToCloudUserFolder
135136
}
136137
}
137138

139+
138140
public string /*ILink.*/TargetPath
139141
{
140142
get
@@ -144,9 +146,12 @@ public string /*ILink.*/TargetPath
144146
}
145147
}
146148

149+
147150
public abstract void /*ILink.*/Undo(); // TODO: Delete folders if they are empty
148151

152+
149153
private ILinkInfo _linkInfo;
154+
private MkLink.IFactory _mkLinkExecutorFactory;
150155
private PathVariablesDTO _pathVariablesDTO;
151156
private IApplicationLogic _programLogic;
152157
private SymbolicLinkHelper _symLinkHelper;
Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
using XElement.CloudSyncHelper.DataTypes;
2-
using XElement.CloudSyncHelper.Logic.Execution;
32

4-
namespace XElement.CloudSyncHelper.Logic
3+
namespace XElement.CloudSyncHelper.Logic.Execution.Link
54
{
65
#region not unit-tested
76
public class LinkFactory : ILinkFactory
87
{
9-
public LinkFactory() { }
8+
public LinkFactory( MkLink.IFactory mkLinkExecutorFactory )
9+
{
10+
this._mkLinkExecutorFactory = mkLinkExecutorFactory;
11+
}
12+
1013

1114
public ILink Get( IApplicationInfo appInfo,
1215
ILinkInfo linkInfo,
@@ -20,25 +23,29 @@ public ILink Get( IApplicationInfo appInfo,
2023
};
2124
return this.Get( linkParamsDTO );
2225
}
26+
2327
public ILink Get( LinkParametersDTO linkParametersDTO )
2428
{
2529
ILink link = null;
2630

31+
var dependenciesDTO = new Link.DependenciesDTO
32+
{
33+
MkLinkExecutorFactory = this._mkLinkExecutorFactory
34+
};
2735
if ( linkParametersDTO.LinkInfo is IFolderLinkInfo )
2836
{
29-
link = new FolderLink( linkParametersDTO.ApplicationInfo,
30-
linkParametersDTO.LinkInfo as IFolderLinkInfo,
31-
linkParametersDTO.PathVariablesDTO );
37+
link = new FolderLink( linkParametersDTO, dependenciesDTO );
3238
}
3339
else
3440
{
35-
link = new FileLink( linkParametersDTO.ApplicationInfo,
36-
linkParametersDTO.LinkInfo as IFileLinkInfo,
37-
linkParametersDTO.PathVariablesDTO );
41+
link = new FileLink( linkParametersDTO, dependenciesDTO );
3842
}
3943

4044
return link;
4145
}
46+
47+
48+
protected MkLink.IFactory _mkLinkExecutorFactory;
4249
}
4350
#endregion
4451
}

Logic/Logic.Implementation/Execution/Link/ToolLogic.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System.IO;
22
using XElement.CloudSyncHelper.DataTypes;
33

4-
namespace XElement.CloudSyncHelper.Logic.Execution
4+
namespace XElement.CloudSyncHelper.Logic.Execution.Link
55
{
66
#region not unit-tested
77
internal class ToolLogic : IApplicationLogic

0 commit comments

Comments
 (0)