summaryrefslogtreecommitdiff
path: root/odk/cfgWin.js
blob: 81fed0585805ebe79591490c242315fd8fba5dd0 (plain)
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
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
// This script asks for variables, which are necessary for building the
// examples of the Office Development Kit. The script duplicates the template
// script and inserts the variables into the copied script.
// The Script was developed for the operating systems Microsoft Windows.
var regKeyOfficeCurrentUser = "HKEY_CURRENT_USER\\Software\\LibreOffice\\UNO\\InstallPath\\";
var regKeyOfficeLocaleMachine = "HKEY_LOCAL_MACHINE\\Software\\LibreOffice\\UNO\\InstallPath\\";
var regKeyDotNetInstallRoot = "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\.NETFramework\\InstallRoot";
var regKeyDotNet1_1 = "HKLM\\Software\\Microsoft\\.NETFramework\\policy\\v1.1\\4322";
var sDirDotNet1_1 = "v1.1.4322";
var regKeyDotNet2_0 = "HKLM\\Software\\Microsoft\\.NETFramework\\Policy\\v2.0\\50727";
var sDirDotNet2_0 = "v2.0.50727";

var regKeyJDK = "HKLM\\Software\\JavaSoft\\Java Development Kit\\";
//var regKeyVC70 = "HKLM\\SOFTWARE\\Microsoft\\VisualStudio\\7.0\\Setup\\VC\\ProductDir";
//var regKeyVC71 = "HKLM\\SOFTWARE\\Microsoft\\VisualStudio\\7.1\\Setup\\VC\\ProductDir";
var regKeyVC90 = "HKLM\\SOFTWARE\\Microsoft\\VisualStudio\\9.0\\Setup\\VC\\ProductDir";

//var regKeyVCExpress80 = "HKLM\\SOFTWARE\\Microsoft\\VCExpress\\8.0\\Setup\\VC\\ProductDir";
var regKeyVCExpress90 = "HKLM\\SOFTWARE\\Microsoft\\VCExpress\\9.0\\Setup\\VC\\ProductDir";

var regKeyWindowsSDK = "HKLM\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\CurrentInstallFolder";

var WshShell = WScript.CreateObject("WScript.Shell");
var WshSysEnv = WshShell.Environment("process");
var aFileSystemObject =  new ActiveXObject("Scripting.FileSystemObject");
var stdin = WScript.StdIn;
var stdout = WScript.StdOut;

stdout.WriteLine("\n" +
" *** Configure your SDK environment ***\n\n" +
" NOTE: This script is working only for Windows 2000, Windows XP or newer versions!\n");

var oo_sdk_name=WshSysEnv("OO_SDK_NAME");
var oo_sdk_home=getSdkHome();
var oo_user_sdk_dir=WshSysEnv("APPDATA") + "\\" + oo_sdk_name;
var oo_user_sdk_env_script=oo_user_sdk_dir + "\\setsdkenv_windows.bat";

var office_home=getOfficeHome();
var oo_sdk_ure_home=getUreHome();

var oo_sdk_make_home=getMakeHome();
var oo_sdk_zip_home=getZipHome();
var oo_sdk_manifest_used="";
var oo_sdk_windowssdk="";
var oo_sdk_cpp_home=getCppHome();
var oo_sdk_cli_home=getCliHome();
var oo_sdk_java_home=getJavaHome();
var oo_sdk_out=getOutputDir();
var sdk_auto_deployment=getAutoDeployment();

writeBatFile(oo_user_sdk_dir, oo_user_sdk_env_script);

stdout.Write(
	"\n ******************************************************************\n" +
    " * ... \"" + oo_user_sdk_env_script + "\"\n" +
    " * batch file has been prepared.\n" +
    " * This batch file will be used in the future to prepare your\n" +
	" * personal configured SDK environment.\n" +
	" ******************************************************************\n\n");
//    " * For each time you want to use this configured SDK environment,\n" +
//    " * you have to run the \"setsdkenv_windows.bat\" file in a new shell!\n" +

// done -------------------------------------------------------------------------


function skipChoice(msg)
{
	stdout.Write("\n Do you want to skip the choice of " + msg + " (YES/NO) [YES]:");
	var sChoice = stdin.ReadLine();
    if (sChoice == "" || sChoice.toLowerCase() == "yes")
	   return true;

	return false;
}

