discord-jadx/app/src/main/java/co/discord/media_engine/internal/AssetManagement.java

85 lines
2.9 KiB
Java

package co.discord.media_engine.internal;
import android.content.Context;
import android.content.res.AssetManager;
import android.util.Log;
import c.d.b.a.a;
import com.hammerandchisel.libdiscord.R;
import d0.y.h;
import d0.z.d.m;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
/* compiled from: AssetManagement.kt */
public final class AssetManagement {
private final Context ctx;
public AssetManagement(Context context) {
m.checkNotNullParameter(context, "ctx");
this.ctx = context;
}
private final void cleanup() {
try {
File file = new File(this.ctx.getFilesDir(), "thz");
if (file.exists()) {
h.deleteRecursively(file);
}
} catch (Exception e) {
StringBuilder K = a.K("Failed removing krisp model files: ");
K.append(e.getMessage());
K.append(": ");
K.append(e.toString());
Log.e("DiscordKrisp", K.toString());
}
}
private final void copy(File file, String str) {
AssetManager assets = this.ctx.getAssets();
InputStream open = assets.open("thz/" + str);
m.checkNotNullExpressionValue(open, "ctx.assets.open(\"thz/\" + name)");
FileOutputStream fileOutputStream = new FileOutputStream(new File(file, str));
d0.y.a.copyTo(open, fileOutputStream, 1024);
open.close();
fileOutputStream.close();
}
public final void ensureKrispModelsCopied(boolean z2) {
if (z2) {
try {
File file = new File(this.ctx.getFilesDir(), "thz");
String string = this.ctx.getString(R.string.krisp_model_version);
m.checkNotNullExpressionValue(string, "ctx.getString(R.string.krisp_model_version)");
if (!new File(file, string).exists()) {
cleanup();
File file2 = new File(this.ctx.getFilesDir(), "thz");
file2.mkdir();
File file3 = new File(file2, string);
file3.mkdir();
String[] list = this.ctx.getAssets().list("thz");
if (list == null) {
list = new String[0];
}
for (String str : list) {
m.checkNotNullExpressionValue(str, "file");
copy(file3, str);
}
}
} catch (Exception e) {
StringBuilder K = a.K("Failed copying krisp model files: ");
K.append(e.getMessage());
K.append(": ");
K.append(e.toString());
Log.e("DiscordKrisp", K.toString());
cleanup();
}
} else {
cleanup();
}
}
public final Context getCtx() {
return this.ctx;
}
}