Use schematic/map names for filenames

This commit is contained in:
Anuken
2023-04-16 12:07:57 -04:00
parent f62096dbd1
commit 2db90408fe
3 changed files with 29 additions and 10 deletions

View File

@@ -320,11 +320,24 @@ public class Schematics implements Loadable{
return block.size + maxLoadoutSchematicPad*2; return block.size + maxLoadoutSchematicPad*2;
} }
Fi findFile(String schematicName){
if(schematicName.isEmpty()) schematicName = "empty";
Fi result = null;
int index = 0;
while(result == null || result.exists()){
result = schematicDirectory.child(schematicName + (index == 0 ? "" : "_" + index) + "." + schematicExtension);
index ++;
}
return result;
}
/** Adds a schematic to the list, also copying it into the files.*/ /** Adds a schematic to the list, also copying it into the files.*/
public void add(Schematic schematic){ public void add(Schematic schematic){
all.add(schematic); all.add(schematic);
try{ try{
Fi file = schematicDirectory.child(Time.millis() + "." + schematicExtension); Fi file = findFile(Strings.sanitizeFilename(schematic.name()));
write(schematic, file); write(schematic, file);
schematic.file = file; schematic.file = file;
}catch(Exception e){ }catch(Exception e){

View File

@@ -190,7 +190,7 @@ public class Maps{
maps.remove(other); maps.remove(other);
file = other.file; file = other.file;
}else{ }else{
file = findFile(); file = findFile(name);
} }
//create map, write it, etc etc etc //create map, write it, etc etc etc
@@ -239,7 +239,7 @@ public class Maps{
/** Import a map, then save it. This updates all values and stored data necessary. */ /** Import a map, then save it. This updates all values and stored data necessary. */
public void importMap(Fi file) throws IOException{ public void importMap(Fi file) throws IOException{
Fi dest = findFile(); Fi dest = findFile(file.name());
file.copyTo(dest); file.copyTo(dest);
Map map = loadMap(dest, true); Map map = loadMap(dest, true);
@@ -429,13 +429,19 @@ public class Maps{
} }
/** Find a new filename to put a map to. */ /** Find a new filename to put a map to. */
private Fi findFile(){ private Fi findFile(String unsanitizedName){
//find a map name that isn't used. String name = Strings.sanitizeFilename(unsanitizedName);
int i = maps.size; if(name.isEmpty()) name = "blank";
while(customMapDirectory.child("map_" + i + "." + mapExtension).exists()){
i++; Fi result = null;
int index = 0;
while(result == null || result.exists()){
result = customMapDirectory.child(name + (index == 0 ? "" : "_" + index) + "." + mapExtension);
index ++;
} }
return customMapDirectory.child("map_" + i + "." + mapExtension);
return result;
} }
private Map loadMap(Fi file, boolean custom) throws IOException{ private Map loadMap(Fi file, boolean custom) throws IOException{

View File

@@ -25,4 +25,4 @@ org.gradle.caching=true
#used for slow jitpack builds; TODO see if this actually works #used for slow jitpack builds; TODO see if this actually works
org.gradle.internal.http.socketTimeout=100000 org.gradle.internal.http.socketTimeout=100000
org.gradle.internal.http.connectionTimeout=100000 org.gradle.internal.http.connectionTimeout=100000
archash=2ef12ecfa1 archash=56c0bbf95f