function getSdkHome()
{
	var sSuggestedHome = WshSysEnv("OO_SDK_HOME");
    if (sSuggestedHome.length == 0) {
        var scriptname = WScript.ScriptFullName;
        sSuggestedHome = scriptname.substr(0,scriptname.length-10);
    }
    
    while(true)
    {
        stdout.Write("\n Enter the Office Software Development Kit directory [" +
                     sSuggestedHome + "]:");
        var sHome = stdin.ReadLine();
        if (sHome.length == 0)
        {
            //No user input, use default. 
            if ( ! aFileSystemObject.FolderExists(sSuggestedHome))
            {
                stdout.WriteLine("\n Error: Could not find directory \"" +
                                 sSuggestedHome + "\". An SDK is required, please" +
								 " specify the path to a valid installation.");
                continue;
            }       
            sHome = sSuggestedHome;
        }
        else
        {
            //validate the user input
            if ( ! aFileSystemObject.FolderExists(sHome))
            {
                stdout.WriteLine("\n Error: The directory \"" + sHome + 
                                 "\" does not exist. Please enter the path to a" +
								 "valid SDK installation.");
                continue;
            }
        }
        //Check if this is an sdk folder by looking for the idl sub - dir
        var idlDir = sHome + "\\idl";
        if (! aFileSystemObject.FolderExists(idlDir))
        {
            stdout.WriteLine("\n Error: Could not find directory \"" +
                             idlDir + "\". An SDK is required, please specify " +
                             "the path to a valid SDK installation.");
            continue;
        }

        return sHome;
    }   
}

function getOfficeOrUre()
{
    var suggestion = "Office";
    var choice;
    while (choice != "office" && choice != "ure") {
        stdout.Write(
            "\n Use an installed Office or an installed UNO Runtime"
            + " Environment (Office/URE) [" + suggestion + "]:");
        choice = stdin.ReadLine();
        if (choice == "") {
            choice = suggestion;
        }
        choice = choice.toLowerCase();
    }
    return choice;
}

function getOfficeHome()
{
    var sSuggestedHome = WshSysEnv("OFFICE_HOME");
    if (sSuggestedHome.length == 0)
    {
        try {   
            sSuggestedHome = WshShell.RegRead(regKeyOfficeCurrentUser);
			//The registry entry points to the program folder but we need the 
			//installation folder
        } catch(exc) {}
        if (sSuggestedHome.length == 0)
        {
            try {
                sSuggestedHome = WshShell.RegRead(regKeyOfficeLocaleMachine);
                //The registry entry points to the program folder but we need 
				//the installation folder
            } catch (exc) {}
        }

		var index=0;
        if ((index = sSuggestedHome.lastIndexOf("\\")) != -1)   
		   sSuggestedHome = sSuggestedHome.substr(0, index);

        if (sSuggestedHome.length == 0)
		   sSuggestedHome = searchOffice();
    }
    
    while(true)
    {
        stdout.Write("\n Enter the Office base installation directory [" +
                     sSuggestedHome + "]:");
        var sHome = stdin.ReadLine();
        if (sHome.length == 0)
        {
            //No user input, use default. 
            if ( ! aFileSystemObject.FolderExists(sSuggestedHome))
            {
                stdout.WriteLine("\n Error: Could not find directory \"" + 
                                 sSuggestedHome + "\" An office installation is " +
								 "required, please specify the path to a valid " +
								 "office installation.");
                sSuggestedHome = "";
                continue;
            }       
            sHome = sSuggestedHome;
        } else
        {
            //validate the user input
            if ( ! aFileSystemObject.FolderExists(sHome))
            {
                stdout.WriteLine("\n Error: The directory \"" + sHome + 
                                 "\" does not exist. Please specify the path to " +
								 "a valid office installation.");
                continue;
            }
        }
        //Check if this is a valid office installtion folder by looking for the 
		//program sub-directory
        var progDir = sHome + "\\program";
        if (! aFileSystemObject.FolderExists(progDir))
        {
            stdout.WriteLine("\n Error: Could not find directory \"" +
                             progDir + "\". An office installation is required, " +
							 "please specify the path to a valid office " +
							 "installation.");
            continue;
        }
        return sHome;
    }
}

function searchOffice()
{
	var tmp = oo_sdk_home;

	if (aFileSystemObject.FileExists(tmp + "\\program\\soffice.exe")) {
	   return tmp;
	}
  
	return "";
}


