@@ -3,6 +3,7 @@ const player = @import("player");
const SoundIo = player.SoundIo;
const fatal = std.zig.fatal;
const Config = @import("Config.zig");
const Allocator = std.mem.Allocator;
const usage =
\\Usage: groovebasin [options]
@@ -55,6 +56,39 @@ pub fn main() anyerror!noreturn {
}
const config = try Config.load(arena, config_zon_path);
std.log.debug("config: {any}\n", .{config});
var files: std.StringArrayHashMapUnmanaged(void) = .{};
defer deinitFiles(gpa, &files);
{
var walker = try config.music_directory.handle.walk(gpa);
defer walker.deinit();
while (try walker.next()) |entry| {
if (entry.kind != .file) continue;
const file = player.File.open(config.music_directory.handle, entry.path, entry.basename) catch |err| {
std.log.warn("unable to open '{s}': {s}", .{ entry.path, @errorName(err) });
continue;
};
defer file.close();
const cloned_path = try gpa.dupe(u8, entry.path);
{
errdefer gpa.free(cloned_path);
try files.putNoClobber(gpa, cloned_path, {});
}
}
}
std.log.debug("loaded {d} files", .{files.entries.len});
@panic("TODO");
}
fn deinitFiles(gpa: Allocator, files: *std.StringArrayHashMapUnmanaged(void)) void {
for (files.keys()) |key| {
gpa.free(key);
}
files.deinit(gpa);
files.* = undefined;
}