<commit_before>﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using DiscUtils.Ntfs;
using RawDiskLib;

namespace PythLR
{
    static class Program
    {
        static void Main(string[] args)
        {
            string[] paths =
            {
                @"\Windows\System32\config",
                @"\Windows\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup",
                @"\Windows\Prefetch",
                @"\Windows\Tasks",
                @"\Windows\SchedLgU.Txt",
                @"\Windows\System32\winevt\logs",
                @"\Windows\System32\drivers\etc\hosts"
            };
            var stopwatch = new Stopwatch();
            stopwatch.Start();

            var system = GetFileSystem('C');

            CollectFilesToArchive(paths, system, "output.zip");

            stopwatch.Stop();
            Console.WriteLine("{0} elapsed", new TimeSpan(stopwatch.ElapsedTicks).ToString("g"));
        }

        private static void CollectFilesToArchive(IEnumerable<string> paths, NtfsFileSystem system, string archivePath)
        {

            using (var outStream = File.OpenWrite(archivePath))
            using (var zipStream = new ZipArchive(outStream, ZipArchiveMode.Create))
            {
                foreach (var path in paths)
                {
                    var directory = system.GetDirectoryInfo(path);
                    if (system.FileExists(path))
                    {
                        using (var stream = system.OpenFile(path, FileMode.Open, FileAccess.Read))
                        {
                            WriteStreamToArchive(zipStream, path, stream);
                        }
                    }
                    else if (directory.Exists)
                    {
                        var files = directory.GetFiles();

                        foreach (var file in files)
                        {
                            using (var stream = system.OpenFile(file.FullName, FileMode.Open, FileAccess.Read))
                            {
                                WriteStreamToArchive(zipStream, file.FullName, stream);
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("Directory '{0}' does not exist and has been skipped.", path);
                    }
                }
            }
        }

        private static NtfsFileSystem GetFileSystem(char driveLetter)
        {
            var disk = new RawDisk(driveLetter);
            var rawDiskStream = disk.CreateDiskStream();
            var system = new NtfsFileSystem(rawDiskStream);
            return system;
        }

        private static void WriteStreamToArchive(ZipArchive zipStream, string entryName, Stream stream)
        {
            var entry = zipStream.CreateEntry(entryName, CompressionLevel.Fastest);
            using (var writer = entry.Open())
            {
                stream.CopyTo(writer);
            }
        }
    }
}
<commit_msg>Collecting to a zip file<commit_after>﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using DiscUtils.Ntfs;
using RawDiskLib;

namespace PythLR
{
    static class Program
    {
        static void Main(string[] args)
        {
            string[] paths =
            {
                @"\Windows\System32\config",
                @"\Windows\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup",
                @"\Windows\Prefetch",
                @"\Windows\Tasks",
                @"\Windows\SchedLgU.Txt",
                @"\Windows\System32\winevt\logs",
                @"\Windows\System32\drivers\etc\hosts"
            };
            var stopwatch = new Stopwatch();
            stopwatch.Start();

            var system = GetFileSystem('C');

            var zipfilename = Environment.MachineName+".zip";
            CollectFilesToArchive(paths, system, zipfilename);

            stopwatch.Stop();
            Console.WriteLine("{0} elapsed", new TimeSpan(stopwatch.ElapsedTicks).ToString("g"));
        }

        private static void CollectFilesToArchive(IEnumerable<string> paths, NtfsFileSystem system, string archivePath)
        {

            using (var outStream = File.OpenWrite(archivePath))
            using (var zipStream = new ZipArchive(outStream, ZipArchiveMode.Create))
            {
                foreach (var path in paths)
                {
                    var directory = system.GetDirectoryInfo(path);
                    if (system.FileExists(path))
                    {
                        writefile(system, zipStream, path.Substring(1));
                    }
                    else if (directory.Exists)
                    {
                        var files = directory.GetFiles();

                        foreach (var file in files)
                        {
                            writefile(system, zipStream, file.FullName);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Directory '{0}' does not exist and has been skipped.", path);
                    }
                }
                writefile(system, zipStream, @"$MFT");
            }
        }

        private static void writefile(NtfsFileSystem system, ZipArchive zipStream, String file)
        {
            Console.WriteLine("Collecting File: {0}", file);
            using (var stream = system.OpenFile(file, FileMode.Open, FileAccess.Read))
            {
                WriteStreamToArchive(zipStream, file, stream);
            }
        }

        private static NtfsFileSystem GetFileSystem(char driveLetter)
        {
            var disk = new RawDisk(driveLetter);
            var rawDiskStream = disk.CreateDiskStream();
            var system = new NtfsFileSystem(rawDiskStream);
            return system;
        }

        private static void WriteStreamToArchive(ZipArchive zipStream, string entryName, Stream stream)
        {
            var entry = zipStream.CreateEntry(entryName, CompressionLevel.Fastest);
            using (var writer = entry.Open())
            {
                stream.CopyTo(writer);
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.09046646772420291, 'fraction_numerical': 0.002827077116381341, 'mean_word_length': 1.3984934086629002, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1039152', 'n_tokens_mistral': 1603, 'n_tokens_neox': 1480, 'n_words': 328}