-
Notifications
You must be signed in to change notification settings - Fork 0
/
winsettings.js
551 lines (512 loc) · 19 KB
/
winsettings.js
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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
tps.sys.RestartHTA(tps.sys.processOption.requestAdmin | tps.sys.processOption.escapeWOW64);
var G = {
path_conf: tps.sys.GetScriptDir(),
path_greensoft: "c:\\cloud\\soft",
path_srcroot: tps.file.FirstExistDir(["c:\\src", "d:\\src", "e:\\src"]) || "d:\\src",
username: shell.Environment("Process")("USERNAME"),
path_profile: shell.Environment("Process")("USERPROFILE"),
path_autorun: shell.SpecialFolders("Startup"),
path_autorun_alluser: shell.SpecialFolders("AllUsersStartup")
};
G.path_softconf = "c:\\cloud\\softconf";
var GUI = {
max_cellwidth: 0,
cell_columns: 0
};
function SimpleRegistryTask(name, values) {
values = [].concat(values);
this.name = name;
this.check = function () {
for (var i in values) {
var v = values[i];
if (v.val == null) {
if (tps.reg.GetStringValue(v.key, v.valname) == null &&
tps.reg.GetIntValue(v.key, v.valname) == null)
return false;
}
else if (typeof v.val === 'string') {
if (v.val != tps.reg.GetStringValue(v.key, v.valname)) return false;
} else {
if (v.val != tps.reg.GetIntValue(v.key, v.valname)) return false;
}
}
return true;
};
this.run = function () {
var uncomplete = false;
for (var i in values) {
var v = values[i];
tps.reg.CreateKey(v.key);
if (v.val == null) {
uncomplete = true;
}
else if (typeof v.val === 'string') {
tps.reg.SetStringValue(v.key, v.valname, v.val);
} else {
tps.reg.SetIntValue(v.key, v.valname, v.val);
}
}
if (uncomplete) {
alert("manual configuration still needed.");
}
};
}
function RunAtLogonTask(name, cmdline, elevate) {
this.name = "autostart: " + name;
this.check = function () {
var o = tps.sys.RunCommandAndGetResult("schtasks.exe /query /tn " + name).output;
return o.indexOf(name) != -1;
};
this.run = function () {
var cmd = 'schtasks.exe /create /sc ONLOGON /tn ' + name + ' /tr "cmd.exe /C start """' + name + '""" ' + cmdline + '"';
if (elevate) cmd += ' /rl HIGHEST';
alert(cmd);
var o = tps.sys.RunCommandAndGetResult(cmd);
alert(o.output ? o.output : o.errors);
};
}
function AutoRunTask(name, target, args, alluser) {
this.name = "autorun: " + name;
this.check = function () {
var filter = new RegExp(name, "i");
var local = tps.file.Glob(G.path_autorun, filter, 1).length > 0;
var global = tps.file.Glob(G.path_autorun_alluser, filter, 1).length > 0;
return (alluser && !local && global) || (!alluser && local && !global);
};
this.run = function () {
var filename = name + ".lnk";
// first delete both
try {
fso.DeleteFile(G.path_autorun + "\\" + filename);
fso.DeleteFile(G.path_autorun_alluser + "\\" + filename);
} catch (e) { }
// create the right one
var dir = alluser ? G.path_autorun_alluser : G.path_autorun;
tps.log.Event("shortcut:" + dir + "\\" + filename + " --> " + target + " " + args);
tps.file.CreateShortcut(dir + "\\" + filename, target, "", args);
};
}
function EnvTask(name, value) {
this.name = "env: " + name;
this.check = function () {
return tps.sys.GetSystemEnv(name) == value;
}
this.run = function () {
tps.sys.SetSystemEnv(name, value);
}
}
function AddToPathTask(name, path) {
path = [].concat(path);
this.name = "Add " + name + " to PATH";
this.check = function () {
for (var i in path) {
if (!tps.sys.InPath(tps.sys.systemEnv, path[i])) return false;
}
return true;
}
this.run = function () {
for (var i in path) {
tps.sys.AddToPath(tps.sys.systemEnv, path[i]);
}
}
}
var tasks = [
//new AutoRunTask("handyrun", G.path_greensoft + "\\handyrun\\handyrun.exe", "", false),
//new RunAtLogonTask("mactype", G.path_greensoft + "\\mactype\\MacTray.exe", true),
new RunAtLogonTask("autoit", G.path_greensoft + "\\autoit\\autoit3.exe " + G.path_softconf + "\\hotkey.au3", false),
//new AutoRunTask("autoit", G.path_greensoft + "\\autoit\\autoit3.exe", G.path_softconf + "\\hotkey.au3", false),
//new AutoRunTask("mactype", G.path_greensoft + "\\mactype\\MacTray.exe", "", false),
//new RunAtLogonTask("ultrasearch", G.path_greensoft + "\\ultrasearch\\ultrasearch.exe", true),
//new EnvTask("GS", G.path_greensoft),
//new EnvTask("SRCROOT", G.path_srcroot),
//new EnvTask("SOFTCONF", G.path_softconf),
{
name: "Explorer favorites",
check: function () {
return tps.file.Glob(G.path_profile + "\\Links", /G40/i, 1).length > 0;
},
run: function () {
tps.file.CreateShortcut(G.path_profile + "\\Links\\G40.lnk", "\\\\stcsrv-g40.fareast.corp.microsoft.com\\Share\\tongjunhui");
}
},
new AddToPathTask("%GS%\\cmdline", G.path_greensoft + "\\cmdline"),
new AddToPathTask("MikTex", G.path_greensoft + "\\texmfs\\install\\miktex\\bin"),
new AddToPathTask("dmd", G.path_greensoft + "\\dmd2\\windows\\bin"),
new AddToPathTask("sdtools", [
G.path_greensoft + "\\sdtools",
G.path_greensoft + "\\sdtools\\sdpack\\bin"
]),
new SimpleRegistryTask("Explore view setting", [
{
key: "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced",
valname: "Hidden",
val: 1
},
{
key: "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced",
valname: "HideFileExt",
val: 0
}
]),
new SimpleRegistryTask("Install 7zip",
{
key: "HKCR\\*\\shellex\\ContextMenuHandlers\\7-Zip",
valname: "",
val: null
}
),
new SimpleRegistryTask("Disable shell hotkeys",
{
key: "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced",
valname: "DisabledHotKeys",
val: "awq"
}
),
new SimpleRegistryTask("Emacs context menu",
{
key: "HKCR\\*\\shell\\Open With Emacs\\command",
valname: "",
val: "wscript.exe \"%GS%\\emacs\\emacs.wsf\" -n -- \"%1\"".replace("%GS%", G.path_greensoft)
}
),
new SimpleRegistryTask("Register .org file", [
{
key: "HKCU\\Software\\Classes\\EmacsClient\\shell\\open\\command",
valname: "",
val: "wscript.exe c:\\cloud\\soft\\emacs\\emacs.wsf -n -- \"%1\""
},
{
key: "HKCU\\Software\\Classes\\.org",
valname: "",
val: "EmacsClient"
},
{
key: "HKCU\\Software\\Classes\\EmacsClient\\DefaultIcon",
valname: "",
val: "c:\\cloud\\soft\\emacs\\bin\\emacs.exe"
}
]),
new SimpleRegistryTask("Register .apk file", [
{
key: "HKCU\\Software\\Classes\\.apk",
valname: "",
val: "apkfile"
},
{
key: "HKCU\\Software\\Classes\\apkfile\\DefaultIcon",
valname: "",
val: "c:\\cloud\\PICTURE\\apk.ico"
},
{
key: "HKCU\\Software\\Classes\\apkfile\\shell\\Open\\command",
valname: "",
val: "c:\\cloud\\soft\\cmdline\\installapk.bat \"%1\""
},
{
key: "HKCU\\Software\\Classes\\apkfile\\shell\\Remove Sign\\command",
valname: "",
val: "c:\\cloud\\soft\\cmdline\\removeapksign.bat \"%1\""
},
{
key: "HKCU\\Software\\Classes\\apkfile\\shell\\View Certificate\\command",
valname: "",
val: "c:\\cloud\\soft\\cmdline\\viewcert.bat \"%1\""
},
{
key: "HKCU\\Software\\Classes\\apkfile\\shell\\Zip Align\\command",
valname: "",
val: "c:\\cloud\\soft\\cmdline\\zipalignapk.bat \"%1\""
}
]),
new SimpleRegistryTask("DisableAeroShake",
{
key: "HKCU\\Software\\Policies\\Microsoft\\Windows\\Explorer",
valname: "NoWindowMinimizingShortcuts",
val: 1
}
// need restart explorer.exe
),
{
name: "Font Link Callback",
// if we meet any of MSGOTHIC.TTC, MSJH.TTC, MSYH.TTC but haven't meet target CN font, we insert it
check: function () {
var fonts = tps.reg.EnumValues(this.keypath());
for (var i in fonts) {
var font = fonts[i].name;
var val = fonts[i].valstr.split("\\0");
tps.log.Debug("checking font:" + font);
tps.log.Indent();
for (var j in val) {
tps.log.Debug(val[j]);
if (val[j].beginWithOneOf(this.checkingTargetFont())) break;
if (val[j].beginWithOneOf(this.cnFont())) {
tps.log.Unindent();
tps.log.Debug("check failed");
return false;
}
}
tps.log.Unindent();
}
return true;
},
run: function () {
var fonts = tps.reg.EnumValues(this.keypath());
for (var i in fonts) {
var font = fonts[i].name;
tps.log.Event("processing font: " + font);
var val = fonts[i].valstr.split("\\0");
var newVal = [];
var targetAdded = false;
for (var j in val) {
var item = val[j];
if (targetAdded) {
if (!item.beginWithOneOf(this.checkingTargetFont())) {
newVal.push(item);
}
} else {
if (item.beginWithOneOf(this.cnFont())) {
newVal.push(this.targetFont());
targetAdded = true;
}
newVal.push(item);
}
}
tps.reg.SetMultiStringValue(this.keypath(), font, newVal);
}
},
keypath: function () {
return "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\FontLink\\SystemLink";
},
cnFont: function () {
return ["msgothic.ttc", "msjh.ttc", "msyh.ttc", "simsun.ttc", "mingliu.ttc", "qingyuan.ttc"];
},
targetFont: function () {
//return "QingYuan.TTC,QingYuan";
return "SimSun.TTC,SimSun"
},
checkingTargetFont: function () {
return this.targetFont().split(",").slice(0, 1);
}
},
{
name: "Font Link Fix",
run: function () {
var fonts = tps.reg.EnumValues(this.keypath());
for (var i in fonts) {
var font = fonts[i].name;
var val = fonts[i].valstr.split("\\0");
for (var j in val) {
if (val[j] == "SimSun.ttc,SimSun,128,96") {
val.splice(j, 1);
tps.log.Event("processing font: " + font);
tps.reg.SetMultiStringValue(this.keypath(), font, val);
break;
}
}
}
},
keypath: function () {
return "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\FontLink\\SystemLink";
},
},
{
name: "Font Link special",
check: function () {
var fontlinks = this.fontLinks();
var fonts = tps.reg.EnumValues(this.keypath());
for (var fontname in fontlinks) {
var value = "";
for (var i in fonts) {
if (fonts[i].name == fontname) value = fonts[i].valstr;
}
if (value != fontlinks[fontname].join("\\0")) return false;
}
return true;
},
run: function () {
var fontlinks = this.fontLinks();
for (var fontname in fontlinks) {
tps.reg.SetMultiStringValue(this.keypath(), fontname, fontlinks[fontname]);
}
},
keypath: function () {
return "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\FontLink\\SystemLink";
},
fontLinks: function () {
var target = ["QingYuan.ttc, QingYuan"];
return {
"Consolas": target,
"Source Code Pro": target,
"Monaco": target,
"Bitstream Vera Sans Mono": target
};
}
},
{
name: "outlook url protocol",
check: function () {
return tps.reg.StringValueExists("HKCR\\outlook\\shell\\open\\command", null);
},
run: function () {
tps.reg.SetStringValue("HKCR\\outlook", null, "URL:OutlookItem");
tps.reg.SetStringValue("HKCR\\outlook", "URL Protocol", "");
tps.reg.SetStringValue("HKCR\\outlook\\shell\\open\\command", null, tps.util.DoubleQuote(this.outlookpath()) + ' /select "%1"');
},
outlookpath: function () {
return tps.reg.GetStringValue("HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\OUTLOOK.EXE", null);
}
},
{
name: "Ubuntu on Windows setup",
check: function () {
var bashrc = tps.file.ReadTextFileSimple(this.bashrcpath());
return bashrc.indexOf(this.mybashpath) >= 0;
},
run: function() {
var text = '\n. ' + tps.util.DoubleQuote(this.mybashpath) + '\n';
tps.file.AppendTextFileSimple(text, this.bashrcpath());
},
bashrcpath: function () {
return shell.ExpandEnvironmentStrings("%localappdata%\\lxss\\home\\timepp\\.bashrc");
},
mybashpath: "/mnt/c/Users/idtong/OneDrive/softconf/mybash.sh"
}
];
var ops = [];
function Init() {
tps.log.AddHtmlElementDevice(document.getElementById("log"));
for (var i in tasks) {
if (tasks[i].name) {
ops.push(tasks[i]);
}
}
var tc = document.getElementById("task_c");
for (var i in ops) {
var op = ops[i];
var cell = document.createElement("span");
cell.innerText = op.name;
cell.className = "task_cell";
tc.appendChild(cell);
if (GUI.max_cellwidth < cell.offsetWidth) GUI.max_cellwidth = cell.offsetWidth;
tc.removeChild(cell);
op.status = false;
}
window.onresize = OnWindowResize;
OnWindowResize();
tps.log.Debug("System Information: ");
tps.log.Indent();
for (var x in G) {
tps.log.Debug(x + ": " + G[x]);
}
tps.log.Unindent();
for (var i in ops) {
var op = ops[i];
try {
if (op.hasOwnProperty("initialize")) op.initialize();
if (op.hasOwnProperty("check")) op.status = op_check(op);
MarkStatus(op.cell, op.status);
}
catch (e) {
var msg = e;
if (e.hasOwnProperty("message")) msg = e.message;
tps.log.Warning("[$T]: task check failed: $M".replace("$T", op.name).replace("$M", msg));
}
}
AddGradientBK(document.getElementById("log_header"), "skyblue", "#FFFFFF");
}
function OnWindowResize() {
RecalcLayout();
}
function RecalcLayout() {
var oLog = document.getElementById("log");
var tbl = document.getElementById("task_table");
var tbl_hdr = document.getElementById("log_header");
var cols = Math.floor(document.body.offsetWidth / GUI.max_cellwidth);
if (cols < 1) cols = 1;
if (cols != GUI.cell_columns) {
GUI.cell_columns = cols;
while (tbl.rows.length > 0) {
tbl.deleteRow(0);
}
var rows = Math.ceil(ops.length / cols);
for (var i = 0; i < rows; i++) {
var row = tbl.insertRow(-1);
for (var j = 0; j < cols; j++) {
if (j * rows + i >= ops.length) continue;
var op = ops[j * rows + i];
var cell = row.insertCell(-1);
cell.appendChild(document.createTextNode(op.name));
cell.className = "task_cell";
cell.op = op;
cell.style.width = GUI.max_cellwidth;
cell.onclick = OnTaskClick;
op.cell = cell;
MarkStatus(cell, op.status);
}
}
}
var h = document.body.offsetHeight - tbl.offsetHeight - tbl_hdr.offsetHeight - 40;
if (h > 100) {
oLog.style.height = h;
}
}
function ClearLog() {
document.getElementById("log").innerHTML = "";
}
function AddGradientBK(o, c1, c2, tp) {
if (c2 == null) c2 = "#FFFFFF";
if (tp == null) tp = 1;
o.style.background = "linear-gradient(to right, %sc, %ec)".replace("%sc", c1).replace("%ec", c2).replace("%tp", tp);
}
function OnTaskClick() {
var cell = window.event.srcElement;
var op = cell.op;
var has_chk_method = op.hasOwnProperty("check");
var has_run_method = op.hasOwnProperty("run");
if (has_chk_method) {
if (has_run_method) {
op_run(op);
}
op.status = op_check(op);
}
else {
if (op.status) {
if (confirm("Reset this task to undone?")) op.status = false;
}
else {
if (has_run_method) {
op_run(op);
op.status = confirm("Task done but cannot check...");
}
else {
op.status = confirm("$T: This task must be done manually...".replace("$T", op.name));
}
}
}
MarkStatus(cell, cell.op.status);
}
function op_run(op) {
tps.log.Event("run task: " + op.name);
tps.log.Indent();
try { op.run(); } catch (e) {
var msg = e;
if (e.hasOwnProperty("message")) msg = e.message;
tps.log.Warning("[$T]: failed. $M".replace("$T", op.name).replace("$M", msg));
}
tps.log.Unindent();
}
function op_check(op) {
tps.log.Event("check " + op.name);
tps.log.Indent();
var ret = false;
try {
ret = op.check();
} catch (e) {
var msg = e;
if (e.hasOwnProperty("message")) msg = e.message;
tps.log.Error("task check failed: $M".replace("$T", op.name).replace("$M", msg));
}
tps.log.Unindent();
return ret;
}
function MarkStatus(o, c) { AddGradientBK(o, c ? "#CCFFCC" : "#FFCCCC"); }