11pub fn main () ! void {
2- // logging
3- const logfile = try std .fs .cwd ().createFile ("/tmp/seamstress.log" , .{});
4- var bw = std .io .bufferedWriter (logfile .writer ());
5- defer bw .flush () catch {};
6- log_writer = bw .writer ().any ();
7-
82 // allocation
93 var gpa : if (builtin.mode == .Debug ) std .heap .GeneralPurposeAllocator (.{
104 .stack_trace_frames = 20 ,
@@ -18,6 +12,19 @@ pub fn main() !void {
1812 };
1913 const allocator = if (builtin .mode == .Debug ) gpa .allocator () else std .heap .c_allocator ;
2014
15+ // logging
16+ var bw = blk : {
17+ const cache_base = try folders .open (allocator , .cache , .{}) orelse break :blk null ;
18+ try cache_base .makePath ("seamstress" );
19+ const path = "seamstress" ++ std .fs .path .sep_str ++ "seamstress.log" ;
20+ const logfile = try cache_base .createFile (path , .{ .truncate = false });
21+ const end = try logfile .getEndPos ();
22+ try logfile .seekTo (end );
23+ break :blk std .io .bufferedWriter (logfile .writer ());
24+ };
25+ defer if (bw ) | * w | w .flush () catch {};
26+ if (bw ) | * w | log_writer = w .writer ().any ();
27+
2128 // arguments
2229 {
2330 const args = try std .process .argsAlloc (allocator );
@@ -83,7 +90,7 @@ pub fn main() !void {
8390
8491 try Seamstress .main (l );
8592 // flush any accumulated logs
86- try bw .flush ();
93+ if ( bw ) | * w | try w .flush ();
8794 // in release modes, this calls `exit(0)`, saving us from having to wait for memory to be freed
8895 std .process .cleanExit ();
8996}
@@ -216,12 +223,18 @@ pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, ret_
216223 @call (.always_inline , std .builtin .default_panic , .{ msg , error_return_trace , ret_addr });
217224}
218225
226+ pub const known_folders_config : folders.KnownFolderConfig = .{
227+ .xdg_force_default = true ,
228+ .xdg_on_mac = true ,
229+ };
230+
219231const std = @import ("std" );
220232const builtin = @import ("builtin" );
221233const Seamstress = @import ("seamstress.zig" );
222234const ziglua = @import ("ziglua" );
223235const Lua = ziglua .Lua ;
224236const lu = @import ("lua_util.zig" );
237+ const folders = @import ("known-folders" );
225238
226239test "ref" {
227240 _ = Seamstress ;
0 commit comments