// ImportPackages.cs
using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using Microsoft.ComponentStudio.ComponentPlatformInterface;
namespace ImportPackages
{
public class ImportPackage
{
private const string distributionSharePath =
@"C:\DistributionShare";
private const string cabFilesPath =
@"C:\Packages";
static void Main()
{
CreateDistributionShare();
// Deletion complete:
Console.WriteLine("Old folders have been deleted.");
// Success message:
Console.WriteLine("The disribution share is created at {0}",
distributionSharePath);
ImportAPackage();
Console.WriteLine("The package is imported from: {0}",
cabFilesPath);
}
private static void CreateDistributionShare()
{
// If exists, delete the old one.
if (Directory.Exists(distributionSharePath))
{
string[] filenames =
Directory.GetFiles(distributionSharePath, "*",
SearchOption.AllDirectories);
foreach (string filename in filenames)
File.SetAttributes(filename,
FileAttributes.Normal);
Directory.Delete(distributionSharePath, true);
}
// Creating new folders:
// Define path of a new folder for packages:
string packagesFolder = Path.Combine(distributionSharePath,
DistributionShareInfo.PackagesFolder);
// Define path of out-of-box drivers:
string oobDriver = Path.Combine(distributionSharePath,
DistributionShareInfo.OutOfBoxDriversFolder);
// Define path of $OEM$:
string oemFolder = Path.Combine(distributionSharePath,
DistributionShareInfo.OemFolder);
// Create the three defining directories of
// a distribution share:
Directory.CreateDirectory(packagesFolder);
Directory.CreateDirectory(oobDriver);
Directory.CreateDirectory(oemFolder);
}
public static void ImportAPackage()
{
// Set the packages folder string:
string packagesFolder = Path.Combine(distributionSharePath,
DistributionShareInfo.PackagesFolder);
// Get the source path for "Calc":
string calc = Path.Combine(cabFilesPath, "Calc.cab");
// Import the "Calc" package:
DistributionShareInfo.ImportPackage(calc,
distributionSharePath);
// Get the source files and check to make sure
// they were imported to the correct location:
string calcResult = Path.Combine(Path.Combine(
Path.Combine(packagesFolder, "HotFix"),
"x86_Microsoft.Windows.Calc.Demo_1.0.0.0_en_6595b64144ccf1df_"),
"calc.cab");
// Get the source path for "Clock":
string clock = Path.Combine(cabFilesPath,
"ClockQfe.cab");
// Import the "Clock" package:
DistributionShareInfo.ImportPackage(clock,
distributionSharePath);
// Get the source files and check to make sure
// they were imported to the correct location:
string clockResultFolder = Path.Combine(Path.Combine(
packagesFolder, "HotFix"),
"x86_Clock.Demo.qfe_1.0.0.0_en_6595b64144ccf1df_");
// Get the source path for "LangPack":
string langpack = Path.Combine(cabFilesPath,
"LangPack.cab");
// Import the "Clock" package:
DistributionShareInfo.ImportPackage(langpack,
distributionSharePath);
// Get the source files and make sure
// they were imported to the correct location:
string langpackResultFolder = Path.Combine(
Path.Combine(packagesFolder, "LanguagePack"),
"x86_Microsoft-Windows-WindowsFoundation-LanguagePack-Package" +
"_6.0.5210.0_en-US_31bf3856ad364e35_nonSxS");
// Get the source path for "OOB":
string oob = Path.Combine(cabFilesPath, "OOB.cab");
// Import the "oob" package:
DistributionShareInfo.ImportPackage(oob,
distributionSharePath);
// Get the source files and make sure
// they were imported to the correct location:
string oobResultFolder = Path.Combine(Path.Combine(
packagesFolder, "HotFix"),
"x86_Clock.Demo_1.0.0.0_en_6595b64144ccf1df_");
// Get the source path for "SP":
string sp = Path.Combine(cabFilesPath, "SP.cab");
// Import the "SP" package:
DistributionShareInfo.ImportPackage(sp,
distributionSharePath);
// Get the source files and make sure
// they were imported to the correct location:
string spResultFolder = Path.Combine(
Path.Combine(packagesFolder, "HotFix"),
"x86_Microsoft-Windows-Kernel32-QFE_6.0.5096.1" +
"_neutral_31bf3856ad364e35_");
}
}
}
|