-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
237 lines (211 loc) · 10.4 KB
/
Copy pathProgram.cs
File metadata and controls
237 lines (211 loc) · 10.4 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
using System;
namespace VersionManager
{
class Program
{
static void Main(string[] args)
{
if (ConfigurationManager.ProjectsRoots.Length == 0 ||
ConfigurationManager.SourcesRoots.Length == 0)
{
Console.WriteLine("Administrator Configuration Error: ProjectsRoot or SourcesRoot is not configured in App.config.");
return;
}
if (TryParseVersionCommand(args, out string projectName, out ArchiveMode archiveMode))
{
VersionManager.CreateVersion(projectName, archiveMode);
return;
}
if (args.Length == 1 && IsHelp(args[0]))
{
PrintUsage();
return;
}
if (args.Length == 2)
{
string command = args[0].ToLowerInvariant();
string name = args[1];
switch (command)
{
case "list":
RestoreManager.ListVersions(name);
break;
case "restore":
RestoreManager.RestoreVersion(name);
break;
case "snapshot":
VersionManager.CreateSnapshot(name);
break;
default:
PrintUsage();
break;
}
return;
}
PrintUsage();
}
private static bool TryParseVersionCommand(string[] args, out string projectName, out ArchiveMode archiveMode)
{
projectName = null;
archiveMode = ArchiveMode.None;
if (args.Length == 0 || args.Length > 3)
return false;
if (args.Length == 1)
{
if (IsHelp(args[0]))
return false;
projectName = args[0];
return true;
}
if (args.Length == 2 && IsKnownCommand(args[0]))
return false;
string project = null;
for (int i = 0; i < args.Length; i++)
{
string arg = args[i];
if (TryParseArchiveTypeFlag(arg, out ArchiveMode mode))
{
archiveMode = mode;
continue;
}
if (arg.Equals("-archive", StringComparison.OrdinalIgnoreCase))
{
if (i + 1 < args.Length && TryParseArchiveTypeValue(args[i + 1], out ArchiveMode typeMode))
{
archiveMode = typeMode;
i++;
}
continue;
}
if (!IsHelp(arg))
project = arg;
}
if (string.IsNullOrEmpty(project))
return false;
projectName = project;
return true;
}
private static bool TryParseArchiveTypeFlag(string arg, out ArchiveMode mode)
{
if (arg.Equals("-archive-git", StringComparison.OrdinalIgnoreCase))
{
mode = ArchiveMode.Git;
return true;
}
if (arg.Equals("-archive-project", StringComparison.OrdinalIgnoreCase))
{
mode = ArchiveMode.Project;
return true;
}
mode = ArchiveMode.None;
return false;
}
private static bool TryParseArchiveTypeValue(string arg, out ArchiveMode mode)
{
if (arg.Equals("git", StringComparison.OrdinalIgnoreCase))
{
mode = ArchiveMode.Git;
return true;
}
if (arg.Equals("project", StringComparison.OrdinalIgnoreCase))
{
mode = ArchiveMode.Project;
return true;
}
mode = ArchiveMode.None;
return false;
}
private static bool IsKnownCommand(string arg)
{
switch (arg.ToLowerInvariant())
{
case "list":
case "restore":
case "snapshot":
return true;
default:
return false;
}
}
private static bool IsHelp(string arg)
{
return arg.Equals("/?", StringComparison.OrdinalIgnoreCase) ||
arg.Equals("-h", StringComparison.OrdinalIgnoreCase) ||
arg.Equals("--help", StringComparison.OrdinalIgnoreCase);
}
private static void PrintUsage()
{
Console.WriteLine("======================================================================");
Console.WriteLine("Version Manager - Help & Documentation");
Console.WriteLine("======================================================================");
Console.WriteLine("Version Manager is a thin abstraction layer over Git that provides");
Console.WriteLine("a simple versioning system for non-technical users.");
Console.WriteLine();
Console.WriteLine("All Git commands are executed internally and hidden from the user.");
Console.WriteLine();
Console.WriteLine("ADMINISTRATOR CONFIGURATION:");
Console.WriteLine(" Configuration is loaded from App.config. It contains:");
Console.WriteLine(" - ProjectsRoot : Semicolon-separated root directories containing user projects.");
Console.WriteLine(" - SourcesRoot : Semicolon-separated root directories where version archives are stored.");
Console.WriteLine(" - ArchivePassword : Password used to encrypt/decrypt ZIP archives.");
Console.WriteLine(" - LogFilePath : Path to the application log file.");
Console.WriteLine();
Console.WriteLine("COMMANDS:");
Console.WriteLine();
Console.WriteLine(" 1. Create a New Version");
Console.WriteLine(" Usage: Version.exe [ProjectName]");
Console.WriteLine(" Version.exe -archive-git [ProjectName]");
Console.WriteLine(" Version.exe -archive-project [ProjectName]");
Console.WriteLine(" Version.exe [ProjectName] -archive git");
Console.WriteLine(" Version.exe [ProjectName] -archive project");
Console.WriteLine(" Description:");
Console.WriteLine(" - Locates the project folder by scanning each configured ProjectsRoot.");
Console.WriteLine(" - Initializes Git internally if not already present.");
Console.WriteLine(" - Detects if there are any modified, deleted, or untracked files.");
Console.WriteLine(" If no changes are detected, the process exits without saving.");
Console.WriteLine(" - Prompts the user to enter a version Comment.");
Console.WriteLine(" - Internally stages and commits the changes.");
Console.WriteLine(" - By default, only the Git repository is updated (no ZIP archive).");
Console.WriteLine(" - With -archive-git (or -archive git), also compresses only the");
Console.WriteLine(" .git directory into Version00x.zip.");
Console.WriteLine(" - With -archive-project (or -archive project), also compresses the");
Console.WriteLine(" entire project folder into VersionProject00x.zip.");
Console.WriteLine(" - Appends version history data (Version index, Date/Time, Comment)");
Console.WriteLine(" to 'History.txt' in the project's archive storage directory.");
Console.WriteLine();
Console.WriteLine(" 2. List Available Versions");
Console.WriteLine(" Usage: Version.exe list [ProjectName]");
Console.WriteLine(" Description:");
Console.WriteLine(" - Reads version history from History.txt across configured SourcesRoot paths.");
Console.WriteLine(" - Displays all saved versions with their sequential index,");
Console.WriteLine(" date/time of creation, archive type, and commit comment.");
Console.WriteLine();
Console.WriteLine(" 3. Restore a Version");
Console.WriteLine(" Usage: Version.exe restore [ProjectName]");
Console.WriteLine(" Description:");
Console.WriteLine(" - Displays versions available for restoration.");
Console.WriteLine(" - Prompts the user to enter the number (index) of the version");
Console.WriteLine(" they wish to restore.");
Console.WriteLine(" - Restores from a git archive (-archive-git) when available.");
Console.WriteLine(" - Otherwise restores from the local Git history in the project.");
Console.WriteLine(" - Performs a hard reset and clean to discard all uncommitted");
Console.WriteLine(" modifications and restore files to the exact state they were in.");
Console.WriteLine(" - Project archives (-archive-project) cannot be restored with this command.");
Console.WriteLine();
Console.WriteLine(" 4. Create a Snapshot (Full Backup)");
Console.WriteLine(" Usage: Version.exe snapshot [ProjectName]");
Console.WriteLine(" Description:");
Console.WriteLine(" - Compresses the entire project directory from the located ProjectsRoot.");
Console.WriteLine(" into a single password-protected ZIP archive named Snapshot00x.zip.");
Console.WriteLine(" - Stored directly in the project's archive directory.");
Console.WriteLine(" - Excludes nothing, serving as a raw filesystem backup.");
Console.WriteLine();
Console.WriteLine("GENERAL HELP:");
Console.WriteLine(" Show this help screen:");
Console.WriteLine(" Version.exe -h");
Console.WriteLine(" Version.exe --help");
Console.WriteLine(" Version.exe /?");
Console.WriteLine("======================================================================");
}
}
}