コード例 #1
0
ファイル: LegendsViewer.cs プロジェクト: RossM/Legends-Viewer
        private void extractZip_DoWork(object sender, DoWorkEventArgs e)
        {
            using (SevenZipExtractor extractor = new SevenZipExtractor(e.Argument as String))
            {
                if (extractor.ArchiveFileNames.Count(file => file.EndsWith(".xml")) > 1 || extractor.ArchiveFileNames.Count(file => file.EndsWith(".xml")) == 0)
                    throw new Exception("Not enough or too many XML Files");
                if (extractor.ArchiveFileNames.Count(file => file.EndsWith(".world_history.txt")) > 1 || extractor.ArchiveFileNames.Count(file => file.EndsWith("-world_history.txt")) == 0)
                    throw new Exception("Not enough or too many World History Text Files");
                if (extractor.ArchiveFileNames.Count(file => file.EndsWith("-world_sites_and_pops.txt")) > 1 || extractor.ArchiveFileNames.Count(file => file.EndsWith("-world_sites_and_pops.txt")) == 0)
                    throw new Exception("Not enough or too many Site & Pops Text Files");
                if (extractor.ArchiveFileNames.Count(file => file.EndsWith(".bmp") || file.EndsWith(".png") || file.EndsWith(".jpg") || file.EndsWith(".jpeg")) == 0)
                    throw new Exception("No map image found.");

                string xml = extractor.ArchiveFileNames.Where(file => file.EndsWith(".xml")).Single();
                if (File.Exists(xml)) throw new Exception(xml + " already exists.");
                extractor.ExtractFiles(System.IO.Directory.GetCurrentDirectory(), xml);
                extractedFiles.Add(xml);

                string history = extractor.ArchiveFileNames.Where(file => file.EndsWith("-world_history.txt")).Single();
                if (File.Exists(history)) throw new Exception(history + " already exists.");
                extractor.ExtractFiles(System.IO.Directory.GetCurrentDirectory(), history);
                extractedFiles.Add(history);

                string sites = extractor.ArchiveFileNames.Where(file => file.EndsWith("-world_sites_and_pops.txt")).Single();
                if (File.Exists(sites)) throw new Exception(sites + " already exists.");
                extractor.ExtractFiles(System.IO.Directory.GetCurrentDirectory(), sites);
                extractedFiles.Add(sites);

                string map = "";

                if (extractor.ArchiveFileNames.Count(file => file.EndsWith(".bmp") || file.EndsWith(".png") || file.EndsWith(".jpg") || file.EndsWith(".jpeg")) == 1)
                    map = extractor.ArchiveFileNames.Single(file => file.EndsWith(".bmp") || file.EndsWith(".png") || file.EndsWith(".jpg") || file.EndsWith(".jpeg"));
                else
                {
                    dlgFileSelect fileSelect = new dlgFileSelect(extractor.ArchiveFileNames.Where(file => file.EndsWith(".bmp") || file.EndsWith(".png") || file.EndsWith(".jpg") || file.EndsWith(".jpeg")).ToList());
                    fileSelect.Text = "Select Base Map";
                    fileSelect.ShowDialog();
                    if (fileSelect.SelectedFile == "") throw new Exception("No map file selected.");
                    if (File.Exists(fileSelect.SelectedFile)) { MessageBox.Show(fileSelect.SelectedFile + " already exists."); return; }
                    map = fileSelect.SelectedFile;
                }

                //extractor.ArchiveFileNames.Where(file => file.EndsWith(".bmp") || file.EndsWith(".png") || file.EndsWith(".jpg") || file.EndsWith(".jpeg")).Single();
                if (File.Exists(map)) throw new Exception(map + " already exists.");
                extractor.ExtractFiles(Directory.GetCurrentDirectory(), map);
                extractedFiles.Add(map);
            }
        }
