discord-jadx/app/src/main/java/c/f/b/b/a.java

430 lines
13 KiB
Java

package c.f.b.b;
import android.os.Environment;
import androidx.annotation.VisibleForTesting;
import c.f.b.b.c;
import c.f.j.c.h;
import com.airbnb.lottie.parser.AnimatableValueParser;
import com.facebook.common.file.FileUtils$CreateDirectoryException;
import com.facebook.common.file.FileUtils$ParentDirNotFoundException;
import com.facebook.common.file.FileUtils$RenameException;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
/* compiled from: DefaultDiskStorage */
public class a implements c {
public static final long a = TimeUnit.MINUTES.toMillis(30);
public static final /* synthetic */ int b = 0;
/* renamed from: c reason: collision with root package name */
public final File f356c;
public final boolean d;
public final File e;
public final c.f.b.a.a f;
public final c.f.d.k.a g;
/* compiled from: DefaultDiskStorage */
public class b implements c.f.d.c.a {
public final List<c.a> a = new ArrayList();
public b(C0058a aVar) {
}
@Override // c.f.d.c.a
public void a(File file) {
d h = a.h(a.this, file);
if (h != null && h.a == ".cnt") {
this.a.add(new c(h.b, file, null));
}
}
@Override // c.f.d.c.a
public void b(File file) {
}
@Override // c.f.d.c.a
public void c(File file) {
}
}
/* compiled from: DefaultDiskStorage */
@VisibleForTesting
public static class c implements c.a {
public final String a;
public final c.f.a.a b;
/* renamed from: c reason: collision with root package name */
public long f357c = -1;
public long d = -1;
public c(String str, File file, C0058a aVar) {
Objects.requireNonNull(str);
this.a = str;
this.b = new c.f.a.a(file);
}
@Override // c.f.b.b.c.a
public long a() {
if (this.d < 0) {
this.d = this.b.a.lastModified();
}
return this.d;
}
@Override // c.f.b.b.c.a
public String getId() {
return this.a;
}
@Override // c.f.b.b.c.a
public long getSize() {
if (this.f357c < 0) {
this.f357c = this.b.a();
}
return this.f357c;
}
}
/* compiled from: DefaultDiskStorage */
public static class d {
public final String a;
public final String b;
public d(String str, String str2) {
this.a = str;
this.b = str2;
}
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(this.a);
sb.append("(");
return c.d.b.a.a.H(sb, this.b, ")");
}
}
/* compiled from: DefaultDiskStorage */
public static class e extends IOException {
public final long actual;
public final long expected;
/* JADX WARNING: Illegal instructions before constructor call */
public e(long j, long j2) {
super(r0.toString());
StringBuilder S = c.d.b.a.a.S("File was not written completely. Expected: ", j, ", found: ");
S.append(j2);
this.expected = j;
this.actual = j2;
}
}
/* compiled from: DefaultDiskStorage */
@VisibleForTesting
public class f implements c.b {
public final String a;
@VisibleForTesting
public final File b;
public f(String str, File file) {
this.a = str;
this.b = file;
}
public boolean a() {
return !this.b.exists() || this.b.delete();
}
public c.f.a.a b(Object obj) throws IOException {
Objects.requireNonNull((c.f.d.k.c) a.this.g);
long currentTimeMillis = System.currentTimeMillis();
File j = a.this.j(this.a);
try {
AnimatableValueParser.q2(this.b, j);
if (j.exists()) {
j.setLastModified(currentTimeMillis);
}
return new c.f.a.a(j);
} catch (FileUtils$RenameException e) {
Throwable cause = e.getCause();
if (cause != null && !(cause instanceof FileUtils$ParentDirNotFoundException)) {
boolean z2 = cause instanceof FileNotFoundException;
}
c.f.b.a.a aVar = a.this.f;
int i = a.b;
Objects.requireNonNull((c.f.b.a.d) aVar);
throw e;
}
}
/* JADX INFO: finally extract failed */
public void c(c.f.b.a.g gVar, Object obj) throws IOException {
try {
FileOutputStream fileOutputStream = new FileOutputStream(this.b);
try {
c.f.d.d.b bVar = new c.f.d.d.b(fileOutputStream);
h hVar = (h) gVar;
hVar.b.f434c.a(hVar.a.e(), bVar);
bVar.flush();
long j = bVar.i;
fileOutputStream.close();
if (this.b.length() != j) {
throw new e(j, this.b.length());
}
} catch (Throwable th) {
fileOutputStream.close();
throw th;
}
} catch (FileNotFoundException e) {
c.f.b.a.a aVar = a.this.f;
int i = a.b;
Objects.requireNonNull((c.f.b.a.d) aVar);
throw e;
}
}
}
/* compiled from: DefaultDiskStorage */
public class g implements c.f.d.c.a {
public boolean a;
public g(C0058a aVar) {
}
/* JADX WARNING: Code restructure failed: missing block: B:7:0x002b, code lost:
if (r3 > (java.lang.System.currentTimeMillis() - c.f.b.b.a.a)) goto L_0x0036;
*/
@Override // c.f.d.c.a
public void a(File file) {
if (this.a) {
d h = a.h(a.this, file);
boolean z2 = false;
if (h != null) {
String str = h.a;
if (str == ".tmp") {
long lastModified = file.lastModified();
Objects.requireNonNull((c.f.d.k.c) a.this.g);
} else {
if (str == ".cnt") {
z2 = true;
}
AnimatableValueParser.B(z2);
}
z2 = true;
}
if (z2) {
return;
}
}
file.delete();
}
@Override // c.f.d.c.a
public void b(File file) {
if (!this.a && file.equals(a.this.e)) {
this.a = true;
}
}
@Override // c.f.d.c.a
public void c(File file) {
if (!a.this.f356c.equals(file) && !this.a) {
file.delete();
}
if (this.a && file.equals(a.this.e)) {
this.a = false;
}
}
}
/* JADX WARNING: Removed duplicated region for block: B:14:0x005b */
/* JADX WARNING: Removed duplicated region for block: B:19:0x0069 A[SYNTHETIC, Splitter:B:19:0x0069] */
public a(File file, int i, c.f.b.a.a aVar) {
boolean z2;
this.f356c = file;
boolean z3 = false;
try {
File externalStorageDirectory = Environment.getExternalStorageDirectory();
if (externalStorageDirectory != null) {
try {
z2 = file.getCanonicalPath().contains(externalStorageDirectory.toString());
} catch (IOException unused) {
Objects.requireNonNull((c.f.b.a.d) aVar);
}
this.d = z2;
File file2 = new File(this.f356c, String.format(null, "%s.ols%d.%d", "v2", 100, Integer.valueOf(i)));
this.e = file2;
this.f = aVar;
if (this.f356c.exists()) {
if (!file2.exists()) {
AnimatableValueParser.b0(this.f356c);
}
if (z3) {
try {
AnimatableValueParser.N1(file2);
} catch (FileUtils$CreateDirectoryException unused2) {
c.f.b.a.a aVar2 = this.f;
StringBuilder P = c.d.b.a.a.P("version directory could not be created: ");
P.append(this.e);
P.toString();
Objects.requireNonNull((c.f.b.a.d) aVar2);
}
}
this.g = c.f.d.k.c.a;
}
z3 = true;
if (z3) {
}
this.g = c.f.d.k.c.a;
}
} catch (Exception unused3) {
Objects.requireNonNull((c.f.b.a.d) aVar);
}
z2 = false;
this.d = z2;
File file2 = new File(this.f356c, String.format(null, "%s.ols%d.%d", "v2", 100, Integer.valueOf(i)));
this.e = file2;
this.f = aVar;
if (this.f356c.exists()) {
}
z3 = true;
if (z3) {
}
this.g = c.f.d.k.c.a;
}
public static d h(a aVar, File file) {
d dVar;
Objects.requireNonNull(aVar);
String name = file.getName();
int lastIndexOf = name.lastIndexOf(46);
if (lastIndexOf > 0) {
String substring = name.substring(lastIndexOf);
String str = ".cnt";
if (!str.equals(substring)) {
str = ".tmp".equals(substring) ? ".tmp" : null;
}
if (str != null) {
String substring2 = name.substring(0, lastIndexOf);
if (str.equals(".tmp")) {
int lastIndexOf2 = substring2.lastIndexOf(46);
if (lastIndexOf2 > 0) {
substring2 = substring2.substring(0, lastIndexOf2);
}
}
dVar = new d(str, substring2);
if (dVar == null && new File(aVar.k(dVar.b)).equals(file.getParentFile())) {
return dVar;
}
return null;
}
}
dVar = null;
if (dVar == null) {
return null;
}
return dVar;
}
@Override // c.f.b.b.c
public void a() {
AnimatableValueParser.Q2(this.f356c, new g(null));
}
@Override // c.f.b.b.c
public c.b b(String str, Object obj) throws IOException {
File file = new File(k(str));
if (!file.exists()) {
try {
AnimatableValueParser.N1(file);
} catch (FileUtils$CreateDirectoryException e2) {
Objects.requireNonNull((c.f.b.a.d) this.f);
throw e2;
}
}
try {
return new f(str, File.createTempFile(str + ".", ".tmp", file));
} catch (IOException e3) {
Objects.requireNonNull((c.f.b.a.d) this.f);
throw e3;
}
}
@Override // c.f.b.b.c
public boolean c(String str, Object obj) {
File j = j(str);
boolean exists = j.exists();
if (exists) {
Objects.requireNonNull((c.f.d.k.c) this.g);
j.setLastModified(System.currentTimeMillis());
}
return exists;
}
@Override // c.f.b.b.c
public c.f.a.a d(String str, Object obj) {
File j = j(str);
if (!j.exists()) {
return null;
}
Objects.requireNonNull((c.f.d.k.c) this.g);
j.setLastModified(System.currentTimeMillis());
return new c.f.a.a(j);
}
@Override // c.f.b.b.c
public Collection e() throws IOException {
b bVar = new b(null);
AnimatableValueParser.Q2(this.e, bVar);
return Collections.unmodifiableList(bVar.a);
}
@Override // c.f.b.b.c
public long f(String str) {
return i(j(str));
}
@Override // c.f.b.b.c
public long g(c.a aVar) {
return i(((c) aVar).b.a);
}
public final long i(File file) {
if (!file.exists()) {
return 0;
}
long length = file.length();
if (file.delete()) {
return length;
}
return -1;
}
@Override // c.f.b.b.c
public boolean isExternal() {
return this.d;
}
@VisibleForTesting
public File j(String str) {
StringBuilder P = c.d.b.a.a.P(k(str));
P.append(File.separator);
P.append(str);
P.append(".cnt");
return new File(P.toString());
}
public final String k(String str) {
String valueOf = String.valueOf(Math.abs(str.hashCode() % 100));
StringBuilder sb = new StringBuilder();
sb.append(this.e);
return c.d.b.a.a.H(sb, File.separator, valueOf);
}
}