-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMountWatch.Main.n
More file actions
98 lines (73 loc) · 2.86 KB
/
Copy pathMountWatch.Main.n
File metadata and controls
98 lines (73 loc) · 2.86 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
/*
* MountWatch version 0.1 by nicksabaka@gmail.com
*/
using Nini.Config;
using Nemerle.Collections;
using Nemerle.Extensions;
using Nemerle.Utility;
//using Nemerle.Text;
using System;
using System.IO;
using System.Diagnostics;
using System.Text;
using System.Threading.Thread;
//using System.Windows.Forms;
namespace MountWatch {
module MountWatchMain
{
static Main(args : array[string]) : void
{
def conf = IniConfigSource(
if (args.Length > 0)
args[0]
else
Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName)
+ @"\"
+ Path.GetFileNameWithoutExtension(Process.GetCurrentProcess().MainModule.FileName)
+ @".ini"
);
conf.ExpandKeyValues();
def batchfile = conf.Configs["diskpart"].Get("batch", "portable.dpt");
mutable count = 0;
using (def ps = Process())
{
ps.StartInfo.FileName = "diskpart.exe";
ps.StartInfo.UseShellExecute = true;
ps.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
mutable batch = array(10) : array[string];
mutable cmd = conf.Configs["diskpart"].Get(count.ToString(), "");
while (cmd.Length > 0 && count <= 100)
{
when (count >= 10)
Array.Resize(ref batch, batch.Length + 1);
batch[count] = cmd;
count++;
cmd = conf.Configs["diskpart"].Get(count.ToString(), "");
}
File.WriteAllLines(batchfile, batch, Encoding.UTF8);
ps.StartInfo.Arguments = "/s" + batchfile;
ignore( ps.Start() );
}
unless (Directory.Exists(conf.Configs["watch"].Get("volume", "p") + @":\"))
Sleep(conf.Configs["watch"].GetInt("delay", 1) * 1000);
File.Delete(batchfile);
count = 0;
mutable exe = conf.Configs["autorun"].Get("exec." + count.ToString(), "");
while (exe.Length > 0)
{
when (File.Exists(exe))
{
def ps = Process();
ps.StartInfo.FileName = exe;
ps.StartInfo.UseShellExecute = true;
ps.StartInfo.Arguments =
conf.Configs["autorun"].Get("args." + count.ToString(), "");
ignore( ps.Start() );
Console.WriteLine(exe);
}
count++;
exe = conf.Configs["autorun"].Get("exec." + count.ToString(), "");
}
}
}
}