-Download upload status error refactoring
This commit is contained in:
tonikelope 2019-10-05 19:10:23 +02:00
parent 5fd982bc6c
commit 86f310401d
6 changed files with 89 additions and 91 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.tonikelope</groupId>
<artifactId>MegaBasterd</artifactId>
<version>6.56</version>
<version>6.57</version>
<packaging>jar</packaging>
<dependencies>
<dependency>

View File

@ -90,8 +90,7 @@ public class Download implements Transference, Runnable, SecureSingleThreadNotif
private boolean _retrying_request;
private Double _progress_bar_rate;
private OutputStream _output_stream;
private String _status_error_message;
private boolean _status_error;
private String _status_error;
private final ConcurrentLinkedQueue<Long> _rejectedChunkIds;
private long _last_chunk_id_dispatched;
private final MegaAPI _ma;
@ -104,9 +103,8 @@ public class Download implements Transference, Runnable, SecureSingleThreadNotif
_ma = ma;
_frozen = main_panel.isInit_paused();
_last_chunk_id_dispatched = 0L;
_status_error = false;
_canceled = false;
_status_error_message = null;
_status_error = null;
_retrying_request = false;
_checking_cbc = false;
_finishing_download = false;
@ -147,9 +145,8 @@ public class Download implements Transference, Runnable, SecureSingleThreadNotif
_paused_workers = 0;
_ma = download.getMa();
_last_chunk_id_dispatched = 0L;
_status_error = false;
_canceled = false;
_status_error_message = null;
_status_error = null;
_retrying_request = false;
_checking_cbc = false;
_finishing_download = false;
@ -750,16 +747,14 @@ public class Download implements Transference, Runnable, SecureSingleThreadNotif
} else if (!_exit) {
getView().printStatusError("BAD NEWS :( File is DAMAGED!");
_status_error = "BAD NEWS :( File is DAMAGED!";
_status_error = true;
getView().printStatusError(_status_error);
} else {
getView().printStatusOK("File successfully downloaded! (but integrity check CANCELED)");
_status_error = true;
}
swingInvoke(
@ -777,11 +772,11 @@ public class Download implements Transference, Runnable, SecureSingleThreadNotif
}
} else if (_status_error) {
} else if (_status_error != null) {
getView().hideAllExceptStatus();
getView().printStatusError(_status_error_message != null ? _status_error_message : "ERROR");
getView().printStatusError(_status_error);
} else {
@ -792,11 +787,11 @@ public class Download implements Transference, Runnable, SecureSingleThreadNotif
getView().printStatusNormal("Download CANCELED!");
}
} else if (_status_error) {
} else if (_status_error != null) {
getView().hideAllExceptStatus();
getView().printStatusError(_status_error_message != null ? _status_error_message : "ERROR");
getView().printStatusError(_status_error != null ? _status_error : "ERROR");
} else {
@ -807,11 +802,11 @@ public class Download implements Transference, Runnable, SecureSingleThreadNotif
getView().printStatusNormal("Download CANCELED!");
}
} else if (_status_error) {
} else if (_status_error != null) {
getView().hideAllExceptStatus();
getView().printStatusError(_status_error_message != null ? _status_error_message : "ERROR");
getView().printStatusError(_status_error);
} else {
@ -821,11 +816,11 @@ public class Download implements Transference, Runnable, SecureSingleThreadNotif
}
} else if (_status_error) {
} else if (_status_error != null) {
getView().hideAllExceptStatus();
getView().printStatusError(_status_error_message != null ? _status_error_message : "ERROR");
getView().printStatusError(_status_error);
} else {
@ -838,9 +833,9 @@ public class Download implements Transference, Runnable, SecureSingleThreadNotif
} catch (IOException ex) {
getView().printStatusError("I/O ERROR " + ex.getMessage());
_status_error = "I/O ERROR " + ex.getMessage();
_status_error = true;
getView().printStatusError(_status_error);
LOG.log(Level.SEVERE, ex.getMessage());
@ -869,7 +864,7 @@ public class Download implements Transference, Runnable, SecureSingleThreadNotif
}
}
if (!_status_error) {
if (_status_error == null) {
try {
deleteDownload(_url);
@ -903,7 +898,7 @@ public class Download implements Transference, Runnable, SecureSingleThreadNotif
getView().getClose_button().setVisible(true);
if (_status_error || _canceled) {
if (_status_error != null || _canceled) {
getView().getRestart_button().setVisible(true);
@ -965,7 +960,7 @@ public class Download implements Transference, Runnable, SecureSingleThreadNotif
LOG.log(SEVERE, null, ex);
_status_error_message = "Error registering download: file is already downloading.";
_status_error = "Error registering download: file is already downloading.";
}
}
@ -980,7 +975,7 @@ public class Download implements Transference, Runnable, SecureSingleThreadNotif
} catch (SQLException ex) {
_status_error_message = "Error registering download: file is already downloading.";
_status_error = "Error registering download: file is already downloading.";
}
} else {
@ -993,12 +988,12 @@ public class Download implements Transference, Runnable, SecureSingleThreadNotif
} catch (NumberFormatException ex) {
_status_error_message = ex.getMessage();
_status_error = ex.getMessage();
}
if (!_provision_ok) {
_status_error = true;
_status_error = "PROVISION FAILED";
if (_file_name != null) {
swingInvoke(
@ -1021,12 +1016,7 @@ public class Download implements Transference, Runnable, SecureSingleThreadNotif
getView().hideAllExceptStatus();
if (_status_error_message == null) {
_status_error_message = "PROVISION FAILED";
}
getView().printStatusError(_status_error_message);
getView().printStatusError(_status_error);
swingInvoke(
new Runnable() {
@ -1413,9 +1403,7 @@ public class Download implements Transference, Runnable, SecureSingleThreadNotif
public void stopDownloader(String reason) {
_status_error = true;
_status_error_message = (reason != null ? LabelTranslatorSingleton.getInstance().translate("FATAL ERROR! ") + reason : LabelTranslatorSingleton.getInstance().translate("FATAL ERROR! "));
_status_error = (reason != null ? LabelTranslatorSingleton.getInstance().translate("FATAL ERROR! ") + reason : LabelTranslatorSingleton.getInstance().translate("FATAL ERROR! "));
stopDownloader();
}
@ -1461,7 +1449,7 @@ public class Download implements Transference, Runnable, SecureSingleThreadNotif
error = true;
_status_error = true;
_status_error = ex.getMessage();
error_code = ex.getCode();
@ -1631,10 +1619,6 @@ public class Download implements Transference, Runnable, SecureSingleThreadNotif
}
public void setStatus_error(boolean status_error) {
_status_error = status_error;
}
public void rejectChunkId(long chunk_id) {
_rejectedChunkIds.add(chunk_id);
}
@ -1694,7 +1678,7 @@ public class Download implements Transference, Runnable, SecureSingleThreadNotif
@Override
public boolean isStatusError() {
return _status_error;
return _status_error != null;
}
@Override

View File

@ -53,7 +53,7 @@ import javax.swing.UIManager;
*/
public class MainPanel {
public static final String VERSION = "6.56";
public static final String VERSION = "6.57";
public static final int THROTTLE_SLICE_SIZE = 16 * 1024;
public static final int DEFAULT_BYTE_BUFFER_SIZE = 16 * 1024;
public static final int STREAMER_PORT = 1337;

View File

@ -31,7 +31,7 @@ public class MegaAPI implements Serializable {
public static final String API_URL = "https://g.api.mega.co.nz";
public static final String API_KEY = null;
public static final int REQ_ID_LENGTH = 10;
public static final Integer[] MEGA_ERROR_EXCEPTION_CODES = {-2, -5, -6, -8, -9, -10, -11, -12, -13, -14, -15, -16, -26};
public static final Integer[] MEGA_ERROR_EXCEPTION_CODES = {-2, -5, -6, -8, -9, -10, -11, -12, -13, -14, -15, -16, -17, -26};
public static final int PBKDF2_ITERATIONS = 100000;
public static final int PBKDF2_OUTPUT_BIT_LENGTH = 256;
private static final Logger LOG = Logger.getLogger(MegaAPI.class.getName());
@ -639,7 +639,7 @@ public class MegaAPI implements Serializable {
return res_map;
}
public String initUploadFile(String filename) {
public String initUploadFile(String filename) throws MegaAPIException {
String ul_url = null;
@ -659,6 +659,10 @@ public class MegaAPI implements Serializable {
ul_url = (String) res_map[0].get("p");
} catch (MegaAPIException mae) {
throw mae;
} catch (Exception ex) {
LOG.log(Level.SEVERE, ex.getMessage());
}
@ -666,7 +670,7 @@ public class MegaAPI implements Serializable {
return ul_url;
}
public HashMap<String, Object> finishUploadFile(String fbasename, int[] ul_key, int[] fkey, int[] meta_mac, String completion_handle, String mega_parent, byte[] master_key, String root_node, byte[] share_key) {
public HashMap<String, Object> finishUploadFile(String fbasename, int[] ul_key, int[] fkey, int[] meta_mac, String completion_handle, String mega_parent, byte[] master_key, String root_node, byte[] share_key) throws MegaAPIException {
HashMap[] res_map = null;
@ -684,6 +688,10 @@ public class MegaAPI implements Serializable {
res_map = objectMapper.readValue(res, HashMap[].class);
} catch (MegaAPIException mae) {
throw mae;
} catch (Exception ex) {
LOG.log(Level.SEVERE, ex.getMessage());
}

View File

@ -33,7 +33,7 @@ public class Upload implements Transference, Runnable, SecureSingleThreadNotifia
private volatile UploadView _view;
private volatile ProgressMeter _progress_meter;
private final Object _progress_lock;
private String _status_error_message;
private String _status_error;
private volatile boolean _exit;
private volatile boolean _frozen;
private int _slots;
@ -60,7 +60,7 @@ public class Upload implements Transference, Runnable, SecureSingleThreadNotifia
private UploadMACGenerator _mac_generator;
private boolean _create_dir;
private boolean _provision_ok;
private boolean _status_error;
private boolean _fatal_error;
private String _file_link;
private final MegaAPI _ma;
private final String _file_name;
@ -80,7 +80,8 @@ public class Upload implements Transference, Runnable, SecureSingleThreadNotifia
_notified = false;
_frozen = main_panel.isInit_paused();
_provision_ok = true;
_status_error = false;
_status_error = null;
_fatal_error = false;
_canceled = false;
_closed = false;
_main_panel = main_panel;
@ -114,7 +115,8 @@ public class Upload implements Transference, Runnable, SecureSingleThreadNotifia
_notified = false;
_provision_ok = true;
_status_error = false;
_status_error = null;
_fatal_error = false;
_canceled = false;
_closed = false;
_restart = true;
@ -242,10 +244,6 @@ public class Upload implements Transference, Runnable, SecureSingleThreadNotifia
return _provision_ok;
}
public boolean isStatus_error() {
return _status_error;
}
public String getFile_link() {
return _file_link;
}
@ -365,7 +363,7 @@ public class Upload implements Transference, Runnable, SecureSingleThreadNotifia
if (!the_file.exists()) {
_status_error_message = "ERROR: FILE NOT FOUND";
_status_error = "ERROR: FILE NOT FOUND";
} else {
@ -403,7 +401,7 @@ public class Upload implements Transference, Runnable, SecureSingleThreadNotifia
if (!_provision_ok) {
_status_error = true;
_status_error = "PROVISION FAILED";
if (_file_name != null) {
swingInvoke(
@ -428,12 +426,7 @@ public class Upload implements Transference, Runnable, SecureSingleThreadNotifia
getView().hideAllExceptStatus();
if (_status_error_message == null) {
_status_error_message = "PROVISION FAILED";
}
getView().printStatusError(_status_error_message);
getView().printStatusError(_status_error);
swingInvoke(
new Runnable() {
@ -700,7 +693,13 @@ public class Upload implements Transference, Runnable, SecureSingleThreadNotifia
int conta_error = 0;
do {
_ul_url = _ma.initUploadFile(_file_name);
try {
_ul_url = _ma.initUploadFile(_file_name);
} catch (MegaAPIException ex) {
Logger.getLogger(Upload.class.getName()).log(Level.SEVERE, ex.getMessage());
stopUploader(ex.getMessage());
_fatal_error = true;
}
if (_ul_url == null && !_exit) {
@ -866,7 +865,7 @@ public class Upload implements Transference, Runnable, SecureSingleThreadNotifia
File f = new File(_file_name);
HashMap<String, Object> upload_res;
HashMap<String, Object> upload_res = null;
int[] ul_key = _ul_key;
@ -875,7 +874,13 @@ public class Upload implements Transference, Runnable, SecureSingleThreadNotifia
int conta_error = 0;
do {
upload_res = _ma.finishUploadFile(f.getName(), ul_key, node_key, _file_meta_mac, _completion_handler, _parent_node, i32a2bin(_ma.getMaster_key()), _root_node, _share_key);
try {
upload_res = _ma.finishUploadFile(f.getName(), ul_key, node_key, _file_meta_mac, _completion_handler, _parent_node, i32a2bin(_ma.getMaster_key()), _root_node, _share_key);
} catch (MegaAPIException ex) {
Logger.getLogger(Upload.class.getName()).log(Level.SEVERE, ex.getMessage());
stopUploader(ex.getMessage());
_fatal_error = true;
}
if (upload_res == null && !_exit) {
@ -936,15 +941,21 @@ public class Upload implements Transference, Runnable, SecureSingleThreadNotifia
}
}
} else if (_status_error != null) {
getView().hideAllExceptStatus();
getView().printStatusError(_status_error);
}
} else {
_status_error = "UPLOAD FAILED! (Empty completion handle!)";
getView().hideAllExceptStatus();
getView().printStatusError(_status_error_message != null ? _status_error_message : "UPLOAD FAILED! (Empty completion handle!)");
getView().printStatusError(_status_error);
_status_error = true;
}
} else {
@ -956,6 +967,12 @@ public class Upload implements Transference, Runnable, SecureSingleThreadNotifia
getView().printStatusNormal("Upload CANCELED!");
}
} else if (_status_error != null) {
getView().hideAllExceptStatus();
getView().printStatusError(_status_error);
} else {
_canceled = true;
@ -974,7 +991,7 @@ public class Upload implements Transference, Runnable, SecureSingleThreadNotifia
getView().printStatusNormal("Upload CANCELED!");
}
if (!_status_error || _main_panel.isExit()) {
if (_status_error == null || _main_panel.isExit()) {
try {
DBTools.deleteUpload(_file_name, _ma.getFull_email());
@ -1008,30 +1025,24 @@ public class Upload implements Transference, Runnable, SecureSingleThreadNotifia
getView().getClose_button().setVisible(true);
if (!_status_error && !_canceled) {
if (_status_error == null && !_canceled) {
getView().getClose_button().setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icons8-ok-30.png")));
}
if (_canceled) {
if (_canceled || _status_error == null) {
getView().getRestart_button().setVisible(true);
}
if (_status_error) {
getView().getRestart_button().setEnabled(false);
}
}
});
THREAD_POOL.execute(
new Runnable() {
@Override
public void run() {
if (_status_error) {
if (_status_error != null && !_fatal_error) {
THREAD_POOL.execute(
new Runnable() {
@Override
public void run() {
for (int i = 3; !_closed && i > 0; i--) {
@ -1057,9 +1068,10 @@ public class Upload implements Transference, Runnable, SecureSingleThreadNotifia
LOG.log(Level.INFO, "{0} Uploader {1} AUTO RESTARTING UPLOAD...", new Object[]{Thread.currentThread().getName(), getFile_name()});
restart();
}
}
}
});
});
}
getMain_panel().getUpload_manager().getFinishing_uploads_queue().remove(this);
@ -1176,10 +1188,6 @@ public class Upload implements Transference, Runnable, SecureSingleThreadNotifia
_exit = exit;
}
public void setStatus_error(boolean status_error) {
_status_error = status_error;
}
public void stopUploader() {
if (!_exit) {
@ -1201,9 +1209,7 @@ public class Upload implements Transference, Runnable, SecureSingleThreadNotifia
public void stopUploader(String reason) {
_status_error = true;
_status_error_message = (reason != null ? LabelTranslatorSingleton.getInstance().translate("FATAL ERROR! ") + reason : LabelTranslatorSingleton.getInstance().translate("FATAL ERROR! "));
_status_error = (reason != null ? LabelTranslatorSingleton.getInstance().translate("FATAL ERROR! ") + reason : LabelTranslatorSingleton.getInstance().translate("FATAL ERROR! "));
stopUploader();
}
@ -1237,7 +1243,7 @@ public class Upload implements Transference, Runnable, SecureSingleThreadNotifia
@Override
public boolean isStatusError() {
return _status_error;
return _status_error != null;
}
public long calculateLastUploadedChunk(long bytes_read) {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 195 KiB

After

Width:  |  Height:  |  Size: 207 KiB