/// <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); } }