Skip to content

Commit ff86824

Browse files
committed
Remove deferredmode argument from Load<T>
1 parent 52fac05 commit ff86824

File tree

3 files changed

+12
-22
lines changed

3 files changed

+12
-22
lines changed

Datamodel.cs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,10 @@ public static Datamodel Load(byte[] data, DeferredMode defer_mode = DeferredMode
270270
/// <param name="data">The input byte array.</param>
271271
/// <param name="defer_mode">How to handle deferred loading.</param>
272272
/// <typeparam name="T">Type hint for what the Root of this datamodel should be when using reflection</param>
273-
public static Datamodel Load<T>(byte[] data, DeferredMode defer_mode = DeferredMode.Automatic, ReflectionParams? reflectionParams = null)
273+
public static Datamodel Load<T>(byte[] data, ReflectionParams? reflectionParams = null)
274274
where T : Element
275275
{
276-
return Load_Internal<T>(new MemoryStream(data, true), Assembly.GetCallingAssembly(), defer_mode, reflectionParams);
276+
return Load_Internal<T>(new MemoryStream(data, true), Assembly.GetCallingAssembly(), DeferredMode.Disabled, reflectionParams);
277277
}
278278

279279
/// <summary>
@@ -296,25 +296,15 @@ public static Datamodel Load(string path, DeferredMode defer_mode = DeferredMode
296296
}
297297
}
298298
/// <summary>
299-
/// Loads a Datamodel from a file path.
299+
/// Loads a Datamodel from a file path, unserializing the Root as <typeparamref name="T"/>.
300300
/// </summary>
301301
/// <param name="path">The source file path.</param>
302-
/// <param name="defer_mode">How to handle deferred loading.</param>
303302
/// <typeparam name="T">Type hint for what the Root of this datamodel should be when using reflection</param>
304-
public static Datamodel Load<T>(string path, DeferredMode defer_mode = DeferredMode.Automatic, ReflectionParams? reflectionParams = null)
303+
public static Datamodel Load<T>(string path, ReflectionParams? reflectionParams = null)
305304
where T : Element
306305
{
307-
var stream = File.OpenRead(path);
308-
Datamodel? dm = null;
309-
try
310-
{
311-
dm = Load_Internal<T>(stream, Assembly.GetCallingAssembly(), defer_mode, reflectionParams);
312-
return dm;
313-
}
314-
finally
315-
{
316-
if (defer_mode == DeferredMode.Disabled || (dm != null && dm.Codec == null)) stream.Dispose();
317-
}
306+
using var stream = File.OpenRead(path);
307+
return Load_Internal<T>(stream, Assembly.GetCallingAssembly(), DeferredMode.Disabled, reflectionParams);
318308
}
319309

320310
private static Datamodel Load_Internal<T>(Stream stream, Assembly callingAssembly, DeferredMode defer_mode = DeferredMode.Automatic, ReflectionParams? reflectionParams = null)

Tests/Tests.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ public class DatamodelTests
2020
protected FileStream Binary_4_File = File.OpenRead(TestContext.CurrentContext.TestDirectory + "/Resources/binary4.dmx");
2121
protected FileStream KeyValues2_1_File = File.OpenRead(TestContext.CurrentContext.TestDirectory + "/Resources/taunt05.dmx");
2222

23-
// TODO: would be nice if this could find this path automatically
24-
//const string GameBin = @"C:/Program Files (x86)/Steam/steamapps/common/Counter-Strike Global Offensive/game/bin/win64";
25-
const string GameBin = @"D:/Steam/steamapps/common/Counter-Strike Global Offensive/game/bin/win64";
23+
const string GameBin = @"C:/Program Files (x86)/Steam/steamapps/common/Counter-Strike Global Offensive/game/bin/win64";
2624

2725
static readonly string DmxConvertExe = Path.Combine(GameBin, "dmxconvert.exe");
2826
static readonly bool DmxConvertExe_Exists = File.Exists(DmxConvertExe);
@@ -294,7 +292,7 @@ public static void TypedArrayAddingRemoving()
294292
Assert.AreEqual(0, array.Count);
295293
}
296294

297-
private void Test_Vmap_Reflection(Datamodel.Datamodel unserialisedVmap)
295+
private static void Validate_Vmap_Reflection(Datamodel.Datamodel unserialisedVmap)
298296
{
299297
Assert.AreEqual(typeof(CMapRootElement), unserialisedVmap.Root.GetType());
300298

@@ -326,14 +324,14 @@ private void Test_Vmap_Reflection(Datamodel.Datamodel unserialisedVmap)
326324
public void LoadVmap_Reflection_Binary()
327325
{
328326
var unserialisedVmap = DM.Load<CMapRootElement>(Path.Combine(TestContext.CurrentContext.TestDirectory, "Resources", "cs2_map.vmap"));
329-
Test_Vmap_Reflection(unserialisedVmap);
327+
Validate_Vmap_Reflection(unserialisedVmap);
330328
}
331329

332330
[Test]
333331
public void LoadVmap_Reflection_Text()
334332
{
335333
var unserialisedVmap = DM.Load<CMapRootElement>(Path.Combine(TestContext.CurrentContext.TestDirectory, "Resources", "cs2_map.vmap.txt"));
336-
Test_Vmap_Reflection(unserialisedVmap);
334+
Validate_Vmap_Reflection(unserialisedVmap);
337335
}
338336

339337
public class NullOwnerElement

Tests/ValveMap.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace VMAP;
66

7+
#nullable enable
8+
79
/// <summary>
810
/// Valve Map (VMAP) format version 29.
911
/// </summary>

0 commit comments

Comments
 (0)