function getUreHome()
{
	var tmpure = oo_sdk_home;
	var ure = "";

    if (aFileSystemObject.FileExists(tmpure + "\\URE\\bin\\uno.exe")) {
	   ure = tmpure + "\URE";
	}

	return ure;

/*
    var suggestion = WshSysEnv("OO_SDK_URE_HOME");
    var choice;
    for (;;) {
        stdout.Write(
            "\n Enter the URE installation directory [" + suggestion + "]:");
        choice = stdin.ReadLine();
        if (choice == "") {
            choice = suggestion;
        }
        if (aFileSystemObject.FileExists(choice + "\\bin\\uno.exe")) {
            break;
        }
        stdout.WriteLine("\n Error: A valid URE installation is required.");
    }
    return choice;
*/
}

function getMakeHome()
{
    var sSuggestedHome = WshSysEnv("OO_SDK_MAKE_HOME");
    
    while(true)
    {
        stdout.Write("\n Enter GNU make (3.79.1 or higher) tools directory [" +
                     sSuggestedHome + "]:");
        var sHome = stdin.ReadLine();
        if (sHome.length == 0)
        {
            //No user input, use default. 
            if ( ! aFileSystemObject.FolderExists(sSuggestedHome))
            {
                stdout.WriteLine("\n Error: Could not find directory \"" +
								 sSuggestedHome + "\". GNU make is required, " +
								 "please specify a GNU make tools directory.");
                sSuggestedHome = "";
                continue;
            }       
            sHome = sSuggestedHome;
        } else
        {
            //validate the user input
            if ( ! aFileSystemObject.FolderExists(sHome))
            {
                stdout.WriteLine("\n Error: The directory \"" + sHome + 
                                 "\" does not exist. GNU make is required, " +
								 "please specify a GNU make tools directory.");
                continue;
            }
        }
        //Check for the make executable
        var sMakePath = sHome + "\\make.exe";
        if (! aFileSystemObject.FileExists(sMakePath))
	{
		sMakePath = sHome + "\\mingw32-make.exe";
	}
        if (! aFileSystemObject.FileExists(sMakePath))
        {
            stdout.WriteLine("\n Error: Could not find \"" + sMakePath + 
							 "\". GNU make is required, please specify a GNU " +
							 "make tools directory.");
            continue;
        }
        return sHome;
    }   
}

function getZipHome()
{
    var sSuggestedHome = WshSysEnv("OO_SDK_ZIP_HOME");
    
    while(true)
    {
        stdout.Write("\n Enter a zip (2.3 or higher) tools directory [" +
                     sSuggestedHome + "]:");
        var sHome = stdin.ReadLine();
        if (sHome.length == 0)
        {
            //No user input, use default. 
            if ( ! aFileSystemObject.FolderExists(sSuggestedHome))
            {
                stdout.WriteLine("\n Error: Could not find directory \"" + 
								 sSuggestedHome + "\". zip is required, please " +
								 "specify a zip tools directory.");
                sSuggestedHome = "";
                continue;
            }       
            sHome = sSuggestedHome;
        }
        else
        {
            //validate the user input
            if ( ! aFileSystemObject.FolderExists(sHome))
            {
                stdout.WriteLine("\n Error: The directory \"" + sHome + 
                                 "\" does not exist. zip is required, please " +
								 "specify a zip tools directory.");
                continue;
            }
        }
        //Check for the make executable
        var sZipPath = sHome + "\\zip.exe";
        if (! aFileSystemObject.FileExists(sZipPath))
        {
            stdout.WriteLine("\n Error: Could not find \"" + sZipPath + 
                             "\". zip is required, please specify a zip tools " +
							 "directory.");
            continue;
        }
        return sHome;
    }   
}

