From 8713e79ccd35e4e0a5e8d1815f9c919768fe632e Mon Sep 17 00:00:00 2001 From: tonikelope Date: Tue, 22 Jun 2021 19:59:11 +0200 Subject: [PATCH] 7.42 https://github.com/tonikelope/megabasterd/issues/327 --- pom.xml | 2 +- .../com/tonikelope/megabasterd/Download.java | 328 +++++++++--------- .../megabasterd/LabelTranslatorSingleton.java | 3 +- .../com/tonikelope/megabasterd/MainPanel.java | 2 +- 4 files changed, 174 insertions(+), 161 deletions(-) diff --git a/pom.xml b/pom.xml index fac3e3124..7496c64c5 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.tonikelope MegaBasterd - 7.41 + 7.42 jar diff --git a/src/main/java/com/tonikelope/megabasterd/Download.java b/src/main/java/com/tonikelope/megabasterd/Download.java index 167dc50eb..892fff91d 100644 --- a/src/main/java/com/tonikelope/megabasterd/Download.java +++ b/src/main/java/com/tonikelope/megabasterd/Download.java @@ -554,258 +554,281 @@ public void run() { path.mkdirs(); } - if (_file.exists()) { - _file_name = _file_name.replaceFirst("\\..*$", "_" + MiscTools.genID(8) + "_$0"); + if (!_file.exists() || _file.length() != _file_size) { - filename = _download_path + "/" + _file_name; + if (_file.exists()) { + _file_name = _file_name.replaceFirst("\\..*$", "_" + MiscTools.genID(8) + "_$0"); - _file = new File(filename); - } + filename = _download_path + "/" + _file_name; - getView().printStatusNormal("Starting download (retrieving MEGA temp link), please wait..."); + _file = new File(filename); + } - _last_download_url = getMegaFileDownloadUrl(_url); + getView().printStatusNormal("Starting download (retrieving MEGA temp link), please wait..."); - if (!_exit) { + _last_download_url = getMegaFileDownloadUrl(_url); - String temp_filename = (getCustom_chunks_dir() != null ? getCustom_chunks_dir() : _download_path) + "/" + _file_name + ".mctemp"; + if (!_exit) { - _file = new File(temp_filename); + String temp_filename = (getCustom_chunks_dir() != null ? getCustom_chunks_dir() : _download_path) + "/" + _file_name + ".mctemp"; - if (_file.getParent() != null) { - File path = new File(_file.getParent()); + _file = new File(temp_filename); - path.mkdirs(); - } + if (_file.getParent() != null) { + File path = new File(_file.getParent()); - if (_file.exists()) { - getView().printStatusNormal("File exists, resuming download..."); + path.mkdirs(); + } + + if (_file.exists()) { + getView().printStatusNormal("File exists, resuming download..."); - long max_size = calculateMaxTempFileSize(_file.length()); + long max_size = calculateMaxTempFileSize(_file.length()); - if (max_size != _file.length()) { + if (max_size != _file.length()) { - LOG.log(Level.INFO, "{0} Downloader truncating mctemp file {1} -> {2} ", new Object[]{Thread.currentThread().getName(), _file.length(), max_size}); + LOG.log(Level.INFO, "{0} Downloader truncating mctemp file {1} -> {2} ", new Object[]{Thread.currentThread().getName(), _file.length(), max_size}); - getView().printStatusNormal("Truncating temp file..."); + getView().printStatusNormal("Truncating temp file..."); - try (FileChannel out_truncate = new FileOutputStream(temp_filename, true).getChannel()) { - out_truncate.truncate(max_size); + try (FileChannel out_truncate = new FileOutputStream(temp_filename, true).getChannel()) { + out_truncate.truncate(max_size); + } } - } - setProgress(_file.length()); + setProgress(_file.length()); - _last_chunk_id_dispatched = calculateLastWrittenChunk(_progress); + _last_chunk_id_dispatched = calculateLastWrittenChunk(_progress); - } else { - setProgress(0); - } + } else { + setProgress(0); + } - _output_stream = new BufferedOutputStream(new FileOutputStream(_file, (_progress > 0))); + _output_stream = new BufferedOutputStream(new FileOutputStream(_file, (_progress > 0))); - _thread_pool.execute(getProgress_meter()); + _thread_pool.execute(getProgress_meter()); - getMain_panel().getGlobal_dl_speed().attachTransference(this); + getMain_panel().getGlobal_dl_speed().attachTransference(this); - synchronized (_workers_lock) { + synchronized (_workers_lock) { - if (_use_slots) { + if (_use_slots) { - _chunkmanager = new ChunkWriterManager(this); + _chunkmanager = new ChunkWriterManager(this); - _thread_pool.execute(_chunkmanager); + _thread_pool.execute(_chunkmanager); - _slots = getMain_panel().getDefault_slots_down(); + _slots = getMain_panel().getDefault_slots_down(); - _view.getSlots_spinner().setValue(_slots); + _view.getSlots_spinner().setValue(_slots); - for (int t = 1; t <= _slots; t++) { - ChunkDownloader c = new ChunkDownloader(t, this); + for (int t = 1; t <= _slots; t++) { + ChunkDownloader c = new ChunkDownloader(t, this); - _chunkworkers.add(c); + _chunkworkers.add(c); - _thread_pool.execute(c); - } + _thread_pool.execute(c); + } - MiscTools.GUIRun(() -> { - for (JComponent c : new JComponent[]{getView().getSlots_label(), getView().getSlots_spinner(), getView().getSlot_status_label()}) { + MiscTools.GUIRun(() -> { + for (JComponent c : new JComponent[]{getView().getSlots_label(), getView().getSlots_spinner(), getView().getSlot_status_label()}) { - c.setVisible(true); - } - }); + c.setVisible(true); + } + }); - } else { + } else { - ChunkDownloaderMono c = new ChunkDownloaderMono(this); + ChunkDownloaderMono c = new ChunkDownloaderMono(this); - _chunkworkers.add(c); + _chunkworkers.add(c); - _thread_pool.execute(c); + _thread_pool.execute(c); - MiscTools.GUIRun(() -> { - for (JComponent c1 : new JComponent[]{getView().getSlots_label(), getView().getSlots_spinner(), getView().getSlot_status_label()}) { - c1.setVisible(false); - } - }); + MiscTools.GUIRun(() -> { + for (JComponent c1 : new JComponent[]{getView().getSlots_label(), getView().getSlots_spinner(), getView().getSlot_status_label()}) { + c1.setVisible(false); + } + }); + } } - } - getView().printStatusNormal(LabelTranslatorSingleton.getInstance().translate("Downloading file from mega ") + (_ma.getFull_email() != null ? "(" + _ma.getFull_email() + ")" : "") + " ..."); + getView().printStatusNormal(LabelTranslatorSingleton.getInstance().translate("Downloading file from mega ") + (_ma.getFull_email() != null ? "(" + _ma.getFull_email() + ")" : "") + " ..."); - MiscTools.GUIRun(() -> { - for (JComponent c : new JComponent[]{getView().getPause_button(), getView().getProgress_pbar()}) { + MiscTools.GUIRun(() -> { + for (JComponent c : new JComponent[]{getView().getPause_button(), getView().getProgress_pbar()}) { - c.setVisible(true); - } - }); + c.setVisible(true); + } + }); - THREAD_POOL.execute(() -> { + THREAD_POOL.execute(() -> { - //PROGRESS WATCHDOG If a download remains more than PROGRESS_WATCHDOG_TIMEOUT seconds without receiving data, we force fatal error in order to restart it. - LOG.log(Level.INFO, "{0} PROGRESS WATCHDOG HELLO!", Thread.currentThread().getName()); + //PROGRESS WATCHDOG If a download remains more than PROGRESS_WATCHDOG_TIMEOUT seconds without receiving data, we force fatal error in order to restart it. + LOG.log(Level.INFO, "{0} PROGRESS WATCHDOG HELLO!", Thread.currentThread().getName()); - long last_progress, progress = getProgress(); + long last_progress, progress = getProgress(); - do { - last_progress = progress; + do { + last_progress = progress; - synchronized (_progress_watchdog_lock) { - try { - _progress_watchdog_lock.wait(PROGRESS_WATCHDOG_TIMEOUT * 1000); - progress = getProgress(); - } catch (InterruptedException ex) { - progress = -1; - Logger.getLogger(Download.class.getName()).log(Level.SEVERE, null, ex); + synchronized (_progress_watchdog_lock) { + try { + _progress_watchdog_lock.wait(PROGRESS_WATCHDOG_TIMEOUT * 1000); + progress = getProgress(); + } catch (InterruptedException ex) { + progress = -1; + Logger.getLogger(Download.class.getName()).log(Level.SEVERE, null, ex); + } } - } - } while (!isExit() && !_thread_pool.isShutdown() && progress < getFile_size() && (isPaused() || progress > last_progress)); + } while (!isExit() && !_thread_pool.isShutdown() && progress < getFile_size() && (isPaused() || progress > last_progress)); - if (!isExit() && !_thread_pool.isShutdown() && _status_error == null && progress < getFile_size() && progress <= last_progress) { - stopDownloader("PROGRESS WATCHDOG TIMEOUT!"); + if (!isExit() && !_thread_pool.isShutdown() && _status_error == null && progress < getFile_size() && progress <= last_progress) { + stopDownloader("PROGRESS WATCHDOG TIMEOUT!"); - if (MainPanel.getProxy_manager() != null) { - MainPanel.getProxy_manager().refreshProxyList(); //Force SmartProxy proxy list refresh + if (MainPanel.getProxy_manager() != null) { + MainPanel.getProxy_manager().refreshProxyList(); //Force SmartProxy proxy list refresh + } } - } - LOG.log(Level.INFO, "{0} PROGRESS WATCHDOG BYE BYE!", Thread.currentThread().getName()); + LOG.log(Level.INFO, "{0} PROGRESS WATCHDOG BYE BYE!", Thread.currentThread().getName()); - }); + }); - secureWait(); + secureWait(); - LOG.log(Level.INFO, "{0} Chunkdownloaders finished!", Thread.currentThread().getName()); + LOG.log(Level.INFO, "{0} Chunkdownloaders finished!", Thread.currentThread().getName()); - getProgress_meter().setExit(true); + getProgress_meter().setExit(true); - getProgress_meter().secureNotify(); + getProgress_meter().secureNotify(); - try { + try { - _thread_pool.shutdown(); + _thread_pool.shutdown(); - LOG.log(Level.INFO, "{0} Waiting all threads to finish...", Thread.currentThread().getName()); + LOG.log(Level.INFO, "{0} Waiting all threads to finish...", Thread.currentThread().getName()); - _thread_pool.awaitTermination(MAX_WAIT_WORKERS_SHUTDOWN, TimeUnit.SECONDS); + _thread_pool.awaitTermination(MAX_WAIT_WORKERS_SHUTDOWN, TimeUnit.SECONDS); - } catch (InterruptedException ex) { - LOG.log(Level.SEVERE, ex.getMessage()); - } + } catch (InterruptedException ex) { + LOG.log(Level.SEVERE, ex.getMessage()); + } - if (!_thread_pool.isTerminated()) { + if (!_thread_pool.isTerminated()) { - LOG.log(Level.INFO, "{0} Closing thread pool ''mecag\u00fcen'' style...", Thread.currentThread().getName()); + LOG.log(Level.INFO, "{0} Closing thread pool ''mecag\u00fcen'' style...", Thread.currentThread().getName()); - _thread_pool.shutdownNow(); - } + _thread_pool.shutdownNow(); + } - LOG.log(Level.INFO, "{0} Downloader thread pool finished!", Thread.currentThread().getName()); + LOG.log(Level.INFO, "{0} Downloader thread pool finished!", Thread.currentThread().getName()); - getMain_panel().getGlobal_dl_speed().detachTransference(this); + getMain_panel().getGlobal_dl_speed().detachTransference(this); - _output_stream.close(); + _output_stream.close(); - MiscTools.GUIRun(() -> { - for (JComponent c : new JComponent[]{getView().getSpeed_label(), getView().getPause_button(), getView().getStop_button(), getView().getSlots_label(), getView().getSlots_spinner(), getView().getKeep_temp_checkbox()}) { + MiscTools.GUIRun(() -> { + for (JComponent c : new JComponent[]{getView().getSpeed_label(), getView().getPause_button(), getView().getStop_button(), getView().getSlots_label(), getView().getSlots_spinner(), getView().getKeep_temp_checkbox()}) { - c.setVisible(false); - } - }); + c.setVisible(false); + } + }); - if (_progress == _file_size) { + if (_progress == _file_size) { - if (_file.length() != _file_size) { + if (_file.length() != _file_size) { - throw new IOException("El tamaño del fichero es incorrecto!"); - } + throw new IOException("El tamaño del fichero es incorrecto!"); + } + + Files.move(Paths.get(_file.getAbsolutePath()), Paths.get(filename), StandardCopyOption.REPLACE_EXISTING); - Files.move(Paths.get(_file.getAbsolutePath()), Paths.get(filename), StandardCopyOption.REPLACE_EXISTING); + if (_custom_chunks_dir != null) { - if (_custom_chunks_dir != null) { + File temp_parent_download_dir = new File(temp_filename).getParentFile(); - File temp_parent_download_dir = new File(temp_filename).getParentFile(); + while (!temp_parent_download_dir.getAbsolutePath().equals(_custom_chunks_dir) && temp_parent_download_dir.listFiles().length == 0) { + temp_parent_download_dir.delete(); + temp_parent_download_dir = temp_parent_download_dir.getParentFile(); + } - while (!temp_parent_download_dir.getAbsolutePath().equals(_custom_chunks_dir) && temp_parent_download_dir.listFiles().length == 0) { - temp_parent_download_dir.delete(); - temp_parent_download_dir = temp_parent_download_dir.getParentFile(); } - } + String verify_file = selectSettingValue("verify_down_file"); - String verify_file = selectSettingValue("verify_down_file"); + if (verify_file != null && verify_file.equals("yes")) { + _checking_cbc = true; - if (verify_file != null && verify_file.equals("yes")) { - _checking_cbc = true; + getView().printStatusNormal("Waiting to check file integrity..."); - getView().printStatusNormal("Waiting to check file integrity..."); + setProgress(0); - setProgress(0); + getView().printStatusNormal("Checking file integrity, please wait..."); - getView().printStatusNormal("Checking file integrity, please wait..."); + MiscTools.GUIRun(() -> { + getView().getStop_button().setVisible(true); - MiscTools.GUIRun(() -> { - getView().getStop_button().setVisible(true); + getView().getStop_button().setText(LabelTranslatorSingleton.getInstance().translate("CANCEL CHECK")); + }); - getView().getStop_button().setText(LabelTranslatorSingleton.getInstance().translate("CANCEL CHECK")); - }); + getMain_panel().getDownload_manager().getTransference_running_list().remove(this); - getMain_panel().getDownload_manager().getTransference_running_list().remove(this); + getMain_panel().getDownload_manager().secureNotify(); - getMain_panel().getDownload_manager().secureNotify(); + if (verifyFileCBCMAC(filename)) { - if (verifyFileCBCMAC(filename)) { + getView().printStatusOK("File successfully downloaded! (Integrity check PASSED)"); - getView().printStatusOK("File successfully downloaded! (Integrity check PASSED)"); + } else if (!_exit) { - } else if (!_exit) { + _status_error = "BAD NEWS :( File is DAMAGED!"; - _status_error = "BAD NEWS :( File is DAMAGED!"; + getView().printStatusError(_status_error); - getView().printStatusError(_status_error); + } else { + + getView().printStatusOK("File successfully downloaded! (but integrity check CANCELED)"); + + } + + MiscTools.GUIRun(() -> { + getView().getStop_button().setVisible(false); + }); } else { - getView().printStatusOK("File successfully downloaded! (but integrity check CANCELED)"); + getView().printStatusOK("File successfully downloaded!"); } - MiscTools.GUIRun(() -> { - getView().getStop_button().setVisible(false); - }); + } else if (_status_error != null) { + + getView().hideAllExceptStatus(); + + getView().printStatusError(_status_error); + + } else if (_canceled) { + + getView().hideAllExceptStatus(); + + getView().printStatusNormal("Download CANCELED!"); } else { - getView().printStatusOK("File successfully downloaded!"); + getView().hideAllExceptStatus(); + + _status_error = "UNEXPECTED ERROR!"; + getView().printStatusError(_status_error); } } else if (_status_error != null) { getView().hideAllExceptStatus(); - getView().printStatusError(_status_error); + getView().printStatusError(_status_error != null ? _status_error : "ERROR"); } else if (_canceled) { @@ -822,23 +845,12 @@ public void run() { getView().printStatusError(_status_error); } - } else if (_status_error != null) { - - getView().hideAllExceptStatus(); - - getView().printStatusError(_status_error != null ? _status_error : "ERROR"); - - } else if (_canceled) { - - getView().hideAllExceptStatus(); - - getView().printStatusNormal("Download CANCELED!"); - } else { - getView().hideAllExceptStatus(); - _status_error = "UNEXPECTED ERROR!"; + _status_error = "FILE WITH SAME NAME AND SIZE ALREADY EXISTS"; + + _auto_retry_on_error = false; getView().printStatusError(_status_error); } @@ -995,7 +1007,7 @@ public void provisionIt(boolean retry) throws APIException { File file = new File(filename); - if (file.exists()) { + if (file.exists() && file.length() != _file_size) { _file_name = _file_name.replaceFirst("\\..*$", "_" + MiscTools.genID(8) + "_$0"); } @@ -1019,7 +1031,7 @@ public void provisionIt(boolean retry) throws APIException { File temp_file = new File(filename + ".mctemp"); - if (file.exists() && !temp_file.exists()) { + if (file.exists() && !temp_file.exists() && file.length() != _file_size) { _file_name = _file_name.replaceFirst("\\..*$", "_" + MiscTools.genID(8) + "_$0"); } diff --git a/src/main/java/com/tonikelope/megabasterd/LabelTranslatorSingleton.java b/src/main/java/com/tonikelope/megabasterd/LabelTranslatorSingleton.java index 24b5080ff..784e6c557 100644 --- a/src/main/java/com/tonikelope/megabasterd/LabelTranslatorSingleton.java +++ b/src/main/java/com/tonikelope/megabasterd/LabelTranslatorSingleton.java @@ -37,7 +37,8 @@ private LabelTranslatorSingleton() { } private void Spanish() { - + + _addTranslation("FILE WITH SAME NAME AND SIZE ALREADY EXISTS", "YA EXISTE UN FICHERO CON EL MISMO NOMBRE Y TAMAÑO"); _addTranslation("WARNING: USING MEGA API WITHOUT API KEY MAY VIOLATE ITS TERM OF USE. YOU SHOULD GET A KEY -> https://mega.nz/sdk", "AVISO: USAR LA API DE MEGA SIN UNA API KEY PUEDE VIOLAR SUS TÉRMINOS DE USO. DEBES CONSEGUIR UNA API KEY -> https://mega.nz/sdk"); _addTranslation("WARNING: USING MEGA API WITHOUT API KEY MAY VIOLATE ITS TERM OF USE.\n\nYOU SHOULD GET A KEY -> https://mega.nz/sdk (and set it in MegaBasterd ADVANCED SETTINGS).\n\nCREATE API KEY NOW?", "AVISO: USAR LA API DE MEGA SIN UNA API KEY PUEDE VIOLAR SUS TÉRMINOS DE USO.\n\nDEBES CONSEGUIR UNA API KEY -> https://mega.nz/sdk (e introducirla en AJUSTES AVANZADOS de MegaBasterd).\n\n¿CREAR AHORA UNA API KEY?"); _addTranslation("WARNING: Using proxies or VPN to bypass MEGA's daily download limitation may violate its Terms of Use. USE THIS OPTION AT YOUR OWN RISK.", "AVISO: El uso de proxies o VPN para saltar el límite diario de descarga de MEGA podría violar sus Términos de Uso. UTILIZA ESTA OPCIÓN BAJO TU RESPONSABILIDAD."); diff --git a/src/main/java/com/tonikelope/megabasterd/MainPanel.java b/src/main/java/com/tonikelope/megabasterd/MainPanel.java index 598f16d2a..bdde4f509 100644 --- a/src/main/java/com/tonikelope/megabasterd/MainPanel.java +++ b/src/main/java/com/tonikelope/megabasterd/MainPanel.java @@ -60,7 +60,7 @@ */ public final class MainPanel { - public static final String VERSION = "7.41"; + public static final String VERSION = "7.42"; public static final boolean FORCE_SMART_PROXY = false; //TRUE FOR DEBUGING SMART PROXY public static final int THROTTLE_SLICE_SIZE = 16 * 1024; public static final int DEFAULT_BYTE_BUFFER_SIZE = 16 * 1024;