litesoft
Diff Revisions
361
vs
889
for /trunk/Java/ScarPlus/src/com/esotericsoftware/filesystem/FilePath.java
|
@@ -1,8 +1,10 @@ |
1 |
1 |
|
package com.esotericsoftware.filesystem; |
2 |
2 |
|
|
3 |
|
- |
import java.io.*; |
|
3 |
+ |
import com.esotericsoftware.scar.Utils; |
|
4 |
+ |
import com.esotericsoftware.utils.FileSupport; |
|
5 |
+ |
import com.esotericsoftware.utils.FileUtil; |
4 |
6 |
|
|
5 |
|
- |
import com.esotericsoftware.scar.*; |
|
7 |
+ |
import java.io.File; |
6 |
8 |
|
|
7 |
9 |
|
public final class FilePath |
8 |
10 |
|
{ |
|
@@ -57,18 +59,56 @@ |
57 |
59 |
|
return mCanonicalPath; |
58 |
60 |
|
} |
59 |
61 |
|
|
|
62 |
+ |
public String relativeFromDir(File pCanonicalJarDir) |
|
63 |
+ |
{ |
|
64 |
+ |
File zCommonDirPath = Utils.findCommonDirPathFromCanonicalDirPaths(pCanonicalJarDir, mCanonicalPath.getParentFile()); |
|
65 |
+ |
if ( zCommonDirPath == null ) |
|
66 |
+ |
{ |
|
67 |
+ |
throw new IllegalStateException( "Unable to create Relative path from '" + pCanonicalJarDir + "' to: " + this ); |
|
68 |
+ |
} |
|
69 |
+ |
String zJarDir = normalize(pCanonicalJarDir, zCommonDirPath); |
|
70 |
+ |
String zFilePath = normalize(mCanonicalPath, zCommonDirPath); |
|
71 |
+ |
while ( zJarDir.length() != 0 ) |
|
72 |
+ |
{ |
|
73 |
+ |
zFilePath = "../" + zFilePath; |
|
74 |
+ |
int zAt = zJarDir.lastIndexOf("/"); |
|
75 |
+ |
if ( zAt == -1 ) |
|
76 |
+ |
{ |
|
77 |
+ |
zJarDir = ""; |
|
78 |
+ |
} |
|
79 |
+ |
else |
|
80 |
+ |
{ |
|
81 |
+ |
zJarDir = zJarDir.substring(0,zAt); |
|
82 |
+ |
} |
|
83 |
+ |
} |
|
84 |
+ |
return zFilePath; |
|
85 |
+ |
} |
|
86 |
+ |
|
|
87 |
+ |
private String normalize(File pPath, File pCommonDirPath) { |
|
88 |
+ |
String zPath = pPath.getPath().substring(pCommonDirPath.getPath().length()).replace('\\', '/'); |
|
89 |
+ |
return zPath.startsWith("/") ? zPath.substring(1) : zPath; |
|
90 |
+ |
} |
|
91 |
+ |
|
60 |
92 |
|
public boolean equals( FilePath them ) |
61 |
93 |
|
{ |
62 |
94 |
|
return this == them || ((them != null) && this.canonical().equals( them.canonical() )); |
63 |
95 |
|
} |
64 |
96 |
|
|
|
97 |
+ |
@Override |
65 |
98 |
|
public boolean equals( Object obj ) |
66 |
99 |
|
{ |
67 |
100 |
|
return (this == obj) || ((obj instanceof FilePath) && equals( (FilePath) obj )); |
68 |
101 |
|
} |
69 |
102 |
|
|
|
103 |
+ |
@Override |
70 |
104 |
|
public int hashCode() |
71 |
105 |
|
{ |
72 |
106 |
|
return canonical().hashCode(); |
73 |
107 |
|
} |
|
108 |
+ |
|
|
109 |
+ |
@Override |
|
110 |
+ |
public String toString() |
|
111 |
+ |
{ |
|
112 |
+ |
return canonical(); |
|
113 |
+ |
} |
74 |
114 |
|
} |