-
Notifications
You must be signed in to change notification settings - Fork 0
/
Options.cs
124 lines (119 loc) · 3.22 KB
/
Options.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
118
119
120
121
122
123
124
using System;
using System.IO;
using System.Windows.Forms;
namespace LnkUtils
{
public static class Options
{
public static void Usage()
{
Log.Message("Usage: "+nameof(LnkUtils)+" (command) [options]"
+"\n Commands:"
+"\n"
+"\n Check (path to folder or .lnk file) [options]"
+"\n - tests link files for bad paths"
+"\n"
+"\n Check Options:"
+"\n -r recurse into sub-folders"
+"\n -v print extra information about links"
+"\n -a show all links not just bad ones"
+"\n"
+"\n Create [options]"
+"\n - create a new link"
+"\n"
+"\n Create Options:"
+"\n -t (path) path to target"
+"\n -n (path) name of link file (defaults to 'target file name'.lnk)"
+"\n -c (text) comment"
+"\n -s (path) start in path"
// +"\n -k (key) shortcut key"
// +"\n -r (run) starting window state"
+"\n -i (path) [index] path to .ico file or .dll/.exe. index defaults to 0"
// +"\n -a enable run as administrator"
+"\n -f force create even if target doesn't exist"
);
}
public static bool Parse(string[] args)
{
// System.Windows.Forms.Keys
int len = args.Length;
for(int a=0; a<len; a++)
{
string curr = args[a];
if (Action == Command.None) {
if (!Enum.TryParse<Command>(curr ?? "",true,out Action)) {
Log.Error("Invalid action "+curr);
return false;
}
}
else if (Action == Command.Check) {
if (curr == "-r") {
Recurse = true;
}
else if (curr == "-v") {
Verbose = true;
}
else if (curr == "-a") {
ShowAll = true;
}
else {
Target = curr;
}
}
else if (Action == Command.Create) {
if (curr == "-t" && ++a < len) {
Target = Path.GetFullPath(args[a]);
}
else if (curr == "-n" && ++a < len) {
LnkFileName = args[a];
}
else if (curr == "-c" && ++a < len) {
Comment = args[a];
}
else if (curr == "-s" && ++a < len) {
StartIn = args[a];
}
else if (curr == "k" && ++a < len) {
//TODO
}
else if (curr == "-r" && ++a < len) {
//TODO
}
else if (curr == "-i" && ++a < len) {
string snum = args[a+1];
IconPath = args[a];
if (int.TryParse(snum,out int num)) {
IconIndex = num; ++a;
}
}
else if (curr == "-a") {
EnableAdmin = true;
//TODO not used yet
}
else if (curr == "-f") {
Force = true;
}
}
}
return true;
}
public enum Command
{
None = 0,
Check = 1,
Create = 2
}
public static Command Action = Command.None;
public static bool Recurse = false;
public static bool Verbose = false;
public static bool ShowAll = false;
public static string Target = null;
public static string Comment = null;
public static string StartIn = null;
public static string IconPath = null;
public static int IconIndex = 0;
public static bool EnableAdmin = false;
public static string LnkFileName = null;
public static bool Force = false;
}
}