From: <dri...@us...> - 2005-12-13 19:20:33
|
Update of /cvsroot/nantcontrib/NAntContrib/src/Tasks In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32567/src/Tasks Modified Files: Vb6Task.cs Log Message: If vb6.exe is not in one of the directorties in PATH environment variable, then lookup path in registry. In registry both major and minor version of a type library are in hex format Fix for bug #1184630: In project file, allow hex numbers for major version of "Reference" and "Object" . For "Reference" entries, the major version is in hex. For "Object" entries the major version is decimal number. Index: Vb6Task.cs =================================================================== RCS file: /cvsroot/nantcontrib/NAntContrib/src/Tasks/Vb6Task.cs,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** Vb6Task.cs 1 Jan 2005 14:04:05 -0000 1.19 --- Vb6Task.cs 13 Dec 2005 19:20:25 -0000 1.20 *************** *** 23,30 **** --- 23,32 ---- // Hani Atassi (han...@us...) + using Microsoft.Win32; using System; using System.Collections.Specialized; using System.Globalization; using System.IO; + using System.Security; using System.Text; using System.Text.RegularExpressions; *************** *** 42,50 **** /// </summary> /// <remarks> ! /// <para>Uses the VB6.EXE executable included with the Visual Basic 6 environment.</para> ! /// <para>The compiler uses the settings and source files specified in the project or group file.</para> /// </remarks> /// <example> ! /// <para>Build the project <c>HelloWorld.vbp</c> in the <c>build</c> directory.</para> /// <code> /// <![CDATA[ --- 44,60 ---- /// </summary> /// <remarks> ! /// <para> ! /// Uses the VB6.EXE executable included with the Visual Basic 6 ! /// environment. ! /// </para> ! /// <para> ! /// The compiler uses the settings and source files specified in the ! /// project or group file. ! /// </para> /// </remarks> /// <example> ! /// <para> ! /// Build the project <c>HelloWorld.vbp</c> in the <c>build</c> directory. ! /// </para> /// <code> /// <![CDATA[ *************** *** 133,137 **** /// </value> public override string ProgramFileName { ! get { return Name; } } --- 143,179 ---- /// </value> public override string ProgramFileName { ! get { ! // first check to see if VB6.EXE is available in one of the ! // directories in the PATH environment variable ! PathScanner scanner = new PathScanner(); ! // check for VB6.EXE ! scanner.Add("VB6.EXE"); ! // get results ! StringCollection results = scanner.Scan(); ! // check if we found a match ! if (results.Count > 0) { ! return results[0]; ! } else { ! try { ! // check registry for VB6 install dir ! RegistryKey vbKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\VisualStudio\6.0\Setup\Microsoft Visual Basic"); ! if (vbKey != null) { ! string productDir = vbKey.GetValue("ProductDir") as string; ! if (productDir != null) { ! string vb6Exe = Path.Combine(productDir, "VB6.EXE"); ! if (File.Exists(vb6Exe)) { ! return vb6Exe; ! } ! } ! } ! } catch (SecurityException) { ! } ! } ! ! // if VB6.exe is not available on PATH, and registry could not ! // be found or access then just have ExternalProgramBase use ! // "vb6" as program file name and deal with error ! return Name; ! } } *************** *** 266,271 **** FileSet references = new FileSet(); ! string basedir=Path.GetDirectoryName( projectFile ); ! if ( basedir != "" ) { sources.BaseDirectory = new DirectoryInfo(Path.GetDirectoryName( projectFile ) ); references.BaseDirectory = sources.BaseDirectory; --- 308,313 ---- FileSet references = new FileSet(); ! string basedir = Path.GetDirectoryName(projectFile); ! if (basedir != "" ) { sources.BaseDirectory = new DirectoryInfo(Path.GetDirectoryName( projectFile ) ); references.BaseDirectory = sources.BaseDirectory; *************** *** 345,349 **** string [] parts = ver.Split('.'); if (parts.Length > 0) { ! tmpMajor = (ushort) double.Parse(parts[0], CultureInfo.InvariantCulture); if (parts.Length > 1) { tmpMinor16 = Convert.ToUInt16(parts[1], 16); // Treat minor as hex --- 387,391 ---- string [] parts = ver.Split('.'); if (parts.Length > 0) { ! tmpMajor = (ushort) Convert.ToUInt16(parts[0], 16); if (parts.Length > 1) { tmpMinor16 = Convert.ToUInt16(parts[1], 16); // Treat minor as hex *************** *** 401,405 **** // Regexp that extracts reference entries from the VBP (Reference=) ! Regex referenceRegEx = new Regex(@"(Object|Reference)\s*=\s*({|\*\\G{)(?<tlbguid>[0-9\-A-Fa-f]*($^\.)*)}\#(?<majorver>[0-9($^\.)]*)\.(?<minorver>[0-9a-fA-F($^\.)]*)\#(?<lcid>[0-9]($^\.)*)(;|\#)(?<tlbname>[^\#\n\r]*)"); string key = String.Empty; --- 443,447 ---- // Regexp that extracts reference entries from the VBP (Reference=) ! Regex referenceRegEx = new Regex(@"(Object|Reference)\s*=\s*({|\*\\G{)(?<tlbguid>[0-9\-A-Fa-f]*($^\.)*)}\#(?<majorver>[0-9a-fA-F($^\.)]*)\.(?<minorver>[0-9a-fA-F($^\.)]*)\#(?<lcid>[0-9]($^\.)*)(;|\#)(?<tlbname>[^\#\n\r]*)"); string key = String.Empty; *************** *** 410,418 **** while ((fileLine = reader.ReadLine()) != null) { match = keyValueRegEx.Match(fileLine); ! if (match.Success) { ! key = match.Groups["key"].Value; ! keyValue = match.Groups["value"].Value; ! if (key == "Class" || key == "Module") { // This is a class or module source file - extract the file name and add it to the sources fileset // The entry is of the form "Class=ClassName;ClassFile.cls" --- 452,465 ---- while ((fileLine = reader.ReadLine()) != null) { match = keyValueRegEx.Match(fileLine); ! if (!match.Success) { ! continue; ! } ! key = match.Groups["key"].Value; ! keyValue = match.Groups["value"].Value; ! ! switch (key) { ! case "Class": ! case "Module": // This is a class or module source file - extract the file name and add it to the sources fileset // The entry is of the form "Class=ClassName;ClassFile.cls" *************** *** 421,478 **** sources.Includes.Add(match.Groups["filename"].Value); } ! } ! else if (key == "Form" || key == "UserControl" || key == "PropertyPage") { // This is a form, control, or property page source file - add the file name to the sources fileset // The entry is of the form "Form=Form1.frm" sources.Includes.Add(keyValue); ! } ! else if (key == "Object" || key == "Reference") { // This is a source file - extract the reference name and add it to the references fileset match = referenceRegEx.Match(fileLine); ! if (match.Success) { ! string tlbName = match.Groups["tlbname"].Value; ! if (File.Exists(tlbName)) { ! references.Includes.Add(tlbName); } ! else { ! //the tlb filename embedded in the VBP file is just ! //a hint about where to look for it. If the file isn't ! //at that location, the typelib ID is used to lookup ! //the file name ! ! // # Added to properly cast the parts of the version # ! // Ensure that we use the correct cast option ! string temp = match.Groups["majorver"].Value; ! ushort majorVer = (ushort) double.Parse(temp, CultureInfo.InvariantCulture); ! ! // Minor is considered a hex value ! temp = match.Groups["minorver"].Value; ! ushort minorVer16 = Convert.ToUInt16(temp, 16); ! temp = match.Groups["lcid"].Value; ! uint lcid = 0; ! ! if ( 0 < temp.Length) { ! lcid = (uint) double.Parse(temp, CultureInfo.InvariantCulture); ! } ! ! string tlbGuid = match.Groups["tlbguid"].Value; ! Guid guid = new Guid(tlbGuid); ! // Find the tlb file ! tlbName = VB6GetTypeLibFile(guid, majorVer, minorVer16, lcid); if (File.Exists(tlbName)) { references.Includes.Add(tlbName); } else { ! // Show a warning if we couldn't find the reference. Don't rely on VB. ! if (tlbName == null) { ! Log(Level.Warning, "Couldn't find the tlb file for '{0}' ver.{1}.{2:x}.", guid, majorVer, minorVer16); ! } else { ! Log(Level.Warning, "Couldn't find the file '{0}'.", tlbName); ! } } } } ! } else if (key == "ExeName32") { // Store away the built file name so that we can check against it later // If the project was never built in the IDE, or the project file wasn't saved --- 468,535 ---- sources.Includes.Add(match.Groups["filename"].Value); } ! break; ! case "Form": ! case "UserControl": ! case "PropertyPage": // This is a form, control, or property page source file - add the file name to the sources fileset // The entry is of the form "Form=Form1.frm" sources.Includes.Add(keyValue); ! break; ! case "Object": ! case "Reference": // This is a source file - extract the reference name and add it to the references fileset match = referenceRegEx.Match(fileLine); ! if (!match.Success) { ! break; ! } ! ! string tlbName = match.Groups["tlbname"].Value; ! if (File.Exists(tlbName)) { ! references.Includes.Add(tlbName); ! } else { ! // the tlb filename embedded in the VBP file is just ! // a hint about where to look for it. If the file isn't ! // at that location, the typelib ID is used to lookup ! // the file name ! ! string temp = match.Groups["majorver"].Value; ! ushort majorVer = 0; ! if (key == "Object") { ! // for OCX's major is a decimal value ! majorVer = ushort.Parse(temp, CultureInfo.InvariantCulture); ! } else { ! // for dll's major is a hex value ! majorVer = (ushort) Convert.ToUInt16(temp, 16); } ! ! // minor is considered a hex value ! temp = match.Groups["minorver"].Value; ! ushort minorVer16 = Convert.ToUInt16(temp, 16); ! temp = match.Groups["lcid"].Value; ! uint lcid = 0; ! ! if (temp.Length != 0) { ! lcid = (uint) double.Parse(temp, CultureInfo.InvariantCulture); ! } ! ! string tlbGuid = match.Groups["tlbguid"].Value; ! Guid guid = new Guid(tlbGuid); ! // find the type library file ! tlbName = VB6GetTypeLibFile(guid, majorVer, minorVer16, lcid); ! if (tlbName == null) { ! Log(Level.Warning, "Type library '{0}' version {1}.{2:x} could not be found.", ! guid, match.Groups["majorver"].Value, match.Groups["minorver"].Value); ! } else { if (File.Exists(tlbName)) { references.Includes.Add(tlbName); } else { ! Log(Level.Warning, "Type library file '{0}' does not exist.", tlbName); } } } ! break; ! case "ExeName32": // Store away the built file name so that we can check against it later // If the project was never built in the IDE, or the project file wasn't saved *************** *** 480,492 **** // ProjectName as the DLL/EXE name outputFile = keyValue.Trim('"'); ! } else if (key == "Type") { // Store away the project type - we may need it to construct the built // file name if ExeName32 doesn't exist projectType = keyValue; ! } else if (key == "Name") { // Store away the project name - we may need it to construct the built // file name if ExeName32 doesn't exist projectName = keyValue.Trim('"'); ! } } } --- 537,551 ---- // ProjectName as the DLL/EXE name outputFile = keyValue.Trim('"'); ! break; ! case "Type": // Store away the project type - we may need it to construct the built // file name if ExeName32 doesn't exist projectType = keyValue; ! break; ! case "Name": // Store away the project name - we may need it to construct the built // file name if ExeName32 doesn't exist projectName = keyValue.Trim('"'); ! break; } } |