function getCppHome()
{
    var sSuggestedHome = WshSysEnv("OO_SDK_CPP_HOME");
    if (sSuggestedHome.length == 0)
    {       
        var sVC="";
        try {
            sVC = WshShell.RegRead(regKeyVCExpress90);
        }catch (exc) {}
        if (sVC.length == 0)
        {
	        try {
				sVC = WshShell.RegRead(regKeyVC90);
			}catch (exc) {}
		}        
		// check Windows SDK if VC 9
        if (sVC.length > 0)
        {
		    oo_sdk_manifest_used="true";	
			try {
				oo_sdk_windowssdk = WshShell.RegRead(regKeyWindowsSDK);
			}catch (exc) {}
		}
        if (sVC.length == 0)
        {
	        try {
				sVC = WshShell.RegRead(regKeyVCExpress80);
			}catch (exc) {}
	        if (sVC.length > 0)
			   oo_sdk_manifest_used="true";
		}        
        if (sVC.length == 0)
        {
	        try {
				sVC = WshShell.RegRead(regKeyVC80);
			}catch (exc) {}
	        if (sVC.length > 0)
			   oo_sdk_manifest_used="true";
		}        
        if (sVC.length == 0)
        {
	        try {
				sVC = WshShell.RegRead(regKeyVC71);
			}catch (exc) {}
		}        
        if (sVC.length > 0)
        {
            sVC += "bin";
            if (aFileSystemObject.FileExists(sVC + "\\cl.exe"))
                sSuggestedHome = sVC;			
        }
    }

    var bSkip = false;       
    while(true)
    {
        stdout.Write("\n Enter the directory of the C++ compiler (optional) [" +
                     sSuggestedHome + "]:");
        var sHome = stdin.ReadLine();
        if (sHome.length == 0)
        {
            //No user input, check OO_SDK_CPP_HOME or suggested value
	    if ( sSuggestedHome.length == 0 ) {
		bSkip = true;
	    } else {
	        if ( !aFileSystemObject.FolderExists(sSuggestedHome) )
		{
		    stdout.WriteLine("\n Error: Could not find directory \"" +
				     sSuggestedHome + "\".");
		    sSuggestedHome = "";
		    bSkip = true;
		}
	    }
       
            sHome = sSuggestedHome;
        } else
        {
            //validate the user input
            if ( ! aFileSystemObject.FolderExists(sHome))
            {
                stdout.WriteLine("\n Error: Could not find directory \"" +
                                 sHome + "\".");
                bSkip = true;
            }
        }

		if ( !bSkip) {
		    //Check if the C++ compiler exist
		    var cl = sHome + "\\cl.exe";
		    var mt = sHome + "\\mt.exe";
        
			if (! aFileSystemObject.FileExists(cl))
			{
				stdout.WriteLine("\n Error: Could not find the C++ compiler \"" 
								 + cl + "\".");
				sHome = "";
				bSkip = true;
			} else {
			    if (aFileSystemObject.FileExists(mt)) {
				    oo_sdk_vc8_used="true";				   
				}
			}
		}

		if ( bSkip ) { 
		   if ( skipChoice("the C++ compiler") ) {
			   return "";
		   } else {
			   bSkip = false;
			   continue;
		   }
		}

        return sHome;
    }   
}

function getCliHome()
{
    var sSuggestedHome = WshSysEnv("OO_SDK_CLI_HOME");
    
    if (sSuggestedHome.length == 0)
    {
        try {
            var _ver = WshShell.RegRead(regKeyDotNet2_0);
            if (_ver.length > 0)
            {
                sSuggestedHome = WshShell.RegRead(regKeyDotNetInstallRoot);
                sSuggestedHome += sDirDotNet2_0;
                if ( ! aFileSystemObject.FolderExists(sSuggestedHome))
                    sSuggestedHome = "";
            }

			if (sSuggestedHome.length == 0) 
			{
				_ver = WshShell.RegRead(regKeyDotNet1_1);
				if (_ver.length > 0)
				{
					sSuggestedHome = WshShell.RegRead(regKeyDotNetInstallRoot);
					sSuggestedHome += sDirDotNet1_1;
					if ( ! aFileSystemObject.FolderExists(sSuggestedHome))
					   sSuggestedHome = "";
				}
			}				
		} catch (exc) {}
    }
    
    var bSkip = false;       
    while(true)
    {
        stdout.Write("\n Enter the directory of the C# and VB.NET compilers (optional) [" + sSuggestedHome + "]:");
        var sHome = stdin.ReadLine();
        if (sHome.length == 0)
        {
            //No user input, check OO_SDK_CLI_HOME or suggested value
			if ( sSuggestedHome.length == 0 ) {
			    bSkip = true;
			} else {
			    if ( !aFileSystemObject.FolderExists(sSuggestedHome) )
				{
					stdout.WriteLine("\n Error: Could not find directory \"" + 
									 sSuggestedHome + "\".");
					sSuggestedHome = "";
					bSkip = true;
				} 
			}

		    sHome = sSuggestedHome;
        }
        else
        {
            //validate the user input
            if ( ! aFileSystemObject.FolderExists(sHome))
            {
                stdout.WriteLine("\n Error: The directory \"" + sHome + 
                                 "\" does not exist.");
                bSkip = true;
            }
        }

		if ( !bSkip ) {
		    //Check if the C# and VB.NET compiler exist
		    var csc = sHome + "\\csc.exe";
		    var vbc = sHome + "\\vbc.exe";
        
			if (! aFileSystemObject.FileExists(csc)) 
			{
				stdout.WriteLine("\n Error: Could not find the C# compiler \"" + 
								 csc + "\".");
				bSkip = true;
			}
			if (! aFileSystemObject.FileExists(vbc))
			{
				stdout.WriteLine("\n Error: Could not find the VB.NET compiler \"" +
								 vbc + "\".");
				bSkip = true;
			}
		}

		if ( bSkip ) { 
		   if ( skipChoice("the C# and VB.NET compilers") ) {
			   return "";
		   } else {
			   bSkip = false;
			   continue;
		   }
		}

        return sHome;
    }   
}

