using System; using System.Collections.Generic; using System.Text; namespace CPF.ReoGrid.Utility { internal class RelativePathUtility { internal static string GetRelativePath(string originalPath, string relativePath) { bool flag = string.IsNullOrEmpty(relativePath); string result; if (flag) { result = originalPath; } else { List pathStack = new List(); bool flag2 = !relativePath.StartsWith("/"); if (flag2) { RelativePathUtility.PushPath(pathStack, originalPath); } RelativePathUtility.PushPath(pathStack, relativePath); result = RelativePathUtility.DumpPathStack(pathStack); } return result; } private static void PushPath(List pathStack, string relativePath) { string[] array = relativePath.Split(new char[] { '/' }); foreach (string text in array) { bool flag = text == ".." && pathStack.Count > 0; if (flag) { pathStack.RemoveAt(pathStack.Count - 1); } else { bool flag2 = text.Length > 0 && text != "."; if (flag2) { pathStack.Add(text); } } } } private static string DumpPathStack(List pathStack) { StringBuilder stringBuilder = new StringBuilder(); foreach (string value in pathStack) { bool flag = stringBuilder.Length > 0; if (flag) { stringBuilder.Append('/'); } stringBuilder.Append(value); } return stringBuilder.ToString(); } internal static string GetFileNameFromPath(string path) { int num = path.LastIndexOf('/'); bool flag = num <= -1; string result; if (flag) { result = path; } else { bool flag2 = num >= path.Length - 1; if (flag2) { result = string.Empty; } else { result = path.Substring(num + 1); } } return result; } internal static string GetPathWithoutFilename(string path) { int num = path.LastIndexOf('/'); bool flag = num <= -1; string result; if (flag) { result = string.Empty; } else { bool flag2 = num == path.Length - 1; if (flag2) { result = path; } else { bool flag3 = num >= path.Length; if (flag3) { result = path + "/"; } else { result = path.Substring(0, num + 1); } } } return result; } } }