Index: /AE/installer2/src/net/oni2/aeinstaller/backend/oni/Installer.java
===================================================================
--- /AE/installer2/src/net/oni2/aeinstaller/backend/oni/Installer.java	(revision 596)
+++ /AE/installer2/src/net/oni2/aeinstaller/backend/oni/Installer.java	(revision 597)
@@ -2,4 +2,5 @@
 
 import java.io.File;
+import java.io.FileFilter;
 import java.io.FilenameFilter;
 import java.io.IOException;
@@ -7,4 +8,6 @@
 
 import net.oni2.aeinstaller.backend.Paths;
+import net.oni2.aeinstaller.backend.Settings;
+import net.oni2.aeinstaller.backend.Settings.Platform;
 
 import org.apache.commons.io.FileUtils;
@@ -18,7 +21,5 @@
 	 */
 	public static boolean isEditionInitialized() {
-		File editionGDF = Paths.getEditionGDF();
-		File vanillaDats = Paths.getVanillaGDF();
-		return editionGDF.exists() && vanillaDats.exists();
+		return Paths.getVanillaOnisPath().exists();
 	}
 
@@ -38,4 +39,10 @@
 			createEmptyPath(Paths.getVanillaOnisPath());
 			createEmptyPath(init);
+			File level0Folder = new File(init, "level0_Final");
+			createEmptyPath(level0Folder);
+			File level0FolderVanilla = new File(Paths.getVanillaOnisPath(),
+					"level0_Final");
+			createEmptyPath(level0FolderVanilla);
+			createEmptyPath(new File(level0FolderVanilla, "characters"));
 
 			for (File f : Paths.getVanillaGDF().listFiles(new FilenameFilter() {
@@ -47,19 +54,180 @@
 				String levelName = f.getName().substring(0,
 						f.getName().indexOf('.'));
-				int levelNumber = -1;
-
 				Scanner fi = new Scanner(levelName);
-				fi.useDelimiter("[^\\p{Alnum}]");
-				while (fi.hasNextInt()) {
-					levelNumber = fi.nextInt();
-				}
-
-				OniSplit.export(new File(init, levelName), f);
-			}
-
-			// TODO: FileUtils.deleteDirectory(Paths.getEditionGDF());
+				int levelNumber = Integer.parseInt(fi.findInLine("[0-9]+"));
+
+				// Edition/GameDataFolder/level*_Final/
+				File tempLevelFolder = new File(init, levelName);
+
+				// Export Vanilla-Level-Dat -> Temp/Level
+				OniSplit.export(tempLevelFolder, f);
+
+				handleFileGlobalisation(tempLevelFolder, level0Folder,
+						level0FolderVanilla, levelNumber);
+			}
+
+			for (File f : init.listFiles()) {
+				String levelName = f.getName();
+
+				// Edition/AEInstaller/vanilla/level*_Final/
+				File vanillaFolder = new File(Paths.getVanillaOnisPath(),
+						levelName);
+				vanillaFolder.mkdirs();
+
+				OniSplit.importLevel(f, new File(vanillaFolder, levelName
+						+ ".oni"));
+			}
+
+			// Copy Oni-configs
+			File persistVanilla = new File(Paths.getOniBasePath(),
+					"persist.dat");
+			File persistEdition = new File(Paths.getEditionBasePath(),
+					"persist.dat");
+			File keyConfVanilla = new File(Paths.getOniBasePath(),
+					"key_config.txt");
+			File keyConfEdition = new File(Paths.getEditionBasePath(),
+					"key_config.txt");
+			if (persistVanilla.exists() && !persistEdition.exists())
+				FileUtils.copyFile(persistVanilla, persistEdition);
+			if (keyConfVanilla.exists() && !keyConfEdition.exists())
+				FileUtils.copyFile(keyConfVanilla, keyConfEdition);
+
+			if (Settings.getPlatform() == Platform.MACOS) {
+				// TODO
+				// /* On Mac only, set the current GDF to the AE GDF by writing
+				// to Oni's global preferences file (thankfully a standard OS X
+				// ".plist" XML file).
+				// Tests for presence of prefs with [ -f ] before doing anything
+				// so it doesn't create a partial prefs file -- just in case
+				// user has never
+				// run Oni before :-p */
+				// string fullAEpath =
+				// escapePath(system_complete(".").parent_path().parent_path().string());
+				// // get full path for Edition/ (Oni wants folder that
+				// *contains* the GDF)
+				// string prefsCommand =
+				// "[ -f ~/Library/Preferences/com.godgames.oni.plist ] && defaults write com.godgames.oni RetailInstallationPath -string '"
+				// + fullAEpath + "'";
+				// system(prefsCommand.c_str());
+			}
+			// TODO: FileUtils.deleteDirectory(init);
 		} catch (IOException e) {
 			e.printStackTrace();
 		}
 	}