function getJavaHome()
{
    var sSuggestedHome = WshSysEnv("OO_SDK_JAVA_HOME");
    if (sSuggestedHome.length == 0)
    {
        try {
            var currentVersion = WshShell.RegRead(regKeyJDK + "CurrentVersion");
            if (currentVersion.length > 0)
            {
                sSuggestedHome = WshShell.RegRead(regKeyJDK + currentVersion + 
												  "\\JavaHome");           
                if ( ! aFileSystemObject.FolderExists(sSuggestedHome) )
                    sSuggestedHome = "";
            }
        } catch (exc) {}
    }
    
    var bSkip = false;       
    while(true)
    {
        stdout.Write("\n Enter JAVA SDK (1.4.1_01 or higher) installation directory (optional) [" + sSuggestedHome + "]:");
        var sHome = stdin.ReadLine();
        if (sHome.length == 0)
        {
            //No user input, check OO_SDK_JAVA_HOME or suggested value
			if ( sSuggestedHome.length == 0 ) {
			    bSkip = true;
			} else {
			    if ( !aFileSystemObject.FolderExists(sSuggestedHome) )
				{
					stdout.WriteLine("\n Error: Could not find directory \"" + 
									 sSuggestedHome + "\".");
					sSuggestedHome = "";
					bSkip=true;
				}
			}	
			
			sHome = sSuggestedHome;
        } else
        {
            //validate the user input
            if ( ! aFileSystemObject.FolderExists(sHome))
            {
                stdout.WriteLine("\n Error: The directory \"" + sHome + 
                                 "\" does not exist.");
				bSkip = true;
            }
        }

		if ( !bSkip) {
		    //Check if this is an sdk folder by looking for the javac compiler
			var javacompiler = sHome + "\\bin\\javac.exe";
			if (! aFileSystemObject.FileExists(javacompiler))
			{
				stdout.WriteLine("\n Error: Could not find \"" +
								 javacompiler + "\".");
				bSkip = true;
			}
        }

		if ( bSkip ) { 
		   if ( skipChoice("the Java SDK") ) {
			   return "";
		   } else {
			   bSkip = false;
			   continue;
		   }
		}

        return sHome;
    }   
}

function getOutputDir()
{
	var defaultdir = "c:\\" + oo_sdk_name;
    var sSuggestedDir = WshSysEnv("OO_SDK_OUT");
	if (sSuggestedDir.length == 0)
	   sSuggestedDir = defaultdir;

    var bSkip = false;       
    while(true)
    {
        stdout.Write(
			"\n Default output directory is the \"c:\\" + oo_sdk_name + "\".\n" +
            " Enter an existent directory if you prefer a different one. But note" +
			" that only\n a path without spaces is allowed because of a" +
			" limitation of gnu make. (optional) [" + sSuggestedDir + "]:");    
        var sDir = stdin.ReadLine();
        if (sDir.length == 0)
        {
            //No user input, check OO_SDK_OUT or suggested value
			if ( sSuggestedDir.length == 0 ) {
			    bSkip = true;
			} else {
				if (sSuggestedDir == oo_user_sdk_dir || sSuggestedDir == defaultdir) {
				    var fso = new ActiveXObject("Scripting.FileSystemObject");
					if ( !fso.FolderExists(sSuggestedDir) )
						fso.CreateFolder(sSuggestedDir);
				}				
			    if ( !aFileSystemObject.FolderExists(sSuggestedDir) )
				{
					stdout.WriteLine("\n Error: Could not find directory \"" +
									 sSuggestedDir + "\".");
					sSuggestedDir = "";
					bSkip = true;
				}
			}
       
            sDir = sSuggestedDir;
        }
        else
        {
			if (sDir.indexOf(' ') != -1) {
				stdout.WriteLine("\n Error: your specified output directory " +
								 "\"" + sDir + "\" " +	 
								 "contains one or more spaces.\n        That " +
								 "causes problems with gnu make. Please specifiy" +
								 " a directory without spaces.");
				bSkip = true;
			}
            //validate the user input
            if ( ! aFileSystemObject.FolderExists(sDir))
            {
                stdout.WriteLine("\n Error: Could not find directory \"" +
                                 sDir + "\".");
                bSkip = true;
            }
        }

		if ( bSkip ) { 
		   if ( skipChoice("a special output directory") ) {
			   return "";
		   } else {
			   bSkip = false;
			   continue;
		   }
		}
        
        return sDir;
    }   
}

