From 6a57bfb43d8b4e952d9b3df72cab93505fae4622 Mon Sep 17 00:00:00 2001 From: morkt Date: Sun, 9 Oct 2016 10:10:12 +0400 Subject: [PATCH] added game title lookup facility. --- ArcFormats/Cyberworks/ArcDAT.cs | 13 +++++++++++-- ArcFormats/KiriKiri/ArcXP3.cs | 17 +++-------------- ArcFormats/ShiinaRio/ArcWARC.cs | 16 ++++++++++++---- GameRes/FormatCatalog.cs | 27 +++++++++++++++++++++++++-- 4 files changed, 51 insertions(+), 22 deletions(-) diff --git a/ArcFormats/Cyberworks/ArcDAT.cs b/ArcFormats/Cyberworks/ArcDAT.cs index 25381571..e88cc31e 100644 --- a/ArcFormats/Cyberworks/ArcDAT.cs +++ b/ArcFormats/Cyberworks/ArcDAT.cs @@ -166,8 +166,8 @@ namespace GameRes.Formats.Cyberworks return null; if (!has_images) return new ArcFile (file, this, dir); - var options = Query (arcStrings.ArcEncryptedNotice); - return new BellArchive (file, this, dir, options.Scheme); + var scheme = QueryScheme (file.Name); + return new BellArchive (file, this, dir, scheme); } byte[] ReadToc (string toc_name) @@ -275,6 +275,15 @@ namespace GameRes.Formats.Cyberworks return v; } + AImageScheme QueryScheme (string arc_name) + { + var title = FormatCatalog.Instance.LookupGame (arc_name); + if (!string.IsNullOrEmpty (title) && KnownSchemes.ContainsKey (title)) + return KnownSchemes[title]; + var options = Query (arcStrings.ArcEncryptedNotice); + return options.Scheme; + } + public override ResourceOptions GetDefaultOptions () { return new BellOptions { Scheme = GetScheme (Settings.Default.BELLTitle) }; diff --git a/ArcFormats/KiriKiri/ArcXP3.cs b/ArcFormats/KiriKiri/ArcXP3.cs index 0470fc9e..da087e58 100644 --- a/ArcFormats/KiriKiri/ArcXP3.cs +++ b/ArcFormats/KiriKiri/ArcXP3.cs @@ -71,7 +71,6 @@ namespace GameRes.Formats.KiriKiri public class Xp3Scheme : ResourceScheme { public Dictionary KnownSchemes; - public Dictionary ExeMap; } // Archive version 1: encrypt file first, then calculate checksum @@ -749,25 +748,15 @@ NextEntry: ICrypt GuessCryptAlgorithm (ArcView file) { - if (0 == KiriKiriScheme.ExeMap.Count) + var title = FormatCatalog.Instance.LookupGame (file.Name); + if (string.IsNullOrEmpty (title)) return null; - var exe_pattern = VFS.CombinePath (VFS.GetDirectoryName (file.Name), "*.exe"); - foreach (var exe in VFS.GetFiles (exe_pattern).Select (e => Path.GetFileName (e.Name))) - { - string title; - if (KiriKiriScheme.ExeMap.TryGetValue (exe, out title)) - { - Settings.Default.XP3Scheme = title; - return GetScheme (title); - } - } - return null; + return GetScheme (title); } static Xp3Scheme KiriKiriScheme = new Xp3Scheme { KnownSchemes = new Dictionary(), - ExeMap = new Dictionary(), }; public static IDictionary KnownSchemes diff --git a/ArcFormats/ShiinaRio/ArcWARC.cs b/ArcFormats/ShiinaRio/ArcWARC.cs index 3a0e27fc..34dc4054 100644 --- a/ArcFormats/ShiinaRio/ArcWARC.cs +++ b/ArcFormats/ShiinaRio/ArcWARC.cs @@ -90,7 +90,7 @@ namespace GameRes.Formats.ShiinaRio // 椎名里緒 if (index_offset >= file.MaxOffset) return null; - var scheme = QueryEncryption(); + var scheme = QueryEncryption (file.Name); if (null == scheme) return null; var decoder = new Decoder (version, scheme); @@ -282,10 +282,18 @@ namespace GameRes.Formats.ShiinaRio // 椎名里緒 return new GUI.WidgetWARC(); } - EncryptionScheme QueryEncryption () + EncryptionScheme QueryEncryption (string arc_name) { - var options = Query (arcStrings.ArcEncryptedNotice); - return options.Scheme; + EncryptionScheme scheme = null; + var title = FormatCatalog.Instance.LookupGame (arc_name); + if (!string.IsNullOrEmpty (title)) + scheme = GetScheme (title); + if (null == scheme) + { + var options = Query (arcStrings.ArcEncryptedNotice); + scheme = options.Scheme; + } + return scheme; } static EncryptionScheme GetScheme (string scheme) diff --git a/GameRes/FormatCatalog.cs b/GameRes/FormatCatalog.cs index 6a0ec4ec..26cb5b5c 100644 --- a/GameRes/FormatCatalog.cs +++ b/GameRes/FormatCatalog.cs @@ -53,6 +53,8 @@ namespace GameRes private MultiValueDictionary m_extension_map = new MultiValueDictionary(); private MultiValueDictionary m_signature_map = new MultiValueDictionary(); + private Dictionary m_game_map = new Dictionary(); + /// The only instance of this class. public static FormatCatalog Instance { get { return m_instance; } } @@ -205,6 +207,23 @@ namespace GameRes return signature; } + /// + /// Look up game title based on archive and files matching + /// in the same directory as archive. + /// + /// Game title, or null if no match was found. + public string LookupGame (string arc_name, string pattern = "*.exe") + { + pattern = VFS.CombinePath (VFS.GetDirectoryName (arc_name), pattern); + foreach (var file in VFS.GetFiles (pattern).Select (e => Path.GetFileName (e.Name))) + { + string title; + if (m_game_map.TryGetValue (file, out title)) + return title; + } + return null; + } + public void DeserializeScheme (Stream input) { using (var reader = new BinaryReader (input, System.Text.Encoding.UTF8, true)) @@ -228,6 +247,8 @@ namespace GameRes format.Scheme = scheme; } CurrentSchemeVersion = db.Version; + if (db.GameMap != null) + m_game_map = db.GameMap; } } @@ -235,7 +256,8 @@ namespace GameRes { var db = new SchemeDataBase { Version = CurrentSchemeVersion, - SchemeMap = new Dictionary() + SchemeMap = new Dictionary(), + GameMap = m_game_map, }; foreach (var format in Formats) { @@ -264,6 +286,7 @@ namespace GameRes { public int Version; - public Dictionary SchemeMap; + public Dictionary SchemeMap; + public Dictionary GameMap; } }