package com.google.android.play.core.assetpacks;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes3.dex */
public final class p2 {

    /* renamed from: c, reason: collision with root package name */
    private static final rj.h0 f14033c = new rj.h0("PackMetadataManager");

    /* renamed from: a, reason: collision with root package name */
    private final e0 f14034a;

    /* renamed from: b, reason: collision with root package name */
    private final r2 f14035b;

    /* JADX INFO: Access modifiers changed from: package-private */
    public p2(e0 e0Var, r2 r2Var) {
        this.f14034a = e0Var;
        this.f14035b = r2Var;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public final String a(String str) {
        if (!this.f14034a.f(str)) {
            return "";
        }
        r2 r2Var = this.f14035b;
        e0 e0Var = this.f14034a;
        int a10 = r2Var.a();
        File w10 = e0Var.w(str, a10, e0Var.q(str));
        try {
            if (!w10.exists()) {
                return String.valueOf(a10);
            }
            FileInputStream fileInputStream = new FileInputStream(w10);
            try {
                Properties properties = new Properties();
                properties.load(fileInputStream);
                fileInputStream.close();
                String property = properties.getProperty("moduleVersionTag");
                return property == null ? String.valueOf(a10) : property;
            } finally {
            }
        } catch (IOException unused) {
            f14033c.b("Failed to read pack version tag for pack %s", str);
            return "";
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public final void b(String str, int i10, long j10, String str2) {
        if (str2 == null || str2.isEmpty()) {
            str2 = String.valueOf(i10);
        }
        Properties properties = new Properties();
        properties.put("moduleVersionTag", str2);
        File w10 = this.f14034a.w(str, i10, j10);
        w10.getParentFile().mkdirs();
        w10.createNewFile();
        FileOutputStream fileOutputStream = new FileOutputStream(w10);
        try {
            properties.store(fileOutputStream, (String) null);
            fileOutputStream.close();
        } catch (Throwable th2) {
            try {
                fileOutputStream.close();
            } catch (Throwable th3) {
                th2.addSuppressed(th3);
            }
            throw th2;
        }
    }
}
