File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed
External/Plugins/ProjectManager/Projects Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -13,8 +13,20 @@ public static string GetRelativePath(string baseDirectory, string path)
13
13
throw new ArgumentException ( "The path is already relative." ) ;
14
14
15
15
char slash = Path . DirectorySeparatorChar ;
16
- string [ ] a = baseDirectory . Trim ( slash ) . Split ( slash ) ;
17
- string [ ] b = path . Trim ( slash ) . Split ( slash ) ;
16
+ path = path . TrimEnd ( slash ) ;
17
+ baseDirectory = baseDirectory . TrimEnd ( slash ) ;
18
+
19
+ // trivial cases
20
+ if ( path == baseDirectory )
21
+ return "" ;
22
+ if ( path [ 1 ] == ':' && path [ 0 ] != baseDirectory [ 0 ] ) // drive
23
+ return path ;
24
+ if ( path . Length > baseDirectory . Length && path . StartsWith ( baseDirectory + slash ) )
25
+ return path . Substring ( baseDirectory . Length + 1 ) ;
26
+
27
+ // resolve relative path
28
+ string [ ] a = baseDirectory . Split ( slash ) ;
29
+ string [ ] b = path . Split ( slash ) ;
18
30
19
31
ArrayList relPath = new ArrayList ( ) ;
20
32
int i = 0 ;
@@ -26,6 +38,10 @@ public static string GetRelativePath(string baseDirectory, string path)
26
38
break ;
27
39
}
28
40
41
+ // only common drive letter, consider not relative
42
+ if ( i <= 1 )
43
+ return path ;
44
+
29
45
// at this point, i is the index of the first diverging element of the two paths
30
46
int backtracks = a . Length - i ;
31
47
for ( int j = 0 ; j < backtracks ; j ++ )
You can’t perform that action at this time.
0 commit comments