Changeset 605 for AE/installer2/src/net/oni2/aeinstaller/backend
- Timestamp:
- Jan 13, 2013, 8:11:07 PM (12 years ago)
- Location:
- AE/installer2/src/net/oni2/aeinstaller/backend
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
AE/installer2/src/net/oni2/aeinstaller/backend/Settings.java
r604 r605 10 10 import java.util.Vector; 11 11 12 13 12 import com.thoughtworks.xstream.XStream; 14 13 import com.thoughtworks.xstream.io.xml.StaxDriver; … … 66 65 67 66 private boolean printNamesNotInMap = false; 68 67 68 /** 69 * @return path to wine 70 */ 71 public static String getWinePath() { 72 if (getPlatform() != Platform.LINUX) 73 return null; 74 75 Vector<String> cmd = new Vector<String>(); 76 cmd.add("which"); 77 cmd.add("wine"); 78 Vector<String> res = null; 79 try { 80 res = QuickAppExecution.execute(cmd); 81 } catch (IOException e) { 82 // TODO Auto-generated catch block 83 e.printStackTrace(); 84 } 85 if (res != null) { 86 if (res.get(0).startsWith("/") && res.get(0).endsWith("wine")) { 87 return res.get(0); 88 } 89 } 90 return null; 91 } 92 69 93 /** 70 94 * Get the singleton instance -
AE/installer2/src/net/oni2/aeinstaller/backend/depot/DepotManager.java
r603 r605 92 92 page = 0; 93 93 do { 94 ja = DrupalJSONQuery.getIndex("taxonomy_vocabulary", page );94 ja = DrupalJSONQuery.getIndex("taxonomy_vocabulary", page, 100); 95 95 for (int i = 0; i < ja.length(); i++) { 96 96 jo = ja.getJSONObject(i); … … 106 106 page = 0; 107 107 do { 108 ja = DrupalJSONQuery.getIndex("taxonomy_term", page );108 ja = DrupalJSONQuery.getIndex("taxonomy_term", page, 100); 109 109 for (int i = 0; i < ja.length(); i++) { 110 110 jo = ja.getJSONObject(i); … … 122 122 page = 0; 123 123 do { 124 ja = DrupalJSONQuery.getIndex("node", page );124 ja = DrupalJSONQuery.getIndex("node", page, 500); 125 125 for (int i = 0; i < ja.length(); i++) { 126 126 jo = ja.getJSONObject(i); … … 152 152 page = 0; 153 153 do { 154 ja = DrupalJSONQuery.getIndex("file", page );154 ja = DrupalJSONQuery.getIndex("file", page, 500); 155 155 for (int i = 0; i < ja.length(); i++) { 156 156 jo = ja.getJSONObject(i); -
AE/installer2/src/net/oni2/aeinstaller/backend/mods/download/ModDownload.java
r604 r605 96 96 */ 97 97 public void start() { 98 state = ModDownloadState.RUNNING; 98 99 downloader.start(); 99 100 } -
AE/installer2/src/net/oni2/aeinstaller/backend/mods/download/ModDownloader.java
r604 r605 67 67 currentDownload++; 68 68 downloadedCurrent = 0; 69 if ( currentDownload < downloads.size()) {69 if ((state == State.RUNNING) && (currentDownload < downloads.size())) { 70 70 downloads.get(currentDownload).start(); 71 71 } else { … … 74 74 } 75 75 76 /** 77 * @return Average download speed for up to now in B/s 78 */ 79 public int getDownloadSpeed() { 80 long duration = new Date().getTime() - startMS; 81 int down = downloadedComplete + downloadedCurrent; 82 return (int) (down * 1000 / duration); 76 private int getTimeElapsed() { 77 int total = (int) (new Date().getTime() - startMS) 78 / 1000; 79 return total; 83 80 } 84 81 85 /** 86 * @return Remaining time for all downloads by avg-speed in seconds 87 */ 88 public int getTimeRemaining() { 82 private int getDownloadSpeed() { 83 int elap = getTimeElapsed(); 84 int down = downloadedComplete + downloadedCurrent; 85 if (elap > 0) 86 return down / elap; 87 else 88 return 1; 89 } 90 91 private int getTimeRemaining() { 89 92 int remainingSize = totalSize 90 93 - (downloadedComplete + downloadedCurrent); … … 94 97 private void notifyListener() { 95 98 listener.updateStatus(this, state, unpacked, downloads.size(), 96 downloadedComplete + downloadedCurrent, totalSize); 99 downloadedComplete + downloadedCurrent, totalSize, 100 getTimeElapsed(), getTimeRemaining(), getDownloadSpeed()); 101 } 102 103 /** 104 * @return total download size 105 */ 106 public int getTotalSize() { 107 return totalSize; 97 108 } 98 109 … … 133 144 } 134 145 146 /** 147 * Abort download process 148 */ 149 public void abort() { 150 if (currentDownload < downloads.size()) { 151 state = State.INTERRUPTED; 152 ModDownload md = downloads.get(currentDownload); 153 md.abort(); 154 } 155 } 156 135 157 } -
AE/installer2/src/net/oni2/aeinstaller/backend/mods/download/ModDownloaderListener.java
r604 r605 22 22 * @param bytesTotal 23 23 * Bytes in total to handle 24 * @param duration 25 * Duration of downloads in seconds 26 * @param remaining 27 * Remaining time in seconds 28 * @param speed 29 * Average download speed in B/s 24 30 */ 25 31 public void updateStatus(ModDownloader source, State state, int filesDown, 26 int filesTotal, int bytesDown, int bytesTotal); 32 int filesTotal, int bytesDown, int bytesTotal, int duration, 33 int remaining, int speed); 27 34 } -
AE/installer2/src/net/oni2/aeinstaller/backend/network/DrupalJSONQuery.java
r600 r605 112 112 * Number of page to get (for limited results, e.g. nodes), -1 to 113 113 * ignore 114 * @param pagesize 115 * Maximum number of elements to return 114 116 * @return JSON structure of item 115 117 * @throws Exception 116 118 * on HTTP error 117 119 */ 118 public static JSONArray getIndex(String resource, int page )120 public static JSONArray getIndex(String resource, int page, int pagesize) 119 121 throws Exception { 120 122 String pageN = ""; 121 123 if (page >= 0) 122 124 pageN = "&page=" + Integer.toString(page); 123 return executeQuery(getDepotUrl() + resource + ".json" + pageN, null); 125 String pagesizeN = ""; 126 if (pagesize >= 0) 127 pagesizeN = "&pagesize=" + Integer.toString(pagesize); 128 return executeQuery(getDepotUrl() + resource + ".json" + pageN 129 + pagesizeN, null); 124 130 } 125 131 -
AE/installer2/src/net/oni2/aeinstaller/backend/network/FileDownloader.java
r604 r605 212 212 213 213 i++; 214 if ((i % 10) == 0)214 if ((i % 50) == 0) 215 215 updateStatus(downloaded, fileLength); 216 216 } -
AE/installer2/src/net/oni2/aeinstaller/backend/unpack/Unpacker.java
r604 r605 117 117 try { 118 118 int pathStart = 0; 119 String pathStartName = ""; 119 120 120 121 ZipFile zf = new ZipFile(zip); … … 124 125 ZipEntry ze = e.nextElement(); 125 126 if (ze.getName().toLowerCase() 126 .endsWith("mod_info.cfg")) { 127 .endsWith("/mod_info.cfg") 128 || ze.getName().toLowerCase() 129 .equals("mod_info.cfg")) { 127 130 pathStart = ze.getName().toLowerCase() 128 131 .indexOf("mod_info.cfg"); 132 pathStartName = ze.getName().substring(0, 133 pathStart); 129 134 } 130 135 } … … 136 141 ZipEntry ze = e.nextElement(); 137 142 if (!ze.isDirectory()) { 138 File targetFile = new File(target, ze.getName() 139 .substring(pathStart)); 140 targetFile.getParentFile().mkdirs(); 143 if (ze.getName().startsWith(pathStartName)) { 144 File targetFile = new File(target, ze 145 .getName().substring(pathStart)); 146 File parent = targetFile.getParentFile(); 147 parent.mkdirs(); 141 148 142 InputStream in = zf.getInputStream(ze);149 InputStream in = zf.getInputStream(ze); 143 150 144 int read = 0; 145 byte[] data = new byte[1024]; 146 FileOutputStream fileOut = new FileOutputStream( 147 targetFile); 148 while ((read = in.read(data, 0, 1024)) != -1) { 149 fileOut.write(data, 0, read); 151 int read = 0; 152 byte[] data = new byte[1024]; 153 FileOutputStream fileOut = new FileOutputStream( 154 targetFile); 155 while ((read = in.read(data, 0, 1024)) != -1) { 156 fileOut.write(data, 0, read); 157 } 158 fileOut.close(); 150 159 } 151 fileOut.close();152 160 } 153 161 }
Note:
See TracChangeset
for help on using the changeset viewer.