Modifying InfoPath manifest.xsf file from script (4/5)

 

Part 4 of 5: Repacking the XSN

For packing algorithm we will use another useful utility from the Cabinet SDK which called “makecab.exe”. It can be found in the same place where extract.exe lives.

 

This utility needs some data description file that we will build automatically from the XSF file.

var MakecabExeLocation = "%SystemRoot%\SYSTEM32";

var MakecabExe = Combine(MakecabExeLocation, "makecab.exe");

function SaveToFile(data, filePath)

{

      var Fso = new ActiveXObject ("Scripting.FileSystemObject");

      Fso.CreateTextFile(filePath, true);

      var TextStream = Fso.OpenTextFile (filePath, 2);

      TextStream.Write(data);

      TextStream.Close();

}

function MakeXSNFromFiles(

      inputDirectory,

      xsfName,

      outputDirectory,

      xsnName)

{

      var DDF = "";

      DDF += ".Set DiskDirectoryTemplate=rn";

      DDF += ".Set CabinetNameTemplate='"

            + Combine(outDir, xsnName) + "'rn";

      var Dom = new ActiveXObject("msxml2.domdocument.5.0");

      Dom.async=false;

      Dom.validateOnParse=false; // for ignoring xsi:nil errors..

      Dom.load(Combine(inputDirectory, xsfName));

      Dom.setProperty("SelectionNamespaces",

                  "xmlns:xsf='" + XsfNamespace + "'");

      DDF += QuoteStr(Combine(inputDirectory, xsfName)) + "rn";

      var Filelist = Dom.selectNodes("//xsf:files/xsf:file/@name");

      for (var i=0; i<Filelist.length; i++)

            DDF += QuoteStr(Combine(inputDirectory, Filelist(i).text))

                  + "rn";

      var DDFPath = Combine(outputDirectory, "makecab.ddf");

      SaveToFile(DDF, DDFPath);

      Exec(QuoteStr(MakecabExe)

            + " /v1 /f " + QuoteStr(DDFPath)

            + " /L " + QuoteStr(outputDirectory), true);

}

In the last fifth part of the discussion we will come up with the final function.