public static string[] GetSupportedFiles(string gameFileDirectory, IGameFile gameFile, string[] supportedExtensions) { List <string> ret = new List <string>(); string file = Path.Combine(gameFileDirectory, gameFile.FileName); if (File.Exists(file)) { using (IArchiveReader reader = ArchiveReader.Create(file)) { foreach (IArchiveEntry entry in reader.Entries) { if (!string.IsNullOrEmpty(entry.Name) && supportedExtensions.Any(x => x.Equals(Path.GetExtension(entry.Name), StringComparison.OrdinalIgnoreCase))) { ret.Add(entry.FullName); } } } } return(ret.ToArray()); }
private List <string> GetFilesFromGameFileSettings(IGameFile gameFile, LauncherPath gameFileDirectory, LauncherPath tempDirectory, bool checkSpecific, string[] extensions) { List <string> files = new List <string>(); using (IArchiveReader reader = ArchiveReader.Create(Path.Combine(gameFileDirectory.GetFullPath(), gameFile.FileName))) { var entries = reader.Entries.Where(x => !string.IsNullOrEmpty(x.Name) && x.Name.Contains('.') && extensions.Any(y => y.Equals(Path.GetExtension(x.Name), StringComparison.OrdinalIgnoreCase))); foreach (IArchiveEntry entry in entries) { bool useFile = true; if (checkSpecific && SpecificFiles != null && SpecificFiles.Length > 0) { useFile = SpecificFiles.Contains(entry.FullName); } if (useFile) { if (entry.ExtractRequired) { string extractFile = Path.Combine(tempDirectory.GetFullPath(), entry.Name); if (ExtractFiles) { entry.ExtractToFile(extractFile, true); } files.Add(extractFile); } else { files.Add(entry.FullName); } } } } return(files); }
private bool HandleGameFileIWad(IGameFile gameFile, ISourcePort sourcePort, StringBuilder sb, LauncherPath gameFileDirectory, LauncherPath tempDirectory) { try { using (IArchiveReader reader = ArchiveReader.Create(Path.Combine(gameFileDirectory.GetFullPath(), gameFile.FileName))) { IArchiveEntry entry = reader.Entries.First(); string extractFile = Path.Combine(tempDirectory.GetFullPath(), entry.Name); if (ExtractFiles && entry.ExtractRequired) { entry.ExtractToFile(extractFile, true); } if (!entry.ExtractRequired) { extractFile = entry.FullName; } sb.Append(sourcePort.IwadParameter(new SpData(extractFile, gameFile, AdditionalFiles))); } } catch (FileNotFoundException) { LastError = string.Format("File not found: {0}", gameFile.FileName); return(false); } catch (IOException) { LastError = string.Format("File in use: {0}", gameFile.FileName); return(false); } catch (Exception) { LastError = string.Format("There was an issue with the IWad: {0}. Corrupted file?", gameFile.FileName); return(false); } return(true); }
//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 (IArchiveReader reader = ArchiveReader.Create(pathFile.ExtractedFile)) { var entry = reader.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()); }
public void Execute(string[] zipFiles) { m_invalidFiles.Clear(); SyncFileCount = zipFiles.Length; SyncFileCurrent = 0; foreach (string fileName in zipFiles) { if (SyncFileChange != null) { CurrentSyncFileName = fileName; SyncFileChange(this, new EventArgs()); } IGameFile file = SyncDataSource.GetGameFile(fileName); IGameFile existing = DbDataSource.GetGameFile(file.FileName); if (existing != null) { file = existing; } if (m_fileManagement == FileManagement.Unmanaged) { file.FileName = fileName; } if (file != null) { CurrentGameFile = file; GameFileDataNeeded?.Invoke(this, new EventArgs()); file.Downloaded = DateTime.Now; try { using (IArchiveReader reader = ArchiveReader.Create(Path.Combine(GameFileDirectory.GetFullPath(), file.FileName))) { FillTextFileInfo(file, reader); FillMapInfo(file, reader); } } catch (IOException) { file.Map = string.Empty; m_invalidFiles.Add(new InvalidFile(fileName, "File is in use/Not found")); } catch (InvalidDataException) { file.Map = string.Empty; m_invalidFiles.Add(new InvalidFile(fileName, "Zip archive invalid or contained an improper pk3")); } catch (Exception ex) { file.Map = string.Empty; m_invalidFiles.Add(new InvalidFile(fileName, CreateExceptionMsg(ex))); } if (existing == null) { DbDataSource.InsertGameFile(file); } else { DbDataSource.UpdateGameFile(file, Util.GetSyncGameFileUpdateFields()); } } else { m_invalidFiles.Add(new InvalidFile(fileName, "Not a valid zip archive")); try { FileInfo fileDelete = new FileInfo(Path.Combine(GameFileDirectory.GetFullPath(), fileName)); if (fileDelete.Exists) { fileDelete.Delete(); } } catch { //delete failed, just keep going } } SyncFileCurrent++; } }