-
Notifications
You must be signed in to change notification settings - Fork 0
/
CLI.cs
86 lines (74 loc) · 2.4 KB
/
CLI.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PersonalFolder {
class CLI {
private static Func<string, bool> matchContext;
private static Action closeContext;
public static void Init (string[] args) {
foreach (var arg in args) {
if (matchContext != null) {
if (matchContext(arg)) continue;
else DisposeMatcher();
}
switch (arg) {
case "--clear-cache":
ClearCache();
break;
case "--sync":
MainForm.Sync();
break;
case "--update-settings":
closeContext = () => SettingsForm.WriteData();
matchContext = MatchSettingsUpdate;
break;
}
}
DisposeMatcher();
}
private static void DisposeMatcher () {
if (closeContext != null)
closeContext();
closeContext = null;
matchContext = null;
}
private static void ClearCache () {
if (SettingsForm.data.inited) {
SettingsForm.data.cache.Clear();
SettingsForm.data.lastSync = 0;
}
SettingsForm.WriteData();
}
private static string paramName;
private static bool MatchSettingsUpdate (string arg) {
if (paramName != null) {
UpdateSettings(arg);
return true;
}
switch (arg) {
case "--local-path":
paramName = "localPath";
break;
case "--remove-path":
paramName = "remotePath";
break;
default:
return false;
}
return true;
}
private static void UpdateSettings (string value) {
switch (paramName) {
case "localPath":
SettingsForm.data.localPath = value;
break;
case "remotePath":
SettingsForm.data.remotePath = value;
break;
}
paramName = null;
}
}
}