51 lines
1.5 KiB
Zig
51 lines
1.5 KiB
Zig
const std = @import("std");
|
|
const fs = std.fs;
|
|
|
|
pub fn main() !void {
|
|
// Get allocator
|
|
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
|
const allocator = gpa.allocator();
|
|
|
|
// Get args
|
|
const args = try std.process.argsAlloc(allocator);
|
|
defer std.process.argsFree(allocator, args);
|
|
|
|
if (args.len < 2) {
|
|
std.debug.print("Usage: {s} <path to extracted pk3>\n", .{args[0]});
|
|
std.process.exit(1);
|
|
}
|
|
|
|
// Extract folder from argv
|
|
const folder = args[1];
|
|
|
|
// Convert folder to absolute
|
|
const dir = try fs.cwd().openDir(folder, .{ .iterate = true });
|
|
|
|
// Prepare hashmap for storing song locations
|
|
var trackLocations = std.StringHashMap([]const u8).init(allocator);
|
|
defer trackLocations.deinit();
|
|
|
|
// Iter through every file inside the directory (recursive)
|
|
var iter = try dir.walk(allocator);
|
|
defer iter.deinit();
|
|
while (try iter.next()) |entry| {
|
|
// Skip non-files
|
|
if (entry.kind != fs.File.Kind.file) {
|
|
continue;
|
|
}
|
|
|
|
// Remove extension
|
|
const extIndex = std.mem.indexOf(u8, entry.basename, ".");
|
|
const filename = if (extIndex) |index| entry.basename[0..index] else entry.basename;
|
|
|
|
// Check if it's a music definition file (and parse it if so)
|
|
if (std.mem.eql(u8, filename, "MUSICDEF")) {
|
|
//TODO
|
|
} else {
|
|
// Save file to hashmap of resolved files
|
|
try trackLocations.put(filename, entry.path);
|
|
}
|
|
std.debug.print("- {s}\n", .{filename});
|
|
}
|
|
}
|