Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/no manager cache #31

Merged
merged 2 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions WolvenKit.App/Controllers/Configuration.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml.Serialization;
Expand Down Expand Up @@ -40,7 +40,7 @@ public static string ConfigurationPath
public bool IsWelcomeFormDisabled { get; set; }
public bool IsAutoInstallModsDisabled { get; set; }

public string[] ManagerVersions { get; set; } = new string[(int)EManagerType.Max];
//public string[] ManagerVersions { get; set; } = new string[(int)EManagerType.Max];

public string GameModDir { get; set; }
public string GameDlcDir { get; set; }
Expand Down Expand Up @@ -94,4 +94,4 @@ public static Configuration Load()
};
}
}
}
}
218 changes: 12 additions & 206 deletions WolvenKit.App/Controllers/MainController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Newtonsoft.Json;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -225,36 +225,7 @@ public static void LogProgress(int value)
#endregion

#region Methods
private static string GetManagerPath(EManagerType type)
{
switch (type)
{
case EManagerType.BundleManager: return Path.Combine(ManagerCacheDir, "bundle_cache.json");
case EManagerType.CollisionManager: return Path.Combine(ManagerCacheDir, "collision_cache.json");
case EManagerType.SoundManager: return Path.Combine(ManagerCacheDir, "sound_cache.json");
case EManagerType.W3StringManager: return Path.Combine(ManagerCacheDir, "string_cache.bin");
case EManagerType.TextureManager: return Path.Combine(ManagerCacheDir, "texture_cache.json");
case EManagerType.Max:
default:
throw new ArgumentOutOfRangeException(nameof(type), type, null);
}
}
private static string GetManagerVersion(EManagerType type)
{
switch (type)
{
case EManagerType.BundleManager: return BundleManager.SerializationVersion;
case EManagerType.CollisionManager: return WolvenKit.Cache.CollisionManager.SerializationVersion;
case EManagerType.SoundManager: return WolvenKit.Cache.SoundManager.SerializationVersion;
case EManagerType.W3StringManager: return W3Strings.W3StringManager.SerializationVersion;
case EManagerType.TextureManager: return WolvenKit.Cache.TextureManager.SerializationVersion;
case EManagerType.Max:
default:
throw new ArgumentOutOfRangeException(nameof(type), type, null);
}
}