+
+	private static void moveFileToTargetOrDelete(File source, File target) {
+		if (source.equals(target))
+			return;
+		if (!target.exists()) {
+			if (!source.renameTo(target)) {
+				System.err.println("File " + source.getPath() + " not moved!");
+			}
+		} else if (!source.delete()) {
+			System.err.println("File " + source.getPath() + " not deleted!");
+		}
+	}
+
+	private static void handleFileGlobalisation(File tempFolder,
+			File level0Folder, File level0FolderVanilla, int levelNumber) {
+		// Move AKEV and related files to subfolder so they're not globalized:
+		if (levelNumber != 0) {
+			File akevFolder = new File(tempFolder, "AKEV");
+			akevFolder.mkdir();
+			OniSplit.move(akevFolder, tempFolder.getPath() + "/AKEV*.oni",
+					"overwrite");
+		}
+
+		for (File f : tempFolder.listFiles(new FileFilter() {
+			@Override
+			public boolean accept(File pathname) {
+				return pathname.isFile();
+			}
+		})) {
+			// Move matching files to subfolder NoGlobal:
+			if (f.getName().startsWith("TXMPfail")
+					|| f.getName().startsWith("TXMPlevel")
+					|| (f.getName().startsWith("TXMP") && f.getName().contains(
+							"intro"))
+					|| f.getName().startsWith("TXMB")
+					|| f.getName().equals("M3GMpowerup_lsi.oni")
+					|| f.getName().equals("TXMPlsi_icon.oni")
+					|| (f.getName().startsWith("TXMB") && f.getName().contains(
+							"splash_screen.oni"))) {
+				File noGlobal = new File(tempFolder, "NoGlobal");
+				noGlobal.mkdir();
+				File noGlobalFile = new File(noGlobal, f.getName());
+				moveFileToTargetOrDelete(f, noGlobalFile);
+			}
+			// Move matching files to level0_Animations/level0_TRAC
+			else if (f.getName().startsWith("TRAC")) {
+				File level0File = new File(level0Folder, f.getName());
+				moveFileToTargetOrDelete(f, level0File);
+			}
+			// Move matching files to level0_Animations/level0_TRAM
+			else if (f.getName().startsWith("TRAM")) {
+				File level0File = new File(level0Folder, f.getName());
+				moveFileToTargetOrDelete(f, level0File);
+			}
+			// Move matching files to level0_Textures
+			else if (f.getName().startsWith("ONSK")
+					|| f.getName().startsWith("TXMP")) {
+				// TODO ? new File(tempFolder, "TexFix").mkdir();
+				File level0File = new File(level0Folder, f.getName());
+				// TODO: delete non-moved?
+				if (!level0File.exists()) {
+					if (!f.renameTo(level0File)) {
+						System.err.println("File " + f.getName()
+								+ " not moved!");
+					}
+				}
+			}
+			// Move matching files to *VANILLA*/level0_Characters
+			else if (f.getName().startsWith("ONCC")
+					|| f.getName().startsWith("TRBS")
+					|| f.getName().startsWith("ONCV")
+					|| f.getName().startsWith("ONVL")
+					|| f.getName().startsWith("TRMA")
+					|| f.getName().startsWith("TRSC")
+					|| f.getName().startsWith("TRAS")) {
+				File level0FolderCharactersVanilla = new File(
+						level0FolderVanilla, "characters");
+				File level0FileVanilla = new File(
+						level0FolderCharactersVanilla, f.getName());
+				moveFileToTargetOrDelete(f, level0FileVanilla);
+			}
+			// Move matching files to level0_Sounds
+			else if (f.getName().startsWith("OSBD")
+					|| f.getName().startsWith("SNDD")) {
+				File level0File = new File(level0Folder, f.getName());
+				moveFileToTargetOrDelete(f, level0File);
+			}
+			// Move matching files to level0_Particles
+			else if (f.getName().startsWith("BINA3")
+					|| f.getName().startsWith("M3GMdebris")
+					|| f.getName().equals("M3GMtoxic_bubble.oni")
+					|| f.getName().startsWith("M3GMelec")
+					|| f.getName().startsWith("M3GMrat")
+					|| f.getName().startsWith("M3GMjet")
+					|| f.getName().startsWith("M3GMbomb_")
+					|| f.getName().equals("M3GMbarab_swave.oni")
+					|| f.getName().equals("M3GMbloodyfoot.oni")) {
+				File level0File = new File(level0Folder, f.getName());
+				moveFileToTargetOrDelete(f, level0File);
+			}
+			// Move matching files to Archive (aka delete them)
+			else if (f.getName().startsWith("AGDB")
+					|| f.getName().startsWith("TRCM")) {
+				f.delete();
+			}
+			// TODO: needed? ONWC to GDF instead?
+			// Move matching files to *VANILLADATS*/level0_Final/level0_Final/
+			// fix for buggy ONWC overriding
+			else if (f.getName().startsWith("ONWC")) {
+				File level0FileVanilla = new File(level0FolderVanilla,
+						f.getName());
+				moveFileToTargetOrDelete(f, level0FileVanilla);
+			}
+		}
+	}
 }
