Fix file bug

pull/301/head
FongMi 2 years ago
parent 08b81a89ac
commit 7ac3f2bba4
  1. 4
      app/src/main/java/com/fongmi/android/tv/utils/Download.java
  2. 14
      catvod/src/main/java/com/github/catvod/utils/Path.java

@ -40,10 +40,10 @@ public class Download {
private void doInBackground() {
try {
Path.clear(file);
Path.create(file);
Response response = OkHttp.newCall(url).execute();
download(response.body().byteStream(), Double.parseDouble(response.header(HttpHeaders.CONTENT_LENGTH, "1")));
if (callback != null) App.post(() -> callback.success(Path.chmod(file)));
if (callback != null) App.post(() -> callback.success(file));
} catch (Exception e) {
if (callback != null) App.post(() -> callback.error(e.getMessage()));
}

@ -148,7 +148,6 @@ public class Path {
fos.write(data);
fos.flush();
fos.close();
chmod(file);
return file;
} catch (Exception ignored) {
ignored.printStackTrace();
@ -176,7 +175,6 @@ public class Path {
while ((read = in.read(buffer)) != -1) fos.write(buffer, 0, read);
fos.close();
in.close();
chmod(out);
} catch (Exception ignored) {
}
}
@ -192,20 +190,20 @@ public class Path {
if (dir.delete()) Log.d(TAG, "Deleted:" + dir.getAbsolutePath());
}
public static File chmod(File file) {
public static File create(File file) throws Exception {
try {
Shell.exec("chmod 777 " + file);
return file;
if (!file.exists()) file.createNewFile();
if (!file.canWrite()) file.setWritable(true);
return chmod(file);
} catch (Exception e) {
e.printStackTrace();
return file;
}
}
public static File create(File file) throws Exception {
public static File chmod(File file) {
try {
if (!file.exists()) file.createNewFile();
if (!file.canWrite()) file.setWritable(true);
Shell.exec("chmod 777 " + file);
return file;
} catch (Exception e) {
e.printStackTrace();

Loading…
Cancel
Save