From 4d48b25512408055a791541e8255a877e027ece5 Mon Sep 17 00:00:00 2001 From: morkt Date: Tue, 1 Sep 2015 14:20:18 +0400 Subject: [PATCH] virtual file system migration. --- ArcFormats/ArcLST.cs | 4 ++-- ArcFormats/BlackCyc/ArcGPK.cs | 5 ++--- ArcFormats/BlackCyc/ArcVPK.cs | 8 ++++---- ArcFormats/Eagls/ArcEAGLS.cs | 8 +++++--- ArcFormats/Ffa/ArcBlackPackage.cs | 12 +++++------- ArcFormats/Kaguya/ArcKaguya.cs | 4 ++-- ArcFormats/Lucifen/ArcLPK.cs | 4 ++-- ArcFormats/Majiro/ImageRCT.cs | 5 ++--- ArcFormats/Malie/ImageDZI.cs | 11 ++++++----- ArcFormats/elf/ArcHED.cs | 4 ++-- 10 files changed, 32 insertions(+), 33 deletions(-) diff --git a/ArcFormats/ArcLST.cs b/ArcFormats/ArcLST.cs index 525e5813..653934eb 100644 --- a/ArcFormats/ArcLST.cs +++ b/ArcFormats/ArcLST.cs @@ -53,9 +53,9 @@ namespace GameRes.Formats.Nexton public override ArcFile TryOpen (ArcView file) { string lstname = file.Name + ".lst"; - if (!File.Exists (lstname)) + if (!VFS.FileExists (lstname)) return null; - using (var lst = new ArcView (lstname)) + using (var lst = VFS.OpenView (lstname)) { List dir = null; try diff --git a/ArcFormats/BlackCyc/ArcGPK.cs b/ArcFormats/BlackCyc/ArcGPK.cs index 8b2c16d8..1d3a458f 100644 --- a/ArcFormats/BlackCyc/ArcGPK.cs +++ b/ArcFormats/BlackCyc/ArcGPK.cs @@ -45,10 +45,9 @@ namespace GameRes.Formats.BlackCyc if (!file.Name.EndsWith (".gpk", StringComparison.InvariantCultureIgnoreCase)) return null; var gtb_name = Path.ChangeExtension (file.Name, "gtb"); - var gtb_info = new FileInfo (gtb_name); - if (!gtb_info.Exists) + if (!VFS.FileExists (gtb_name)) return null; - using (var gtb = new ArcView (gtb_name)) + using (var gtb = VFS.OpenView (gtb_name)) { int count = gtb.View.ReadInt32 (0); if (!IsSaneCount (count)) diff --git a/ArcFormats/BlackCyc/ArcVPK.cs b/ArcFormats/BlackCyc/ArcVPK.cs index 78995e18..fff50dbc 100644 --- a/ArcFormats/BlackCyc/ArcVPK.cs +++ b/ArcFormats/BlackCyc/ArcVPK.cs @@ -45,14 +45,14 @@ namespace GameRes.Formats.BlackCyc if (!file.Name.EndsWith (".vpk", StringComparison.InvariantCultureIgnoreCase)) return null; var vtb_name = Path.ChangeExtension (file.Name, "vtb"); - var vtb_info = new FileInfo (vtb_name); - if (!vtb_info.Exists) + if (!VFS.FileExists (vtb_name)) return null; - int count = (int)(vtb_info.Length / 0x0C) - 1; + var vtb_entry = VFS.FindFile (vtb_name); + int count = (int)(vtb_entry.Size / 0x0C) - 1; if (!IsSaneCount (count)) return null; - using (var vtb = new ArcView (vtb_name)) + using (var vtb = VFS.OpenView (vtb_entry)) { vtb.View.Reserve (0, (uint)vtb.MaxOffset); uint index_offset = 0; diff --git a/ArcFormats/Eagls/ArcEAGLS.cs b/ArcFormats/Eagls/ArcEAGLS.cs index 71bc5eca..5b90fe6f 100644 --- a/ArcFormats/Eagls/ArcEAGLS.cs +++ b/ArcFormats/Eagls/ArcEAGLS.cs @@ -51,12 +51,14 @@ namespace GameRes.Formats.Eagls public override ArcFile TryOpen (ArcView file) { string idx_name = Path.ChangeExtension (file.Name, ".idx"); - var idx_info = new FileInfo (idx_name); - if (!idx_info.Exists || idx_info.Length > 0xfffff || idx_info.Length < 10000) + if (!VFS.FileExists (idx_name)) + return null; + var idx_entry = VFS.FindFile (idx_name); + if (idx_entry.Size > 0xfffff || idx_entry.Size < 10000) return null; byte[] index; - using (var idx = new ArcView (idx_name)) + using (var idx = VFS.OpenView (idx_entry)) index = DecryptIndex (idx); int index_offset = 0; int entry_size = index.Length / 10000; diff --git a/ArcFormats/Ffa/ArcBlackPackage.cs b/ArcFormats/Ffa/ArcBlackPackage.cs index 8ca924dc..81648c91 100644 --- a/ArcFormats/Ffa/ArcBlackPackage.cs +++ b/ArcFormats/Ffa/ArcBlackPackage.cs @@ -49,15 +49,13 @@ namespace GameRes.Formats.Ffa public override ArcFile TryOpen (ArcView file) { string lst_name = Path.ChangeExtension (file.Name, ".lst"); - if (lst_name == file.Name) + if (lst_name == file.Name || !VFS.FileExists (lst_name)) return null; - var lst_info = new FileInfo (lst_name); - if (!lst_info.Exists) + var lst_entry = VFS.FindFile (lst_name); + int count = (int)(lst_entry.Size/0x16); + if (count > 0xffff || count*0x16 != lst_entry.Size) return null; - int count = (int)(lst_info.Length/0x16); - if (count > 0xffff || count*0x16 != lst_info.Length) - return null; - using (var lst = new ArcView (lst_name)) + using (var lst = VFS.OpenView (lst_entry)) { var dir = new List (count); uint index_offset = 0; diff --git a/ArcFormats/Kaguya/ArcKaguya.cs b/ArcFormats/Kaguya/ArcKaguya.cs index 89ca531e..356bafe2 100644 --- a/ArcFormats/Kaguya/ArcKaguya.cs +++ b/ArcFormats/Kaguya/ArcKaguya.cs @@ -84,7 +84,7 @@ namespace GameRes.Formats.Kaguya { string ari_name = Path.ChangeExtension (file.Name, "ari"); List dir = null; - if (file.Name != ari_name && File.Exists (ari_name)) + if (file.Name != ari_name && VFS.FileExists (ari_name)) dir = ReadAriIndex (file, ari_name); if (null == dir || 0 == dir.Count) dir = BuildIndex (file); @@ -94,7 +94,7 @@ namespace GameRes.Formats.Kaguya List ReadAriIndex (ArcView file, string ari_name) { long arc_offset = 4; - using (var ari = new ArcView (ari_name)) + using (var ari = VFS.OpenView (ari_name)) { long index_offset = 0; while (index_offset+4 < ari.MaxOffset) diff --git a/ArcFormats/Lucifen/ArcLPK.cs b/ArcFormats/Lucifen/ArcLPK.cs index f50aaaae..e9f1f13f 100644 --- a/ArcFormats/Lucifen/ArcLPK.cs +++ b/ArcFormats/Lucifen/ArcLPK.cs @@ -320,8 +320,8 @@ namespace GameRes.Formats.Lucifen void ImportKeys (string source_name) { - var script_lpk = Path.Combine (Path.GetDirectoryName (source_name), "SCRIPT.LPK"); - using (var script_file = new ArcView (script_lpk)) + var script_lpk = VFS.CombinePath (Path.GetDirectoryName (source_name), "SCRIPT.LPK"); + using (var script_file = VFS.OpenView (script_lpk)) using (var script_arc = Open (ScriptName, script_file, CurrentScheme, null)) { if (null == script_arc) diff --git a/ArcFormats/Majiro/ImageRCT.cs b/ArcFormats/Majiro/ImageRCT.cs index bf49ad9f..95ef7985 100644 --- a/ArcFormats/Majiro/ImageRCT.cs +++ b/ArcFormats/Majiro/ImageRCT.cs @@ -28,7 +28,6 @@ using System.IO; using System.Text; using System.Collections.Generic; using System.ComponentModel.Composition; -using System.Diagnostics; using System.Windows; using System.Windows.Media; using System.Windows.Media.Imaging; @@ -178,9 +177,9 @@ namespace GameRes.Formats.Majiro string name = Encodings.cp932.GetString (name_bin, 0, name_bin.Length-1); string dir_name = Path.GetDirectoryName (meta.FileName); name = Path.Combine (dir_name, name); - if (File.Exists (name)) + if (VFS.FileExists (name)) { - using (var base_file = File.OpenRead (name)) + using (var base_file = VFS.OpenSeekableStream (name)) { var base_info = ReadMetaData (base_file) as RctMetaData; if (null != base_info && 0 == base_info.AddSize diff --git a/ArcFormats/Malie/ImageDZI.cs b/ArcFormats/Malie/ImageDZI.cs index d92adcb4..d1df1536 100644 --- a/ArcFormats/Malie/ImageDZI.cs +++ b/ArcFormats/Malie/ImageDZI.cs @@ -58,9 +58,7 @@ namespace GameRes.Formats.Malie public override ImageMetaData ReadMetaData (Stream stream) { - var tex = new DirectoryInfo ("tex"); - if (!tex.Exists) - return null; + var tex = VFS.FindFile ("tex"); using (var reader = new StreamReader (stream, Encoding.UTF8, false, 2048, true)) { reader.ReadLine(); // skip signature @@ -101,7 +99,10 @@ namespace GameRes.Formats.Malie foreach (var file in line.Split (',')) { if (!string.IsNullOrEmpty (file)) - tiles.Add (new DziTile { X = x, Y = y, FileName = Path.Combine (tex.Name, file + ".png") }); + { + var filename = VFS.CombinePath (tex.Name, file + ".png"); + tiles.Add (new DziTile { X = x, Y = y, FileName = filename }); + } x += 256; } y += 256; @@ -131,7 +132,7 @@ namespace GameRes.Formats.Malie int actual_height = 0; foreach (var tile in meta.Tiles.First()) { - using (var file = File.OpenRead (tile.FileName)) + using (var file = VFS.OpenStream (VFS.FindFile (tile.FileName))) { var decoder = new PngBitmapDecoder (file, BitmapCreateOptions.None, BitmapCacheOption.OnLoad); diff --git a/ArcFormats/elf/ArcHED.cs b/ArcFormats/elf/ArcHED.cs index c42c108b..86900cb9 100644 --- a/ArcFormats/elf/ArcHED.cs +++ b/ArcFormats/elf/ArcHED.cs @@ -50,14 +50,14 @@ namespace GameRes.Formats.Elf public override ArcFile TryOpen (ArcView file) { string pak_name = Path.ChangeExtension (file.Name, "pak"); - if (pak_name == file.Name || !File.Exists (pak_name)) + if (pak_name == file.Name || !VFS.FileExists (pak_name)) return null; var file_map = GetFileMap (pak_name); if (null == file_map) return null; string base_name = Path.GetFileNameWithoutExtension (pak_name); - using (var pak = new ArcView (pak_name)) + using (var pak = VFS.OpenView (pak_name)) { if (0x00646568 != pak.View.ReadUInt32 (0)) return null;