-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
305 lines (257 loc) · 13 KB
/
Copy pathProgram.cs
File metadata and controls
305 lines (257 loc) · 13 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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
namespace RandomFilePicker
{
public static class Program
{
/// <summary>
/// General program mode - are we picking a file randomly, showing a list of files, or quiting.
/// </summary>
enum pickModes
{
single = 1,
threaded = 2,
noPick = 3
}
/// <summary>
/// List of follow-up strings that we are expecting.
/// </summary>
enum parseModes
{
Default = 1,
exclude = 2,
filetype = 3,
repeatDur = 4,
repeatCnt = 5,
overrideext = 6,
overrideapp = 7,
loadfile = 8,
cache_min = 9,
cache_max = 10,
cachefolder =11
}
private static pickModes PickMode = pickModes.single;
private static parseModes ParseMode = parseModes.Default;
private static List<String> commands = new List<string>();
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
try
{
//Load all the commands in args[] into a list so that we can add to them later if we get passed a filename,
foreach (String s1 in args)
{
commands.Add(s1);
}
string s = "";
string lastext = "";
if (args.Length > 0)
{
while (commands.Count > 0)
{
s = commands[0];
s.Trim();
commands.RemoveAt(0);
switch (ParseMode)
{
//deafault mode
case parseModes.Default:
switch (s)
{
case "-x":
ParseMode = parseModes.exclude;
break;
case "-nr":
PickRandomFile.recurse = false;
break;
case "-1":
PickRandomFile.firstfileonly = true;
break;
case "-shuffle":
PickRandomFile.shuffle = true;
break;
case "-stat":
PickRandomFile.showStats = true;
break;
case "-i":
PickRandomFile.ignoreMissingFolders = true;
break;
case "-f":
ParseMode = parseModes.filetype;
PickRandomFile.usingFileTypes = true;
break;
case "-?":
Help helpwindow = new Help(
"Usage: \n" +
"<dir>" + "\t\t" + "Include directory" + "\n" +
"-c" + "\t\t" + "Choose file after search" + "\n" +
"-x <dir>" + "\t\t" + "Exclude directory" + "\n" +
"-nr" + "\t\t" + "Disable recursing directories" + "\n" +
"-f <list>" + "\t\t" + "Comma separated list of filetypes (e.g. .avi,.mpg,.mpeg)" + "\n" +
"-r" + "\t\t" + "Repeat pick files " + "\n" +
"-rc <cnt>" + "\t\t" + "How many times to repeat the pick operation (infinite if not specified)" + "\n" +
"-rd <dur>" + "\t\t" + "Duration between pick attempts (seconds)" + "\n" +
"-stat" + "\t\t" + "Show stats (for certain modes) in the window" + "\n" +
"-cachestats" + "\t\t" + "Show cache / pick stats" + "\n" +
"-1" + "\t\t" + "Pick first file in directory" + "\n" +
"-o <ext> <app>" + "\t" + "Override app to open a filetype with" + "\n" +
"-l <filename>" + "\t" + "Load a set of commands from a file" + "\n" +
"-h" + "\t" + "Runs any spawned applications in the background" + "\n" +
"-i" + "\t" + "Silently ignore any missing directories" + "\n" +
"-shuffle" + "\t" + "Picks one at a time until all files have been picked once" + "\n" +
"-cache <min> <max>" + "\t" + "Cache file access for min < x < max hours" + "\n" +
"-cachefolder <directory>" + "\t" + "Folder where cache data should be written" + "\n" +
"--" + "\t" + "Null argument, use in scripts as a placeholder" + "\n" +
"\n" +
"Example File:" + "\n" +
"-f" + "\n" +
".avi,.mpg,.mpeg,.mkv,.mp4,.rm" + "\n" +
@"E:\eps\30 rock" + "\n" +
@"E:\eps\drawn together" + "\n" +
@"E:\eps\Harvey Birdman" + "\n"
);
Application.Run(helpwindow);
PickMode = pickModes.noPick;
break;
case "-h":
PickRandomFile.hideSpawnedWindows = true;
break;
case "-c":
PickRandomFile.showChooser = true;
break;
case "-r":
PickMode = pickModes.threaded;
break;
case "-rc":
ParseMode = parseModes.repeatCnt;
break;
case "-rd":
ParseMode = parseModes.repeatDur;
break;
case "-o":
ParseMode = parseModes.overrideext;
break;
case "-l":
ParseMode = parseModes.loadfile;
break;
case "-cachestats":
PickRandomFile.showCacheStats = true;
break;
case "-cache":
PickRandomFile.useCache = true;
ParseMode = parseModes.cache_min;
break;
case "-cachefolder":
ParseMode = parseModes.cachefolder;
break;
case "--":
//Nothing needed here
break;
default:
PickRandomFile.addPath(s);
break;
}
break;
//exclude directory mode
case parseModes.exclude:
ParseMode = parseModes.Default;
PickRandomFile.excludePath(s);
break;
case parseModes.cachefolder:
ParseMode = parseModes.Default;
PickRandomFile.cachefolder = s;
break;
case parseModes.filetype:
ParseMode = parseModes.Default;
PickRandomFile.usingFileTypes = true;
PickRandomFile.fileFilter = s;
string[] split = s.Split(',');
foreach (string filetype in split)
{
PickRandomFile.addFileType(filetype);
}
break;
case parseModes.repeatDur:
ParseMode = parseModes.Default;
int duration;
if (Int32.TryParse(s, out duration))
{
PickRandomFile.threadWaitDuration = duration * 1000;
}
break;
case parseModes.repeatCnt:
ParseMode = parseModes.Default;
int count;
if (Int32.TryParse(s, out count))
{
PickRandomFile.threadRepeatCount = count;
}
break;
case parseModes.overrideext:
ParseMode = parseModes.overrideapp;
lastext = s;
break;
case parseModes.overrideapp:
ParseMode = parseModes.Default;
PickRandomFile.addOverride(lastext, s);
break;
case parseModes.loadfile:
//load a file one row at a time into args[]
ParseMode = parseModes.Default;
StreamReader f = new StreamReader(s);
string line;
while ((line = f.ReadLine()) != null)
{
commands.Add(line);
}
break;
case parseModes.cache_min:
ParseMode = parseModes.cache_max;
PickRandomFile.cacheHoursMin = Convert.ToInt32(s);
break;
case parseModes.cache_max:
ParseMode = parseModes.Default;
PickRandomFile.cacheHoursMax = Convert.ToInt32(s);
break;
}
}
#region pickModes
switch (PickMode)
{
case pickModes.single:
PickRandomFile.scanDirectories();
if (PickRandomFile.showChooser)
{
PickRandomFile.pickChoice();
}
else
{
PickRandomFile.pickRandom();
}
break;
case pickModes.threaded:
Application.Run(new Monitor());
break;
}
#endregion
}
//else
//{
// Application.EnableVisualStyles();
// Application.SetCompatibleTextRenderingDefault(false);
// Application.Run(new Monitor());
//}
}
catch (Exception e)
{
MessageBox.Show(e.StackTrace + "\n\n" + e.InnerException + "\n\n" + e.Source + "\n\n" + e.Data , e.Message);
}
}
}
}