/// <summary>
/// Initializes the archive managers in an async thread
/// </summary>
Expand All @@ -263,20 +234,6 @@ public async Task Initialize()
{
try
{
// add a mechanism to update individual cache managers
for (var j = 0; j < Configuration.ManagerVersions.Length; j++)
{
var savedversions = Configuration.ManagerVersions[j];
var e = (EManagerType)j;
var curversion = GetManagerVersion(e);

if (savedversions != curversion)
{
if (File.Exists(GetManagerPath(e)))
File.Delete(GetManagerPath(e));
}
}

//multithread these
var loadStringsManagerTask = LoadStringsManager();
var loadBundleManagerTask = LoadBundleManager();
Expand Down Expand Up @@ -362,35 +319,8 @@ private async Task LoadStringsManager()
sw.Start();
if (W3StringManager == null)
{
try
{
if (File.Exists(GetManagerPath(EManagerType.W3StringManager)) && new FileInfo(GetManagerPath(EManagerType.W3StringManager)).Length > 0)
{
using (var file = File.Open(GetManagerPath(EManagerType.W3StringManager), FileMode.Open))
{
W3StringManager = ProtoBuf.Serializer.Deserialize<W3StringManager>(file);
}
}
else
{
W3StringManager = new W3StringManager();
W3StringManager.Load(Configuration.TextLanguage, Path.GetDirectoryName(Configuration.ExecutablePath));
Directory.CreateDirectory(ManagerCacheDir);
using (var file = File.Open(GetManagerPath(EManagerType.W3StringManager), FileMode.Create))
{
ProtoBuf.Serializer.Serialize(file, W3StringManager);
}

Configuration.ManagerVersions[(int)EManagerType.W3StringManager] = W3StringManager.SerializationVersion;
}
}
catch (System.Exception)
{
if (File.Exists(GetManagerPath(EManagerType.W3StringManager)))
File.Delete(GetManagerPath(EManagerType.W3StringManager));
W3StringManager = new W3StringManager();
W3StringManager.Load(Configuration.TextLanguage, Path.GetDirectoryName(Configuration.ExecutablePath));
}
W3StringManager = new W3StringManager();
W3StringManager.Load(Configuration.TextLanguage, Path.GetDirectoryName(Configuration.ExecutablePath));
}

var i = sw.ElapsedMilliseconds;
Expand All @@ -404,39 +334,8 @@ private async Task LoadBundleManager()
#region Load bundle manager
if (BundleManager == null)
{
try
{
if (File.Exists(GetManagerPath(EManagerType.BundleManager)))
{
using (StreamReader file = File.OpenText(GetManagerPath(EManagerType.BundleManager)))
{
JsonSerializer serializer = new JsonSerializer();
serializer.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
serializer.PreserveReferencesHandling = PreserveReferencesHandling.Objects;
serializer.TypeNameHandling = TypeNameHandling.Auto;
BundleManager = (BundleManager)serializer.Deserialize(file, typeof(BundleManager));
}
}
else
{
BundleManager = new BundleManager();
BundleManager.LoadAll(Path.GetDirectoryName(Configuration.ExecutablePath));
File.WriteAllText(GetManagerPath(EManagerType.BundleManager), JsonConvert.SerializeObject(BundleManager, Formatting.None, new JsonSerializerSettings()
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
PreserveReferencesHandling = PreserveReferencesHandling.Objects,
TypeNameHandling = TypeNameHandling.Auto
}));
Configuration.ManagerVersions[(int)EManagerType.BundleManager] = BundleManager.SerializationVersion;
}
}
catch (System.Exception ex)
{
if (File.Exists(GetManagerPath(EManagerType.BundleManager)))
File.Delete(GetManagerPath(EManagerType.BundleManager));
BundleManager = new BundleManager();
BundleManager.LoadAll(Path.GetDirectoryName(Configuration.ExecutablePath));
}
BundleManager = new BundleManager();
BundleManager.LoadAll(Path.GetDirectoryName(Configuration.ExecutablePath));
}
#endregion
}
Expand All @@ -447,39 +346,8 @@ private async Task LoadTextureManager()
#region Load texture manager
if (TextureManager == null)
{
try
{
if (File.Exists(GetManagerPath(EManagerType.TextureManager)))
{
using (StreamReader file = File.OpenText(GetManagerPath(EManagerType.TextureManager)))
{
JsonSerializer serializer = new JsonSerializer();
serializer.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
serializer.PreserveReferencesHandling = PreserveReferencesHandling.Objects;
serializer.TypeNameHandling = TypeNameHandling.Auto;
TextureManager = (TextureManager)serializer.Deserialize(file, typeof(TextureManager));
}
}
else
{
TextureManager = new TextureManager();
TextureManager.LoadAll(Path.GetDirectoryName(Configuration.ExecutablePath));
File.WriteAllText(GetManagerPath(EManagerType.TextureManager), JsonConvert.SerializeObject(TextureManager, Formatting.None, new JsonSerializerSettings()
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
PreserveReferencesHandling = PreserveReferencesHandling.Objects,
TypeNameHandling = TypeNameHandling.Auto
}));
Configuration.ManagerVersions[(int)EManagerType.TextureManager] = TextureManager.SerializationVersion;
}
}
catch (System.Exception)
{
if (File.Exists(GetManagerPath(EManagerType.TextureManager)))
File.Delete(GetManagerPath(EManagerType.TextureManager));
TextureManager = new TextureManager();
TextureManager.LoadAll(Path.GetDirectoryName(Configuration.ExecutablePath));
}
TextureManager = new TextureManager();
TextureManager.LoadAll(Path.GetDirectoryName(Configuration.ExecutablePath));
}
#endregion
}
Expand All @@ -490,39 +358,8 @@ private async Task LoadCollisionManager()
#region Load collision manager
if (CollisionManager == null)
{
try
{
if (File.Exists(GetManagerPath(EManagerType.CollisionManager)))
{
using (StreamReader file = File.OpenText(GetManagerPath(EManagerType.CollisionManager)))
{
JsonSerializer serializer = new JsonSerializer();
serializer.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
serializer.PreserveReferencesHandling = PreserveReferencesHandling.Objects;
serializer.TypeNameHandling = TypeNameHandling.Auto;
CollisionManager = (CollisionManager)serializer.Deserialize(file, typeof(CollisionManager));
}
}
else
{
CollisionManager = new CollisionManager();
CollisionManager.LoadAll(Path.GetDirectoryName(Configuration.ExecutablePath));
File.WriteAllText(GetManagerPath(EManagerType.CollisionManager), JsonConvert.SerializeObject(CollisionManager, Formatting.None, new JsonSerializerSettings()
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
PreserveReferencesHandling = PreserveReferencesHandling.Objects,
TypeNameHandling = TypeNameHandling.Auto
}));
Configuration.ManagerVersions[(int)EManagerType.CollisionManager] = CollisionManager.SerializationVersion;
}
}
catch (System.Exception)
{
if (File.Exists(GetManagerPath(EManagerType.CollisionManager)))
File.Delete(GetManagerPath(EManagerType.CollisionManager));
CollisionManager = new CollisionManager();
CollisionManager.LoadAll(Path.GetDirectoryName(Configuration.ExecutablePath));
}
CollisionManager = new CollisionManager();
CollisionManager.LoadAll(Path.GetDirectoryName(Configuration.ExecutablePath));
}
#endregion
}
Expand All @@ -533,39 +370,8 @@ private async Task LoadSoundManager()
#region Load sound manager
if (SoundManager == null)
{
try
{
if (File.Exists(GetManagerPath(EManagerType.SoundManager)))
{
using (StreamReader file = File.OpenText(GetManagerPath(EManagerType.SoundManager)))
{
JsonSerializer serializer = new JsonSerializer();
serializer.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
serializer.PreserveReferencesHandling = PreserveReferencesHandling.Objects;
serializer.TypeNameHandling = TypeNameHandling.Auto;
SoundManager = (SoundManager)serializer.Deserialize(file, typeof(SoundManager));
}
}
else
{
SoundManager = new SoundManager();
SoundManager.LoadAll(Path.GetDirectoryName(Configuration.ExecutablePath));
File.WriteAllText(GetManagerPath(EManagerType.SoundManager), JsonConvert.SerializeObject(SoundManager, Formatting.None, new JsonSerializerSettings()
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
PreserveReferencesHandling = PreserveReferencesHandling.Objects,
TypeNameHandling = TypeNameHandling.Auto
}));
Configuration.ManagerVersions[(int)EManagerType.SoundManager] = SoundManager.SerializationVersion;
}
}
catch (System.Exception ex)
{
if (File.Exists(GetManagerPath(EManagerType.SoundManager)))
File.Delete(GetManagerPath(EManagerType.SoundManager));
SoundManager = new SoundManager();
SoundManager.LoadAll(Path.GetDirectoryName(Configuration.ExecutablePath));
}
SoundManager = new SoundManager();
SoundManager.LoadAll(Path.GetDirectoryName(Configuration.ExecutablePath));
}
#endregion
}
Expand Down
24 changes: 0 additions & 24 deletions WolvenKit.App/Enums.cs

