Merge pull request #437 from zod/fixes

Minor fixes to DownloadWorker and setup
This commit is contained in:
afischerdev 2022-05-30 13:52:37 +02:00 committed by GitHub
commit c67374a268
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 7 deletions

View file

@ -181,18 +181,23 @@ public class BInstallerActivity extends AppCompatActivity {
String result; String result;
switch (workInfo.getState()) { switch (workInfo.getState()) {
case FAILED: case FAILED:
result = "failed."; result = "Download failed";
break; break;
case CANCELLED: case CANCELLED:
result = "cancelled"; result = "Download cancelled";
break; break;
case SUCCEEDED: case SUCCEEDED:
result = "succeeded"; result = "Download succeeded";
break; break;
default: default:
result = ""; result = "";
} }
Toast.makeText(this, "Download " + result + ".", Toast.LENGTH_SHORT).show(); if (workInfo.getState() != WorkInfo.State.FAILED) {
Toast.makeText(this, result, Toast.LENGTH_SHORT).show();
} else {
String error = workInfo.getOutputData().getString(DownloadWorker.KEY_OUTPUT_ERROR);
Toast.makeText(this, result + ": " + error, Toast.LENGTH_LONG).show();
}
mProgressIndicator.hide(); mProgressIndicator.hide();
scanExistingFiles(); scanExistingFiles();
} }

View file

@ -603,6 +603,9 @@ public class BRouterView extends View {
ZipEntry ze = zis.getNextEntry(); ZipEntry ze = zis.getNextEntry();
if (ze == null) if (ze == null)
break; break;
if (ze.isDirectory()) {
continue;
}
String name = ze.getName(); String name = ze.getName();
File outfile = new File(path, name); File outfile = new File(path, name);
if (!outfile.exists()) { if (!outfile.exists()) {

View file

@ -32,6 +32,7 @@ import btools.util.ProgressListener;
public class DownloadWorker extends Worker { public class DownloadWorker extends Worker {
public static final String KEY_INPUT_SEGMENT_NAMES = "SEGMENT_NAMES"; public static final String KEY_INPUT_SEGMENT_NAMES = "SEGMENT_NAMES";
public static final String KEY_OUTPUT_ERROR = "ERROR";
public static final String PROGRESS_SEGMENT_NAME = "PROGRESS_SEGMENT_NAME"; public static final String PROGRESS_SEGMENT_NAME = "PROGRESS_SEGMENT_NAME";
public static final String PROGRESS_SEGMENT_PERCENT = "PROGRESS_SEGMENT_PERCENT"; public static final String PROGRESS_SEGMENT_PERCENT = "PROGRESS_SEGMENT_PERCENT";
@ -128,6 +129,7 @@ public class DownloadWorker extends Worker {
@Override @Override
public Result doWork() { public Result doWork() {
Data inputData = getInputData(); Data inputData = getInputData();
Data.Builder output = new Data.Builder();
String[] segmentNames = inputData.getStringArray(KEY_INPUT_SEGMENT_NAMES); String[] segmentNames = inputData.getStringArray(KEY_INPUT_SEGMENT_NAMES);
if (segmentNames == null) { if (segmentNames == null) {
if (DEBUG) Log.d(LOG_TAG, "Failure: no segmentNames"); if (DEBUG) Log.d(LOG_TAG, "Failure: no segmentNames");
@ -147,10 +149,12 @@ public class DownloadWorker extends Worker {
} }
} catch (IOException e) { } catch (IOException e) {
Log.w(LOG_TAG, e); Log.w(LOG_TAG, e);
return Result.failure(); output.putString(KEY_OUTPUT_ERROR, e.toString());
return Result.failure(output.build());
} catch (InterruptedException e) { } catch (InterruptedException e) {
Log.w(LOG_TAG, e); Log.w(LOG_TAG, e);
return Result.failure(); output.putString(KEY_OUTPUT_ERROR, e.toString());
return Result.failure(output.build());
} }
if (DEBUG) Log.d(LOG_TAG, "doWork finished"); if (DEBUG) Log.d(LOG_TAG, "doWork finished");
return Result.success(); return Result.success();
@ -242,7 +246,7 @@ public class DownloadWorker extends Worker {
connection.connect(); connection.connect();
if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) { if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
throw new IOException("HTTP Request failed"); throw new IOException("HTTP Request failed: " + downloadUrl + " returned " + connection.getResponseCode());
} }
int fileLength = connection.getContentLength(); int fileLength = connection.getContentLength();
try ( try (