function getAutoDeployment()
{
    var sSuggestedAuto = WshSysEnv("SDK_AUTO_DEPLOYMENT");
    if (sSuggestedAuto.length == 0)
        sSuggestedAuto = "YES";
    
    while(true)
    {
        stdout.Write("\n Automatic deployment of UNO components (YES/NO) ["+
                     sSuggestedAuto + "]:");   
        var sAuto = stdin.ReadLine();
        if (sAuto.length == 0)
            sAuto = sSuggestedAuto;
        else
        {
            sAutoU = sAuto.toUpperCase();
            if (sAutoU != "YES" && sAutoU != "NO")
            {
                stdout.WriteLine("\n Error: The value \"" + sAuto + "\" is " +
								 "invalid. Please answer YES or NO.")
                    continue;
            }
            sAuto = sAutoU;
        }
        return sAuto;
    }   
}

//The function uses sp2bv.exe to obtain a file URL from a
//system path. The URL is already escaped for use as bootstrap variable.
//($ -> \$). Then the resulting string is escaped for use in a bat file.
//That is % signs are made to double % (% -> %%);
function makeBootstrapFileUrl(systemPath)
{
    var oExec = WshShell.Exec("sp2bv.exe \"" + systemPath + "\"");
    var output="";
    while (true)
    {
        if (!oExec.StdOut.AtEndOfStream)
        {
            var next = oExec.StdOut.Read(1);
            if (next == '%')
                output += "%%";
            else
                output += next;
        }
        else
            break;
    }
    return output;
}

