package com.ubt.jimu.base.download; import android.content.Context; import android.text.TextUtils; import com.ubt.jimu.JimuApplication; import com.ubt.jimu.base.cache.Constants; import com.ubt.jimu.base.db.DatabaseUtils; import com.ubt.jimu.base.db.FileDownloadRecordDbHandler; import com.ubt.jimu.base.db.course.JimuCourseDbHandler; import com.ubt.jimu.base.entities.FileDownloadRecord; import com.ubt.jimu.base.entities.FirmwareVersion; import com.ubt.jimu.base.entities.PartFileInfo; import com.ubt.jimu.base.entities.Robot; import com.ubt.jimu.base.entities.Story; import com.ubt.jimu.blockly.Utils; import com.ubt.jimu.course.repository.JimuCourse; import com.ubt.jimu.diy.DiyRobotFile; import com.ubt.jimu.gen.PartFileInfoDao; import com.ubt.jimu.transport.model.TransportFile; import com.ubt.jimu.transport3.dao.TransportFileDbHandler2; import com.ubt.jimu.unity.ModelType; import com.ubt.jimu.utils.ExternalOverFroyoUtils; import com.ubtrobot.log.ALog; import java.io.File; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.greenrobot.greendao.query.QueryBuilder; import org.greenrobot.greendao.query.WhereCondition; /* loaded from: classes.dex */ public class DownloadInfo { public static final int COURSE = 4; public static final int COURSE_COMMON = 3; public static final int DIY_FILE = 7; public static final int FIRMWARE = 6; public static final int MODEL = 0; public static final int PARTS = 1; public static final int STAR_COURSE = 8; public static final int STORY_COMMON = 2; public static final int SYNC_FILE = 5; private static final String TAG = "DownloadInfo"; private String savePath; private int type; private String url; public DownloadInfo(int i, String str, String str2) { this.type = i; this.url = str; this.savePath = str2; } private static List getNeedDownPart(List list) { ArrayList arrayList = new ArrayList(); if (list != null && list.size() != 0) { for (PartFileInfo partFileInfo : list) { if (!isInDB(partFileInfo) || !isInDir(partFileInfo)) { arrayList.add(partFileInfo); } } } return arrayList; } public static List getNeedDownloadCourse(JimuCourse jimuCourse) { ArrayList arrayList = new ArrayList(); JimuCourse downloadedCourse = JimuCourseDbHandler.getDownloadedCourse(jimuCourse); String str = Constants.COURSE_RESOURCE_PATH; if (downloadedCourse != null && downloadedCourse.getDownload()) { if (new File(str + jimuCourse.getId()).exists() && jimuCourse.getUpdatedTime() == downloadedCourse.getUpdatedTime()) { return arrayList; } } arrayList.add(new DownloadInfo(4, jimuCourse.getResourceZip(), str + jimuCourse.getFolderName() + ".zip")); return arrayList; } public static List getNeedDownloadDiyRobotFile(String str, List list) { String str2; ArrayList arrayList = new ArrayList(); if (list != null && list.size() != 0) { String str3 = ExternalOverFroyoUtils.a(JimuApplication.l(), ModelType.DOWNLOAD) + str + File.separator; for (DiyRobotFile diyRobotFile : list) { if (513 == diyRobotFile.getFileType()) { str2 = str3 + "actions" + File.separator + diyRobotFile.getFileName(); } else if (769 == diyRobotFile.getFileType()) { str2 = str3 + str + Utils.BLOCKLY_ADD_PATH + File.separator + diyRobotFile.getFileName(); } else if (258 == diyRobotFile.getFileType()) { str2 = str3 + "servos" + File.separator + diyRobotFile.getFileName(); } else if (257 == diyRobotFile.getFileType()) { str2 = str3 + str + ".xml"; } else if (259 == diyRobotFile.getFileType()) { str2 = str3 + str + ".jpg"; } else { str2 = str3 + diyRobotFile.getFileName(); } arrayList.add(new DownloadInfo(7, diyRobotFile.getFileUrl(), str2)); } } return arrayList; } public static List getNeedDownloadFirmware(Context context, List list) { ArrayList arrayList = new ArrayList(); if (list != null && list.size() != 0) { for (FirmwareVersion firmwareVersion : list) { arrayList.add(new DownloadInfo(6, firmwareVersion.getVersionPath(), FirmwareVersion.getPath(context, firmwareVersion))); } } return arrayList; } public static List getNeedDownloadInfo(List list) { ArrayList arrayList = new ArrayList(); if (list != null && list.size() != 0) { long currentTimeMillis = System.currentTimeMillis(); for (TransportFile transportFile : list) { String fileUrl = transportFile.getFileUrl(); if (!TextUtils.isEmpty(fileUrl)) { int indexOf = fileUrl.indexOf("?"); fileUrl = indexOf < 0 ? fileUrl + "?t=" + currentTimeMillis : fileUrl.substring(0, indexOf) + "t=" + currentTimeMillis; } arrayList.add(new DownloadInfo(5, fileUrl, TransportFileDbHandler2.getAbsoluteModelFilePath(transportFile))); } } return arrayList; } /* JADX WARN: Code restructure failed: missing block: B:13:0x009f, code lost: if (r2.getModelUpdateTime() == r8.getModelUpdateTime()) goto L17; */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct code enable 'Show inconsistent code' option in preferences */ public static com.ubt.jimu.base.download.DownloadInfo getNeedDownloadModelInfo(com.ubt.jimu.base.entities.Robot r8) { /* java.lang.StringBuilder r0 = new java.lang.StringBuilder r0.() com.ubt.jimu.JimuApplication r1 = com.ubt.jimu.JimuApplication.l() com.ubt.jimu.unity.ModelType r2 = com.ubt.jimu.unity.ModelType.DEFAULT java.lang.String r1 = com.ubt.jimu.utils.ExternalOverFroyoUtils.a(r1, r2) r0.append(r1) java.lang.String r1 = r8.getModelName() r0.append(r1) java.lang.String r0 = r0.toString() java.lang.StringBuilder r1 = new java.lang.StringBuilder r1.() r1.append(r0) java.lang.String r2 = ".zip" r1.append(r2) java.lang.String r1 = r1.toString() java.io.File r2 = new java.io.File r2.(r0) r0 = 1 java.lang.Object[] r3 = new java.lang.Object[r0] java.lang.String r4 = r8.toString() r5 = 0 r3[r5] = r4 java.lang.String r4 = "download" java.lang.String r6 = "robot from cache : %s" com.ubtech.utils.XLog.a(r4, r6, r3) boolean r2 = r2.exists() if (r2 == 0) goto La2 com.ubt.jimu.gen.DaoSession r2 = com.ubt.jimu.base.db.DatabaseUtils.getDaoSession(r0) com.ubt.jimu.gen.RobotDao r2 = r2.s() org.greenrobot.greendao.query.QueryBuilder r2 = r2.k() org.greenrobot.greendao.Property r3 = com.ubt.jimu.gen.RobotDao.Properties.ModelName java.lang.String r6 = r8.getModelName() org.greenrobot.greendao.query.WhereCondition r3 = r3.a(r6) org.greenrobot.greendao.query.WhereCondition[] r6 = new org.greenrobot.greendao.query.WhereCondition[r5] r2.a(r3, r6) java.util.List r2 = r2.b() if (r2 == 0) goto La2 int r3 = r2.size() if (r3 <= 0) goto La2 int r3 = r2.size() if (r3 <= r0) goto L7c java.lang.String r3 = "There have more than one robot with the same modelName. Is there reinstall the app with different server" com.ubtech.utils.XLog.b(r4, r3) L7c: java.lang.Object r2 = r2.get(r5) com.ubt.jimu.base.entities.Robot r2 = (com.ubt.jimu.base.entities.Robot) r2 java.lang.Object[] r3 = new java.lang.Object[r0] java.lang.String r6 = r2.toString() r3[r5] = r6 java.lang.String r6 = "robot from db : %s" com.ubtech.utils.XLog.a(r4, r6, r3) boolean r3 = r2.getDownload() if (r3 == 0) goto La2 long r2 = r2.getModelUpdateTime() long r6 = r8.getModelUpdateTime() int r4 = (r2 > r6 ? 1 : (r2 == r6 ? 0 : -1)) if (r4 != 0) goto La2 goto La3 La2: r0 = 0 La3: if (r0 != 0) goto Laf com.ubt.jimu.base.download.DownloadInfo r0 = new com.ubt.jimu.base.download.DownloadInfo java.lang.String r8 = r8.getJarUrl() r0.(r5, r8, r1) goto Lb0 Laf: r0 = 0 Lb0: return r0 */ throw new UnsupportedOperationException("Method not decompiled: com.ubt.jimu.base.download.DownloadInfo.getNeedDownloadModelInfo(com.ubt.jimu.base.entities.Robot):com.ubt.jimu.base.download.DownloadInfo"); } public static List getNeedDownloadStory(Context context, Story story) { ArrayList arrayList = new ArrayList(); if (story != null && !TextUtils.isEmpty(story.getResourceZip())) { List fileDownloadRecordByUrl = FileDownloadRecordDbHandler.getFileDownloadRecordByUrl(story.getResourceZip(), FileDownloadRecord.Type.Star_Course.getValue()); if (fileDownloadRecordByUrl != null && fileDownloadRecordByUrl.size() != 0) { Iterator it = fileDownloadRecordByUrl.iterator(); while (true) { if (!it.hasNext()) { break; } FileDownloadRecord next = it.next(); if (next.getFileUrl().equals(story.getResourceZip()) && next.getUpdateTime() < story.getUpdateTime()) { arrayList.add(new DownloadInfo(FileDownloadRecord.Type.Star_Course.getValue(), story.getResourceZip(), Story.getSdcardSavePath(context, story.getResourceZip()))); break; } } } else { arrayList.add(new DownloadInfo(FileDownloadRecord.Type.Star_Course.getValue(), story.getResourceZip(), Story.getSdcardSavePath(context, story.getResourceZip()))); } } return arrayList; } public static List getNewDownloadPartsInfo(Robot robot) { ArrayList arrayList; String str = ExternalOverFroyoUtils.a(JimuApplication.l(), (ModelType) null) + Constants.PARTS; File file = new File(str); if (!file.exists()) { file.mkdirs(); } try { List needDownPart = getNeedDownPart(robot.getComponentsFileInfos()); arrayList = new ArrayList(); if (needDownPart != null) { try { if (needDownPart.size() > 0) { for (PartFileInfo partFileInfo : needDownPart) { if (!TextUtils.isEmpty(partFileInfo.getAndroidFilePath())) { arrayList.add(new DownloadInfo(1, partFileInfo.getAndroidFilePath(), str + partFileInfo.getName() + ".assetbundle")); } } } } catch (Exception e) { e = e; e.printStackTrace(); return arrayList; } } } catch (Exception e2) { e = e2; arrayList = null; } return arrayList; } private static boolean isInDB(PartFileInfo partFileInfo) { if (partFileInfo == null) { return true; } QueryBuilder k = DatabaseUtils.getDaoSession(true).r().k(); k.a(PartFileInfoDao.Properties.Id.a(partFileInfo.getId()), new WhereCondition[0]); PartFileInfo c = k.c(); if (c == null || c.getUpdateTime() != partFileInfo.getUpdateTime()) { return false; } ALog.a(TAG).d("零件已是最新:" + c.getName()); return true; } private static boolean isInDir(PartFileInfo partFileInfo) { if (partFileInfo == null) { return true; } if (!new File(ExternalOverFroyoUtils.a(JimuApplication.l(), (ModelType) null) + Constants.PARTS).exists()) { return false; } String str = ExternalOverFroyoUtils.a(JimuApplication.l(), (ModelType) null) + Constants.PARTS + partFileInfo.getName() + ".assetbundle"; if (!new File(str).exists()) { return false; } ALog.a(TAG).d("零件已在文件夹:" + str); return true; } public String getSavePath() { return this.savePath; } public int getType() { return this.type; } public String getUrl() { return this.url; } }