| 1 |
package net.oni2.aeinstaller.backend.oni.management.tools; |
| 2 |
|
| 3 |
import java.io.File; |
| 4 |
|
| 5 |
import net.oni2.aeinstaller.backend.CaseInsensitiveFile; |
| 6 |
import net.oni2.aeinstaller.backend.Paths; |
| 7 |
import net.oni2.aeinstaller.backend.packages.Package; |
| 8 |
import net.oni2.platformtools.PlatformInformation; |
| 9 |
import net.oni2.platformtools.PlatformInformation.Platform; |
| 10 |
|
| 11 |
/** |
| 12 |
* @author Christian Illy |
| 13 |
*/ |
| 14 |
public class ToolFileIterator { |
| 15 |
|
| 16 |
/** |
| 17 |
* Iterate over tool package files with source and respective target file |
| 18 |
* |
| 19 |
* @param tool |
| 20 |
* Tool to iterate over |
| 21 |
* @param handler |
| 22 |
* Handler to handle found files |
| 23 |
*/ |
| 24 |
public static void iteratePlatformToolFiles(Package tool, |
| 25 |
ToolFileIteratorEntry handler) { |
| 26 |
File plain = CaseInsensitiveFile.getCaseInsensitiveFile( |
| 27 |
tool.getLocalPath(), "plain"); |
| 28 |
if (plain.exists()) { |
| 29 |
if (tool.hasSeparatePlatformDirs()) { |
| 30 |
File plainCommon = CaseInsensitiveFile.getCaseInsensitiveFile( |
| 31 |
plain, "common"); |
| 32 |
File plainMac = CaseInsensitiveFile.getCaseInsensitiveFile( |
| 33 |
plain, "mac_only"); |
| 34 |
File plainWin = CaseInsensitiveFile.getCaseInsensitiveFile( |
| 35 |
plain, "win_only"); |
| 36 |
if (plainCommon.exists()) |
| 37 |
iterateFiles(plainCommon, Paths.getEditionBasePath(), |
| 38 |
handler); |
| 39 |
if (PlatformInformation.getPlatform() == Platform.MACOS |
| 40 |
&& plainMac.exists()) |
| 41 |
iterateFiles(plainMac, Paths.getEditionBasePath(), handler); |
| 42 |
else if (plainWin.exists()) |
| 43 |
iterateFiles(plainWin, Paths.getEditionBasePath(), handler); |
| 44 |
} else { |
| 45 |
iterateFiles(plain, Paths.getEditionBasePath(), handler); |
| 46 |
} |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
private static void iterateFiles(File srcFolder, File targetFolder, |
| 51 |
ToolFileIteratorEntry handler) { |
| 52 |
for (File f : srcFolder.listFiles()) { |
| 53 |
if (f.isDirectory()) { |
| 54 |
if (f.getName().endsWith(".app")) { |
| 55 |
handler.toolFile(f, new File(targetFolder, f.getName()), f.isDirectory()); |
| 56 |
} |
| 57 |
iterateFiles(f, CaseInsensitiveFile.getCaseInsensitiveFile( |
| 58 |
targetFolder, f.getName()), handler); |
| 59 |
} else { |
| 60 |
handler.toolFile(f, new File(targetFolder, f.getName()), f.isDirectory()); |
| 61 |
} |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
} |