forked from ildar-shaimordanov/jsxt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDENWERLink3.hta
347 lines (284 loc) · 7.26 KB
/
DENWERLink3.hta
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
<html>
<!--
DENWER
Copyright (C) 2001-2005 Dmitry Koteroff
DENWER Link Creator
Copyright (C) 2005,2008 Ildar Shaimordanov
-->
<head>
<HTA:APPLICATION ID="oHTA"
APPLICATIONNAME="DENWERLink"
BORDER="dialog"
BORDERSTYLE="static"
CAPTION="yes"
CONTEXTMENU="no"
ICON=""
INNERBORDER="no"
MAXIMIZEBUTTON="no"
MINIMIZEBUTTON="no"
NAVIGABLE="no"
SCROLL="no"
SCROLLFLAT="no"
SELECTION="no"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="yes"
VERSION="1.0"
WINDOWSTATE="normal"/>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
<title>DENWER Link</title>
<style type="text/css">
* {
font-family: Verdana, Helvetica, Tahoma, 'Courier New', sans-serif;
}
body {
background-color: #CCCCCC;
font-family: Verdana, Helvetica, Tahoma, 'Courier New', sans-serif;
margin: 10px;
padding: 0;
text-align: left;
}
table {
width: 100%;
}
.label {
text-align: right;
vertical-align: top;
width: 150px;
}
select {
width: 100%;
}
.button {
width: 100px;
}
</style>
<script type="text/javascript" language="javascript">
// System dependent handlers
var fso = new ActiveXObject('Scripting.FileSystemObject');
var wsh = new ActiveXObject('WScript.Shell');
// DENWER installed folders
var denwerCtrlPath2 = 'etc';
var denwerCtrlPath3 = 'denwer';
var denwerStdFolders = [
'(' + denwerCtrlPath2 + '|' + denwerCtrlPath3 + ')',
'home',
'tmp',
'usr'
];
var denwerStdFoldersRegex = new RegExp('\\b(?:' + denwerStdFolders.join('|') + ')\\b', 'g');
// DENWER control applications
var shortcuts = [
{
name: 'Start servers',
prog: 'Run.exe',
wstyle: 1,
hotkey: '',
icon: 'run.ico',
descr: '',
wdir: ''
},
{
name: 'Stop servers',
prog: 'Stop.exe',
wstyle: 1,
hotkey: '',
icon: 'stop.ico',
descr: '',
wdir: ''
},
{
name: 'Restart servers',
prog: 'Restart.exe',
wstyle: 1,
hotkey: '',
icon: 'restart.ico',
descr: '',
wdir: ''
}
];
// Lookup DENWER installation
function getDenwerFolder(spec)
{
var f = fso.GetFolder(spec);
var fc = new Enumerator(f.SubFolders);
var result = [];
for ( ; ! fc.atEnd(); fc.moveNext()) {
var folder = fc.item();
result[result.length] = folder.Name;
}
// amount of folders at least the same as amount of the DENWER folders
if ( denwerStdFolders.length > result.length ) {
return false;
}
// contains the same folders like the DENWER
result = result.sort().join(':').match(denwerStdFoldersRegex);
if ( ! result || result.length != denwerStdFolders.length ) {
return false;
}
// Control path /etc for DENWER-2 and /denwer for DENWER-3
var denwerCtrlPath = result[0];
// contains control files exactly
for (var i = 0; i < shortcuts.length; i++) {
if ( ! fso.FileExists(spec + '\\' + denwerCtrlPath + '\\' + shortcuts[i].prog) ) {
return false;
}
if ( ! fso.FileExists(spec + '\\' + denwerCtrlPath + '\\utils\\' + shortcuts[i].icon) ) {
return false;
}
}
return spec;
};
function getDenwerList()
{
var result = [];
var e = new Enumerator(fso.Drives);
for ( ; ! e.atEnd(); e.moveNext()) {
var drive = e.item();
// skip network drives
if ( drive.DriveType == 3 ) {
continue;
}
// ready drives only
if ( ! drive.IsReady ) {
continue;
}
// specific folders only
var path = getDenwerFolder(drive.RootFolder);
if ( path ) {
// this the DENWER drive
result[result.length] = path;
} else {
// lookup for DENWER folder
var f = fso.GetFolder(drive.RootFolder);
var fc = new Enumerator(f.SubFolders);
for ( ; ! fc.atEnd(); fc.moveNext()) {
var folder = fc.item();
path = getDenwerFolder(folder);
if ( path ) {
result[result.length] = path;
}
}
}
}
return result;
};
function createDenwerList()
{
var list = getDenwerList();
if ( list && list.length ) {
document.getElementById('execute').disabled = false;
}
var installPath = document.getElementById('installpath');
for (var i = 0; i < list.length; i++) {
installPath.options[i] = new Option(list[i], list[i]);
}
};
// Creator of shortcuts
function createShortcut(location, installPath, shortcut)
{
// workaround to differ DENWER-2 and DENWER-3 when creating shortcuts
if ( fso.FolderExists(installPath + '\\' + denwerCtrlPath3) ) {
var denwerCtrlPath = denwerCtrlPath3;
var shortcutName = shortcut.name.replace(/servers/, 'Denwer');
} else {
var denwerCtrlPath = denwerCtrlPath2;
var shortcutName = shortcut.name;
}
var lnk = wsh.CreateShortcut(location + '\\' + shortcutName + '.lnk');
lnk.TargetPath = installPath + '\\' + denwerCtrlPath + '\\' + shortcut.prog;
lnk.WindowStyle = shortcut.wstyle;
lnk.HotKey = shortcut.hotkey;
lnk.IconLocation = installPath + '\\' + denwerCtrlPath + '\\utils\\' + shortcut.icon;
lnk.Description = shortcut.descr;
lnk.WorkingDirectory = (shortcut.wdir) ? shortcut.wdir : installPath + '\\' + denwerCtrlPath;
lnk.Save();
};
function execCreateShortcut()
{
var allUsers, location, installPath;
allUsers = document.getElementById('allusers').checked;
location = document.getElementById('location').options;
location = location.options[location.selectedIndex].value;
if ( allUsers ) {
location = 'AllUsers' + location;
}
location = wsh.SpecialFolders(location);
installPath = document.getElementById('installpath').options;
installPath = installPath.options[installPath.selectedIndex].value;
if ( location.match(/Startup/) ) {
createShortcut(location, installPath, shortcuts[0]);
} else {
for (var i = 0; i < shortcuts.length; i++) {
createShortcut(location, installPath, shortcuts[i]);
}
}
if (confirm('All links are created.\nClose the application?')) {
window.close();
}
};
</script>
<script type="text/javascript" language="javascript">
// Initialization of window
function initWin()
{
if (oHTA.applicationName !== "DENWERLink") {
window.close();
return;
}
// sets window size
with (window.screen) {
var w = 600, h = 400;
moveTo((width - w) / 2, (height - h) / 2);
resizeTo(w, h);
}
createDenwerList();
};
</script>
</head>
<body onload="initWin()">
<p>
<h4>DENWER Link Version 3</h4>
Utility for creating of links for the DENWER
</p>
<form>
<table>
<tr>
<td class="label">
<label for="installpath">DENWER folder</label>
</td>
<td>
<select id="installpath" size="5">
<option></option>
</select>
</td>
</tr>
<tr>
<td class="label">
<label for="location">Location</label>
</td>
<td>
<select id="location" size="3">
<option value="Desktop">Desktop</option>
<option value="StartMenu">Start Menu</option>
<option value="Startup">Startup</option>
</select>
</td>
</tr>
<tr>
<td class="label"> </td>
<td>
<input type="checkbox" id="allusers" value="1" /><label for="allusers">For all users</label>
</td>
</tr>
<tr>
<td class="label"> </td>
<td>
<input type="button" class="button" id="execute" value="Create" disabled="disabled" onclick="execCreateShortcut()" />
<input type="button" class="button" id="close" value="Close" onclick="window.close()" />
</td>
</tr>
</table>
</form>
</body>
</html>