From 6f220a3a2b4302e8d3a169e0adfda2f144e42bcd Mon Sep 17 00:00:00 2001 From: stephen Date: Wed, 4 Sep 2013 17:55:06 +0800 Subject: [PATCH] Fix AWSTAT config generate problem all unmatched environmentvariable will retain --- .../WebsitePanel.Server.Utils/FileUtils.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/WebsitePanel/Sources/WebsitePanel.Server.Utils/FileUtils.cs b/WebsitePanel/Sources/WebsitePanel.Server.Utils/FileUtils.cs index cdc199d3..d88563cf 100644 --- a/WebsitePanel/Sources/WebsitePanel.Server.Utils/FileUtils.cs +++ b/WebsitePanel/Sources/WebsitePanel.Server.Utils/FileUtils.cs @@ -136,7 +136,7 @@ namespace WebsitePanel.Providers.Utils if (String.IsNullOrEmpty(str)) return str; - Regex re = new Regex("%(.+)%", RegexOptions.IgnoreCase); + Regex re = new Regex("%([^\\s\\%]+)%", RegexOptions.IgnoreCase); return re.Replace(str, new MatchEvaluator(EvaluateSystemVariable)); } @@ -185,7 +185,15 @@ namespace WebsitePanel.Providers.Utils private static string EvaluateSystemVariable(Match match) { - return Environment.GetEnvironmentVariable(match.Groups[1].Value); + string EnvVar = Environment.GetEnvironmentVariable(match.Groups[1].Value); + if (string.IsNullOrEmpty(EnvVar)) + { + return @"%" + match.Groups[1].Value + @"%"; + } + else + { + return EnvVar; + } } public static bool FileExists(string path) @@ -964,8 +972,7 @@ namespace WebsitePanel.Providers.Utils catch { } } - - #region Advanced Delete + #region Advanced Delete /// /// Deletes the specified file. ///