From 4f78cafa215903e8a2bd06099536ca01f1a15a15 Mon Sep 17 00:00:00 2001 From: Stewart Cossey Date: Tue, 23 Feb 2021 21:28:35 +1300 Subject: [PATCH] Set Service Configuration Folder Set service configuration folder to correct location. --- DnsService/DnsService.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/DnsService/DnsService.cs b/DnsService/DnsService.cs index 9879082b..8982f463 100644 --- a/DnsService/DnsService.cs +++ b/DnsService/DnsService.cs @@ -34,10 +34,25 @@ namespace DnsService protected override void OnStart(string[] args) { - _service = new WebService(null, new Uri("https://go.technitium.com/?id=22")); + _service = new WebService(getConfigFolder(), new Uri("https://go.technitium.com/?id=22")); _service.Start(); } + /// + /// If the service file path has the configuration files, use it, otherwise use the localapppath folder. + /// + /// The configuration path. + private string getConfigFolder() + { + string userConfigFolder = String.Concat(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"\Technitium\DNSServer"); + + if (System.IO.Directory.Exists(Environment.CurrentDirectory)) + { + return Environment.CurrentDirectory; + } + return userConfigFolder; + } + protected override void OnStop() { _service.Dispose();