[596] | 1 | package net.oni2.aeinstaller.backend.oni;
|
---|
| 2 |
|
---|
| 3 | import java.io.File;
|
---|
| 4 | import java.io.FilenameFilter;
|
---|
| 5 | import java.io.IOException;
|
---|
| 6 | import java.util.Scanner;
|
---|
| 7 |
|
---|
| 8 | import net.oni2.aeinstaller.backend.Paths;
|
---|
| 9 |
|
---|
| 10 | import org.apache.commons.io.FileUtils;
|
---|
| 11 |
|
---|
| 12 | /**
|
---|
| 13 | * @author Christian Illy
|
---|
| 14 | */
|
---|
| 15 | public class Installer {
|
---|
| 16 | /**
|
---|
| 17 | * @return Is Edition Core initialized
|
---|
| 18 | */
|
---|
| 19 | public static boolean isEditionInitialized() {
|
---|
| 20 | File editionGDF = Paths.getEditionGDF();
|
---|
| 21 | File vanillaDats = Paths.getVanillaGDF();
|
---|
| 22 | return editionGDF.exists() && vanillaDats.exists();
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | private static void createEmptyPath(File path) throws IOException {
|
---|
| 26 | if (path.exists())
|
---|
| 27 | FileUtils.deleteDirectory(path);
|
---|
| 28 | path.mkdirs();
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | /**
|
---|
| 32 | * Initializes the Edition core
|
---|
| 33 | */
|
---|
| 34 | public static void initializeEdition() {
|
---|
| 35 | File init = new File(Paths.getTempPath(), "init");
|
---|
| 36 | try {
|
---|
| 37 | createEmptyPath(Paths.getEditionGDF());
|
---|
| 38 | createEmptyPath(Paths.getVanillaOnisPath());
|
---|
| 39 | createEmptyPath(init);
|
---|
| 40 |
|
---|
| 41 | for (File f : Paths.getVanillaGDF().listFiles(new FilenameFilter() {
|
---|
| 42 | @Override
|
---|
| 43 | public boolean accept(File dir, String name) {
|
---|
| 44 | return name.endsWith(".dat");
|
---|
| 45 | }
|
---|
| 46 | })) {
|
---|
| 47 | String levelName = f.getName().substring(0,
|
---|
| 48 | f.getName().indexOf('.'));
|
---|
| 49 | int levelNumber = -1;
|
---|
| 50 |
|
---|
| 51 | Scanner fi = new Scanner(levelName);
|
---|
| 52 | fi.useDelimiter("[^\\p{Alnum}]");
|
---|
| 53 | while (fi.hasNextInt()) {
|
---|
| 54 | levelNumber = fi.nextInt();
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | OniSplit.export(new File(init, levelName), f);
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | // TODO: FileUtils.deleteDirectory(Paths.getEditionGDF());
|
---|
| 61 | } catch (IOException e) {
|
---|
| 62 | e.printStackTrace();
|
---|
| 63 | }
|
---|
| 64 | }
|
---|
| 65 | }
|
---|