コード例 #2
0
        private void extract_DoWork(object sender, DoWorkEventArgs e)
        {
            using (SevenZipExtractor extractor = new SevenZipExtractor(e.Argument as String))
            {
                if (extractor.ArchiveFileNames.Count(file => file.EndsWith("-legends.xml")) > 1 || extractor.ArchiveFileNames.Count(file => file.EndsWith("-legends.xml")) == 0)
                {
                    throw new Exception("Not enough or too many XML Files");
                }
                if (extractor.ArchiveFileNames.Count(file => file.EndsWith("-world_history.txt")) > 1 || extractor.ArchiveFileNames.Count(file => file.EndsWith("-world_history.txt")) == 0)
                {
                    throw new Exception("Not enough or too many World History Text Files");
                }
                if (extractor.ArchiveFileNames.Count(file => file.EndsWith("-world_sites_and_pops.txt")) > 1 || extractor.ArchiveFileNames.Count(file => file.EndsWith("-world_sites_and_pops.txt")) == 0)
                {
                    throw new Exception("Not enough or too many Site & Pops Text Files");
                }
                if (extractor.ArchiveFileNames.Count(file => file.EndsWith(".bmp") || file.EndsWith(".png") || file.EndsWith(".jpg") || file.EndsWith(".jpeg")) == 0)
                {
                    throw new Exception("No map image found.");
                }

                string outputDirectory = new FileInfo(extractor.FileName).Directory.FullName;

                string xml = extractor.ArchiveFileNames.Single(file => file.EndsWith("-legends.xml"));
                if (File.Exists(Path.Combine(outputDirectory, xml)))
                {
                    throw new Exception(xml + " already exists.");
                }
                extractor.ExtractFiles(outputDirectory, xml);
                ExtractedFiles.Add(Path.Combine(outputDirectory, xml));

                string history = extractor.ArchiveFileNames.Single(file => file.EndsWith("-world_history.txt"));
                if (File.Exists(Path.Combine(outputDirectory, history)))
                {
                    throw new Exception(history + " already exists.");
                }
                extractor.ExtractFiles(outputDirectory, history);
                ExtractedFiles.Add(Path.Combine(outputDirectory, history));

                string sites = extractor.ArchiveFileNames.Single(file => file.EndsWith("-world_sites_and_pops.txt"));
                if (File.Exists(Path.Combine(outputDirectory, sites)))
                {
                    throw new Exception(sites + " already exists.");
                }
                extractor.ExtractFiles(outputDirectory, sites);
                ExtractedFiles.Add(Path.Combine(outputDirectory, sites));

                string map = "";

                if (extractor.ArchiveFileNames.Count(file => file.EndsWith(".bmp") || file.EndsWith(".png") || file.EndsWith(".jpg") || file.EndsWith(".jpeg")) == 1)
                {
                    map = extractor.ArchiveFileNames.Single(file => file.EndsWith(".bmp") || file.EndsWith(".png") || file.EndsWith(".jpg") || file.EndsWith(".jpeg"));
                }
                else
                {
                    dlgFileSelect fileSelect = new dlgFileSelect(extractor.ArchiveFileNames.Where(file => file.EndsWith(".bmp") || file.EndsWith(".png") || file.EndsWith(".jpg") || file.EndsWith(".jpeg")).ToList());
                    fileSelect.Text = "Select Base Map";
                    fileSelect.ShowDialog();
                    if (fileSelect.SelectedFile == "")
                    {
                        throw new Exception("No map file selected.");
                    }
                    if (File.Exists(fileSelect.SelectedFile))
                    {
                        MessageBox.Show(fileSelect.SelectedFile + " already exists."); return;
                    }
                    map = fileSelect.SelectedFile;
                }

                if (File.Exists(Path.Combine(outputDirectory, map)))
                {
                    throw new Exception(map + " already exists.");
                }
                extractor.ExtractFiles(outputDirectory, map);
                ExtractedFiles.Add(Path.Combine(outputDirectory, map));

                string xmlplus = extractor.ArchiveFileNames.Single(file => file.EndsWith("-legends_plus.xml"));
                if (File.Exists(Path.Combine(outputDirectory, xmlplus)))
                {
                    throw new Exception(xmlplus + " already exists.");
                }
                extractor.ExtractFiles(outputDirectory, xmlplus);
                ExtractedFiles.Add(Path.Combine(outputDirectory, xmlplus));
            }
        }