private String NormalizePath(String path, bool useAppBase)
{
if(path == null)
return null;
if (!useAppBase)
path = System.Security.Util.URLString.PreProcessForExtendedPathRemoval(path, false);
int len = path.Length;
if (len == 0)
return null;
#if !PLATFORM_UNIX
bool UNCpath = false;
#endif // !PLATFORM_UNIX
if ((len > 7) &&
(String.Compare( path, 0, "file:", 0, 5, StringComparison.OrdinalIgnoreCase) == 0)) {
int trim;
if (path[6] == '\\') {
if ((path[7] == '\\') || (path[7] == '/')) {
// Don't allow "file:\\\\", because we can't tell the difference
// with it for "file:\\" + "\\server" and "file:\\\" + "\localpath"
if ( (len > 8) &&
((path[8] == '\\') || (path[8] == '/')) )
throw new ArgumentException(Environment.GetResourceString("Argument_InvalidPathChars"));
// file:\\\ means local path
else
#if !PLATFORM_UNIX
trim = 8;
#else
// For Unix platform, trim the first 7 charcaters only.
// Trimming the first 8 characters will cause
// the root path separator to be trimmed away,
// and the absolute local path becomes a relative local path.
trim = 7;
#endif // !PLATFORM_UNIX
}
// file:\\ means remote server
else {
trim = 5;
#if !PLATFORM_UNIX
UNCpath = true;
#endif // !PLATFORM_UNIX
}
}
// local path
else if (path[7] == '/')
#if !PLATFORM_UNIX
trim = 8;
#else
// For Unix platform, trim the first 7 characters only.
// Trimming the first 8 characters will cause
// the root path separator to be trimmed away,
// and the absolute local path becomes a relative local path.
trim = 7;
#endif // !PLATFORM_UNIX
// remote
else {
// file://\\remote
if ( (len > 8) && (path[7] == '\\') && (path[8] == '\\') )
trim = 7;
else { // file://remote
trim = 5;
#if !PLATFORM_UNIX
// Create valid UNC path by changing
// all occurences of '/' to '\\' in path
System.Text.StringBuilder winPathBuilder =
new System.Text.StringBuilder(len);
for (int i = 0; i < len; i++) {
char c = path[i];
if (c == '/')
winPathBuilder.Append('\\');
else
winPathBuilder.Append(c);
}
path = winPathBuilder.ToString();
#endif // !PLATFORM_UNIX
}
#if !PLATFORM_UNIX
UNCpath = true;
#endif // !PLATFORM_UNIX
}
path = path.Substring(trim);
len -= trim;
}