Skip to content

Commit

Permalink
Fix a potential related-path issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
HeddaZ committed Dec 17, 2015
1 parent eb37c60 commit c11137e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 100 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*.suo
*.user
*.sln.docstates
.vs/

# Build results

Expand Down
38 changes: 18 additions & 20 deletions ServiceOnset/Config/ServiceOnsetConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,13 @@ public string Command
{
throw new ArgumentNullException("command");
}
else if (!Path.IsPathRooted(_originalCommand))
else if (Path.IsPathRooted(_originalCommand))
{
#region 程序路径、工作目录或系统路径
_command = _originalCommand;
}
else
{
#region 非完整路径,尝试匹配程序路径、工作目录、系统路径

string possibleCommand = Path.Combine(AppHelper.AppDirectory, _originalCommand);
if (CommandExists(possibleCommand))
Expand All @@ -131,30 +135,22 @@ public string Command
}
else
{
if (!string.IsNullOrWhiteSpace(_originalWorkingDirectory))
if (string.IsNullOrWhiteSpace(_originalWorkingDirectory))
{
possibleCommand = Path.Combine(_originalWorkingDirectory, _originalCommand);
if (CommandExists(possibleCommand))
{
_originalCommand = possibleCommand;
}
else
{
//系统路径无需处理,自动应用 Path 环境变量
_command = _originalCommand;
}
_command = _originalCommand;
}
else
{
_command = _originalCommand;
possibleCommand = Path.IsPathRooted(_originalWorkingDirectory)
? Path.Combine(_originalWorkingDirectory, _originalCommand)
: Path.Combine(AppHelper.AppDirectory, _originalWorkingDirectory, _originalCommand);
_command = CommandExists(possibleCommand)
? possibleCommand
: _originalCommand;
}
}

#endregion
}
else
{
_command = _originalCommand;
#endregion
}
}
return _command;
Expand Down Expand Up @@ -183,7 +179,9 @@ public string WorkingDirectory
{
_workingDirectory = string.IsNullOrWhiteSpace(_originalWorkingDirectory)
? Path.GetDirectoryName(this.Command)
: _originalWorkingDirectory;
: (Path.IsPathRooted(_originalWorkingDirectory)
? _originalWorkingDirectory
: Path.Combine(AppHelper.AppDirectory, _originalWorkingDirectory));
}
return _workingDirectory;
}
Expand Down
55 changes: 0 additions & 55 deletions ServiceOnset/ServiceManager.cs.orig

This file was deleted.

50 changes: 25 additions & 25 deletions ServiceOnset/ServiceOnset.exe.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
{
"enableLog": true,
"services": [
{
"name": "PingBaidu",
"command": "ping",
"arguments": "www.baidu.com",
"workingDirectory": "",
"runMode": "interval",
"intervalInSeconds": 10,
"useShellExecute": false,
"killExistingProcess": false,
"enableLog": true
},
{
"name": "mywin_AppPath",
"command": "mywin",
"killExistingProcess": true
},
{
"name": "mywin_RelativePath",
"command": "test\\mywin.exe",
"runMode": "interval",
"killExistingProcess": true
}
]
"enableLog": true,
"services": [
{
"name": "PingBaidu",
"command": "ping",
"arguments": "www.baidu.com",
"workingDirectory": "",
"runMode": "interval",
"intervalInSeconds": 10,
"useShellExecute": false,
"killExistingProcess": false,
"enableLog": true
},
{
"name": "mywin_AppPath",
"command": "mywin",
"killExistingProcess": true
},
{
"name": "mywin_RelativePath",
"command": "test\\mywin.exe",
"runMode": "interval",
"killExistingProcess": true
}
]
}

0 comments on commit c11137e

Please sign in to comment.