// MonoGame - Copyright (C) The MonoGame Team
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.
using System;
using Microsoft.Xna.Framework.Content.Pipeline;
namespace MonoGame.Framework.Content.Pipeline.Builder
{
public static class PathHelper
{
///
/// The/universal/standard/directory/seperator.
///
public const char DirectorySeparator = '/';
///
/// Returns a path string normalized to the/universal/standard.
///
public static string Normalize(string path)
{
return path.Replace('\\', '/');
}
///
/// Returns a directory path string normalized to the/universal/standard
/// with a trailing seperator.
///
public static string NormalizeDirectory(string path)
{
return path.Replace('\\', '/').TrimEnd('/') + '/';
}
///
/// Returns a path string normalized to the\Windows\standard.
///
public static string NormalizeWindows(string path)
{
return path.Replace('/', '\\');
}
///
/// Returns a path relative to the base path.
///
/// The path to make relative to. Must end with directory seperator.
/// The path to be made relative to the basePath.
/// The relative path or the original string if it is not absolute or cannot be made relative.
public static string GetRelativePath(string basePath, string path)
{
Uri uri;
if (!Uri.TryCreate(path, UriKind.Absolute, out uri))
return path;
uri = new Uri(basePath).MakeRelativeUri(uri);
var str = Uri.UnescapeDataString(uri.ToString());
return Normalize(str);
}
}
}