Skip to content

GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.

fix(domain): get sample user config from embedded resource in entry assembly

Lars Berger9828d9c0e47c
diff --git a/GlazeWM.Domain/UserConfigs/CommandHandlers/EvaluateUserConfigHandler.cs b/GlazeWM.Domain/UserConfigs/CommandHandlers/EvaluateUserConfigHandler.cs
index 10589f18..a922ed47 100644
--- a/GlazeWM.Domain/UserConfigs/CommandHandlers/EvaluateUserConfigHandler.cs
+++ b/GlazeWM.Domain/UserConfigs/CommandHandlers/EvaluateUserConfigHandler.cs
@@ -5,6 +5,7 @@ using GlazeWM.Infrastructure.WindowsApi;
using GlazeWM.Infrastructure.Yaml;
using System;
using System.IO;
+using System.Reflection;
using System.Text.RegularExpressions;
namespace GlazeWM.Domain.UserConfigs.CommandHandlers
@@ -33,11 +34,7 @@ namespace GlazeWM.Domain.UserConfigs.CommandHandlers
var userConfigPath = _userConfigService.UserConfigPath;
if (!File.Exists(userConfigPath))
- {
- // Initialize the user config with the sample config.
- Directory.CreateDirectory(Path.GetDirectoryName(userConfigPath));
- File.Copy(_userConfigService.SampleUserConfigPath, userConfigPath, false);
- }
+ InitializeSampleUserConfig(userConfigPath);
deserializedConfig = DeserializeUserConfig(userConfigPath);
}
@@ -63,6 +60,23 @@ namespace GlazeWM.Domain.UserConfigs.CommandHandlers
return CommandResponse.Ok;
}
+ private void InitializeSampleUserConfig(string userConfigPath)
+ {
+ var assembly = Assembly.GetEntryAssembly();
+ var sampleConfigResourceName = "GlazeWM.Bootstrapper.sample-config.yaml";
+
+ // Get the embedded sample user config from the entry assembly.
+ using (Stream stream = assembly.GetManifestResourceStream(sampleConfigResourceName))
+ {
+ // Write the sample user config to the appropriate destination.
+ using (var fileStream = new FileStream(userConfigPath, FileMode.Create, FileAccess.Write))
+ {
+ Directory.CreateDirectory(Path.GetDirectoryName(userConfigPath));
+ stream.CopyTo(fileStream);
+ }
+ }
+ }
+
private UserConfig DeserializeUserConfig(string userConfigPath)
{
var userConfigLines = File.ReadAllLines(userConfigPath);