xref: /trunk/main/odk/cfgWin.js (revision a893be29)
1// *************************************************************
2//
3//  Licensed to the Apache Software Foundation (ASF) under one
4//  or more contributor license agreements.  See the NOTICE file
5//  distributed with this work for additional information
6//  regarding copyright ownership.  The ASF licenses this file
7//  to you under the Apache License, Version 2.0 (the
8//  "License"); you may not use this file except in compliance
9//  with the License.  You may obtain a copy of the License at
10//
11//    http://www.apache.org/licenses/LICENSE-2.0
12//
13//  Unless required by applicable law or agreed to in writing,
14//  software distributed under the License is distributed on an
15//  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16//  KIND, either express or implied.  See the License for the
17//  specific language governing permissions and limitations
18//  under the License.
19//
20// *************************************************************
21
22// This script asks for variables, which are necessary for building the
23// examples of the Office Development Kit. The script duplicates the template
24// script and inserts the variables into the copied script.
25// The Script was developed for the operating systems Microsoft Windows.
26var regKeyOfficeCurrentUser6432Node = "HKEY_CURRENT_USER\\Software\\Wow6432Node\\OpenOffice\\UNO\\InstallPath\\";
27var regKeyOfficeLocaleMachine6432Node = "HKEY_LOCAL_MACHINE\\Software\\Wow6432Node\\OpenOffice\\UNO\\InstallPath\\";
28var regKeyOfficeCurrentUser = "HKEY_CURRENT_USER\\Software\\OpenOffice\\UNO\\InstallPath\\";
29var regKeyOfficeLocaleMachine = "HKEY_LOCAL_MACHINE\\Software\\OpenOffice\\UNO\\InstallPath\\";
30var regKeyDotNetInstallRoot = "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\.NETFramework\\InstallRoot";
31var regKeyDotNet1_1 = "HKLM\\Software\\Microsoft\\.NETFramework\\policy\\v1.1\\4322";
32var sDirDotNet1_1 = "v1.1.4322";
33var regKeyDotNet2_0 = "HKLM\\Software\\Microsoft\\.NETFramework\\Policy\\v2.0\\50727";
34var sDirDotNet2_0 = "v2.0.50727";
35
36var regKeyJDK = "HKLM\\Software\\JavaSoft\\Java Development Kit\\";
37//var regKeyVC70 = "HKLM\\SOFTWARE\\Microsoft\\VisualStudio\\7.0\\Setup\\VC\\ProductDir";
38//var regKeyVC71 = "HKLM\\SOFTWARE\\Microsoft\\VisualStudio\\7.1\\Setup\\VC\\ProductDir";
39var regKeyVC90 = "HKLM\\SOFTWARE\\Microsoft\\VisualStudio\\9.0\\Setup\\VC\\ProductDir";
40
41//var regKeyVCExpress80 = "HKLM\\SOFTWARE\\Microsoft\\VCExpress\\8.0\\Setup\\VC\\ProductDir";
42var regKeyVCExpress90 = "HKLM\\SOFTWARE\\Microsoft\\VCExpress\\9.0\\Setup\\VC\\ProductDir";
43var regKeyVCExpress90_2 = "HKLM\\SOFTWARE\\Wow6432Node\\Microsoft\\VCExpress\\9.0\\Setup\\VC\\ProductDir";
44var regKeyWindowsSDK = "HKLM\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\CurrentInstallFolder";
45
46var WshShell = WScript.CreateObject("WScript.Shell");
47var WshSysEnv = WshShell.Environment("process");
48var aFileSystemObject =  new ActiveXObject("Scripting.FileSystemObject");
49var stdin = WScript.StdIn;
50var stdout = WScript.StdOut;
51
52stdout.WriteLine("\n" +
53" *** Configure your SDK environment ***\n\n" +
54" NOTE: This script is working only for Windows 2000, Windows XP or newer versions!\n");
55
56var oo_sdk_name=WshSysEnv("OO_SDK_NAME");
57var stldebug="";
58var oo_sdk_home=getSdkHome();
59var oo_user_sdk_dir=WshSysEnv("APPDATA") + "\\" + oo_sdk_name;
60var oo_user_sdk_env_script=oo_user_sdk_dir + "\\setsdkenv_windows.bat";
61
62var office_home=getOfficeHome();
63var office_base_home=getOfficeBaseHome();
64
65var oo_sdk_make_home=getMakeHome();
66var oo_sdk_zip_home=getZipHome();
67var oo_sdk_cat_home=getCatHome();
68var oo_sdk_sed_home=getSedHome();
69var oo_sdk_manifest_used="";
70var oo_sdk_windowssdk="";
71var oo_sdk_cpp_home=getCppHome();
72var oo_sdk_cli_home=getCliHome();
73var oo_sdk_java_home=getJavaHome();
74var oo_sdk_out=getOutputDir();
75var sdk_auto_deployment=getAutoDeployment();
76
77writeBatFile(oo_user_sdk_dir, oo_user_sdk_env_script);
78
79stdout.Write(
80	"\n ******************************************************************\n" +
81    " * ... \"" + oo_user_sdk_env_script + "\"\n" +
82    " * batch file has been prepared.\n" +
83    " * This batch file will be used in the future to prepare your\n" +
84	" * personal configured SDK environment.\n" +
85	" ******************************************************************\n\n");
86//    " * For each time you want to use this configured SDK environment,\n" +
87//    " * you have to run the \"setsdkenv_windows.bat\" file in a new shell!\n" +
88
89// done -------------------------------------------------------------------------
90
91
92function skipChoice(msg)
93{
94	stdout.Write("\n Do you want to skip the choice of " + msg + " (YES/NO) [YES]:");
95	var sChoice = stdin.ReadLine();
96    if (sChoice == "" || sChoice.toLowerCase() == "yes")
97	   return true;
98
99	return false;
100}
101
102function getSdkHome()
103{
104	var sSuggestedHome = WshSysEnv("OO_SDK_HOME");
105    if (sSuggestedHome.length == 0) {
106        var scriptname = WScript.ScriptFullName;
107        sSuggestedHome = scriptname.substr(0,scriptname.length-10);
108    }
109
110    while(true)
111    {
112        stdout.Write("\n Enter the Office Software Development Kit directory [" +
113                     sSuggestedHome + "]:");
114        var sHome = stdin.ReadLine();
115        if (sHome.length == 0)
116        {
117            //No user input, use default.
118            if ( ! aFileSystemObject.FolderExists(sSuggestedHome))
119            {
120                stdout.WriteLine("\n Error: Could not find directory \"" +
121                                 sSuggestedHome + "\". An SDK is required, please" +
122								 " specify the path to a valid installation.");
123                continue;
124            }
125            sHome = sSuggestedHome;
126        }
127        else
128        {
129            //validate the user input
130            if ( ! aFileSystemObject.FolderExists(sHome))
131            {
132                stdout.WriteLine("\n Error: The directory \"" + sHome +
133                                 "\" does not exist. Please enter the path to a" +
134								 "valid SDK installation.");
135                continue;
136            }
137        }
138        //Check if this is an sdk folder by looking for the idl sub - dir
139        var idlDir = sHome + "\\idl";
140        if (! aFileSystemObject.FolderExists(idlDir))
141        {
142            stdout.WriteLine("\n Error: Could not find directory \"" +
143                             idlDir + "\". An SDK is required, please specify " +
144                             "the path to a valid SDK installation.");
145            continue;
146        }
147
148        if (aFileSystemObject.FileExists(sHome + "\\lib\\stlport_vc71_stldebug.lib")) {
149		    stldebug="_stldebug";
150		}
151
152        return sHome;
153    }
154}
155
156function getOfficeOrUre()
157{
158    var suggestion = "Office";
159    var choice;
160    while (choice != "office" && choice != "ure") {
161        stdout.Write(
162            "\n Use an installed Office or an installed UNO Runtime"
163            + " Environment (Office/URE) [" + suggestion + "]:");
164        choice = stdin.ReadLine();
165        if (choice == "") {
166            choice = suggestion;
167        }
168        choice = choice.toLowerCase();
169    }
170    return choice;
171}
172
173function getOfficeHome()
174{
175    var sSuggestedHome = WshSysEnv("OFFICE_HOME");
176    if (sSuggestedHome.length == 0)
177    {
178        try {
179            sSuggestedHome = WshShell.RegRead(regKeyOfficeCurrentUser6432Node);
180	    //The registry entry points to the program folder but we need the
181	    //installation folder
182        } catch(exc) {}
183        if (sSuggestedHome.length == 0)
184        {
185            try {
186                sSuggestedHome = WshShell.RegRead(regKeyOfficeLocaleMachine6432Node);
187                //The registry entry points to the program folder but we need
188		//the installation folder
189            } catch (exc) {}
190        }
191 	if (sSuggestedHome.length == 0)
192        {
193            try {
194                sSuggestedHome = WshShell.RegRead(regKeyOfficeLocaleMachine);
195                //The registry entry points to the program folder but we need
196		//the installation folder
197            } catch (exc) {}
198        }
199 	if (sSuggestedHome.length == 0)
200        {
201            try {
202                sSuggestedHome = WshShell.RegRead(regKeyOfficeLocaleMachine);
203                //The registry entry points to the program folder but we need
204		//the installation folder
205            } catch (exc) {}
206        }
207
208		var index=0;
209        if ((index = sSuggestedHome.lastIndexOf("\\")) != -1)
210		   sSuggestedHome = sSuggestedHome.substr(0, index);
211
212        if (sSuggestedHome.length == 0)
213		   sSuggestedHome = searchOffice();
214    }
215
216    while(true)
217    {
218        stdout.Write("\n Enter the Office base installation directory [" +
219                     sSuggestedHome + "]:");
220        var sHome = stdin.ReadLine();
221        if (sHome.length == 0)
222        {
223            //No user input, use default.
224            if ( ! aFileSystemObject.FolderExists(sSuggestedHome))
225            {
226                stdout.WriteLine("\n Error: Could not find directory \"" +
227                                 sSuggestedHome + "\" An office installation is " +
228								 "required, please specify the path to a valid " +
229								 "office installation.");
230                sSuggestedHome = "";
231                continue;
232            }
233            sHome = sSuggestedHome;
234        } else
235        {
236            //validate the user input
237            if ( ! aFileSystemObject.FolderExists(sHome))
238            {
239                stdout.WriteLine("\n Error: The directory \"" + sHome +
240                                 "\" does not exist. Please specify the path to " +
241								 "a valid office installation.");
242                continue;
243            }
244        }
245        //Check if this is a valid office installtion folder by looking for the
246		//program sub-directory
247        var progDir = sHome + "\\program";
248        if (! aFileSystemObject.FolderExists(progDir))
249        {
250            stdout.WriteLine("\n Error: Could not find directory \"" +
251                             progDir + "\". An office installation is required, " +
252							 "please specify the path to a valid office " +
253							 "installation.");
254            continue;
255        }
256        return sHome;
257    }
258}
259
260function searchOffice()
261{
262	var tmp = oo_sdk_home;
263	var officepath ="";
264	var index=-1;
265
266	if ((index = tmp.lastIndexOf("\\sdk")) != -1) {
267	   tmp = tmp.substr(0, index);
268	}
269
270	if (aFileSystemObject.FileExists(tmp + "\\program\\soffice.exe")) {
271	   return tmp;
272	}
273
274	return "";
275}
276
277
278function getOfficeBaseHome()
279{
280	var officebase = oo_sdk_home;
281	var index=officebase.lastIndexOf("\\");
282
283	officebase = officebase.substr(0, index);
284
285	return officebase;
286}
287
288function getMakeHome()
289{
290    var sSuggestedHome = WshSysEnv("OO_SDK_MAKE_HOME");
291
292    while(true)
293    {
294        stdout.Write("\n Enter GNU make (3.79.1 or higher) tools directory [" +
295                     sSuggestedHome + "]:");
296        var sHome = stdin.ReadLine();
297        if (sHome.length == 0)
298        {
299            //No user input, use default.
300            if ( ! aFileSystemObject.FolderExists(sSuggestedHome))
301            {
302                stdout.WriteLine("\n Error: Could not find directory \"" +
303								 sSuggestedHome + "\". GNU make is required, " +
304								 "please specify a GNU make tools directory.");
305                sSuggestedHome = "";
306                continue;
307            }
308            sHome = sSuggestedHome;
309        } else
310        {
311            //validate the user input
312            if ( ! aFileSystemObject.FolderExists(sHome))
313            {
314                stdout.WriteLine("\n Error: The directory \"" + sHome +
315                                 "\" does not exist. GNU make is required, " +
316								 "please specify a GNU make tools directory.");
317                continue;
318            }
319        }
320        //Check for the make executable
321        var sMakePath = sHome + "\\make.exe";
322        if (! aFileSystemObject.FileExists(sMakePath))
323	{
324		sMakePath = sHome + "\\mingw32-make.exe";
325	}
326        if (! aFileSystemObject.FileExists(sMakePath))
327        {
328            stdout.WriteLine("\n Error: Could not find \"" + sMakePath +
329							 "\". GNU make is required, please specify a GNU " +
330							 "make tools directory.");
331            continue;
332        }
333        return sHome;
334    }
335}
336
337function getZipHome()
338{
339    var sSuggestedHome = WshSysEnv("OO_SDK_ZIP_HOME");
340
341    if (sSuggestedHome.length == 0 && oo_sdk_make_home.length > 0) {
342       sSuggestedHome = oo_sdk_make_home;
343    }
344
345    while(true)
346    {
347        stdout.Write("\n Enter a zip (2.3 or higher) tools directory [" +
348                     sSuggestedHome + "]:");
349        var sHome = stdin.ReadLine();
350        if (sHome.length == 0)
351        {
352            //No user input, use default.
353            if ( ! aFileSystemObject.FolderExists(sSuggestedHome))
354            {
355                stdout.WriteLine("\n Error: Could not find directory \"" +
356								 sSuggestedHome + "\". zip is required, please " +
357								 "specify a zip tools directory.");
358                sSuggestedHome = "";
359                continue;
360            }
361            sHome = sSuggestedHome;
362        }
363        else
364        {
365            //validate the user input
366            if ( ! aFileSystemObject.FolderExists(sHome))
367            {
368                stdout.WriteLine("\n Error: The directory \"" + sHome +
369                                 "\" does not exist. zip is required, please " +
370								 "specify a zip tools directory.");
371                continue;
372            }
373        }
374        //Check for the make executable
375        var sZipPath = sHome + "\\zip.exe";
376        if (! aFileSystemObject.FileExists(sZipPath))
377        {
378            stdout.WriteLine("\n Error: Could not find \"" + sZipPath +
379                             "\". zip is required, please specify a zip tools " +
380							 "directory.");
381            continue;
382        }
383        return sHome;
384    }
385}
386
387function getCatHome()
388{
389    var sSuggestedHome = WshSysEnv("OO_SDK_CAT_HOME");
390
391    if (sSuggestedHome.length == 0 && oo_sdk_make_home.length > 0) {
392       sSuggestedHome = oo_sdk_make_home;
393    }
394
395    while(true)
396    {
397        stdout.Write("\n Enter a cat (2.0 or higher) tools directory [" +
398                     sSuggestedHome + "]:");
399        var sHome = stdin.ReadLine();
400        if (sHome.length == 0)
401        {
402            //No user input, use default.
403            if ( ! aFileSystemObject.FolderExists(sSuggestedHome))
404            {
405                stdout.WriteLine("\n Error: Could not find directory \"" +
406                                 sSuggestedHome + "\". cat is required, please " +
407                                 "specify a cat tools directory." +
408                                 "\nYou can get cat from " +
409                                 "http://sourceforge.net/projects/unxutils/files/latest/download");
410                sSuggestedHome = "";
411                continue;
412            }
413            sHome = sSuggestedHome;
414        }
415        else
416        {
417            //validate the user input
418            if ( ! aFileSystemObject.FolderExists(sHome))
419            {
420                stdout.WriteLine("\n Error: The directory \"" + sHome +
421                                 "\" does not exist. cat is required, please " +
422                                 "specify a cat tools directory." +
423                                 "\nYou can get cat from " +
424                                 "http://sourceforge.net/projects/unxutils/files/latest/download");
425                continue;
426            }
427        }
428        //Check for the make executable
429        var sCatPath = sHome + "\\cat.exe";
430        if (! aFileSystemObject.FileExists(sCatPath))
431        {
432            stdout.WriteLine("\n Error: Could not find \"" + sCatPath +
433                             "\". cat is required, please specify a cat tools " +
434                             "directory." +
435                             "\nYou can get cat from " +
436                             "http://sourceforge.net/projects/unxutils/files/latest/download");
437            continue;
438        }
439        return sHome;
440    }
441}
442
443function getSedHome()
444{
445    var sSuggestedHome = WshSysEnv("OO_SDK_SED_HOME");
446
447    if (sSuggestedHome.length == 0 && oo_sdk_make_home.length > 0) {
448       sSuggestedHome = oo_sdk_make_home;
449    }
450
451    while(true)
452    {
453        stdout.Write("\n Enter a sed (3.02 or higher) tools directory [" +
454                     sSuggestedHome + "]:");
455        var sHome = stdin.ReadLine();
456        if (sHome.length == 0)
457        {
458            //No user input, use default.
459            if ( ! aFileSystemObject.FolderExists(sSuggestedHome))
460            {
461                stdout.WriteLine("\n Error: Could not find directory \"" +
462                                 sSuggestedHome + "\". sed is required, please " +
463                                 "specify a sed tools directory." +
464                                 "\nYou can get sed from " +
465                                 "http://sourceforge.net/projects/unxutils/files/latest/download");
466                sSuggestedHome = "";
467                continue;
468            }
469            sHome = sSuggestedHome;
470        }
471        else
472        {
473            //validate the user input
474            if ( ! aFileSystemObject.FolderExists(sHome))
475            {
476                stdout.WriteLine("\n Error: The directory \"" + sHome +
477                                 "\" does not exist. sed is required, please " +
478                                 "specify a sed tools directory." +
479                                 "\nYou can get sed from " +
480                                 "http://sourceforge.net/projects/unxutils/files/latest/download");
481                continue;
482            }
483        }
484        //Check for the make executable
485        var sSedPath = sHome + "\\sed.exe";
486        if (! aFileSystemObject.FileExists(sSedPath))
487        {
488            stdout.WriteLine("\n Error: Could not find \"" + sSedPath +
489                             "\". sed is required, please specify a sed tools " +
490                             "directory." +
491                             "\nYou can get sed from " +
492                             "http://sourceforge.net/projects/unxutils/files/latest/download");
493            continue;
494        }
495        return sHome;
496    }
497}
498
499function getCppHome()
500{
501    var sSuggestedHome = WshSysEnv("OO_SDK_CPP_HOME");
502    if (sSuggestedHome.length == 0)
503    {
504        var sVC="";
505        try {
506            sVC = WshShell.RegRead(regKeyVCExpress90);
507        }catch (exc) {}
508        if (sVC.length == 0)
509        {
510	   try {
511	       sVC = WshShell.RegRead(regKeyVCExpress90_2);
512	   }catch (exc) {}
513	}
514	if (sVC.length == 0)
515        {
516	   try {
517	       sVC = WshShell.RegRead(regKeyVC90);
518	   }catch (exc) {}
519	}
520	// check Windows SDK if VC 9
521        if (sVC.length > 0)
522        {
523		    oo_sdk_manifest_used="true";
524			try {
525				oo_sdk_windowssdk = WshShell.RegRead(regKeyWindowsSDK);
526			}catch (exc) {}
527		}
528        if (sVC.length == 0)
529        {
530	        try {
531				sVC = WshShell.RegRead(regKeyVCExpress80);
532			}catch (exc) {}
533	        if (sVC.length > 0)
534			   oo_sdk_manifest_used="true";
535		}
536        if (sVC.length == 0)
537        {
538	        try {
539				sVC = WshShell.RegRead(regKeyVC80);
540			}catch (exc) {}
541	        if (sVC.length > 0)
542			   oo_sdk_manifest_used="true";
543		}
544        if (sVC.length == 0)
545        {
546	        try {
547				sVC = WshShell.RegRead(regKeyVC71);
548			}catch (exc) {}
549		}
550        if (sVC.length > 0)
551        {
552            sVC += "bin";
553            if (aFileSystemObject.FileExists(sVC + "\\cl.exe"))
554                sSuggestedHome = sVC;
555        }
556    }
557
558    var bSkip = false;
559    while(true)
560    {
561        stdout.Write("\n Enter the directory of the C++ compiler (optional) [" +
562                     sSuggestedHome + "]:");
563        var sHome = stdin.ReadLine();
564        if (sHome.length == 0)
565        {
566            //No user input, check OO_SDK_CPP_HOME or suggested value
567	    if ( sSuggestedHome.length == 0 ) {
568		bSkip = true;
569	    } else {
570	        if ( !aFileSystemObject.FolderExists(sSuggestedHome) )
571		{
572		    stdout.WriteLine("\n Error: Could not find directory \"" +
573				     sSuggestedHome + "\".");
574		    sSuggestedHome = "";
575		    bSkip = true;
576		}
577	    }
578
579            sHome = sSuggestedHome;
580        } else
581        {
582            //validate the user input
583            if ( ! aFileSystemObject.FolderExists(sHome))
584            {
585                stdout.WriteLine("\n Error: Could not find directory \"" +
586                                 sHome + "\".");
587                bSkip = true;
588            }
589        }
590
591		if ( !bSkip) {
592		    //Check if the C++ compiler exist
593		    var cl = sHome + "\\cl.exe";
594		    var mt = sHome + "\\mt.exe";
595
596			if (! aFileSystemObject.FileExists(cl))
597			{
598				stdout.WriteLine("\n Error: Could not find the C++ compiler \""
599								 + cl + "\".");
600				sHome = "";
601				bSkip = true;
602			} else {
603			    if (aFileSystemObject.FileExists(mt)) {
604				    oo_sdk_vc8_used="true";
605				}
606			}
607		}
608
609		if ( bSkip ) {
610		   if ( skipChoice("the C++ compiler") ) {
611			   return "";
612		   } else {
613			   bSkip = false;
614			   continue;
615		   }
616		}
617
618        return sHome;
619    }
620}
621
622function getCliHome()
623{
624    var sSuggestedHome = WshSysEnv("OO_SDK_CLI_HOME");
625
626    if (sSuggestedHome.length == 0)
627    {
628        try {
629            var _ver = WshShell.RegRead(regKeyDotNet2_0);
630            if (_ver.length > 0)
631            {
632                sSuggestedHome = WshShell.RegRead(regKeyDotNetInstallRoot);
633                sSuggestedHome += sDirDotNet2_0;
634                if ( ! aFileSystemObject.FolderExists(sSuggestedHome))
635                    sSuggestedHome = "";
636            }
637
638			if (sSuggestedHome.length == 0)
639			{
640				_ver = WshShell.RegRead(regKeyDotNet1_1);
641				if (_ver.length > 0)
642				{
643					sSuggestedHome = WshShell.RegRead(regKeyDotNetInstallRoot);
644					sSuggestedHome += sDirDotNet1_1;
645					if ( ! aFileSystemObject.FolderExists(sSuggestedHome))
646					   sSuggestedHome = "";
647				}
648			}
649		} catch (exc) {}
650    }
651
652    var bSkip = false;
653    while(true)
654    {
655        stdout.Write("\n Enter the directory of the C# and VB.NET compilers (optional) [" + sSuggestedHome + "]:");
656        var sHome = stdin.ReadLine();
657        if (sHome.length == 0)
658        {
659            //No user input, check OO_SDK_CLI_HOME or suggested value
660			if ( sSuggestedHome.length == 0 ) {
661			    bSkip = true;
662			} else {
663			    if ( !aFileSystemObject.FolderExists(sSuggestedHome) )
664				{
665					stdout.WriteLine("\n Error: Could not find directory \"" +
666									 sSuggestedHome + "\".");
667					sSuggestedHome = "";
668					bSkip = true;
669				}
670			}
671
672		    sHome = sSuggestedHome;
673        }
674        else
675        {
676            //validate the user input
677            if ( ! aFileSystemObject.FolderExists(sHome))
678            {
679                stdout.WriteLine("\n Error: The directory \"" + sHome +
680                                 "\" does not exist.");
681                bSkip = true;
682            }
683        }
684
685		if ( !bSkip ) {
686		    //Check if the C# and VB.NET compiler exist
687		    var csc = sHome + "\\csc.exe";
688		    var vbc = sHome + "\\vbc.exe";
689
690			if (! aFileSystemObject.FileExists(csc))
691			{
692				stdout.WriteLine("\n Error: Could not find the C# compiler \"" +
693								 csc + "\".");
694				bSkip = true;
695			}
696			if (! aFileSystemObject.FileExists(vbc))
697			{
698				stdout.WriteLine("\n Error: Could not find the VB.NET compiler \"" +
699								 vbc + "\".");
700				bSkip = true;
701			}
702		}
703
704		if ( bSkip ) {
705		   if ( skipChoice("the C# and VB.NET compilers") ) {
706			   return "";
707		   } else {
708			   bSkip = false;
709			   continue;
710		   }
711		}
712
713        return sHome;
714    }
715}
716
717function getJavaHome()
718{
719    var sSuggestedHome = WshSysEnv("OO_SDK_JAVA_HOME");
720    if (sSuggestedHome.length == 0)
721    {
722        try {
723            var currentVersion = WshShell.RegRead(regKeyJDK + "CurrentVersion");
724            if (currentVersion.length > 0)
725            {
726                sSuggestedHome = WshShell.RegRead(regKeyJDK + currentVersion +
727												  "\\JavaHome");
728                if ( ! aFileSystemObject.FolderExists(sSuggestedHome) )
729                    sSuggestedHome = "";
730            }
731        } catch (exc) {}
732    }
733
734    var bSkip = false;
735    while(true)
736    {
737        stdout.Write("\n Enter JAVA SDK (1.4.1_01 or higher) installation directory (optional) [" + sSuggestedHome + "]:");
738        var sHome = stdin.ReadLine();
739        if (sHome.length == 0)
740        {
741            //No user input, check OO_SDK_JAVA_HOME or suggested value
742			if ( sSuggestedHome.length == 0 ) {
743			    bSkip = true;
744			} else {
745			    if ( !aFileSystemObject.FolderExists(sSuggestedHome) )
746				{
747					stdout.WriteLine("\n Error: Could not find directory \"" +
748									 sSuggestedHome + "\".");
749					sSuggestedHome = "";
750					bSkip=true;
751				}
752			}
753
754			sHome = sSuggestedHome;
755        } else
756        {
757            //validate the user input
758            if ( ! aFileSystemObject.FolderExists(sHome))
759            {
760                stdout.WriteLine("\n Error: The directory \"" + sHome +
761                                 "\" does not exist.");
762				bSkip = true;
763            }
764        }
765
766		if ( !bSkip) {
767		    //Check if this is an sdk folder by looking for the javac compiler
768			var javacompiler = sHome + "\\bin\\javac.exe";
769			if (! aFileSystemObject.FileExists(javacompiler))
770			{
771				stdout.WriteLine("\n Error: Could not find \"" +
772								 javacompiler + "\".");
773				bSkip = true;
774			}
775        }
776
777		if ( bSkip ) {
778		   if ( skipChoice("the Java SDK") ) {
779			   return "";
780		   } else {
781			   bSkip = false;
782			   continue;
783		   }
784		}
785
786        return sHome;
787    }
788}
789
790function getOutputDir()
791{
792	var defaultdir = "c:\\" + oo_sdk_name;
793    var sSuggestedDir = WshSysEnv("OO_SDK_OUT");
794	if (sSuggestedDir.length == 0)
795	   sSuggestedDir = defaultdir;
796
797    var bSkip = false;
798    while(true)
799    {
800        stdout.Write(
801			"\n Default output directory is the \"c:\\" + oo_sdk_name + "\".\n" +
802            " Enter an existent directory if you prefer a different one. But note" +
803			" that only\n a path without spaces is allowed because of a" +
804			" limitation of gnu make. (optional) [" + sSuggestedDir + "]:");
805        var sDir = stdin.ReadLine();
806        if (sDir.length == 0)
807        {
808            //No user input, check OO_SDK_OUT or suggested value
809			if ( sSuggestedDir.length == 0 ) {
810			    bSkip = true;
811			} else {
812				if (sSuggestedDir == oo_user_sdk_dir || sSuggestedDir == defaultdir) {
813				    var fso = new ActiveXObject("Scripting.FileSystemObject");
814					if ( !fso.FolderExists(sSuggestedDir) )
815						fso.CreateFolder(sSuggestedDir);
816				}
817			    if ( !aFileSystemObject.FolderExists(sSuggestedDir) )
818				{
819					stdout.WriteLine("\n Error: Could not find directory \"" +
820									 sSuggestedDir + "\".");
821					sSuggestedDir = "";
822					bSkip = true;
823				}
824			}
825
826            sDir = sSuggestedDir;
827        }
828        else
829        {
830			if (sDir.indexOf(' ') != -1) {
831				stdout.WriteLine("\n Error: your specified output directory " +
832								 "\"" + sDir + "\" " +
833								 "contains one or more spaces.\n        That " +
834								 "causes problems with gnu make. Please specifiy" +
835								 " a directory without spaces.");
836				bSkip = true;
837			}
838            //validate the user input
839            if ( ! aFileSystemObject.FolderExists(sDir))
840            {
841                stdout.WriteLine("\n Error: Could not find directory \"" +
842                                 sDir + "\".");
843                bSkip = true;
844            }
845        }
846
847		if ( bSkip ) {
848		   if ( skipChoice("a special output directory") ) {
849			   return "";
850		   } else {
851			   bSkip = false;
852			   continue;
853		   }
854		}
855
856        return sDir;
857    }
858}
859
860function getAutoDeployment()
861{
862    var sSuggestedAuto = WshSysEnv("SDK_AUTO_DEPLOYMENT");
863    if (sSuggestedAuto.length == 0)
864        sSuggestedAuto = "YES";
865
866    while(true)
867    {
868        stdout.Write("\n Automatic deployment of UNO components (YES/NO) ["+
869                     sSuggestedAuto + "]:");
870        var sAuto = stdin.ReadLine();
871        if (sAuto.length == 0)
872            sAuto = sSuggestedAuto;
873        else
874        {
875            sAutoU = sAuto.toUpperCase();
876            if (sAutoU != "YES" && sAutoU != "NO")
877            {
878                stdout.WriteLine("\n Error: The value \"" + sAuto + "\" is " +
879								 "invalid. Please answer YES or NO.")
880                    continue;
881            }
882            sAuto = sAutoU;
883        }
884        return sAuto;
885    }
886}
887
888//The function uses sp2bv.exe to obtain a file URL from a
889//system path. The URL is already escaped for use as bootstrap variable.
890//($ -> \$). Then the resulting string is escaped for use in a bat file.
891//That is % signs are made to double % (% -> %%);
892function makeBootstrapFileUrl(systemPath)
893{
894    var oExec = WshShell.Exec("sp2bv.exe \"" + systemPath + "\"");
895    var output="";
896    while (true)
897    {
898        if (!oExec.StdOut.AtEndOfStream)
899        {
900            var next = oExec.StdOut.Read(1);
901            if (next == '%')
902                output += "%%";
903            else
904                output += next;
905        }
906        else
907            break;
908    }
909    return output;
910}
911
912function writeBatFile(fdir, file)
913{
914    var fso = new ActiveXObject("Scripting.FileSystemObject");
915    if ( !fso.FolderExists(fdir) )
916       fso.CreateFolder(fdir);
917    var newFile = fso.CreateTextFile(file, true);
918
919    newFile.Write(
920        "@echo off\n" +
921        "REM This script sets all environment variables, which\n" +
922        "REM are necessary for building the examples of the Office Development Kit.\n" +
923        "REM The Script was developed for the operating systems Windows.\n" +
924        "REM The SDK name\n" +
925        "REM Example: @set \"OO_SDK_NAME=openoffice4.0_sdk\"\n" +
926        "@set \"OO_SDK_NAME=" + oo_sdk_name  +
927        "\"\n\n" +
928        "REM Installation directory of the Software Development Kit.\n" +
929        "REM Example: @set \"OO_SDK_HOME=C:\\Program Files\\OpenOffice\\4\\sdk\"\n" +
930        "@set \"OO_SDK_HOME=" + oo_sdk_home  +
931        "\"\n\n" +
932        "REM Office installation directory.\n" +
933        "REM Example: @set \"OFFICE_HOME=C:\\Program Files\\OpenOffice 4\"\n" +
934        "@set \"OFFICE_HOME=" + office_home +
935        "\"\n\n" +
936        "REM Directory of the make command.\n" +
937        "REM Example: @set \"OO_SDK_MAKE_HOME=C:\\UnxUtils\\usr\\local\\wbin\"\n" +
938        "@set \"OO_SDK_MAKE_HOME=" + oo_sdk_make_home +
939        "\"\n\n" +
940	"REM Directory of the zip tool.\n" +
941	"REM Example: @set \"OO_SDK_ZIP_HOME=C:\\UnxUtils\\usr\\local\\wbin\"\n" +
942	"@set \"OO_SDK_ZIP_HOME=" + oo_sdk_zip_home +
943        "\"\n\n" +
944        "REM Directory of the cat tool.\n" +
945        "REM Example: @set \"OO_SDK_CAT_HOME=C:\\UnxUtils\\usr\\local\\wbin\"\n" +
946        "@set \"OO_SDK_CAT_HOME=" + oo_sdk_cat_home +
947        "\"\n\n" +
948        "REM Directory of the sed tool.\n" +
949        "REM Example: @set \"OO_SDK_SED_HOME=C:\\UnxUtils\\usr\\local\\wbin\"\n" +
950        "@set \"OO_SDK_SED_HOME=" + oo_sdk_sed_home +
951        "\"\n\n" +
952        "REM Directory of the C++ compiler.\n" +
953        "REM Example: @set \"OO_SDK_CPP_HOME=C:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\bin\"\n" +
954        "@set \"OO_SDK_CPP_HOME=" + oo_sdk_cpp_home +
955	"\"\n@set \"CPP_MANIFEST=" + oo_sdk_manifest_used +
956	"\"\n@set \"CPP_WINDOWS_SDK=" + oo_sdk_windowssdk +
957        "\"\n\n" +
958        "REM Directory of the C# and VB.NET compilers.\n" +
959        "REM Example: @set \"OO_SDK_CLI_HOME=C:\\WINXP\\Microsoft.NET\\Framework\\v1.0.3705\"\n" +
960        "@set \"OO_SDK_CLI_HOME=" + oo_sdk_cli_home +
961        "\"\n\n" +
962        "REM Java SDK installation directory.\n" +
963        "REM Example: @set \"OO_SDK_JAVA_HOME=C:\\Program Files\\Java\\jdk1.6.0_05\"\n" +
964        "@set \"OO_SDK_JAVA_HOME=" + oo_sdk_java_home +
965        "\"\n\n" +
966        "REM Special output directory\n" +
967        "REM Example: @set \"OO_SDK_OUT=C:\\" + oo_sdk_name + "\"\n" +
968        "@set \"OO_SDK_OUT=" + oo_sdk_out +
969        "\"\n\n" +
970        "REM Automatic deployment\n" +
971        "REM Example: @set \"SDK_AUTO_DEPLOYMENT=YES\"\n" +
972        "@set \"SDK_AUTO_DEPLOYMENT=" + sdk_auto_deployment +
973        "\"\n\n" +
974	"REM Check installation path for the Office Development Kit.\n" +
975        "if not defined OO_SDK_HOME (\n" +
976        "   echo Error: the variable OO_SDK_HOME is missing!\n" +
977        "   goto :error\n" +
978        " )\n" +
979        "\n\n" +
980        "REM Check installation path for GNU make.\n" +
981        "if not defined OO_SDK_MAKE_HOME (\n" +
982        "   echo Error: the variable OO_SDK_MAKE_HOME is missing!\n" +
983        "   goto :error\n" +
984        " )\n" +
985        "\n" +
986        "REM Check installation path for the zip tool.\n" +
987        "if not defined OO_SDK_ZIP_HOME (\n" +
988        "   echo Error: the variable OO_SDK_ZIP_HOME is missing!\n" +
989        "   goto :error\n" +
990        " )\n" +
991        "\n" +
992        "REM Check installation path for the cat tool.\n" +
993        "if not defined OO_SDK_CAT_HOME (\n" +
994        "   echo Error: the variable OO_SDK_CAT_HOME is missing!\n" +
995        "   goto :error\n" +
996        " )\n" +
997        "\n" +
998        "REM Check installation path for the sed tool.\n" +
999        "if not defined OO_SDK_SED_HOME (\n" +
1000        "   echo Error: the variable OO_SDK_SED_HOME is missing!\n" +
1001        "   goto :error\n" +
1002        " )\n" +
1003        "\n" +
1004        "REM Set library path. \n" +
1005        "@set \"LIB=%OO_SDK_HOME%\\lib;%LIB%\"\n" +
1006        "if defined CPP_WINDOWS_SDK (\n" +
1007        "   @set \"LIB=%LIB%;%CPP_WINDOWS_SDK%\\lib\"\n" +
1008        " )\n" +
1009        "\n" +
1010        "REM Set office program path.\n" +
1011        "if defined OFFICE_HOME (\n" +
1012        "   @set \"OFFICE_PROGRAM_PATH=%OFFICE_HOME%\\program\"\n" +
1013        " )" +
1014        "\n" +
1015        "REM Set UNO path, necessary to ensure that the cpp examples using the\n" +
1016	"REM new UNO bootstrap mechanism use the configured office installation\n" +
1017	 "REM (only set when using an Office).\n" +
1018	"if defined OFFICE_HOME (\n" +
1019	"   @set \"UNO_PATH=%OFFICE_PROGRAM_PATH%\"\n" +
1020	" )\n" +
1021        "\n\n" +
1022        "@set \"OO_SDK_OFFICE_BIN_DIR=%OFFICE_PROGRAM_PATH%\"\n" +
1023        "@set \"OO_SDK_OFFICE_LIB_DIR=%OFFICE_PROGRAM_PATH%\"\n" +
1024        "@set \"OO_SDK_OFFICE_JAVA_DIR=%OFFICE_PROGRAM_PATH%\\classes\"\n" +
1025        "\n" +
1026        "REM Set classpath\n" +
1027        "@set \"CLASSPATH=%OO_SDK_OFFICE_JAVA_DIR%\\juh.jar;%OO_SDK_OFFICE_JAVA_DIR%\\jurt.jar;%OO_SDK_OFFICE_JAVA_DIR%\\ridl.jar;%OO_SDK_OFFICE_JAVA_DIR%\\unoloader.jar;%OO_SDK_OFFICE_JAVA_DIR%\\unoil.jar\"\n" +
1028        "\n" +
1029        "REM Add directory of the SDK tools to the path.\n" +
1030        "set \"PATH=%OO_SDK_HOME%\\bin;%OO_SDK_OFFICE_BIN_DIR%;%OO_SDK_OFFICE_BIN_DIR%;%OO_SDK_HOME%\\WINexample.out\\bin;%OO_SDK_MAKE_HOME%;%OO_SDK_ZIP_HOME%;%OO_SDK_CAT_HOME%;%OO_SDK_SED_HOME%;%PATH%\"\n" +
1031        "\n" +
1032        "REM Set PATH appropriate to the output directory\n" +
1033        "if defined OO_SDK_OUT (\n" +
1034        "   @set \"PATH=%OO_SDK_OUT%\\WINexample.out\\bin;%PATH%\"\n" +
1035        " ) else (\n" +
1036        "   @set \"PATH=%OO_SDK_HOME%\\WINexample.out\\bin;%PATH%\"\n" +
1037        " )\n" +
1038        "\n" +
1039        "REM Add directory of the Win SDK to the path, if necessary.\n" +
1040        "if defined CPP_WINDOWS_SDK (\n" +
1041	"   @set \"PATH=%CPP_WINDOWS_SDK\\bin%;%PATH%\"\n" +
1042	"   @set \"INCLUDE=%CPP_WINDOWS_SDK\\Include%;%INCLUDE%\"\n" +
1043        ")\n" +
1044        "REM Add directory of the C# and VB.NET compilers to the path, if necessary.\n" +
1045        "if defined OO_SDK_CLI_HOME @set \"PATH=%OO_SDK_CLI_HOME%;%PATH%\"\n" +
1046        "\n" +
1047        "REM Add directory of the Java tools to the path, if necessary.\n" +
1048        "if defined OO_SDK_JAVA_HOME @set \"PATH=%OO_SDK_JAVA_HOME%\\bin;%OO_SDK_JAVA_HOME%\\jre\\bin;%PATH%\"\n" +
1049        "\n" +
1050        "REM Set environment for C++ compiler tools, if necessary.\n" +
1051        "if defined OO_SDK_CPP_HOME call \"%OO_SDK_CPP_HOME%\\VCVARS32.bat\"\n" +
1052        "\n" +
1053        "REM Set tilte to identify the prepared shell.\n" +
1054        "title Shell prepared for SDK\n" +
1055        "\nREM Prepare shell with all necessary environment variables.\n" +
1056        "echo.\n" +
1057        "echo  ******************************************************************\n" +
1058        "echo  *\n" +
1059        "echo  * SDK environment is prepared for Windows\n" +
1060        "echo  *\n" +
1061        "echo  * SDK = %OO_SDK_HOME%\n" +
1062        "echo  * Office = %OFFICE_HOME%\n" +
1063        "echo  * Make = %OO_SDK_MAKE_HOME%\n" +
1064        "echo  * Zip = %OO_SDK_ZIP_HOME%\n" +
1065        "echo  * cat = %OO_SDK_CAT_HOME%\n" +
1066        "echo  * sed = %OO_SDK_SED_HOME%\n" +
1067        "echo  * C++ Compiler = %OO_SDK_CPP_HOME%\n" +
1068        "echo  * C# and VB.NET compilers = %OO_SDK_CLI_HOME%\n" +
1069        "echo  * Java = %OO_SDK_JAVA_HOME%\n" +
1070        "echo  * Special Output directory = %OO_SDK_OUT%\n" +
1071        "echo  * Auto deployment = %SDK_AUTO_DEPLOYMENT%\n" +
1072        "echo  *\n" +
1073        "echo  ******************************************************************\n" +
1074        "echo.\n" +
1075        "goto end\n" +
1076        "\n" +
1077        " :error\n" +
1078        "Error: Please insert the necessary environment variables into the batch file.\n" +
1079        "\n" +
1080        " :end\n"
1081        );
1082        newFile.Close();
1083}
1084