1
1
package com .dfsek .converter ;
2
2
3
3
import com .dfsek .converter .dummy .DummyBlock ;
4
- import com .dfsek .converter .dummy .DummySpawn ;
5
4
import com .dfsek .converter .dummy .DummyStructure ;
6
5
7
6
import java .io .BufferedWriter ;
8
7
import java .io .File ;
9
8
import java .io .FileInputStream ;
10
- import java .io .FileOutputStream ;
11
9
import java .io .FileWriter ;
12
10
import java .io .IOException ;
11
+ import java .nio .file .Files ;
12
+ import java .nio .file .Path ;
13
13
import java .nio .file .Paths ;
14
14
import java .util .HashMap ;
15
15
import java .util .Map ;
16
- import java .util .Objects ;
17
16
18
17
public class ScriptConverter {
19
18
public static void main (String [] args ) throws IOException {
@@ -29,18 +28,13 @@ public static void main(String[] args) throws IOException {
29
28
converter .put ("[[Lcom.dfsek.terra.structure.StructureContainedBlock;" , "[[Lcom.dfsek.converter.dummy.DummyBlock;" );
30
29
converter .put ("[Lcom.dfsek.terra.structure.StructureContainedBlock;" , "[Lcom.dfsek.converter.dummy.DummyBlock;" );
31
30
32
- File working = Paths .get ("." ). toFile ( );
31
+ Path working = Paths .get ("." );
33
32
34
- System .out .println ("Working directory: " + working .getName ());
33
+ System .out .println ("Working directory: " + working .toFile (). getAbsolutePath ());
35
34
36
- File [] files = working .listFiles (file -> file .getName ().endsWith (".tstructure" ));
37
-
38
- if (files == null || files .length == 0 ) {
39
- System .out .println ("No tstructure files discovered" );
40
- return ;
41
- }
42
-
43
- for (File file : files ) {
35
+ Files .walk (working )
36
+ .filter (file -> file .toFile ().getName ().endsWith (".tstructure" )).forEach (path -> {
37
+ File file = path .toFile ();
44
38
System .out .println ("Converting " + file .getName ());
45
39
46
40
try (MovedObjectInputStream inputStream = new MovedObjectInputStream (new FileInputStream (file ), converter )) {
@@ -51,21 +45,26 @@ public static void main(String[] args) throws IOException {
51
45
System .out .println ("Converting structure to TerraScript..." );
52
46
53
47
String script = buildStructure (structure );
54
- String oldName = file .getName ();
48
+
49
+ String oldName = working .toUri ().relativize (file .toURI ()).getPath (); // get relative path (to preserve structure)
50
+
55
51
String newName = oldName .substring (0 , oldName .length () - 10 ) + "tesf" ;
56
- File output = new File (working , newName );
57
- if (!output .exists ()) output .createNewFile ();
52
+ File output = new File (working .toFile (), "out" + File .separator + newName );
53
+ if (!output .exists ()) {
54
+ output .getParentFile ().mkdirs ();
55
+ output .createNewFile ();
56
+ }
58
57
59
58
try (BufferedWriter writer = new BufferedWriter (new FileWriter (output ))) {
60
59
writer .write (script );
61
60
}
62
- System .out .println ("Converted to TerraScript. Saving structure to " + output .getName ());
63
- } catch (ClassNotFoundException e ) {
61
+ System .out .println ("Converted to TerraScript. Saving structure to " + output .getAbsolutePath ());
62
+ } catch (ClassNotFoundException | IOException e ) {
64
63
System .err .println ("Failed to convert structure!" );
65
64
e .printStackTrace ();
66
65
System .err .println ("Please report this issue." );
67
66
}
68
- }
67
+ });
69
68
}
70
69
71
70
public static String buildStructure (DummyStructure structure ) {
0 commit comments