Skip to content

Commit

Permalink
Renamed IWitcherArchive.FileName to IWitcherArchive.ArchiveAbsolutePath
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxzor authored and Traderain committed Sep 13, 2020
1 parent 5f0f1ec commit 5cd2f3b
Show file tree
Hide file tree
Showing 16 changed files with 44 additions and 44 deletions.
4 changes: 2 additions & 2 deletions CR2WTests/StressTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ public static void Setup(TestContext context)
//Load MemoryMapped Bundles
foreach (var b in bm.Bundles.Values)
{
var e = b.FileName.GetHashMD5();
var e = b.ArchiveAbsolutePath.GetHashMD5();

memorymappedbundles.Add(e, MemoryMappedFile.CreateFromFile(b.FileName, FileMode.Open, e, 0, MemoryMappedFileAccess.Read));
memorymappedbundles.Add(e, MemoryMappedFile.CreateFromFile(b.ArchiveAbsolutePath, FileMode.Open, e, 0, MemoryMappedFileAccess.Read));

}
}
Expand Down
2 changes: 1 addition & 1 deletion WolvenKit.App/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ public int UnbundleFileToProject(string relativePath, bool isDLC, EProjectFolder
{
var archives = manager.FileList
.Where(x => x.Name == relativePath)
.Select(y => new KeyValuePair<string, IWitcherFile>(y.Bundle.FileName, y))
.Select(y => new KeyValuePair<string, IWitcherFile>(y.Bundle.ArchiveAbsolutePath, y))
.ToList();


Expand Down
8 changes: 4 additions & 4 deletions WolvenKit.Bundles/Bundle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class Bundle : IWitcherArchive

public Bundle(string filename)
{
FileName = filename;
ArchiveAbsolutePath = filename;
Read();
}

Expand All @@ -41,7 +41,7 @@ public Bundle()
}

public EBundleType TypeName { get { return EBundleType.Bundle; } }
public string FileName { get; set; }
public string ArchiveAbsolutePath { get; set; }
public Dictionary<string, BundleItem> Items { get; set; }

/// <summary>
Expand All @@ -51,7 +51,7 @@ private void Read()
{
Items = new Dictionary<string, BundleItem>();

using (var reader = new BinaryReader(new FileStream(FileName, FileMode.Open, FileAccess.Read)))
using (var reader = new BinaryReader(new FileStream(ArchiveAbsolutePath, FileMode.Open, FileAccess.Read)))
{
var idstring = reader.ReadBytes(IDString.Length);

Expand Down Expand Up @@ -104,7 +104,7 @@ private void Read()
}
else
{
Console.WriteLine("Warning: Bundle '" + FileName + "' could not be fully loaded as resource '" + item.Name + "' is defined more than once. Thus, only the first definition was loaded.");
Console.WriteLine("Warning: Bundle '" + ArchiveAbsolutePath + "' could not be fully loaded as resource '" + item.Name + "' is defined more than once. Thus, only the first definition was loaded.");
}
}

Expand Down
4 changes: 2 additions & 2 deletions WolvenKit.Bundles/BundleItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public string CompressionType
public void ExtractExistingMMF(Stream output)
{
// old deprecated way of loading mmfs still used in unit test
var hash = Bundle.FileName.GetHashMD5();
var hash = Bundle.ArchiveAbsolutePath.GetHashMD5();
using (MemoryMappedFile mmf = MemoryMappedFile.OpenExisting(hash, MemoryMappedFileRights.Read))
//using (var viewstream = mmf.CreateViewStream(PageOffset, ZSize, MemoryMappedFileAccess.Read))
ExtractExistingMMF(output, mmf);
Expand Down Expand Up @@ -123,7 +123,7 @@ public void ExtractExistingMMF(Stream output, MemoryMappedFile memorymappedbundl

public void Extract(Stream output)
{
using (var file = MemoryMappedFile.CreateFromFile(Bundle.FileName, FileMode.Open))
using (var file = MemoryMappedFile.CreateFromFile(Bundle.ArchiveAbsolutePath, FileMode.Open))
using (var viewstream = file.CreateViewStream(PageOffset, ZSize, MemoryMappedFileAccess.Read))
{
switch (CompressionType)
Expand Down
2 changes: 1 addition & 1 deletion WolvenKit.Bundles/BundleManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void LoadBundle(string filename, bool ispatch = false)
{
// if file is already in content0 remove file.
List<IWitcherFile> filesInBundles = Items[item.Key];
if (filesInBundles.First().Bundle.FileName.Contains("content0"))
if (filesInBundles.First().Bundle.ArchiveAbsolutePath.Contains("content0"))
{
bundle.Patchedfiles.Add(filesInBundles.First());
filesInBundles.RemoveAt(0);
Expand Down
2 changes: 1 addition & 1 deletion WolvenKit.Cache/CollisionCache/CollisionCacheItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public class CollisionCacheItem : IWitcherFile

public void Extract(Stream output)
{
using (var file = MemoryMappedFile.CreateFromFile(Bundle.FileName, FileMode.Open))
using (var file = MemoryMappedFile.CreateFromFile(Bundle.ArchiveAbsolutePath, FileMode.Open))
using (var viewstream = file.CreateViewStream(PageOffset, ZSize, MemoryMappedFileAccess.Read))
{
var zlib = new ZlibStream(viewstream, CompressionMode.Decompress);
Expand Down
4 changes: 2 additions & 2 deletions WolvenKit.Cache/CollisionCache/Collision_Cache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ public class CollisionCache : IWitcherArchive
public List<CollisionCacheItem> Files = new List<CollisionCacheItem>();

public EBundleType TypeName => EBundleType.CollisionCache;
public string FileName { get; set; }
public string ArchiveAbsolutePath { get; set; }

public CollisionCache(string filename)
{
this.FileName = filename;
this.ArchiveAbsolutePath = filename;
using (var br = new BinaryReader(new FileStream(filename, FileMode.Open)))
this.Read(br);
}
Expand Down
6 changes: 3 additions & 3 deletions WolvenKit.Cache/TextureCache/Texture_Cache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class TextureCache : IWitcherArchive
public List<TextureCacheItem> Files;

public EBundleType TypeName => EBundleType.TextureCache;
public string FileName { get; set; }
public string ArchiveAbsolutePath { get; set; }
public List<uint> Chunkoffsets;
public UInt64 Crc;
public UInt32 UsedPages;
Expand Down Expand Up @@ -46,7 +46,7 @@ public void Read(string filepath)
{
try
{
FileName = filepath;
ArchiveAbsolutePath = filepath;
Chunkoffsets = new List<uint>();
using (var br = new BinaryReader(new FileStream(filepath, FileMode.Open)))
{
Expand Down Expand Up @@ -81,7 +81,7 @@ public void Read(string filepath)
var ti = new TextureCacheItem(this)
{
Name = Names[i],
ParentFile = FileName,
ParentFile = ArchiveAbsolutePath,
Hash = br.ReadUInt32(),
/*-------------TextureCacheEntryBase---------------*/
PathStringIndex = br.ReadInt32(),
Expand Down
2 changes: 1 addition & 1 deletion WolvenKit.Common/Model/IWitcherArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ namespace WolvenKit.Common
public interface IWitcherArchive
{
EBundleType TypeName { get; }
string FileName { get; set; }
string ArchiveAbsolutePath { get; set; }
}
}
16 changes: 8 additions & 8 deletions WolvenKit.Console/Console_CR2WToPostgres.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ private static int CR2WToPostgres(CR2WToPostgresOptions options)
#region bundleloop
lock (pg)
{
pb.Refresh(++pg.pgr, bundle.FileName);
pb.Refresh(++pg.pgr, bundle.ArchiveAbsolutePath);
}

/* if (bundle == bundles[21])
Expand All @@ -211,32 +211,32 @@ private static int CR2WToPostgres(CR2WToPostgresOptions options)
*/


if (bundle.FileName.Contains("buffers") ||
bundle.FileName.Contains("xml"))
if (bundle.ArchiveAbsolutePath.Contains("buffers") ||
bundle.ArchiveAbsolutePath.Contains("xml"))
continue;//return;


bundlepb.Max = (int)bundle.Items.Count();
var bundlepg = new Progress(0);
//Cannot use bundle.GetSize, it is broken on patch1 bundle
var filerealsize = new FileInfo(bundle.FileName).Length;
var filerealsize = new FileInfo(bundle.ArchiveAbsolutePath).Length;

var e = bundle.FileName.GetHashMD5();
var e = bundle.ArchiveAbsolutePath.GetHashMD5();
var mmf = MemoryMappedFile.CreateNew(e, /*bundle.GetSize*/filerealsize, MemoryMappedFileAccess.ReadWrite);

//We try to create a non-persisted memory-mapped file from RAM, or if we can't a persisted mmf from disk.
// no memory stream on > 2GB files, win32 api.
if(filerealsize<1900000000)
{
using (MemoryStream ms0 = new MemoryStream(File.ReadAllBytes(bundle.FileName), 0, (int)filerealsize, false, true))
using (MemoryStream ms0 = new MemoryStream(File.ReadAllBytes(bundle.ArchiveAbsolutePath), 0, (int)filerealsize, false, true))
using (MemoryMappedViewStream mmvs = mmf.CreateViewStream())
{
ms0.CopyTo(mmvs);
}
}
else
{
using (FileStream fs = File.OpenRead(bundle.FileName))
using (FileStream fs = File.OpenRead(bundle.ArchiveAbsolutePath))
//using (MemoryStream ms0 = new MemoryStream(File.ReadAllBytes(bundle.FileName), 0, (int)filerealsize, false, true))
using (MemoryMappedViewStream mmvs = mmf.CreateViewStream())
{
Expand Down Expand Up @@ -268,7 +268,7 @@ private static int CR2WToPostgres(CR2WToPostgresOptions options)
}

// Getting bundle database file id - lod2dict - lod2 absolute_path --> lod2_file_id
var lod_2_file_name = f.Bundle.FileName.Replace("C:\\Program Files (x86)\\Steam\\steamapps\\common\\The Witcher 3\\", "").Replace("\\", "/");
var lod_2_file_name = f.Bundle.ArchiveAbsolutePath.Replace("C:\\Program Files (x86)\\Steam\\steamapps\\common\\The Witcher 3\\", "").Replace("\\", "/");
int lod2_file_id = lod2dict[lod_2_file_name];

// Getting cr2w database general file id (lod1) - lod1dict - lod2_id + absolute_virtual_path --> lod1_file_id
Expand Down
10 changes: 5 additions & 5 deletions WolvenKit.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ private static int DumpCookedEffects(DumpCookedEffectsOptions options)
//Load MemoryMapped Bundles
foreach (var b in bm.Bundles.Values)
{
var e = b.FileName.GetHashMD5();
var e = b.ArchiveAbsolutePath.GetHashMD5();

memorymappedbundles.Add(e, MemoryMappedFile.CreateFromFile(b.FileName, FileMode.Open, e, 0, MemoryMappedFileAccess.Read));
memorymappedbundles.Add(e, MemoryMappedFile.CreateFromFile(b.ArchiveAbsolutePath, FileMode.Open, e, 0, MemoryMappedFileAccess.Read));

}

Expand Down Expand Up @@ -241,10 +241,10 @@ private static int DumpCollision(DumpCollisionOptions options)
if (f is CollisionCacheItem x)
{

var bundlename = new DirectoryInfo(x.Bundle.FileName).Parent.Name;
var bundlename = new DirectoryInfo(x.Bundle.ArchiveAbsolutePath).Parent.Name;
if (bundlename == "content")
{
var par2 = new DirectoryInfo(x.Bundle.FileName).Parent.Parent.Name;
var par2 = new DirectoryInfo(x.Bundle.ArchiveAbsolutePath).Parent.Parent.Name;
bundlename = par2;
}

Expand Down Expand Up @@ -719,7 +719,7 @@ private static int DumpArchivedFileInfos(DumpArchivedFileInfosOptions options)
{
foreach (var file in manager.FileList)
{
writer.WriteLine(cnt++ + ";" + file.Bundle.FileName + ";" + file.Name + ";" +
writer.WriteLine(cnt++ + ";" + file.Bundle.ArchiveAbsolutePath + ";" + file.Name + ";" +
file.Bundle.TypeName + ";" + file.Size + ";" + file.CompressionType
+ ";" + file.ZSize + ";" + file.PageOffset);
}
Expand Down
2 changes: 1 addition & 1 deletion WolvenKit.W3Speech/Coder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static W3Speech Decode(IWitcherArchive parent, BinaryReader br)
})
.ToList()
.AsReadOnly();
return new W3Speech(parent.FileName, str, version, key, item_infos);
return new W3Speech(parent.ArchiveAbsolutePath, str, version, key, item_infos);
}

/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions WolvenKit.W3Speech/DataStructures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public SpeechEntry(IWitcherArchive bundle, LanguageSpecificID id, UInt32 id_high

public void Extract(Stream output)
{
using (var file = MemoryMappedFile.CreateFromFile(Bundle.FileName, FileMode.Open))
using (var file = MemoryMappedFile.CreateFromFile(Bundle.ArchiveAbsolutePath, FileMode.Open))
{
using (var viewstream = file.CreateViewStream(PageOffset, ZSize, MemoryMappedFileAccess.Read))
{
Expand Down Expand Up @@ -128,12 +128,12 @@ public W3Speech()

public W3Speech(string name)
{
FileName = name;
ArchiveAbsolutePath = name;
}

public W3Speech(String filename, String id, UInt32 version, W3LanguageKey language_key, IEnumerable<SpeechEntry> item_infos)
{
this.FileName = filename;
this.ArchiveAbsolutePath = filename;
this.id = id;
this.version = version;
this.language_key = language_key;
Expand All @@ -142,7 +142,7 @@ public W3Speech(String filename, String id, UInt32 version, W3LanguageKey langua

public EBundleType TypeName => EBundleType.Speech;

public string FileName { get; set; }
public string ArchiveAbsolutePath { get; set; }

public override string ToString()
{
Expand Down
6 changes: 3 additions & 3 deletions WolvenKit.Wwise/SoundCache/Sound_Cache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class SoundCache : IWitcherArchive
public long checksum;

public EBundleType TypeName => EBundleType.SoundCache;
public string FileName { get; set; }
public string ArchiveAbsolutePath { get; set; }

public static SoundBanksInfoXML info = new SoundBanksInfoXML("SoundCache\\soundbanksinfo.xml");

Expand All @@ -51,7 +51,7 @@ public class SoundCache : IWitcherArchive
/// <param name="fileName"></param>
public SoundCache(string fileName)
{
FileName = fileName;
ArchiveAbsolutePath = fileName;
using (var br = new BinaryReader(new FileStream(fileName, FileMode.Open)))
Read(br);
}
Expand Down Expand Up @@ -203,7 +203,7 @@ public void Read(BinaryReader br)
{
f.Name = info.StreamedFiles.First(x => x.Id == (f.Name.Split('.')[0])).Path;
}
f.ParentFile = this.FileName;
f.ParentFile = this.ArchiveAbsolutePath;
}
}

Expand Down
6 changes: 3 additions & 3 deletions WolvenKit/Forms/MVVM/frmMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2308,7 +2308,7 @@ private bool AddToMod(string relativePath, IWitcherArchiveManager manager, bool
{
var archives = manager.FileList
.Where(x => x.Name == relativePath)
.Select(y => new KeyValuePair<string, IWitcherFile>(y.Bundle.FileName, y));
.Select(y => new KeyValuePair<string, IWitcherFile>(y.Bundle.ArchiveAbsolutePath, y));
string newpath = "";


Expand Down Expand Up @@ -3388,8 +3388,8 @@ protected object UnbundleGame(object sender, DoWorkEventArgs e)
//Load MemoryMapped Bundles
foreach (var b in bm.Bundles.Values)
{
var hash = b.FileName.GetHashMD5();
memorymappedbundles.Add(hash, MemoryMappedFile.CreateFromFile(b.FileName, FileMode.Open, hash, 0, MemoryMappedFileAccess.Read));
var hash = b.ArchiveAbsolutePath.GetHashMD5();
memorymappedbundles.Add(hash, MemoryMappedFile.CreateFromFile(b.ArchiveAbsolutePath, FileMode.Open, hash, 0, MemoryMappedFileAccess.Read));
}

var files = bm.FileList
Expand Down
6 changes: 3 additions & 3 deletions WolvenKit/Forms/frmAssetBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ public Tuple<WitcherListViewItem,IWitcherFile>[] SearchFiles(IWitcherFile[] file
{
if (currentfolderCheckBox.Checked)
{
return files.Where(item => item.Bundle.FileName.Contains(ActiveNode.Name) && new Regex(searchkeyword).IsMatch(item.Name)).Select(x => new Tuple<WitcherListViewItem, IWitcherFile>(new WitcherListViewItem(x), x)).ToArray();
return files.Where(item => item.Bundle.ArchiveAbsolutePath.Contains(ActiveNode.Name) && new Regex(searchkeyword).IsMatch(item.Name)).Select(x => new Tuple<WitcherListViewItem, IWitcherFile>(new WitcherListViewItem(x), x)).ToArray();
}

return files.Where(item => new Regex(searchkeyword).IsMatch(item.Name)).Select(x => new Tuple<WitcherListViewItem, IWitcherFile>(new WitcherListViewItem(x), x)).ToArray();
Expand All @@ -382,12 +382,12 @@ public Tuple<WitcherListViewItem,IWitcherFile>[] SearchFiles(IWitcherFile[] file
if (currentfolderCheckBox.Checked)
{
return caseCheckBox.Checked
? files.Where(item => item.Bundle.FileName.Contains(ActiveNode.Name)
? files.Where(item => item.Bundle.ArchiveAbsolutePath.Contains(ActiveNode.Name)
&& item.Name.ToUpper().Contains(searchkeyword.ToUpper())
&& (item.Name.ToUpper().EndsWith(extension.ToUpper()) || extension.ToUpper() == "ANY")
&& (item.Bundle.TypeName == bundletype || bundletype == EBundleType.ANY))
.Distinct().Select(x => new Tuple<WitcherListViewItem, IWitcherFile>(new WitcherListViewItem(x), x)).ToArray()
: files.Where(item => item.Bundle.FileName.Contains(ActiveNode.Name)
: files.Where(item => item.Bundle.ArchiveAbsolutePath.Contains(ActiveNode.Name)
&& item.Name.Contains(searchkeyword)
&& (item.Name.EndsWith(extension) || extension.ToUpper() == "ANY")
&& (item.Bundle.TypeName == bundletype || bundletype == EBundleType.ANY))
Expand Down

0 comments on commit 5cd2f3b

Please sign in to comment.