/// <summary> /// Packs a set of files into a docpak exe. /// </summary> private void Pack() { ConsoleHelper.UseConsole(); string rootDirectory = Path.Combine(Environment.CurrentDirectory, DirectoryLocation); // Check that input directory contains at least an index.htm / index.html file if (!File.Exists(Path.Combine(rootDirectory, Archive.DefaultHtmlRoot)) && File.Exists(Path.Combine(rootDirectory, Archive.DefaultHtmlRootAlternate))) { UsageError("Directory [{0}] must contain at least an {1} or {2} file", rootDirectory, Archive.DefaultHtmlRoot, Archive.DefaultHtmlRootAlternate); } // Initialize the indexer var indexer = new DocumentIndexer { Tags = Tags }; indexer.Init(); // Initialize the archive var archive = new Archive { Title = Title, Tags = indexer.Tags, Index = indexer.Index }; // Iterate on all files var files = Directory.GetFiles(rootDirectory, "*", SearchOption.AllDirectories); foreach (var file in files) { var fileName = file.Substring(rootDirectory.Length).Replace('\\', '/'); byte[] buffer = File.ReadAllBytes(file); archive.Files.Add(fileName, buffer); indexer.AddFile(fileName, buffer); } // Close the indexer indexer.Close(); // Create a docpak exe Output = Path.ChangeExtension(Output, ".exe"); var input = new FileStream(typeof(SharpDocPakApp).Assembly.Location, FileMode.Open, FileAccess.Read); var output = new FileStream(Output, FileMode.Create, FileAccess.Write); // Appends the archive archive.Append(input, output); input.Close(); output.Close(); Console.WriteLine("Docpak exe successfully generated to [{0}]", Output); }
/// <summary> /// Packs a set of files into a docpak exe. /// </summary> private void Pack() { ConsoleHelper.UseConsole(); string rootDirectory = Path.Combine(Environment.CurrentDirectory, DirectoryLocation); // Check that input directory contains at least an index.htm / index.html file if (!File.Exists(Path.Combine(rootDirectory, Archive.DefaultHtmlRoot)) && File.Exists(Path.Combine(rootDirectory, Archive.DefaultHtmlRootAlternate))) { UsageError("Directory [{0}] must contain at least an {1} or {2} file", rootDirectory, Archive.DefaultHtmlRoot, Archive.DefaultHtmlRootAlternate); } // Initialize the indexer var indexer = new DocumentIndexer {Tags = Tags}; indexer.Init(); // Initialize the archive var archive = new Archive { Title = Title, Tags = indexer.Tags, Index = indexer.Index }; // Iterate on all files var files = Directory.GetFiles(rootDirectory, "*", SearchOption.AllDirectories); foreach (var file in files) { var fileName = file.Substring(rootDirectory.Length).Replace('\\', '/'); byte[] buffer = File.ReadAllBytes(file); archive.Files.Add(fileName, buffer); indexer.AddFile(fileName, buffer); } // Close the indexer indexer.Close(); // Create a docpak exe Output = Path.ChangeExtension(Output, ".exe"); var input = new FileStream(typeof(SharpDocPakApp).Assembly.Location, FileMode.Open, FileAccess.Read); var output = new FileStream(Output, FileMode.Create, FileAccess.Write); // Appends the archive archive.Append(input, output); input.Close(); output.Close(); Console.WriteLine("Docpak exe successfully generated to [{0}]", Output); }