- Timestamp:
- Apr 12, 2013, 5:57:57 PM (12 years ago)
- Location:
- java/installer2/src/net/oni2/aeinstaller/backend/oni/management/tools
- Files:
-
- 4 added
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
java/installer2/src/net/oni2/aeinstaller/backend/oni/management/tools/ToolsManager.java
r784 r804 1 package net.oni2.aeinstaller.backend.oni.management ;1 package net.oni2.aeinstaller.backend.oni.management.tools; 2 2 3 3 import java.io.File; 4 import java.io.FileInputStream;5 import java.io.FileNotFoundException;6 import java.io.FileOutputStream;7 4 import java.io.IOException; 5 import java.util.Arrays; 6 import java.util.HashSet; 8 7 import java.util.TreeSet; 9 8 10 9 import net.oni2.aeinstaller.backend.CaseInsensitiveFile; 10 import net.oni2.aeinstaller.backend.FileChecksum; 11 11 import net.oni2.aeinstaller.backend.Paths; 12 12 import net.oni2.aeinstaller.backend.packages.Package; 13 import net.oni2.platformtools.PlatformInformation; 14 import net.oni2.platformtools.PlatformInformation.Platform; 13 import net.oni2.aeinstaller.backend.packages.PackageManager; 15 14 16 15 import org.apache.commons.io.FileUtils; 17 18 import com.thoughtworks.xstream.XStream;19 import com.thoughtworks.xstream.io.xml.StaxDriver;20 16 21 17 /** … … 23 19 */ 24 20 public class ToolsManager { 21 25 22 /** 26 * @return Currentlyinstalled tools23 * Verify integrity of installed tools 27 24 */ 28 @SuppressWarnings("unchecked") 29 public static TreeSet<Integer> getInstalledTools() { 30 File installCfg = new File(Paths.getInstallerPath(), 31 "installed_tools.xml"); 32 TreeSet<Integer> res = new TreeSet<Integer>(); 33 try { 34 if (installCfg.exists()) { 35 FileInputStream fis = new FileInputStream(installCfg); 36 XStream xs = new XStream(new StaxDriver()); 37 Object obj = xs.fromXML(fis); 38 if (obj instanceof TreeSet<?>) 39 res = (TreeSet<Integer>) obj; 40 fis.close(); 41 } 42 } catch (FileNotFoundException e) { 43 e.printStackTrace(); 44 } catch (IOException e) { 45 e.printStackTrace(); 46 } 47 return res; 48 } 49 50 private static void writeInstalledTools(TreeSet<Integer> tools) { 51 File installCfg = new File(Paths.getInstallerPath(), 52 "installed_tools.xml"); 53 try { 54 FileOutputStream fos = new FileOutputStream(installCfg); 55 XStream xs = new XStream(new StaxDriver()); 56 xs.toXML(tools, fos); 57 fos.close(); 58 } catch (FileNotFoundException e) { 59 e.printStackTrace(); 60 } catch (IOException e) { 61 e.printStackTrace(); 25 public static void verifyToolsIntegrity() { 26 final ToolInstallationList til = ToolInstallationList.getInstance(); 27 for (final Package m : PackageManager.getInstance().getInstalledTools()) { 28 ToolFileIterator.iteratePlatformToolFiles(m, 29 new ToolFileIteratorEntry() { 30 @Override 31 public void toolFile(File source, File target) { 32 byte[] chkSrc = FileChecksum 33 .calculateFileMD5(source); 34 if (!target.exists()) { 35 til.markModified(m.getPackageNumber(), true); 36 } else { 37 byte[] chkTrg = FileChecksum 38 .calculateFileMD5(target); 39 if (!Arrays.equals(chkSrc, chkTrg)) 40 til.markModified(m.getPackageNumber(), true); 41 } 42 } 43 }); 62 44 } 63 45 } … … 70 52 */ 71 53 public static void installTools(TreeSet<Package> tools, boolean uninstall) { 72 T reeSet<Integer> installed = getInstalledTools();54 ToolInstallationList til = ToolInstallationList.getInstance(); 73 55 for (Package m : tools) { 74 if (!uninstall || installed.contains(m.getPackageNumber())) { 75 File plain = CaseInsensitiveFile.getCaseInsensitiveFile( 76 m.getLocalPath(), "plain"); 77 if (plain.exists()) { 78 if (m.hasSeparatePlatformDirs()) { 79 File plainCommon = CaseInsensitiveFile 80 .getCaseInsensitiveFile(plain, "common"); 81 File plainMac = CaseInsensitiveFile 82 .getCaseInsensitiveFile(plain, "mac_only"); 83 File plainWin = CaseInsensitiveFile 84 .getCaseInsensitiveFile(plain, "win_only"); 85 if (plainCommon.exists()) 86 copyRemoveToolsFiles(plainCommon, 87 Paths.getEditionBasePath(), uninstall); 88 if (PlatformInformation.getPlatform() == Platform.MACOS 89 && plainMac.exists()) 90 copyRemoveToolsFiles(plainMac, 91 Paths.getEditionBasePath(), uninstall); 92 else if (plainWin.exists()) 93 copyRemoveToolsFiles(plainWin, 94 Paths.getEditionBasePath(), uninstall); 95 } else { 96 copyRemoveToolsFiles(plain, Paths.getEditionBasePath(), 97 uninstall); 98 } 56 if (!uninstall) { // Install: 57 final HashSet<String> files = new HashSet<String>(); 58 ToolFileIterator.iteratePlatformToolFiles(m, 59 new ToolFileIteratorEntry() { 60 @Override 61 public void toolFile(File source, File target) { 62 copyToolsFiles(source, target, files); 63 } 64 }); 65 til.addTool(m.getPackageNumber(), files); 66 } else { // Uninstall: 67 if (til.isInstalled(m.getPackageNumber())) { 68 removeTool(til.getFiles(m.getPackageNumber())); 69 til.removeTool(m.getPackageNumber()); 99 70 } 100 71 } 101 if (uninstall)102 installed.remove(m.getPackageNumber());103 else104 installed.add(m.getPackageNumber());105 72 } 106 writeInstalledTools(installed);73 til.saveList(); 107 74 } 108 75 109 private static void copyRemoveToolsFiles(File srcFolder, File targetFolder, 110 boolean remove) { 111 for (File f : srcFolder.listFiles()) { 112 try { 113 if (f.isDirectory()) 114 copyRemoveToolsFiles(f, 115 CaseInsensitiveFile.getCaseInsensitiveFile( 116 targetFolder, f.getName()), remove); 117 else { 118 File targetFile = CaseInsensitiveFile 119 .getCaseInsensitiveFile(targetFolder, f.getName()); 120 if (remove) { 121 if (targetFile.exists()) 122 targetFile.delete(); 123 } else { 124 if (!targetFile.getName().equals(f.getName())) 125 targetFile.delete(); 126 FileUtils.copyFileToDirectory(f, targetFolder); 127 if (f.canExecute()) 128 CaseInsensitiveFile.getCaseInsensitiveFile( 129 targetFolder, f.getName()).setExecutable( 130 true); 131 } 132 } 133 } catch (IOException e) { 134 e.printStackTrace(); 76 private static void copyToolsFiles(File src, File target, 77 HashSet<String> files) { 78 try { 79 File targetFile = CaseInsensitiveFile.getCaseInsensitiveFile( 80 target.getParentFile(), target.getName()); 81 82 // Case mismatch? 83 if (!targetFile.getName().equals(src.getName())) 84 targetFile.delete(); 85 86 files.add(target.getPath().replace( 87 Paths.getEditionBasePath().getPath(), "")); 88 89 FileUtils.copyFile(src, target); 90 if (src.canExecute()) 91 target.setExecutable(true); 92 } catch (IOException e) { 93 e.printStackTrace(); 94 } 95 } 96 97 private static void removeTool(HashSet<String> files) { 98 for (String p : files) { 99 File targetFile = new File(Paths.getEditionBasePath().getPath() + p); 100 if (targetFile.getPath().contains( 101 Paths.getEditionBasePath().getPath())) { 102 File targetFolder = targetFile.getParentFile(); 103 104 if (targetFile.exists()) 105 targetFile.delete(); 106 if (targetFolder.list().length == 0) 107 targetFolder.delete(); 135 108 } 136 109 } 137 if (remove)138 if (targetFolder.list().length == 0)139 targetFolder.delete();140 110 } 141 142 111 }
Note:
See TracChangeset
for help on using the changeset viewer.