Java Code Examples for com.tencent.tinker.loader.shareutil.SharePatchFileUtil#getMD5()

The following examples show how to use com.tencent.tinker.loader.shareutil.SharePatchFileUtil#getMD5() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultPatchRequestCallback.java    From tinkerpatch-sdk with MIT License 6 votes vote down vote up
private void tryPatchFile(File patchFile, Integer newVersion) {
    TinkerServerClient client = TinkerServerClient.get();
    Context context = client.getContext();
    //In order to calculate the user number, just report success here
    String patchMd5 = SharePatchFileUtil.getMD5(patchFile);
    //update version
    client.updateTinkerVersion(newVersion, patchMd5);
    //delete old patch sever file
    File serverDir = ServerUtils.getServerDirectory(context);
    if (serverDir != null) {
        File[] files = serverDir.listFiles();
        if (files != null) {
            String currentName = patchFile.getName();
            for (File file : files) {
                String fileName = file.getName();
                if (fileName.equals(currentName) || fileName.equals(ServerUtils.TINKER_VERSION_FILE)) {
                    continue;
                }
                SharePatchFileUtil.safeDeleteFile(file);
            }
        }
        client.reportPatchApplySuccess(newVersion);
        //try install
        TinkerInstaller.onReceiveUpgradePatch(context, patchFile.getAbsolutePath());
    }
}
 
Example 2
Source File: TinkerServerPatchListener.java    From tinkerpatch-sdk with MIT License 5 votes vote down vote up
/**
 * because we use the defaultCheckPatchReceived method
 * the error code define by myself should after {@code ShareConstants.ERROR_RECOVER_INSERVICE
 *
 * @param path
 * @param newPatch
 * @return
 */
@Override
public int patchCheck(String path) {
    File patchFile = new File(path);
    TinkerLog.i(TAG, "receive a patch file: %s, file size:%d",
        path, SharePatchFileUtil.getFileOrDirectorySize(patchFile)
    );
    int returnCode = super.patchCheck(path);

    //把这个添加到你的PatchListener实现中
    String patchMd5 = SharePatchFileUtil.getMD5(patchFile);
    TinkerServerManager.reportTinkerPatchListenerFail(returnCode, patchMd5);
    return returnCode;
}
 
Example 3
Source File: TinkerServerManager.java    From tinkerpatch-sdk with MIT License 5 votes vote down vote up
/**
 * 上报补丁合成情况
 * @param patchResult
 */
public static void reportTinkerPatchFail(PatchResult patchResult) {
    if (sTinkerServerClient == null) {
        TinkerLog.e(TAG, "reportTinkerPatchFail, sTinkerServerClient == null");
        return;
    }
    if (patchResult == null) {
        TinkerLog.e(TAG, "reportTinkerPatchFail, patchResult == null");
        return;
    }

    if (patchResult.isSuccess) {
        TinkerLog.i(TAG, "reportTinkerPatchFail, patch success, just return");
        return;
    }
    String patchMd5 = (patchResult.patchVersion != null)
        ? patchResult.patchVersion : SharePatchFileUtil.getMD5(new File(patchResult.rawPatchFilePath));

    if (!patchMd5.equals(sTinkerServerClient.getCurrentPatchMd5())) {
        TinkerLog.e(TAG, "reportTinkerPatchFail, md5 not equal, patchMd5:%s, currentPatchMd5:%s",
            patchMd5, sTinkerServerClient.getCurrentPatchMd5()
        );
        return;
    }
    sTinkerServerClient.reportPatchFail(
        sTinkerServerClient.getCurrentPatchVersion(),
        DefaultPatchRequestCallback.ERROR_PATCH_FAIL
    );
}