This file was deleted.

2 changes: 0 additions & 2 deletions WolvenKit.App/WolvenKit.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
<PackageReference Include="NETStandard.Library" Version="2.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="Pfim" Version="0.11.1" />
<PackageReference Include="protobuf-net" Version="3.1.26" />
<PackageReference Include="protobuf-net.Core" Version="3.1.26" />
<PackageReference Include="SharpZipLib" Version="1.4.1" />
<PackageReference Include="SymbolicLinkSupport" Version="1.2.0" />
<PackageReference Include="System.AppContext" Version="4.3.0" />
Expand Down
7 changes: 2 additions & 5 deletions WolvenKit.Bundles/Bundle.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
Expand Down Expand Up @@ -107,9 +107,6 @@ private void Read()
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.");
}
}


reader.Close();
}
}

Expand Down Expand Up @@ -238,4 +235,4 @@ public static string GetRelativePath(string filespec, string folder)
return Uri.UnescapeDataString(folderUri.MakeRelativeUri(pathUri).ToString().Replace('/', Path.DirectorySeparatorChar));
}
}
}
}
4 changes: 2 additions & 2 deletions WolvenKit.Bundles/BundleManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
Expand Down Expand Up @@ -69,7 +69,7 @@ public override void LoadBundle(string filename, bool ispatch = false)
// if file is already in another bundle
if (ispatch && Items[item.Key].Count > 0)
{
// check if file is already in contentN directory (content0, content1 etc)
// check if file is already in content directory (content0, content1 etc)
List<IWitcherFile> filesInBundles = Items[item.Key];
var splits = filesInBundles.First().Bundle.ArchiveAbsolutePath.Split(Path.DirectorySeparatorChar);
var contentdir = splits[splits.Length - 3];
Expand Down
2 changes: 0 additions & 2 deletions WolvenKit.Bundles/WolvenKit.Bundles.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@
<PackageReference Include="doboz4net" Version="1.0.1" />
<PackageReference Include="lz4net" Version="1.0.15.93" />
<PackageReference Include="MarkerMetro.Unity.Ionic.Zlib" Version="2.0.0.14" />
<PackageReference Include="protobuf-net" Version="3.1.26" />
<PackageReference Include="protobuf-net.Core" Version="3.1.26" />
<PackageReference Include="Snappy.NET" Version="1.1.1.8" />
<PackageReference Include="System.Buffers" Version="4.5.1" />
<PackageReference Include="System.Collections.Immutable" Version="7.0.0" />
Expand Down
2 changes: 1 addition & 1 deletion WolvenKit.CR2W/WolvenKit.CR2W.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<NoWarn>CS1591</NoWarn>
<DefineConstants>TRACE;NGE_VERSION</DefineConstants>
<PlatformTarget>x64</PlatformTarget>
<Optimize>true</Optimize>
<!--<Optimize>true</Optimize>-->
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<DebugType>pdbonly</DebugType>
Expand Down
16 changes: 0 additions & 16 deletions WolvenKit.Common/Tools/ProtoList.cs

This file was deleted.

Loading