Scan() public method

Scans all direcetories in the PATH environment variable for files.
public Scan ( ) : StringCollection
return System.Collections.Specialized.StringCollection
        /// <summary>
        /// Creates a .cab file with all source files included.
        /// </summary>
        /// <param name="database">The MSI database.</param>
        private void CreateCabFile(InstallerDatabase database) {
            Log(Level.Info, "Compressing Files...");

            string shortCabDir = GetShortDir(Path.Combine(Project.BaseDirectory, msi.sourcedir));
            string cabFilePath = shortCabDir + @"\" + CabFileName;

            if (!Directory.Exists(TempFolderPath))
                Directory.CreateDirectory(TempFolderPath);

            // holds output buffer
            MemoryStream ms = new MemoryStream();

            // create task for creating cab file
            ExecTask cabarcTask = new ExecTask();
            cabarcTask.Project = Project;
            cabarcTask.Parent = task;
            cabarcTask.Verbose = Verbose;
            // write output to (Memory)Stream
            cabarcTask.ErrorWriter = cabarcTask.OutputWriter = new StreamWriter(ms);
            // set tool to execute
            cabarcTask.FileName = "cabarc";
            // set command line arguments
            cabarcTask.CommandLineArguments = "-r N " + cabFilePath + " *";
            // use directory containing files to add as working directory
            cabarcTask.WorkingDirectory = new DirectoryInfo(TempFolderPath);

            try {
                // increment indentation level
                cabarcTask.Project.Indent();

                // execute task
                cabarcTask.Execute();
            } catch (Exception ex) {
                // read output of cabarc
                ms.Position = 0;
                StreamReader sr = new StreamReader(ms);
                string output = sr.ReadToEnd();
                sr.Close();

                // if anything was output, log it as warning
                if (output.Length != 0) {
                    cabarcTask.Log(Level.Warning, output);
                }
                
                string path = Environment.GetEnvironmentVariable ("PATH");
                if (path != null) {
                    Console.WriteLine ("PATH=" + path);
                    PathScanner scanner = new PathScanner ();
                    scanner.Add ("cabarc.exe");
                    StringCollection files = scanner.Scan ();
                    if (files.Count > 0) {
                        foreach (string file in files)
                            Console.WriteLine ("FILE=" + file);
                    } else {
                            Console.WriteLine ("NOT FOUND IN PATH!");
                    }
                }

                // signal error
                throw new BuildException("Error creating cab file.", Location, ex);
            } finally {
                // restore indentation level
                cabarcTask.Project.Unindent();

                // close MemoryStream
                ms.Close();
            }

            if (File.Exists(cabFilePath)) {
                Log(Level.Verbose, "Storing Cabinet in Installer Database...");

                using (InstallerTable cabTable = database.OpenTable("_Streams")) {
                    cabTable.InsertRecord(Path.GetFileName(cabFilePath), 
                        new InstallerStream(cabFilePath));
                }
            } else {
                throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                    "Cabinet file '{0}' does not exist.", cabFilePath), Location);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Determines whether any file that are includes in the specified
        /// source file has been updated after the obj was compiled.
        /// </summary>
        /// <param name="srcFileName">The source file to check.</param>
        /// <param name="objLastWriteTime">The last write time of the compiled obj.</param>
        /// <returns>
        /// The full path to the include file that was modified after the obj
        /// was compiled, or <see langword="null" /> if no include files were
        /// modified since the obj was compiled.
        /// </returns>
        /// <remarks>
        ///   <para>
        ///   To determine what includes are defined in a source file, conditional
        ///   directives are not honored.
        ///   </para>
        ///   <para>
        ///   If a given include cannot be resolved to an existing file, then
        ///   it will be considered stable.
        ///   </para>
        /// </remarks>
        private string FindUpdatedInclude(string srcFileName, DateTime objLastWriteTime) {
            // quick and dirty code to check whether includes have been modified
            // after the source was last modified

            // TODO: recursively check includes

            Log(Level.Debug, "Checking whether includes of \"{0}\" have been"
                + " updated.", srcFileName);

            // holds the line we're parsing
            string line;

            // locate include directives in source file
            using (StreamReader sr = new StreamReader(srcFileName, true)) {
                while ((line = sr.ReadLine()) != null) {
                    Match match = _includeRegex.Match(line);
                    if (match.Groups.Count != 2) {
                        continue;
                    }

                    string includeFile = match.Groups["includefile"].Value;

                    Log(Level.Debug, "Checking include \"{0}\"...", includeFile);

                    string resolvedInclude = _resolvedIncludes[includeFile] as string;
                    if (resolvedInclude == null) {
                        foreach (string includeDir in IncludeDirs.DirectoryNames) {
                            string foundIncludeFile = FileUtils.CombinePaths(includeDir, includeFile);
                            if (File.Exists(foundIncludeFile)) {
                                Log(Level.Debug, "Found include \"{0}\" in"
                                    + " includedirs.", includeFile);
                                resolvedInclude = foundIncludeFile;
                                break;
                            }
                        }

                        // if we could not locate include in include dirs and
                        // source dir, then try to locate include in INCLUDE 
                        // env var
                        if (resolvedInclude == null) {
                            PathScanner pathScanner = new PathScanner();
                            pathScanner.Add(includeFile);
                            StringCollection includes = pathScanner.Scan("INCLUDE");
                            if (includes.Count > 0) {
                                Log(Level.Debug, "Found include \"{0}\" in"
                                    + " INCLUDE.", includeFile);
                                resolvedInclude = includes[0];
                            }
                        }

                        // if we could not locate include in include dirs
                        // and INCLUDE env var then check for include in base
                        // directory (which is used as working dir)
                        if (resolvedInclude == null) {
                            string foundIncludeFile = FileUtils.CombinePaths(
                                BaseDirectory.FullName, includeFile);
                            if (File.Exists(foundIncludeFile)) {
                                Log(Level.Debug, "Found include \"{0}\" in"
                                    + " working directory.", includeFile);
                                resolvedInclude = foundIncludeFile;
                            }
                        }

                        if (resolvedInclude != null) {
                            _resolvedIncludes.Add(includeFile, resolvedInclude);
                        }
                    }

                    if (resolvedInclude != null) {
                        if (File.GetLastWriteTime(resolvedInclude) > objLastWriteTime) {
                            return resolvedInclude;
                        }
                    } else {
                        // TODO: what do we do if the include cannot be located ?
                        //
                        // for now we'll consider the obj file to be up-to-date
                        Log(Level.Debug, "Include \"{0}\" could not be located.", 
                            includeFile);
                    }
                }
            }

            return null;
        }
