|
|
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|
|
using System.ComponentModel;
|
|
|
using System.Data;
|
|
|
using System.Diagnostics;
|
|
|
+using System.Reflection;
|
|
|
using System.Runtime.InteropServices;
|
|
|
using System.ServiceProcess;
|
|
|
using System.Text;
|
|
|
@@ -69,11 +70,11 @@ namespace winsw
|
|
|
dom.Load(BasePath + ".xml");
|
|
|
}
|
|
|
|
|
|
- private string SingleElement(string tagName)
|
|
|
+ private string SingleElement(string tagName, bool optional = false)
|
|
|
{
|
|
|
var n = dom.SelectSingleNode("//" + tagName);
|
|
|
- if (n == null) throw new InvalidDataException("<" + tagName + "> is missing in configuration XML");
|
|
|
- return Environment.ExpandEnvironmentVariables(n.InnerText);
|
|
|
+ if (n == null && !optional) throw new InvalidDataException("<" + tagName + "> is missing in configuration XML");
|
|
|
+ return n == null ? null : Environment.ExpandEnvironmentVariables(n.InnerText);
|
|
|
}
|
|
|
|
|
|
private int SingleIntElement(XmlNode parent, string tagName, int defaultValue)
|
|
|
@@ -169,6 +170,16 @@ namespace winsw
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Optional working directory.
|
|
|
+ /// </summary>
|
|
|
+ public string WorkingDirectory {
|
|
|
+ get {
|
|
|
+ var wd = SingleElement("workingdirectory", true);
|
|
|
+ return String.IsNullOrEmpty(wd) ? Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) : wd;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// Combines the contents of all the elements of the given name,
|
|
|
/// or return null if no element exists. Handles whitespace quotation.
|