/* Copyright (c) 2011, BogDan Vatra This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ package org.kde.necessitas.ministro; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import android.os.Bundle; class Library { public String name = null; public String filePath = null; public String[] depends = null; public String[] replaces = null; public NeedsStruct[] needs = null; public int level=0; public long size = 0; public String sha1 = null; public String url; public static String[] getLibNames(Element libNode) { if (libNode == null) return null; NodeList list=libNode.getElementsByTagName("lib"); ArrayList libs = new ArrayList(); for (int i=0;i needs = new ArrayList(); for (int i=0;i>> 4) & 0x0F; int two_halfs = 0; do { if ((0 <= halfbyte) && (halfbyte <= 9)) buf.append((char) ('0' + halfbyte)); else buf.append((char) ('a' + (halfbyte - 10))); halfbyte = data[i] & 0x0F; } while(two_halfs++ < 1); } return buf.toString(); } public static boolean checkCRC(String fileName, String sha1) throws IOException { try { byte[] tmp = new byte[2048]; MessageDigest digester = MessageDigest.getInstance("SHA-1"); int downloaded; FileInputStream inFile = new FileInputStream(new File(fileName)); while ((downloaded = inFile.read(tmp)) != -1) { digester.update(tmp, 0, downloaded); } inFile.close(); return sha1.equalsIgnoreCase(convertToHex(digester.digest())); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return false; } public static String mkdirParents(String rootPath, String filePath, int skip) { String[] paths=filePath.split("/"); String path = ""; for (int pit=0;pit s, String delimiter) { if (s == null || s.isEmpty()) return ""; Iterator iter = s.iterator(); StringBuilder builder = new StringBuilder(iter.next()); while( iter.hasNext() ) { builder.append(delimiter).append(iter.next()); } return builder.toString(); } public static void mergeBundleParameters(Bundle out, String outKey, Bundle in, String inKey) { if (!in.containsKey(inKey)) return; String value = null; if (out.containsKey(outKey)) value=out.getString(outKey); if (value!=null && value.length()>0 && value.charAt(value.length()-1)!='\t') value=value+"\t"; value=value+in.getString(inKey); out.putString(outKey, value); } }; class NeedsStruct { public String name = null; public String filePath = null; public String sha1 = null; public String url = null; public String type = null; public long size = 0; };