/// <summary> /// Look up game title based on archive <paramref name="arc_name"/> and files matching /// <paramref name="pattern"/> in the same directory as archive. /// </summary> /// <returns>Game title, or null if no match was found.</returns> public string LookupGame(string arc_name, string pattern = "*.exe") { string title; if (m_game_map.TryGetValue(Path.GetFileName(arc_name), out title)) { return(title); } pattern = VFS.CombinePath(VFS.GetDirectoryName(arc_name), pattern); foreach (var file in VFS.GetFiles(pattern).Select(e => Path.GetFileName(e.Name))) { if (m_game_map.TryGetValue(file, out title)) { return(title); } } return(null); }
public static ArcFile TryOpen(Entry entry) { if (entry.Size < 4) { return(null); } var file = VFS.OpenView(entry); try { uint signature = file.View.ReadUInt32(0); foreach (var impl in FormatCatalog.Instance.FindFormats <ArchiveFormat> (entry.Name, signature)) { try { var arc = impl.TryOpen(file); if (null != arc) { file = null; // file ownership passed to ArcFile return(arc); } } catch (OperationCanceledException X) { FormatCatalog.Instance.LastError = X; return(null); } catch (Exception X) { // ignore failed open attmepts Trace.WriteLine(string.Format("[{0}] {1}: {2}", impl.Tag, entry.Name, X.Message)); FormatCatalog.Instance.LastError = X; } } } finally { if (null != file) { file.Dispose(); } } return(null); }
/// <summary> /// Try to open <paramref name="filename"/> as archive. /// </summary> /// <returns> /// ArcFile object if file is opened successfully, null otherwise. /// </returns> public static ArcFile TryOpen(string filename) { return(TryOpen(VFS.FindFile(filename))); }
/// <summary> /// Try to open <paramref name="filename"/> as archive. /// </summary> /// <returns> /// ArcFile object if file is opened successfully, null otherwise. /// </returns> public static ArcFile TryOpen(string filename) { var entry = VFS.FindFile(filename); if (entry.Size < 4) { return(null); } var ext = new Lazy <string> (() => Path.GetExtension(filename).TrimStart('.').ToLowerInvariant()); var file = VFS.OpenView(entry); try { uint signature = file.View.ReadUInt32(0); for (;;) { var range = FormatCatalog.Instance.LookupSignature <ArchiveFormat> (signature); // check formats that match filename extension first if (range.Skip(1).Any()) // if range.Count() > 1 { range = range.OrderByDescending(f => f.Extensions.Any(e => e == ext.Value)); } foreach (var impl in range) { try { var arc = impl.TryOpen(file); if (null != arc) { file = null; // file ownership passed to ArcFile return(arc); } } catch (OperationCanceledException X) { FormatCatalog.Instance.LastError = X; return(null); } catch (Exception X) { // ignore failed open attmepts Trace.WriteLine(string.Format("[{0}] {1}: {2}", impl.Tag, filename, X.Message)); FormatCatalog.Instance.LastError = X; } } if (0 == signature) { break; } signature = 0; } } finally { if (null != file) { file.Dispose(); } } return(null); }