function writeBatFile(fdir, file)
{
    var fso = new ActiveXObject("Scripting.FileSystemObject");
    if ( !fso.FolderExists(fdir) )
       fso.CreateFolder(fdir);
    var newFile = fso.CreateTextFile(file, true);

    newFile.Write(
        "@echo off\n" +
        "REM This script sets all enviroment variables, which\n" +
        "REM are necessary for building the examples of the Office Development Kit.\n" +
        "REM The Script was developed for the operating systems Windows.\n" +
        "REM The SDK name\n" +
        "REM Example: set OO_SDK_NAME=libreoffice3.4_sdk\n" +
        "set OO_SDK_NAME=" + oo_sdk_name  +
        "\n\n" +
        "REM Installation directory of the Software Development Kit.\n" +
        "REM Example: set OO_SDK_HOME=C:\\Program Files\\LibreOffice 3\\sdk\n" +
        "set OO_SDK_HOME=" + oo_sdk_home  +
        "\n\n" +
        "REM Office installation directory.\n" +
        "REM Example: set OFFICE_HOME=C:\\Program Files\\LibreOffice 3\n" +
        "set OFFICE_HOME=" + office_home +
        "\n\n" +
        "REM URE installation directory.\n" +
        "REM Example: set OO_SDK_URE_HOME=C:\\Program Files\\LibreOffice 3\\URE\n" +
        "set OO_SDK_URE_HOME=" + oo_sdk_ure_home +
        "\n\n" +
        "REM Directory of the make command.\n" +
        "REM Example: set OO_SDK_MAKE_HOME=D:\\NextGenerationMake\\make\n" + 
        "set OO_SDK_MAKE_HOME=" + oo_sdk_make_home + 
        "\n\n" +
		"REM Directory of the zip tool.\n" +
		"REM Example: set OO_SDK_ZIP_HOME=D:\\infozip\\bin\n" +
		"set OO_SDK_ZIP_HOME=" + oo_sdk_zip_home + 
        "\n\n" +
        "REM Directory of the C++ compiler.\n" + 
        "REM Example:set OO_SDK_CPP_HOME=C:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\bin\n" + 
        "set OO_SDK_CPP_HOME=" + oo_sdk_cpp_home + 
		"\nset CPP_MANIFEST=" + oo_sdk_manifest_used +
		"\nset CPP_WINDOWS_SDK=" + oo_sdk_windowssdk +
        "\n\n" + 
        "REM Directory of the C# and VB.NET compilers.\n" + 
        "REM Example:set OO_SDK_CLI_HOME=C:\\WINXP\\Microsoft.NET\\Framework\\v1.0.3705\n" +
        "set OO_SDK_CLI_HOME=" + oo_sdk_cli_home + 
        "\n\n" +
        "REM Java SDK installation directory.\n" + 
        "REM Example: set OO_SDK_JAVA_HOME=C:\\Program Files\\Java\\jdk1.6.0_05\n" + 
        "set OO_SDK_JAVA_HOME=" + oo_sdk_java_home + 
        "\n\n" + 
        "REM Special output directory\n" + 
        "REM Example: set OO_SDK_OUT=C:\\" + oo_sdk_name + "\n" +
        "set OO_SDK_OUT=" + oo_sdk_out + 
        "\n\n" +
        "REM Automatic deployment\n" + 
        "REM Example: set SDK_AUTO_DEPLOYMENT=YES\n" +
        "set SDK_AUTO_DEPLOYMENT=" + sdk_auto_deployment +
        "\n\n" +
        "REM Check installation path for the Office Development Kit.\n" +
        "if not defined OO_SDK_HOME (\n" +
        "   echo Error: the variable OO_SDK_HOME is missing!\n" +
        "   goto :error\n" +
        " )\n" + 
        "\n" + 
        "REM Check installation path for the office.\n" + 
        "REM if not defined OFFICE_HOME (\n" + 
        "REM if not defined OO_SDK_URE_HOME (\n" + 
        "REM    echo Error: either of the variables OFFICE_HOME and\n" +
        "REM    echo OO_SDK_URE_HOME is missing!\n" + 
        "REM    goto :error\n" + 
        "REM  )\n" +
        "REM  )\n" +
        "\n" +
        "REM Check installation path for GNU make.\n" + 
        "if not defined OO_SDK_MAKE_HOME (\n" + 
        "   echo Error: the variable OO_SDK_MAKE_HOME is missing!\n" +
        "   goto :error\n" +
        " )\n" + 
        "\n" +
        "REM Check installation path for the zip tool.\n" + 
        "if not defined OO_SDK_ZIP_HOME (\n" +
        "   echo Error: the variable OO_SDK_ZIP_HOME is missing!\n" + 
        "   goto :error\n" +
        " )\n" +
        "\n" +
        "REM Set library path. \n" + 
        "set LIB=%OO_SDK_HOME%\\lib;%LIB%\n" +
        "if defined CPP_WINDOWS_SDK (\n" +
        "   set LIB=%LIB%;%CPP_WINDOWS_SDK%\\lib\n" +
        " )\n" +
        "\n" +
        "REM Set office program path.\n" +
        "if defined OFFICE_HOME (\n" +
        "   set OFFICE_PROGRAM_PATH=%OFFICE_HOME%\\program\n" +
        " )\n" +
        "\n" +
		"REM Set UNO path, necessary to ensure that the cpp examples using the\n" +
		"REM new UNO bootstrap mechanism use the configured office installation\n" +
		"REM (only set when using an Office).\n" +
		"if defined OFFICE_HOME (\n" +
		"   set UNO_PATH=%OFFICE_PROGRAM_PATH%\n" +
		" )\n" +
        "\n" +
        "REM if defined OO_SDK_URE_HOME (\n" +
        "set OO_SDK_URE_BIN_DIR=%OO_SDK_URE_HOME%\\bin\n" +
        "set OO_SDK_URE_LIB_DIR=%OO_SDK_URE_HOME%\\bin\n" +
        "set OO_SDK_URE_JAVA_DIR=%OO_SDK_URE_HOME%\\java\n" +
        "REM ) else (\n" +
        "set OO_SDK_OFFICE_BIN_DIR=%OFFICE_PROGRAM_PATH%\n" +
        "set OO_SDK_OFFICE_LIB_DIR=%OFFICE_PROGRAM_PATH%\n" +
        "set OO_SDK_OFFICE_JAVA_DIR=%OFFICE_PROGRAM_PATH%\\classes\n" +
        "REM )\n" +
        "\n" +
        "REM Set classpath\n" +
        "set CLASSPATH=%OO_SDK_URE_JAVA_DIR%\\juh.jar;%OO_SDK_URE_JAVA_DIR%\\jurt.jar;%OO_SDK_URE_JAVA_DIR%\\ridl.jar;%OO_SDK_URE_JAVA_DIR%\\unoloader.jar;%OO_SDK_OFFICE_JAVA_DIR%\\unoil.jar\n" +
        "REM if defined OFFICE_HOME (\n" +
        "REM     set CLASSPATH=%CLASSPATH%;%OO_SDK_OFFICE_JAVA_DIR%\\unoil.jar\n" +
        "REM  )\n" +
        "\n" +
        "REM Add directory of the SDK tools to the path.\n" +
        "set PATH=%OO_SDK_HOME%\\bin;%OO_SDK_URE_BIN_DIR%;%OO_SDK_OFFICE_BIN_DIR%;%OO_SDK_HOME%\\WINexample.out\\bin;%PATH%\n" +
        "\n" +
        "REM Set PATH appropriate to the output directory\n" +
        "if defined OO_SDK_OUT (\n" + 
        "   set PATH=%OO_SDK_OUT%\\WINexample.out\\bin;%PATH%\n" + 
        " ) else (\n" + 
        "   set PATH=%OO_SDK_HOME%\\WINexample.out\\bin;%PATH%\n" + 
        " )\n" + 
        "\n" +
        "REM Add directory of the command make to the path, if necessary.\n" +
        "if defined OO_SDK_MAKE_HOME set PATH=%OO_SDK_MAKE_HOME%;%PATH%\n" + 
        "\n" + 
	"REM Add directory of the zip tool to the path, if necessary.\n" +
	"if defined OO_SDK_ZIP_HOME set PATH=%OO_SDK_ZIP_HOME%;%PATH%\n" +
        "\n" + 
        "REM Add directory of the C++ compiler to the path, if necessary.\n" +
        "if defined OO_SDK_CPP_HOME set PATH=%OO_SDK_CPP_HOME%;%PATH%\n" + 
        "\n" +
        "REM Add directory of the Win SDK to the path, if necessary.\n" +
        "if defined CPP_WINDOWS_SDK (\n" +
		"   set PATH=%CPP_WINDOWS_SDK%\\bin;%PATH%\n" + 
		"   set INCLUDE=%CPP_WINDOWS_SDK%\\Include;%INCLUDE%\n" + 
        ")\n" +
        "REM Add directory of the C# and VB.NET compilers to the path, if necessary.\n" + 
        "if defined OO_SDK_CLI_HOME set PATH=%OO_SDK_CLI_HOME%;%PATH%\n" + 
        "\n" + 
        "REM Add directory of the Java tools to the path, if necessary.\n" + 
        "if defined OO_SDK_JAVA_HOME set PATH=%OO_SDK_JAVA_HOME%\\bin;%OO_SDK_JAVA_HOME%\\jre\\bin;%PATH%\n" +
        "\n" +
        "REM Set environment for C++ compiler tools, if necessary.\n" + 
        "if defined OO_SDK_CPP_HOME call \"%OO_SDK_CPP_HOME%\\VCVARS32.bat\"\n" +
        "\n" +
        "REM Set tilte to identify the prepared shell.\n" + 
        "title Shell prepared for SDK\n" + 
        "\nREM Prepare shell with all necessary environment variables.\n" +
        "echo.\n" +
        "echo  ******************************************************************\n" +
        "echo  *\n" + 
        "echo  * SDK environment is prepared for Windows\n" +
        "echo  *\n" +       
        "echo  * SDK = %OO_SDK_HOME%\n" +
        "echo  * Office = %OFFICE_HOME%\n" +
        "echo  * URE = %OO_SDK_URE_HOME%\n" +
        "echo  * Make = %OO_SDK_MAKE_HOME%\n" +
        "echo  * Zip = %OO_SDK_ZIP_HOME%\n" +
        "echo  * C++ Compiler = %OO_SDK_CPP_HOME%\n" +
        "echo  * C# and VB.NET compilers = %OO_SDK_CLI_HOME%\n" +
        "echo  * Java = %OO_SDK_JAVA_HOME%\n" +
        "echo  * Special Output directory = %OO_SDK_OUT%\n" +
        "echo  * Auto deployment = %SDK_AUTO_DEPLOYMENT%\n" +
        "echo  *\n" +
        "echo  ******************************************************************\n" +
        "echo.\n" +
        "goto end\n" + 
        "\n" +
        " :error\n" +
        "Error: Please insert the necessary environment variables into the batch file.\n" + 
        "\n" + 
        " :end\n" 
        );
        newFile.Close();        
}