Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
PathExt.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.Collections.Generic;
5 using System.IO;
6 using System.Linq;
7 using System.Runtime.InteropServices;
8 using System.Text;
9 using System.Text.RegularExpressions;
10 using System.Threading.Tasks;
11 
12 namespace SiliconStudio.BuildEngine
13 {
14  public static class PathExt
15  {
16  public static bool IsValidPath(string path)
17  {
18  if (string.IsNullOrWhiteSpace(path))
19  return false;
20 
21  try
22  {
23  // ReSharper disable ReturnValueOfPureMethodIsNotUsed
24  Path.GetFullPath(path);
25  // ReSharper restore ReturnValueOfPureMethodIsNotUsed
26  return true;
27  }
28  catch
29  {
30  return false;
31  }
32  }
33 
34  public static string GetRelativePath(string absoluteRoot, string absolutePath)
35  {
36  var path = new StringBuilder(260); // MAX_PATH
37  if (string.IsNullOrWhiteSpace(absolutePath))
38  return absolutePath;
39 
40  string sourcePath = new DirectoryInfo(absolutePath).FullName;
41  absoluteRoot = new DirectoryInfo(absoluteRoot).FullName;
42  return PathRelativePathTo(path, absoluteRoot, FILE_ATTRIBUTE_DIRECTORY, sourcePath, FILE_ATTRIBUTE_DIRECTORY) == 0 ? sourcePath : path.ToString();
43  }
44 
45  // ReSharper disable InconsistentNaming
46  private const int FILE_ATTRIBUTE_DIRECTORY = 0x10;
47  //private const int FILE_ATTRIBUTE_NORMAL = 0x80;
48  // ReSharper restore InconsistentNaming
49 
50  [DllImport("shlwapi.dll", SetLastError = true)]
51  private static extern int PathRelativePathTo(StringBuilder pszPath, string pszFrom, int dwAttrFrom, string pszTo, int dwAttrTo);
52 
53  }
54 }
static bool IsValidPath(string path)
Definition: PathExt.cs:16
static string GetRelativePath(string absoluteRoot, string absolutePath)
Definition: PathExt.cs:34