private string MapStringFromMapInfo(ZipArchiveEntry zae) { string extractedFile = Util.ExtractTempFile(TempDirectory.GetFullPath(), zae); StringBuilder sb = new StringBuilder(); if (File.Exists(extractedFile)) { Regex mapRegex = new Regex(@"\s*map\s+\w+"); string text = File.ReadAllText(extractedFile); MatchCollection matches = mapRegex.Matches(text); foreach (Match match in matches) { sb.Append(match.Value.Trim().Substring(3).Trim()); sb.Append(", "); } FileInfo deleteFile = new FileInfo(extractedFile); deleteFile.Delete(); } if (sb.Length > 2) { sb.Remove(sb.Length - 2, 2); } return(sb.ToString()); }
private string GetMaps(ZipArchive za) { IEnumerable <ZipArchiveEntry> txtEntries = GetEntriesByExtension(za, ".txt").Where(x => x.Name.Equals("mapinfo.txt", StringComparison.InvariantCultureIgnoreCase)); if (txtEntries.Any()) { return(MapStringFromMapInfo(txtEntries.First())); } StringBuilder sb = new StringBuilder(); sb.Append(MapStringFromGameFile(za)); IEnumerable <ZipArchiveEntry> pk3Entries = Util.GetEntriesByExtension(za, Util.GetPkExtenstions()); foreach (ZipArchiveEntry zae in pk3Entries) { string extractedFile = Util.ExtractTempFile(TempDirectory.GetFullPath(), zae); using (var extractedZip = ZipFile.OpenRead(extractedFile)) { sb.Append(GetMaps(extractedZip)); } } return(sb.ToString()); }
private void HandleDefaultSelection(string file, IArchiveReader reader) { IEnumerable <IArchiveEntry> filteredEntries = reader.Entries.Where(x => !string.IsNullOrEmpty(x.Name) && !x.Name.EndsWith(Path.PathSeparator.ToString()) && m_supportedExtensions.Any(y => y.Equals(Path.GetExtension(x.Name), StringComparison.OrdinalIgnoreCase))).OrderBy(x => x.Name, StringComparer.OrdinalIgnoreCase).ToList(); if (chkPkContents.Checked) { IEnumerable <IArchiveEntry> pk3Entries = Util.GetEntriesByExtension(reader, Util.GetPkExtenstions()); //should check for MAPINFO (e.g. joyofmapping) foreach (IArchiveEntry entry in pk3Entries) { string extractedFile = Util.ExtractTempFile(m_temp.GetFullPath(), entry); using (IArchiveReader zaInner = ArchiveReader.Create(extractedFile)) { HandleDefaultSelection(extractedFile, zaInner); } } } foreach (IArchiveEntry entry in reader.Entries) { if (!string.IsNullOrEmpty(entry.Name)) { if (m_ct.IsCancellationRequested) { break; } HandleAddItem(file, entry.FullName, entry.Name, filteredEntries.Contains(entry)); } } }
private string MapStringFromMapInfo(ZipArchiveEntry zae) { string extractedFile = Util.ExtractTempFile(TempDirectory.GetFullPath(), zae); if (File.Exists(extractedFile)) { string mapinfo = File.ReadAllText(extractedFile); File.Delete(extractedFile); return(GetMapStringFromMapInfo(mapinfo)); } return(string.Empty); }
private string MapStringFromGameFile(IArchiveReader reader) { List <string> maps = new List <string>(); IEnumerable <IArchiveEntry> wadEntries = GetEntriesByExtension(reader, ".wad"); foreach (IArchiveEntry entry in wadEntries) { string extractFile = Util.ExtractTempFile(TempDirectory.GetFullPath(), entry); string mapString = Util.GetMapStringFromWad(extractFile); if (!string.IsNullOrEmpty(mapString)) { maps.Add(mapString); } } return(string.Join(", ", maps.ToArray())); }
private string MapStringFromMapInfo(IArchiveReader reader, IArchiveEntry entry) { StringBuilder sb = new StringBuilder(); string extractedFile = Util.ExtractTempFile(TempDirectory.GetFullPath(), entry); if (File.Exists(extractedFile)) { string mapinfo = File.ReadAllText(extractedFile); AppendMapSet(sb, ParseMapInfoInclude(reader, mapinfo)); if (entry.ExtractRequired) { File.Delete(extractedFile); } AppendMapSet(sb, GetMapStringFromMapInfo(mapinfo)); } return(sb.ToString()); }
private string MapStringFromGameFile(ZipArchive za) { StringBuilder sb = new StringBuilder(); IEnumerable <ZipArchiveEntry> wadEntries = GetEntriesByExtension(za, ".wad"); foreach (ZipArchiveEntry zae in wadEntries) { string extractFile = Util.ExtractTempFile(TempDirectory.GetFullPath(), zae); sb.Append(Util.GetMapStringFromWad(extractFile)); } if (sb.Length > 2) { sb.Remove(sb.Length - 2, 2); } return(sb.ToString()); }
//This function is currently only used for loading files by utility (which also uses ISourcePort). //This uses Util.ExtractTempFile to avoid extracting files with the same name where the user can have the previous file locked. //E.g. opening MAP01 from a pk3, and then opening another MAP01 from a different pk3 public bool HandleGameFile(IGameFile gameFile, StringBuilder sb, LauncherPath gameFileDirectory, LauncherPath tempDirectory, ISourcePort sourcePort, List <SpecificFilesForm.SpecificFilePath> pathFiles) { try { List <string> files = new List <string>(); foreach (var pathFile in pathFiles) { if (File.Exists(pathFile.ExtractedFile)) { using (ZipArchive za = ZipFile.OpenRead(pathFile.ExtractedFile)) { var entry = za.Entries.FirstOrDefault(x => x.FullName == pathFile.InternalFilePath); if (entry != null) { files.Add(Util.ExtractTempFile(tempDirectory.GetFullPath(), entry)); } } } } BuildLaunchString(sb, sourcePort, files); } catch (FileNotFoundException) { LastError = string.Format("The game file was not found: {0}", gameFile.FileName); return(false); } catch (InvalidDataException) { LastError = string.Format("The game file does not appear to be a valid zip file: {0}", gameFile.FileName); return(false); } return(true); }
private string GetMaps(IArchiveReader reader) { var txtEntries = GetEntriesByExtension(reader, ".txt").Where(x => x.Name.Equals("mapinfo.txt", StringComparison.InvariantCultureIgnoreCase)); if (txtEntries.Any()) { return(MapStringFromMapInfo(txtEntries.First())); } StringBuilder sb = new StringBuilder(); sb.Append(MapStringFromGameFile(reader)); IEnumerable <IArchiveEntry> pk3Entries = Util.GetEntriesByExtension(reader, Util.GetReadablePkExtensions()); foreach (IArchiveEntry entry in pk3Entries) { string extractedFile = Util.ExtractTempFile(TempDirectory.GetFullPath(), entry); using (var extractedZip = ArchiveReader.Create(extractedFile)) sb.Append(GetMaps(extractedZip)); } return(sb.ToString()); }