Skip to content

Commit 7be1e3d

Browse files
committed
Partial PackfileVFS port
Partially ported PackfileVFS from the C++ version. Will implement the rest of it when it's needed. Just using the existing behavior for now. Will rewrite it in the near future since it's not sufficient for Nanoforge anymore.
1 parent 9bae5d0 commit 7be1e3d

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

src/FileSystem/PackfileVFS.bf

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using System.Collections;
2+
using RfgTools.Formats;
3+
using Nanoforge;
4+
using System.IO;
5+
using System;
6+
7+
namespace Nanoforge.FileSystem
8+
{
9+
///RFG packfile interface
10+
///NOTE: This API sucks and will be rewritten in the near future. It's a port from the C++ version. This was originally written when Nanoforge was just a file viewer.
11+
/// It's insufficient for the new goals of Nanoforge of being a full modding suite. It will be rewritten after adding the map editor, but before adding other features.
12+
/// I'm using the existing code initially to save time. I want to get the rewrite public ASAP so improvements to the map editor can be started again.
13+
/// Doing all the code rewrites up front would likely delay that by months. It's better to get early feedback IMO.
14+
public static class PackfileVFS
15+
{
16+
private static String _dataFolder = new .() ~delete _;
17+
public static List<PackfileV3> Packfiles = new .() ~DeleteContainerAndItems!(_);
18+
19+
///Scan all packfiles in the data folder
20+
public static void SetDataFolder(StringView dataFolderPath)
21+
{
22+
if (!Directory.Exists(dataFolderPath))
23+
{
24+
//TODO: Add error logging here
25+
return;
26+
}
27+
28+
//Clear packfiles
29+
_dataFolder.Set(dataFolderPath);
30+
ClearAndDeleteItems(Packfiles);
31+
32+
//Scan headers of packfiles in new data folder
33+
for (var file in Directory.EnumerateFiles(_dataFolder))
34+
{
35+
if (file.GetExtension(.. scope .()) != ".vpp_pc")
36+
continue;
37+
38+
String filePath = file.GetFilePath(.. scope .());
39+
PackfileV3 packfile = new .(filePath);
40+
if (packfile.ReadMetadata() case .Err(let err))
41+
{
42+
delete packfile;
43+
Runtime.FatalError(scope $"Failed to read packfile. Error: '{err}'"); //TODO: Add proper error logging instead of crashing
44+
continue;
45+
}
46+
if (packfile.ReadAsmFiles() case .Err(let err))
47+
{
48+
delete packfile;
49+
Runtime.FatalError(scope $"Failed to read asm_pc file in packfile. Error: '{err}'"); //TODO: Add proper error logging instead of crashing
50+
continue;
51+
}
52+
Packfiles.Add(packfile);
53+
}
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)