Index: /AE/installer2/src/net/oni2/aeinstaller/backend/oni/OniSplit.java
===================================================================
--- /AE/installer2/src/net/oni2/aeinstaller/backend/oni/OniSplit.java	(revision 596)
+++ /AE/installer2/src/net/oni2/aeinstaller/backend/oni/OniSplit.java	(revision 597)
@@ -92,5 +92,5 @@
 		cmdLine.add(targetFolder.getPath());
 		cmdLine.add(input.getPath());
-		System.out.println(cmdLine.toString());
+		// System.out.println(cmdLine.toString());
 		Vector<String> res = null;
 		try {
@@ -101,10 +101,65 @@
 		}
 		if (res != null) {
+			// check for errors
 			System.out.println(res.toString());
 		}
 	}
 
-	public static void importLevel() {
-		getImportParam();
+	/**
+	 * Import given folder to a .dat-file
+	 * @param sourceFolder Folder containing .oni-files
+	 * @param targetFile Target .dat-file
+	 */
+	public static void importLevel(File sourceFolder, File targetFile) {
+		Vector<String> cmdLine = getProgramInvocation();
+		cmdLine.add(getImportParam());
+		cmdLine.add(sourceFolder.getPath());
+		cmdLine.add(targetFile.getPath());
+		// System.out.println(cmdLine.toString());
+		Vector<String> res = null;
+		try {
+			res = QuickAppExecution.execute(cmdLine);
+		} catch (IOException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+		if (res != null) {
+			// check for errors
+			System.out.println(res.toString());
+		}
+	}
+
+	/**
+	 * Move files from one location to another using OniSplit so relations are
+	 * handled
+	 * 
+	 * @param targetFolder
+	 *            Target folder for files
+	 * @param input
+	 *            Files to move, can contain wildcards
+	 * @param moveParameter
+	 *            e.g. overwrite, delete
+	 */
+	public static void move(File targetFolder, String input,
+			String moveParameter) {
+		if (!targetFolder.exists())
+			targetFolder.mkdir();
+
+		Vector<String> cmdLine = getProgramInvocation();
+		cmdLine.add("-move"
+				+ (moveParameter != null ? ":" + moveParameter : ""));
+		cmdLine.add(targetFolder.getPath());
+		cmdLine.add(input);
+		Vector<String> res = null;
+		try {
+			res = QuickAppExecution.execute(cmdLine);
+		} catch (IOException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+		if (res != null && res.size() > 0) {
+			// TODO: errors
+			System.out.println(res.toString());
+		}
 	}
 
