fix(gui): allow file and directory have same name in tree (#2420)

This commit is contained in:
Skylot
2025-03-02 21:14:31 +00:00
parent c9d650d186
commit 5d720dd29c
2 changed files with 7 additions and 8 deletions
@@ -348,11 +348,12 @@ public class JResource extends JLoadableNode {
if (o == null || getClass() != o.getClass()) {
return false;
}
return name.equals(((JResource) o).name);
JResource other = (JResource) o;
return name.equals(other.name) && type.equals(other.type);
}
@Override
public int hashCode() {
return name.hashCode();
return name.hashCode() + 31 * type.ordinal();
}
}
@@ -64,19 +64,17 @@ public class JRoot extends JNode {
String[] parts = new File(rfName).getPath().split(splitPathStr);
JResource curRf = root;
int count = parts.length;
for (int i = 0; i < count; i++) {
for (int i = 0; i < count - 1; i++) {
String name = parts[i];
JResource subRF = getResourceByName(curRf, name);
if (subRF == null) {
if (i != count - 1) {
subRF = new JResource(null, name, JResType.DIR);
} else {
subRF = new JResource(rf, rf.getDeobfName(), name, JResType.FILE);
}
subRF = new JResource(null, name, JResType.DIR);
curRf.addSubNode(subRF);
}
curRf = subRF;
}
JResource leaf = new JResource(rf, rf.getDeobfName(), parts[count - 1], JResType.FILE);
curRf.addSubNode(leaf);
}
root.sortSubNodes();
root.update();