feat(windows): fix windows bugs
This commit is contained in:
16
build.zig
16
build.zig
@@ -4,6 +4,16 @@ pub fn build(b: *std.Build) void {
|
|||||||
const target = b.standardTargetOptions(.{});
|
const target = b.standardTargetOptions(.{});
|
||||||
const optimize = b.standardOptimizeOption(.{});
|
const optimize = b.standardOptimizeOption(.{});
|
||||||
|
|
||||||
|
const sandbox_mod = b.createModule(.{
|
||||||
|
.root_source_file = b.path("src/main.zig"),
|
||||||
|
.target = target,
|
||||||
|
.optimize = optimize,
|
||||||
|
});
|
||||||
|
const sandbox_exe = b.addExecutable(.{
|
||||||
|
.name = "sandbox_ftime",
|
||||||
|
.root_module = sandbox_mod,
|
||||||
|
});
|
||||||
|
|
||||||
const console_exe_mod = b.createModule(.{
|
const console_exe_mod = b.createModule(.{
|
||||||
.root_source_file = b.path("src/console_main.zig"),
|
.root_source_file = b.path("src/console_main.zig"),
|
||||||
.target = target,
|
.target = target,
|
||||||
@@ -41,6 +51,9 @@ pub fn build(b: *std.Build) void {
|
|||||||
gui_exe.root_module.addImport("dvui", dvui.module("dvui_raylib"));
|
gui_exe.root_module.addImport("dvui", dvui.module("dvui_raylib"));
|
||||||
b.installArtifact(gui_exe);
|
b.installArtifact(gui_exe);
|
||||||
|
|
||||||
|
const run_sandbox_cmd = b.addRunArtifact(sandbox_exe);
|
||||||
|
run_sandbox_cmd.step.dependOn(b.getInstallStep());
|
||||||
|
|
||||||
const run_console_cmd = b.addRunArtifact(console_exe);
|
const run_console_cmd = b.addRunArtifact(console_exe);
|
||||||
run_console_cmd.step.dependOn(b.getInstallStep());
|
run_console_cmd.step.dependOn(b.getInstallStep());
|
||||||
|
|
||||||
@@ -52,6 +65,9 @@ pub fn build(b: *std.Build) void {
|
|||||||
run_gui_cmd.addArgs(args);
|
run_gui_cmd.addArgs(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const run_sandbox_step = b.step("run:s", "Run the sandbox");
|
||||||
|
run_sandbox_step.dependOn(&run_sandbox_cmd.step);
|
||||||
|
|
||||||
const run_console_step = b.step("run:console", "Run the console app");
|
const run_console_step = b.step("run:console", "Run the console app");
|
||||||
run_console_step.dependOn(&run_console_cmd.step);
|
run_console_step.dependOn(&run_console_cmd.step);
|
||||||
|
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ fn loadChildren(container: *Container) void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var dir = std.fs.cwd().openDir(container.item.nativePath.path, .{ .iterate = true }) catch {
|
var dir = std.fs.cwd().openDir(container.item.nativePath.path, .{ .iterate = true }) catch {
|
||||||
const errorContent = std.fmt.allocPrint(container.item.allocator, "Could not open directory '{s}'.", .{container.item.nativePath.path}) catch return;
|
// const errorContent = std.fmt.allocPrint(container.item.allocator, "Could not open directory '{s}'.", .{container.item.nativePath.path}) catch return;
|
||||||
container.item.errors.append(.{ .content = errorContent }) catch return;
|
// container.item.errors.append(.{ .content = errorContent }) catch return;
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
defer dir.close();
|
defer dir.close();
|
||||||
@@ -56,9 +56,27 @@ pub const LocalContentProvider = struct {
|
|||||||
initContext: *const InitContext,
|
initContext: *const InitContext,
|
||||||
allocator: std.mem.Allocator,
|
allocator: std.mem.Allocator,
|
||||||
) GetItemsError!*Item {
|
) GetItemsError!*Item {
|
||||||
const stat = std.fs.cwd().statFile(fullName.path) catch return GetItemsError.NotExists;
|
const path = try std.mem.replaceOwned(u8, allocator, fullName.path, "/", "\\");
|
||||||
|
defer allocator.free(path);
|
||||||
|
|
||||||
return switch (stat.kind) {
|
const kind: union(enum) { directory, file } = blk: {
|
||||||
|
// FIXME: properly handle different errors
|
||||||
|
var dir = std.fs.cwd().openDir(path, .{});
|
||||||
|
if (dir) |*d| {
|
||||||
|
d.close();
|
||||||
|
break :blk .directory;
|
||||||
|
} else |_| {}
|
||||||
|
|
||||||
|
var file = std.fs.cwd().openFile(path, .{});
|
||||||
|
if (file) |*f| {
|
||||||
|
f.close();
|
||||||
|
break :blk .file;
|
||||||
|
} else |_| {}
|
||||||
|
|
||||||
|
return GetItemsError.NotExists;
|
||||||
|
};
|
||||||
|
|
||||||
|
return switch (kind) {
|
||||||
.directory => blk: {
|
.directory => blk: {
|
||||||
const container = try allocator.create(Container);
|
const container = try allocator.create(Container);
|
||||||
container.* = Container{
|
container.* = Container{
|
||||||
@@ -106,9 +124,6 @@ pub const LocalContentProvider = struct {
|
|||||||
|
|
||||||
break :blk &element.item;
|
break :blk &element.item;
|
||||||
},
|
},
|
||||||
else => @panic(
|
|
||||||
"Unsupported file type\n",
|
|
||||||
),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ pub const VTable = struct {
|
|||||||
pub const GetItemsError = error{
|
pub const GetItemsError = error{
|
||||||
OutOfMemory,
|
OutOfMemory,
|
||||||
NotExists,
|
NotExists,
|
||||||
|
NotSupported,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const Provider = struct {
|
pub const Provider = struct {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ pub const Tab = struct {
|
|||||||
_private: Private,
|
_private: Private,
|
||||||
|
|
||||||
const Private = struct {
|
const Private = struct {
|
||||||
currentItemsAllocator: ?std.heap.ArenaAllocator,
|
currentItemsAllocator: std.heap.ArenaAllocator,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn init(
|
pub fn init(
|
||||||
@@ -31,7 +31,7 @@ pub const Tab = struct {
|
|||||||
.currentLocation = null,
|
.currentLocation = null,
|
||||||
.threadPool = threadPool,
|
.threadPool = threadPool,
|
||||||
._private = .{
|
._private = .{
|
||||||
.currentItemsAllocator = null,
|
.currentItemsAllocator = std.heap.ArenaAllocator.init(allocator),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -51,9 +51,7 @@ pub const Tab = struct {
|
|||||||
loadItems(self, location) catch return;
|
loadItems(self, location) catch return;
|
||||||
}
|
}
|
||||||
fn loadItems(self: *Tab, location: *Container) !void {
|
fn loadItems(self: *Tab, location: *Container) !void {
|
||||||
if (self._private.currentItemsAllocator) |arena| {
|
_ = self._private.currentItemsAllocator.reset(.retain_capacity);
|
||||||
arena.deinit();
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
self.currentItems.mutex.lock();
|
self.currentItems.mutex.lock();
|
||||||
@@ -63,16 +61,14 @@ pub const Tab = struct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self._private.currentItemsAllocator = std.heap.ArenaAllocator.init(self.allocator);
|
const arenaAllocator = &self._private.currentItemsAllocator;
|
||||||
const arenaAllocator = &self._private.currentItemsAllocator.?;
|
|
||||||
const arena = arenaAllocator.allocator();
|
const arena = arenaAllocator.allocator();
|
||||||
|
|
||||||
var threadSafeAllocator = std.heap.ThreadSafeAllocator{ .child_allocator = arena };
|
var threadSafeAllocator = std.heap.ThreadSafeAllocator{ .child_allocator = arena };
|
||||||
const allocator = threadSafeAllocator.allocator();
|
const allocator = threadSafeAllocator.allocator();
|
||||||
|
|
||||||
errdefer {
|
errdefer {
|
||||||
arenaAllocator.deinit();
|
_ = self._private.currentItemsAllocator.reset(.free_all);
|
||||||
self._private.currentItemsAllocator = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -80,18 +76,23 @@ pub const Tab = struct {
|
|||||||
defer self.currentItems.mutex.unlock();
|
defer self.currentItems.mutex.unlock();
|
||||||
|
|
||||||
self.currentItems.data = std.ArrayList(*Item).init(allocator);
|
self.currentItems.data = std.ArrayList(*Item).init(allocator);
|
||||||
|
}
|
||||||
errdefer {
|
errdefer {
|
||||||
self.currentItems.data.?.deinit();
|
self.currentItems.data.?.deinit();
|
||||||
self.currentItems.data = null;
|
self.currentItems.data = null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
//TODO: add async
|
||||||
while (location.childrenLoading) {
|
while (location.childrenLoading) {
|
||||||
std.Thread.sleep(1 * std.time.ns_per_ms);
|
std.Thread.sleep(1 * std.time.ns_per_ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (location.children.items) |item| {
|
for (location.children.items) |item| {
|
||||||
const resolvedItem = try location.item.provider.getItemByFullName(item, &.{ .skipChildInit = false }, allocator);
|
const resolvedItem = location.item.provider.getItemByFullName(item, &.{ .skipChildInit = true }, allocator) catch |e| {
|
||||||
|
//TODO: save error to container errors
|
||||||
|
std.debug.print("error {} {s}\r\n", .{e, item.path});
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
|
||||||
self.currentItems.mutex.lock();
|
self.currentItems.mutex.lock();
|
||||||
defer self.currentItems.mutex.unlock();
|
defer self.currentItems.mutex.unlock();
|
||||||
@@ -105,8 +106,6 @@ pub const Tab = struct {
|
|||||||
if (self.currentLocation) |c| {
|
if (self.currentLocation) |c| {
|
||||||
c.item.deinit();
|
c.item.deinit();
|
||||||
}
|
}
|
||||||
if (self._private.currentItemsAllocator) |arena| {
|
self._private.currentItemsAllocator.deinit();
|
||||||
arena.deinit();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -72,13 +72,14 @@ pub fn main() !void {
|
|||||||
.tab = tab1,
|
.tab = tab1,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
defer model.core_model.deinit();
|
defer model.core_model.deinit();
|
||||||
try pool.spawn(core.data_loop, .{&model.core_model});
|
try pool.spawn(core.data_loop, .{&model.core_model});
|
||||||
|
|
||||||
// init Raylib backend (creates OS window)
|
// init Raylib backend (creates OS window)
|
||||||
// initWindow() means the backend calls CloseWindow for you in deinit()
|
// initWindow() means the backend calls CloseWindow for you in deinit()
|
||||||
var backend = try RaylibBackend.initWindow(.{
|
var backend = try RaylibBackend.initWindow(.{
|
||||||
.gpa = gpa,
|
.gpa = allocator,
|
||||||
.size = .{ .w = 800.0, .h = 600.0 },
|
.size = .{ .w = 800.0, .h = 600.0 },
|
||||||
.vsync = vsync,
|
.vsync = vsync,
|
||||||
.title = "DVUI Raylib Standalone Example",
|
.title = "DVUI Raylib Standalone Example",
|
||||||
@@ -88,7 +89,7 @@ pub fn main() !void {
|
|||||||
backend.log_events = true;
|
backend.log_events = true;
|
||||||
|
|
||||||
// init dvui Window (maps onto a single OS window)
|
// init dvui Window (maps onto a single OS window)
|
||||||
var win = try dvui.Window.init(@src(), gpa, backend.backend(), .{});
|
var win = try dvui.Window.init(@src(), allocator, backend.backend(), .{});
|
||||||
defer win.deinit();
|
defer win.deinit();
|
||||||
|
|
||||||
main_loop: while (true) {
|
main_loop: while (true) {
|
||||||
|
|||||||
17
src/main.zig
17
src/main.zig
@@ -20,21 +20,26 @@ pub fn main() !void {
|
|||||||
var localContentProvider = local_provider.LocalContentProvider{ .threadPool = &pool };
|
var localContentProvider = local_provider.LocalContentProvider{ .threadPool = &pool };
|
||||||
|
|
||||||
const fullName: models.FullName = .{ .path = "/home/adam/1.txt" };
|
const fullName: models.FullName = .{ .path = "/home/adam/1.txt" };
|
||||||
var item = try localContentProvider.getItemByFullName(fullName, allocator, allocator);
|
var item = try localContentProvider.getItemByFullName(fullName, &.{}, allocator);
|
||||||
defer item.deinit();
|
defer item.deinit();
|
||||||
|
|
||||||
const homeFullName: models.FullName = .{ .path = "/home/adam/" };
|
const homeFullName: models.FullName = .{ .path = "C:\\Users\\adakovacs" };
|
||||||
var homeItem = try localContentProvider.getItemByFullName(homeFullName, allocator, allocator);
|
const homeItem = try localContentProvider.getItemByFullName(homeFullName, &.{}, allocator);
|
||||||
defer homeItem.deinit();
|
// defer homeItem.deinit();
|
||||||
const c = switch (homeItem.item) {
|
const c = switch (homeItem.item) {
|
||||||
.container => |c| c,
|
.container => |c| c,
|
||||||
.element => unreachable,
|
.element => unreachable,
|
||||||
};
|
};
|
||||||
|
|
||||||
var tab1 = Tab.create(&pool, allocator);
|
var tab1 = try allocator.create(Tab);
|
||||||
|
defer allocator.destroy(tab1);
|
||||||
|
|
||||||
|
tab1.init(&pool, allocator);
|
||||||
|
defer tab1.deinit();
|
||||||
|
|
||||||
tab1.setCurrentLocation(c);
|
tab1.setCurrentLocation(c);
|
||||||
|
|
||||||
std.Thread.sleep(1 * std.time.ns_per_s);
|
std.Thread.sleep(5 * std.time.ns_per_s);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|||||||
Reference in New Issue
Block a user