Пример #1
0
  public void saveAppDiff(AppDiff entity) {

    if (StringUtils.isEmpty(entity.getId())) {
      initEntity(entity);
    }

    // save apk
    if (entity.getDiffAttachment() != null
        && StringUtils.isNotEmpty(entity.getDiffAttachment().getFileName())) {
      try {
        String distPath =
            "/attachment/content/" + new SimpleDateFormat("yyyy/MM").format(new Date());
        File distFile = new File(explodedPath + distPath);
        if (!distFile.exists()) {
          FileUtils.forceMkdir(distFile);
        }
        entity.setDiff(
            distPath
                + "/"
                + entity.getDiffAttachment().getTempFileName()
                + "."
                + FilenameUtils.getExtension(entity.getDiffAttachment().getFileName()));
        entity.setDiffFilename(entity.getDiffAttachment().getFileName());
        FileUtils.copyFile(
            new File(tempPath + "/" + entity.getDiffAttachment().getTempFileName()),
            new File(explodedPath + entity.getDiff()));
      } catch (IOException e) {
        e.printStackTrace();
      }
    }

    appDiffDao.save(entity);
  }
Пример #2
0
  public JSONObject checkUpdate(String clientVersionName) {

    // 服务器上 app 最新版本号
    String currentVersionName = getCurrentVersionName();

    // 若客户端已经是最新版本,则不需要更新
    if (currentVersionName.equals(clientVersionName)) {
      JSONObject result = new JSONObject();
      result.put("needUpdate", false);
      return result;
    }

    // 获取对应的差分包地址
    AppDiff appDiff =
        appDiffDao.findOneByVersionNameAndClientVersionNameAndDeleteFlag(
            currentVersionName, clientVersionName, 0);
    JSONObject result = new JSONObject();
    result.put("needUpdate", true);
    result.put("diff", appDiff.getDiff());

    String apkPath = explodedPath + File.separator + "app.apk";
    File apk = new File(apkPath);
    String md5Sign = MD5Utils.getMd5ByFile(apk);
    result.put("md5Sign", md5Sign);

    return result;
  }
Пример #3
0
 public void deleteAppDiff(String id) {
   AppDiff appDiff = getAppDiff(id);
   appDiff.setDeleteFlag(1);
   appDiffDao.save(appDiff);
 }