mirror of https://github.com/winsw/winsw
Set a default working directory for the wrapper
parent
c3771e391c
commit
94954e076f
|
@ -12,6 +12,8 @@ namespace WinSW.Configuration
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class DefaultWinSWSettings : IWinSWConfiguration
|
public sealed class DefaultWinSWSettings : IWinSWConfiguration
|
||||||
{
|
{
|
||||||
|
public string FullPath => throw new InvalidOperationException(nameof(this.FullPath) + " must be specified.");
|
||||||
|
|
||||||
public string Id => throw new InvalidOperationException(nameof(this.Id) + " must be specified.");
|
public string Id => throw new InvalidOperationException(nameof(this.Id) + " must be specified.");
|
||||||
|
|
||||||
public string Caption => string.Empty;
|
public string Caption => string.Empty;
|
||||||
|
@ -44,7 +46,7 @@ namespace WinSW.Configuration
|
||||||
|
|
||||||
public string? StopArguments => null;
|
public string? StopArguments => null;
|
||||||
|
|
||||||
public string WorkingDirectory => Path.GetDirectoryName(this.ExecutablePath)!;
|
public string WorkingDirectory => Path.GetDirectoryName(this.FullPath)!;
|
||||||
|
|
||||||
public ProcessPriorityClass Priority => ProcessPriorityClass.Normal;
|
public ProcessPriorityClass Priority => ProcessPriorityClass.Normal;
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,8 @@ namespace WinSW.Configuration
|
||||||
// TODO: Document the parameters && refactor
|
// TODO: Document the parameters && refactor
|
||||||
public interface IWinSWConfiguration
|
public interface IWinSWConfiguration
|
||||||
{
|
{
|
||||||
|
string FullPath { get; }
|
||||||
|
|
||||||
string Id { get; }
|
string Id { get; }
|
||||||
|
|
||||||
string Caption { get; }
|
string Caption { get; }
|
||||||
|
|
|
@ -25,6 +25,8 @@ namespace WinSW
|
||||||
|
|
||||||
public static DefaultWinSWSettings Defaults { get; } = new DefaultWinSWSettings();
|
public static DefaultWinSWSettings Defaults { get; } = new DefaultWinSWSettings();
|
||||||
|
|
||||||
|
public string FullPath { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Where did we find the configuration file?
|
/// Where did we find the configuration file?
|
||||||
///
|
///
|
||||||
|
@ -48,7 +50,8 @@ namespace WinSW
|
||||||
string baseName = Path.GetFileNameWithoutExtension(path);
|
string baseName = Path.GetFileNameWithoutExtension(path);
|
||||||
string baseDir = Path.GetDirectoryName(path)!;
|
string baseDir = Path.GetDirectoryName(path)!;
|
||||||
|
|
||||||
if (!File.Exists(Path.Combine(baseDir, baseName + ".xml")))
|
string fullPath = this.FullPath = Path.Combine(baseDir, baseName + ".xml");
|
||||||
|
if (!File.Exists(fullPath))
|
||||||
{
|
{
|
||||||
throw new FileNotFoundException("Unable to locate " + baseName + ".xml file within executable directory");
|
throw new FileNotFoundException("Unable to locate " + baseName + ".xml file within executable directory");
|
||||||
}
|
}
|
||||||
|
@ -58,7 +61,7 @@ namespace WinSW
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
this.dom.Load(this.BasePath + ".xml");
|
this.dom.Load(fullPath);
|
||||||
}
|
}
|
||||||
catch (XmlException e)
|
catch (XmlException e)
|
||||||
{
|
{
|
||||||
|
@ -88,10 +91,10 @@ namespace WinSW
|
||||||
throw new FileNotFoundException(null, path);
|
throw new FileNotFoundException(null, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
string baseName = Path.GetFileNameWithoutExtension(path);
|
string fullPath = this.FullPath = Path.GetFullPath(path);
|
||||||
string baseDir = Path.GetDirectoryName(Path.GetFullPath(path))!;
|
string baseName = this.BaseName = Path.GetFileNameWithoutExtension(path);
|
||||||
|
string baseDir = Path.GetDirectoryName(fullPath)!;
|
||||||
|
|
||||||
this.BaseName = baseName;
|
|
||||||
this.BasePath = Path.Combine(baseDir, baseName);
|
this.BasePath = Path.Combine(baseDir, baseName);
|
||||||
|
|
||||||
try
|
try
|
||||||
|
|
|
@ -53,8 +53,10 @@ namespace WinSW.Tests.Util
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
var properties = AllProperties;
|
var properties = AllProperties;
|
||||||
|
properties.Remove("FullPath");
|
||||||
properties.Remove("Id");
|
properties.Remove("Id");
|
||||||
properties.Remove("Executable");
|
properties.Remove("Executable");
|
||||||
|
properties.Remove("WorkingDirectory");
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,6 +63,8 @@ namespace WinSW
|
||||||
{
|
{
|
||||||
this.AcceptPreshutdown();
|
this.AcceptPreshutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Environment.CurrentDirectory = descriptor.WorkingDirectory;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
Loading…
Reference in New Issue