-
Notifications
You must be signed in to change notification settings - Fork 119
/
ChoAppCmdLineArgs.cs
117 lines (104 loc) · 3.73 KB
/
ChoAppCmdLineArgs.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
using Cinchoo.Core;
using Cinchoo.Core.Diagnostics;
using Cinchoo.Core.IO;
using Cinchoo.Core.Shell;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
namespace ChoEazyCopy
{
[ChoCommandLineArgObject(DisplayDefaultValue = true, UsageSwitch = "_")]
public class ChoShellExtCmdLineArgs : ChoCommandLineArgObject
{
[ChoCommandLineArg("d", Description = "Source directory.", Order = -2)]
public string Directory
{
get;
set;
}
}
[ChoCommandLineArgObject(DisplayDefaultValue = true, UsageSwitch = "_")]
public class ChoFileAssociationCmdLineArgs : ChoCommandLineArgObject
{
[ChoPositionalCommandLineArg(1, "SettingsFilePath", Description = "Settings file path.")]
public string SettingsFilePath
{
get;
set;
}
public bool IsAppFile;
protected override void OnAfterCommandLineArgObjectLoaded(string[] commandLineArgs)
{
if (!SettingsFilePath.IsNullOrWhiteSpace())
{
IsAppFile = Path.GetExtension(SettingsFilePath) == AppHost.AppFileExt;
}
}
}
[ChoCommandLineArgObject(DisplayDefaultValue=true)]
public class ChoAppCmdLineArgs : ChoCommandLineArgObject
{
[ChoPositionalCommandLineArg(1, "SettingsFilePath", Description = "Settings file path.", IsRequired = true)]
public string SettingsFilePath
{
get;
set;
}
[ChoCommandLineArg("s", Description = "Source directory.", Order = 2, NoOfTabsSwitchDescFormatSeparator=3)]
public string SourceDirectory
{
get;
set;
}
[ChoCommandLineArg("d", Description = "Destination directory.", Order = 3, NoOfTabsSwitchDescFormatSeparator = 3)]
public string DestDirectory
{
get;
set;
}
protected override void OnAfterCommandLineArgObjectLoaded(string[] commandLineArgs)
{
if (!SettingsFilePath.IsNullOrWhiteSpace())
{
SettingsFilePath = ChoPath.GetFullPath(SettingsFilePath);
}
}
public void StartFileCopy(string sourceDirectory = null, string destDirectory = null)
{
try
{
ChoAppSettings appSettings = new ChoAppSettings();
if (!SettingsFilePath.IsNullOrWhiteSpace())
{
if (!File.Exists(SettingsFilePath))
throw new ArgumentException("Can't find '{0}' settings file.".FormatString(SettingsFilePath));
appSettings.LoadXml(File.ReadAllText(SettingsFilePath));
}
ChoConsole.WriteLine();
ChoRoboCopyManager _roboCopyManager = new ChoRoboCopyManager(SettingsFilePath);
_roboCopyManager.Status += (sender, e) =>
{
ChoTrace.Write(e.Message);
ChoConsole.Write(e.Message, ConsoleColor.Yellow);
};
_roboCopyManager.AppStatus += (sender, e) =>
{
ChoTrace.Write(e.Message);
ChoConsole.Write(e.Message, ConsoleColor.Yellow);
};
_roboCopyManager.Process(appSettings, true);
}
catch (ThreadAbortException)
{
Console.WriteLine("RoboCopy operation cancelled by user.");
}
catch (Exception ex)
{
Console.WriteLine("RoboCopy operation failed." + Environment.NewLine + ChoApplicationException.ToString(ex));
}
}
}
}