/// <summary>
        /// Extracts all dat archives to C:\skeletonKey\SourceDats\
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void btnDeArchiveDATs_Click(object sender, RoutedEventArgs e)
        {
            var    dats      = DATFile.GetDatFiles();
            string outputDir = @"C:\skeletonKey\SourceDats\";

            Directory.CreateDirectory(outputDir);
            Console.WriteLine("Retrieving local DAT file archives - Count: " + dats.Count());
            Console.WriteLine("Extracting DATs to " + outputDir);

            await Task.Run(() =>
            {
                foreach (var d in dats)
                {
                    try
                    {
                        using (SevenZip.SevenZipExtractor archive = new SevenZip.SevenZipExtractor(d))
                        {
                            Console.WriteLine("Extracting: " + Path.GetFileName(d) + " To: " + outputDir + Path.GetFileNameWithoutExtension(d));
                            archive.ExtractArchive(outputDir);
                        }
                    }
                    catch (Exception ex)
                    {
                        string eS = ex.ToString();
                    }
                }
            });

            Console.WriteLine("------------Done------------");
        }
        /// <summary>
        /// Prints current source DAT files
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnEnumDatFiles_Click(object sender, RoutedEventArgs e)
        {
            var dats = DATFile.GetDatFiles();

            Console.WriteLine("Retrieving local DAT file archives - Count: " + dats.Count());
            Console.WriteLine("Enumerating.....");
            foreach (var dat in dats)
            {
                Console.WriteLine(Path.GetFileName(dat));
            }
            Console.WriteLine("------------Done------------");
        }
        /// <summary>
        /// Scans the DAT archives returning the different system names
        /// then imports them to the database
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnImportSystems_Click(object sender, RoutedEventArgs e)
        {
            var dats = DATFile.GetDatFiles();

            Console.WriteLine("Retrieving local DAT file archives - Count: " + dats.Count());
            Console.WriteLine("Enumerating.....");

            List <string> sysNames = new List <string>();

            foreach (var dat in dats)
            {
                string dName = Path.GetFileNameWithoutExtension(dat);
                sysNames.Add(dName);
                Console.WriteLine(dName);
            }

            Console.WriteLine("Adding/updating systems in the database...");

            Database.DBFunctions.AddUpdateSystems(sysNames);

            Console.WriteLine("...Done");

            Console.WriteLine("------------Done------------");
        }
        /// <summary>
        /// Processes DAT files from disk (from archives)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void btnProcessDATs_Click(object sender, RoutedEventArgs e)
        {
            var dats = DATFile.GetDatFiles();

            Console.WriteLine("Retrieving local DAT file archives - Count: " + dats.Count());
            int counter = 0;

            // setup output directory
            string baseDir         = AppDomain.CurrentDomain.BaseDirectory;
            string exportedDir     = "C:\\skeletonKey\\ExportedDats\\";
            string baseExportedDir = "rj\\scrapeart\\";
            string rootPath        = exportedDir + baseExportedDir;

            Directory.CreateDirectory(rootPath);

            foreach (var dat in dats)//.Where(a => a.ToLower().Contains("lynx")))
            {
                // create dir for DAT
                string datExportDir = rootPath + Path.GetFileNameWithoutExtension(dat);
                Directory.CreateDirectory(datExportDir);

                counter++;
                Console.WriteLine("Processing " + System.IO.Path.GetFileName(dat) + " (" + counter + " of " + dats.Count() + ")");
                Archive arch = new Archive();
                Console.WriteLine("(Exporting to " + datExportDir + ")");

                await Task.Run(() =>
                {
                    var results    = arch.ProcessArchive(dat);
                    var rCount     = results.Results.Count();
                    var percentage = rCount / 50;
                    int cnt        = 0;
                    int cnter      = 0;

                    // process each archived file
                    foreach (var file in results.Results)
                    {
                        string finalXml = string.Empty;
                        using (Stream archiveStream = File.OpenRead(dat))
                        {
                            byte[] fData = Archive.ExtractFileToByteArray(archiveStream, file.InternalPath);
                            var str      = Encoding.ASCII.GetString(fData);
                            string fix   = XML.FixXml(str, this);
                            finalXml     = fix;
                        }
                        cnt++;


                        // write file to disk
                        File.WriteAllText(datExportDir + "\\" + file.FileName, finalXml);

                        // percentage complete
                        int currPos = Convert.ToInt32((double)(((double)cnt / (double)rCount) * 100));

                        if (currPos > cnter)
                        {
                            Console.Write(".");
                            cnter = currPos;
                        }
                    }
                    Console.Write("\n");

                    foreach (var res in results.Results)
                    {
                        //Console.WriteLine(res.InternalPath);
                    }
                });
            }
            Console.WriteLine("------------Done------------");
        }