Esempio n. 3
0
 /// <summary>
 /// Routine which checks if the resource compiler is present.
 /// </summary>
 /// <returns>
 /// <see langword="true" /> if the resource compiler is present; 
 /// otherwise, <see langword="false" />.
 /// </returns>
 private static bool CheckResourceCompilerPresent() {
     PathScanner scanner = new PathScanner();
     scanner.Add("rc.exe");
     return scanner.Scan("PATH").Count > 0;
 }
Esempio n. 4
0
 private static StringCollection GetCompilersOnPath() {
     PathScanner scanner = new PathScanner();
     scanner.Add("cl.exe");
     return scanner.Scan("PATH");
 }
Esempio n. 5
0
 /// <summary>
 /// Routine which checks if the header files are present.
 /// </summary>
 /// <returns>
 /// <see langword="true" /> if the header files are present; otherwise,
 /// <see langword="false" />.
 /// </returns>
 private static bool CheckHeaderFilesPresent() {
     foreach (string headerFile in ExpectedHeaderFiles) {
         PathScanner scanner = new PathScanner();
         scanner.Add(headerFile);
         if (scanner.Scan("INCLUDE").Count == 0) {
             return false;
         }
     }
     return true;
 }
Esempio n. 6
0
 /// <summary>
 /// Routine which checks if the libs are present.
 /// </summary>
 /// <returns>
 /// <see langword="true" /> if the libs are present; otherwise,
 /// <see langword="false" />.
 /// </returns>
 private static bool CheckLibsPresent() {
     foreach (string lib in ExpectedLibs) {
         PathScanner scanner = new PathScanner();
         scanner.Add(lib);
         if (scanner.Scan("LIB").Count == 0) {
             return false;
         }
     }
     return true;
 }
Esempio n. 7
0
        protected string MKSExecute(string command) {
            // locate Source Integrity client on PATH
            PathScanner pathScanner = new PathScanner();
            pathScanner.Add("si.exe");
            StringCollection files = pathScanner.Scan();

            if (files.Count == 0) {
                throw new BuildException("Could not find MKS Integrity Client on the system path.",
                    Location);
            }

            // set up process
            Process proc = new Process();
            proc.StartInfo.UseShellExecute=false;
            proc.StartInfo.CreateNoWindow=true;
            proc.StartInfo.RedirectStandardOutput=true;
            proc.StartInfo.RedirectStandardError=true;
            proc.StartInfo.FileName = files[0];
            proc.StartInfo.Arguments = command;
            proc.Start();
            proc.WaitForExit();

            if (proc.ExitCode != 0) {
                throw new BuildException(proc.ExitCode.ToString(), Location, 
                    new Exception(proc.StandardError.ReadToEnd()));
            } else {
                return proc.StandardOutput.ReadToEnd();
            }
        }