InstallManager.java 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5. package de.nplusc.izc.InstallPak;
  6. import de.nplusc.izc.tools.baseTools.Messagers;
  7. import de.nplusc.izc.tools.baseTools.Tools;
  8. import java.util.ArrayList;
  9. import java.util.Arrays;
  10. import java.util.HashMap;
  11. /**
  12. *
  13. * @author LH
  14. */
  15. public class InstallManager
  16. {
  17. public static final int VERSION_MAJOR = 1,VERSION_MINOR=1,REVISION=0;
  18. public static final String VERSION_GUI_TXT="izSetup "+VERSION_MAJOR+"."+VERSION_MINOR+"."+REVISION+" (c) 2013 iZc";
  19. public static InstallManager Main;
  20. private String[][] InstallQueue;
  21. private String[] Groups;
  22. private String[] enabledGroupIDs;
  23. private HashMap<String,ArrayList<String[]>> groupsplitted = new HashMap<>();
  24. static{
  25. Main= new InstallManager();
  26. // Main.setInstallScript(ModeSel.filePath);
  27. }
  28. public String[] getToggleAblePrograms()
  29. {
  30. Arrays.sort(Groups);
  31. return Groups;
  32. }
  33. public void setInstallScript(String path)
  34. {
  35. String[][] data = izsetupReader.getSysSpezSetupFile(path);
  36. if(data==null)
  37. {
  38. Messagers.SingleLineMsg("WTF?!?!?!?!?!?!?!?", "...");
  39. System.exit(0xfa11);
  40. }
  41. String groupID="000";
  42. String previousGRPID ="000";
  43. ArrayList<String[]> SubGroup = new ArrayList<>();
  44. for (String[] line : data)
  45. {
  46. if(!(line==null))
  47. {
  48. //DBG_START
  49. try{
  50. Tools.DebugHelperPrint(line[0]+"|GRP", true, "iZsetup.enableFinerDebug");
  51. Tools.DebugHelperPrint(line[1]+"|KEY", true, "iZsetup.enableFinerDebug");
  52. Tools.DebugHelperPrint(line[2]+"|VAL", true, "iZsetup.enableFinerDebug");
  53. //Tools.DebugHelperPrint(splittedLine[3]+"|CMNT", true, "iZsetup.enableFinerDebug");
  54. //DBG_STOP
  55. }
  56. catch(Exception ignored)//wenn 4ter null da kein CMNT feld vorhanden solls nicht errorn
  57. {
  58. }
  59. if(!line[0].equals("000"))
  60. {
  61. groupID=line[0];
  62. if(!previousGRPID.equals(groupID)&&!previousGRPID.equals("000"))
  63. {
  64. groupsplitted.put(previousGRPID, SubGroup);//Einlagern der abgeschlossenen gruppe
  65. SubGroup = new ArrayList<>();//resetten für neue daten;
  66. }
  67. SubGroup.add(line);
  68. previousGRPID=groupID;
  69. }
  70. }
  71. }
  72. groupsplitted.put(previousGRPID, SubGroup);//die letzte auch noch einflanschen
  73. String[] groupIDs = groupsplitted.keySet().toArray(new String[0]);
  74. ArrayList<String> lenabledGroupIDs = new ArrayList<>();
  75. ArrayList<String> lGroups = new ArrayList<>();
  76. for (String id : groupIDs)
  77. {
  78. lenabledGroupIDs.add(id);
  79. if(groupsplitted.get(id).get(0)[1].equalsIgnoreCase("grp")||groupsplitted.get(id).get(0)[1].equalsIgnoreCase("group"))
  80. {
  81. String groupname = groupsplitted.get(id).get(0)[2];//angelt sich erste zeile der Gruppe davon 3. Wert
  82. //wenn nicht mit grp oder group eingeleitetdann immer ausgeführt
  83. lGroups.add(id+"|"+groupname);
  84. }
  85. }
  86. Groups = lGroups.toArray(new String[0]);
  87. enabledGroupIDs=lenabledGroupIDs.toArray(new String[0]);
  88. }
  89. public void setGroupState(String grpid,boolean state)
  90. {
  91. boolean exists = false;
  92. for (int i = 0; i < enabledGroupIDs.length; i++)
  93. {
  94. String id = enabledGroupIDs[i];
  95. if(grpid.equals(id))
  96. {
  97. exists=true;
  98. if(!state)
  99. {
  100. enabledGroupIDs[i]="";
  101. }
  102. }
  103. }
  104. ArrayList<String> newGrps = new ArrayList<>();
  105. for (String cnt : enabledGroupIDs)
  106. {
  107. if(cnt.length()>1)
  108. {
  109. newGrps.add(cnt);
  110. }
  111. }
  112. if(!exists&&state)
  113. {
  114. newGrps.add(grpid);
  115. }
  116. enabledGroupIDs = newGrps.toArray(new String[0]);
  117. }
  118. public String[][] getInstallQueue()
  119. {
  120. return InstallQueue;
  121. }
  122. public void createQueue()
  123. {
  124. ArrayList<String[]> TempQueue = new ArrayList<>();
  125. Arrays.sort(enabledGroupIDs);
  126. //System.err.println("nop");
  127. for (String id : enabledGroupIDs)
  128. {
  129. ArrayList<String[]> loadedGroup = groupsplitted.get(id);
  130. for (String[] lines : loadedGroup)
  131. {
  132. String[] linedata =lines;
  133. if(linedata[1].equalsIgnoreCase("msg")||linedata[1].equalsIgnoreCase("exec")||linedata[1].equalsIgnoreCase("requireExec"))
  134. {
  135. TempQueue.add(Arrays.copyOfRange(lines, 2, lines.length));
  136. }
  137. }
  138. }
  139. //InstallQueue = TempQueue.toArray(new String[0]);
  140. InstallQueue=new String[TempQueue.size()][];
  141. for (int i = 0; i < InstallQueue.length; i++)
  142. {
  143. InstallQueue[i]=TempQueue.get(i);
  144. }
  145. }
  146. }