summary refs log tree commit diff
path: root/src/config.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/config.zig')
-rw-r--r--src/config.zig13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/config.zig b/src/config.zig
index 2ecb69b..dbe0f7d 100644
--- a/src/config.zig
+++ b/src/config.zig
@@ -16,9 +16,10 @@
 // You should have received a copy of the GNU General Public License
 // along with Black Shades.  If not, see <https://www.gnu.org/licenses/>.
 
-const Allocator = std.mem.Allocator;
+const allocator = std.heap.c_allocator;
 const createFile = std.fs.createFileAbsolute;
 const cwd = std.fs.cwd;
+const data_dir = @import("build_options").data_dir;
 const eql = std.mem.eql;
 const ini = @import("ini");
 const join = std.fs.path.join;
@@ -46,16 +47,18 @@ pub const Config = extern struct {
 };
 
 /// Parse config.ini in the given base directory.
-pub fn parse(allocator: *Allocator, base_dir: []const u8) !Config {
+pub fn parse(base_dir: []const u8) !Config {
     const config_dir = try join(allocator, &.{ base_dir, "blackshades" });
     defer allocator.free(config_dir);
     var dir = try cwd().makeOpenPath(config_dir, .{});
     defer dir.close();
 
     var config = Config{};
-    const input = dir.openFile("config.ini", .{}) catch {
-        try dir.writeFile("config.ini", @embedFile("config.ini"));
-        return config;
+    const input = dir.openFile("config.ini", .{}) catch blk: {
+        var source = try cwd().makeOpenPath(data_dir, .{});
+        defer source.close();
+        try source.copyFile("config.ini", dir, "config.ini", .{});
+        break :blk try dir.openFile("config.ini", .{});
     };
     defer input.close();