This commit is contained in:
tonikelope 2018-01-04 00:08:39 +01:00
parent bea3c16c02
commit e99c2ef292
20 changed files with 224 additions and 278 deletions

View File

@ -131,7 +131,7 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
try {
httpclient.close();
} catch (IOException ex) {
Logger.getLogger(ChunkDownloader.class.getName()).log(Level.SEVERE, null, ex);
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
}
}
@ -280,14 +280,14 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
} catch (URISyntaxException ex) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
} catch (Exception ex) {
Logger.getLogger(ChunkDownloader.class.getName()).log(Level.SEVERE, null, ex);
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
} finally {
if (httpclient != null) {
try {
httpclient.close();
} catch (IOException ex) {
Logger.getLogger(ChunkDownloader.class.getName()).log(Level.SEVERE, null, ex);
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
}
}
}

View File

@ -182,7 +182,7 @@ public class ChunkDownloaderMono extends ChunkDownloader {
} catch (URISyntaxException ex) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
} catch (Exception ex) {
Logger.getLogger(ChunkDownloaderMono.class.getName()).log(Level.SEVERE, null, ex);
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
}
getDownload().stopThisSlot(this);

View File

@ -207,6 +207,7 @@ public class ChunkUploader implements Runnable, SecureSingleThreadNotifiable {
} else {
if (tot_bytes_up < chunk.getSize()) {
if (tot_bytes_up > 0) {
_upload.getPartialProgress().add(-1 * tot_bytes_up);
@ -220,6 +221,8 @@ public class ChunkUploader implements Runnable, SecureSingleThreadNotifiable {
if (httpresponse != null && _upload.getCompletion_handle() == null) {
Logger.getLogger(getClass().getName()).log(Level.WARNING, "{0} all chunks uploaded. Waiting for completion handle...", new Object[]{Thread.currentThread().getName()});
InputStream is = httpresponse.getEntity().getContent();
try (ByteArrayOutputStream byte_res = new ByteArrayOutputStream()) {
@ -319,6 +322,7 @@ public class ChunkUploader implements Runnable, SecureSingleThreadNotifiable {
_upload.rejectChunkId(chunk.getId());
}
} catch (IOException ex) {
Logger.getLogger(getClass().getName()).log(Level.WARNING, "{0} Uploading chunk {1} from worker {2} FAILED!...", new Object[]{Thread.currentThread().getName(), chunk.getId(), _id});
@ -348,15 +352,12 @@ public class ChunkUploader implements Runnable, SecureSingleThreadNotifiable {
} catch (ChunkInvalidException e) {
} catch (IOException ex) {
} catch (IOException | URISyntaxException ex) {
_upload.emergencyStopUploader(ex.getMessage());
_upload.stopUploader();
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
} catch (URISyntaxException ex) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
}
_upload.stopThisSlot(this);

View File

@ -131,6 +131,7 @@ public class ChunkUploaderMono extends ChunkUploader {
if (!getUpload().isStopped()) {
if (tot_bytes_up < chunk.getSize()) {
if (tot_bytes_up > 0) {
getUpload().getPartialProgress().add(-1 * tot_bytes_up);
@ -164,16 +165,12 @@ public class ChunkUploaderMono extends ChunkUploader {
Logger.getLogger(getClass().getName()).log(Level.INFO, "{0} {1} {2}", new Object[]{chunk.getOffset(), tot_bytes_up, getUpload().getFile_size()});
if (chunk.getOffset() + tot_bytes_up < getUpload().getFile_size()) {
getUpload().getMac_generator().getChunk_queue().put(chunk.getId(), chunk);
getUpload().getMac_generator().getChunk_queue().put(chunk.getId(), chunk);
getUpload().getMac_generator().secureNotify();
getUpload().getMac_generator().secureNotify();
conta_error = 0;
}
conta_error = 0;
}
}
} else if (isExit()) {
@ -205,6 +202,8 @@ public class ChunkUploaderMono extends ChunkUploader {
if (!error && chunk.getOffset() + tot_bytes_up == getUpload().getFile_size() && futureTask != null) {
Logger.getLogger(getClass().getName()).log(Level.WARNING, "{0} has finished uploading all chunks. Waiting for completion handle...", new Object[]{Thread.currentThread().getName()});
try {
httpresponse = futureTask.get();
@ -212,6 +211,7 @@ public class ChunkUploaderMono extends ChunkUploader {
http_status = httpresponse.getStatusLine().getStatusCode();
if (http_status != HttpStatus.SC_OK) {
throw new IOException("UPLOAD FAILED! (HTTP STATUS: " + http_status + ")");
} else {
@ -230,6 +230,7 @@ public class ChunkUploaderMono extends ChunkUploader {
if (response.length() > 0) {
if (MegaAPI.checkMEGAError(response) != 0) {
throw new IOException("UPLOAD FAILED! (MEGA ERROR: " + MegaAPI.checkMEGAError(response) + ")");
} else {
@ -237,34 +238,18 @@ public class ChunkUploaderMono extends ChunkUploader {
Logger.getLogger(getClass().getName()).log(Level.INFO, "{0} Completion handle -> {1}", new Object[]{Thread.currentThread().getName(), response});
getUpload().setCompletion_handle(response);
conta_error = 0;
getUpload().getMac_generator().getChunk_queue().put(chunk.getId(), chunk);
getUpload().getMac_generator().secureNotify();
}
} else {
throw new IOException("UPLOAD FAILED! (UPLOAD RESPONSE IS EMPTY)");
throw new IOException("UPLOAD FAILED! (Completion handle is empty)");
}
}
}
} catch (ExecutionException | InterruptedException | CancellationException exception) {
Logger.getLogger(getClass().getName()).log(Level.WARNING, "{0} Uploading chunk {1} FAILED!...", new Object[]{Thread.currentThread().getName(), chunk.getId()});
error = true;
getUpload().rejectChunkId(chunk.getId());
if (tot_bytes_up > 0) {
getUpload().getPartialProgress().add(-1 * tot_bytes_up);
getUpload().getProgress_meter().secureNotify();
}
throw new IOException("UPLOAD FAILED! (Completion handle is empty)");
} finally {
@ -273,7 +258,6 @@ public class ChunkUploaderMono extends ChunkUploader {
}
if (httpresponse != null) {
httpresponse.close();
}
}
@ -293,13 +277,8 @@ public class ChunkUploaderMono extends ChunkUploader {
} catch (ChunkInvalidException e) {
} catch (IOException ex) {
} catch (URISyntaxException | IOException ex) {
getUpload().emergencyStopUploader(ex.getMessage());
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
} catch (URISyntaxException ex) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
}

View File

@ -128,7 +128,7 @@ public final class ChunkWriter implements Runnable, SecureSingleThreadNotifiable
_download.getOutput_stream().write(buffer, 0, reads);
}
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | InvalidAlgorithmParameterException ex) {
Logger.getLogger(ChunkWriter.class.getName()).log(Level.SEVERE, null, ex);
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
}
_bytes_written += current_chunk.getSize();
@ -163,7 +163,7 @@ public final class ChunkWriter implements Runnable, SecureSingleThreadNotifiable
private long calculateLastWrittenChunk(long temp_file_size) {
if (temp_file_size > 3584 * 1024) {
return 7 + (long) Math.ceil((temp_file_size - 3584 * 1024) / (1024 * 1024 * (_download.isUse_slots() ? Download.CHUNK_SIZE_MULTI : 1)));
return 7 + (long) Math.ceil((float) (temp_file_size - 3584 * 1024) / (1024 * 1024 * (_download.isUse_slots() ? Download.CHUNK_SIZE_MULTI : 1)));
} else {
int i = 0, tot = 0;

View File

@ -276,7 +276,7 @@ public final class Download implements Transference, Runnable, SecureSingleThrea
try {
Thread.sleep(250);
} catch (InterruptedException ex) {
Logger.getLogger(Upload.class.getName()).log(Level.SEVERE, null, ex);
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
}
}
@ -290,7 +290,7 @@ public final class Download implements Transference, Runnable, SecureSingleThrea
try {
Thread.sleep(250);
} catch (InterruptedException ex) {
Logger.getLogger(Upload.class.getName()).log(Level.SEVERE, null, ex);
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
}
}

View File

@ -91,7 +91,7 @@
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="file_tree_scrollpane" alignment="0" pref="237" max="32767" attributes="0"/>
<Component id="file_tree_scrollpane" alignment="0" pref="215" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
@ -121,6 +121,13 @@
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="jPanel2">
<Properties>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.TitledBorderInfo">
<TitledBorder title="Upload info"/>
</Border>
</Property>
</Properties>
<Layout>
<DimensionLayout dim="0">
@ -134,9 +141,9 @@
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="add_files_button" min="-2" pref="250" max="-2" attributes="0"/>
<Component id="add_files_button" max="32767" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="add_folder_button" min="-2" pref="250" max="-2" attributes="0"/>
<Component id="add_folder_button" max="32767" attributes="0"/>
</Group>
<Component id="dir_name_textfield" max="32767" attributes="0"/>
<Component id="account_combobox" max="32767" attributes="0"/>

View File

@ -141,9 +141,11 @@ public final class FileGrabberDialog extends javax.swing.JDialog {
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(file_tree_scrollpane, javax.swing.GroupLayout.DEFAULT_SIZE, 237, Short.MAX_VALUE)
.addComponent(file_tree_scrollpane, javax.swing.GroupLayout.DEFAULT_SIZE, 215, Short.MAX_VALUE)
);
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Upload info"));
dir_name_label.setFont(new java.awt.Font("Dialog", 1, 18)); // NOI18N
dir_name_label.setText("Upload name:");
dir_name_label.setDoubleBuffered(true);
@ -203,9 +205,9 @@ public final class FileGrabberDialog extends javax.swing.JDialog {
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(add_files_button, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(add_files_button, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(add_folder_button, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(add_folder_button, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(dir_name_textfield)
.addComponent(account_combobox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(used_space_label, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
@ -519,7 +521,7 @@ public final class FileGrabberDialog extends javax.swing.JDialog {
warning_label.setEnabled(false);
file_tree.setEnabled(false);
swingInvoke(new Runnable() {
THREAD_POOL.execute(new Runnable() {
@Override
public void run() {
@ -553,37 +555,50 @@ public final class FileGrabberDialog extends javax.swing.JDialog {
used_space_color = Color.red;
}
boolean root_childs = ((TreeNode) file_tree.getModel().getRoot()).getChildCount() > 0;
final String quota_message = "Quota used: " + formatBytes(quota[0]) + "/" + formatBytes(quota[1]);
used_space_label.setText("Quota used: " + formatBytes(quota[0]) + "/" + formatBytes(quota[1]));
swingInvoke(new Runnable() {
@Override
public void run() {
used_space_label.setForeground(used_space_color);
boolean root_childs = ((TreeNode) file_tree.getModel().getRoot()).getChildCount() > 0;
for (JComponent c : new JComponent[]{add_files_button, add_folder_button, account_combobox, account_label}) {
used_space_label.setText(quota_message);
c.setEnabled(true);
}
used_space_label.setForeground(used_space_color);
for (JComponent c : new JComponent[]{dir_name_textfield, dir_name_label, warning_label, dance_button, file_tree, total_file_size_label, skip_button, skip_rest_button}) {
for (JComponent c : new JComponent[]{add_files_button, add_folder_button, account_combobox, account_label}) {
c.setEnabled(root_childs);
}
c.setEnabled(true);
}
for (JComponent c : new JComponent[]{dir_name_textfield, dir_name_label, warning_label, dance_button, file_tree, total_file_size_label, skip_button, skip_rest_button}) {
c.setEnabled(root_childs);
}
}
});
} else {
_last_selected_account = null;
account_combobox.setEnabled(true);
swingInvoke(new Runnable() {
@Override
public void run() {
account_label.setEnabled(true);
account_combobox.setEnabled(true);
account_combobox.setSelectedIndex(-1);
account_label.setEnabled(true);
used_space_label.setForeground(Color.red);
account_combobox.setSelectedIndex(-1);
used_space_label.setText("ERROR checking account quota!");
used_space_label.setForeground(Color.red);
used_space_label.setText("ERROR checking account quota!");
}
});
}
}
});
}

View File

@ -32,6 +32,7 @@ import static java.util.logging.Level.SEVERE;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import static javax.swing.JOptionPane.QUESTION_MESSAGE;
import static javax.swing.JOptionPane.WARNING_MESSAGE;
import static javax.swing.JOptionPane.YES_NO_CANCEL_OPTION;
import static javax.swing.JOptionPane.showOptionDialog;
import javax.swing.UIManager;
@ -47,7 +48,7 @@ import org.apache.http.auth.UsernamePasswordCredentials;
*/
public final class MainPanel {
public static final String VERSION = "2.70";
public static final String VERSION = "2.71";
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;
@ -344,7 +345,7 @@ public final class MainPanel {
try {
Thread.sleep(250);
} catch (InterruptedException ex) {
Logger.getLogger(Upload.class.getName()).log(Level.SEVERE, null, ex);
Logger.getLogger(MainPanel.class.getName()).log(Level.SEVERE, null, ex);
}
}
@ -654,8 +655,8 @@ public final class MainPanel {
"Yes"};
int n = showOptionDialog(getView(),
"It seems MegaBasterd is provisioning down/uploads.\nIf you exit now, unprovisioned down/uploads will be lost.\nDo you want to continue?",
"Warning!", YES_NO_CANCEL_OPTION, QUESTION_MESSAGE,
"It seems MegaBasterd is provisioning down/uploads.\n\nIf you exit now, unprovisioned down/uploads will be lost.\n\nDo you want to continue?",
"Warning!", YES_NO_CANCEL_OPTION, WARNING_MESSAGE,
null,
options,
options[0]);
@ -665,6 +666,22 @@ public final class MainPanel {
exit = false;
}
} else if (!getUpload_manager().getFinishing_uploads_queue().isEmpty()) {
Object[] options = {"No",
"Yes"};
int n = showOptionDialog(getView(),
"It seems MegaBasterd is just finishing uploading some files.\n\nIF YOU EXIT NOW, THOSE UPLOADS WILL FAIL.\n\nDo you want to continue?",
"Warning!", YES_NO_CANCEL_OPTION, WARNING_MESSAGE,
null,
options,
options[0]);
if (n == 0) {
exit = false;
}
}
if (exit) {
@ -741,7 +758,7 @@ public final class MainPanel {
new Runnable() {
@Override
public void run() {
getView().getStatus_down_label().setText("Checking it there are previous downloads, please wait...");
getView().getStatus_down_label().setText("Checking if there are previous downloads, please wait...");
}
});
@ -913,7 +930,7 @@ public final class MainPanel {
new Runnable() {
@Override
public void run() {
getView().getStatus_up_label().setText("Checking it there are previous uploads, please wait...");
getView().getStatus_up_label().setText("Checking if there are previous uploads, please wait...");
}
});

View File

@ -672,7 +672,7 @@ public final class MainPanelView extends javax.swing.JFrame {
getMain_panel().getDownload_manager().secureNotify();
} catch (UnsupportedEncodingException ex) {
Logger.getLogger(MainPanelView.class.getName()).log(Level.SEVERE, null, ex);
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
}
}

View File

@ -1599,6 +1599,8 @@ public final class SettingsDialog extends javax.swing.JDialog {
final DefaultTableModel model = (DefaultTableModel) mega_accounts_table.getModel();
final int model_row_count = model.getRowCount();
status.setText("Checking your MEGA accounts, please wait...");
pack();
@ -1625,13 +1627,13 @@ public final class SettingsDialog extends javax.swing.JDialog {
final Dialog tthis = this;
swingInvoke(new Runnable() {
THREAD_POOL.execute(new Runnable() {
@Override
public void run() {
ArrayList<String> email_error = new ArrayList<>();
for (int i = 0; i < model.getRowCount(); i++) {
for (int i = 0; i < model_row_count; i++) {
String email = (String) model.getValueAt(i, 0);
@ -1730,36 +1732,50 @@ public final class SettingsDialog extends javax.swing.JDialog {
email_error_s += s + "\n";
}
status.setText("");
final String final_email_error = email_error_s;
pack();
swingInvoke(new Runnable() {
@Override
public void run() {
JOptionPane.showMessageDialog(tthis, "There were errors with some accounts. Please, check them:\n\n" + email_error_s, "Error", JOptionPane.ERROR_MESSAGE);
status.setText("");
save_button.setEnabled(true);
pack();
cancel_button.setEnabled(true);
JOptionPane.showMessageDialog(tthis, "There were errors with some accounts. Please, check them:\n\n" + final_email_error, "Error", JOptionPane.ERROR_MESSAGE);
remove_mega_account_button.setEnabled(mega_accounts_table.getModel().getRowCount() > 0);
save_button.setEnabled(true);
remove_elc_account_button.setEnabled(elc_accounts_table.getModel().getRowCount() > 0);
cancel_button.setEnabled(true);
add_mega_account_button.setEnabled(true);
remove_mega_account_button.setEnabled(mega_accounts_table.getModel().getRowCount() > 0);
add_elc_account_button.setEnabled(true);
remove_elc_account_button.setEnabled(elc_accounts_table.getModel().getRowCount() > 0);
mega_accounts_table.setEnabled(true);
add_mega_account_button.setEnabled(true);
elc_accounts_table.setEnabled(true);
add_elc_account_button.setEnabled(true);
delete_all_accounts_button.setEnabled(true);
mega_accounts_table.setEnabled(true);
encrypt_pass_checkbox.setEnabled(true);
elc_accounts_table.setEnabled(true);
delete_all_accounts_button.setEnabled(true);
encrypt_pass_checkbox.setEnabled(true);
}
});
} else {
status.setText("");
JOptionPane.showMessageDialog(tthis, "Settings successfully saved!", "Settings saved", JOptionPane.INFORMATION_MESSAGE);
setVisible(false);
swingInvoke(new Runnable() {
@Override
public void run() {
status.setText("");
JOptionPane.showMessageDialog(tthis, "Settings successfully saved!", "Settings saved", JOptionPane.INFORMATION_MESSAGE);
setVisible(false);
}
});
}
}
});
@ -2245,11 +2261,11 @@ public final class SettingsDialog extends javax.swing.JDialog {
setVisible(false);
} catch (SQLException | ClassNotFoundException ex) {
Logger.getLogger(SettingsDialog.class.getName()).log(Level.SEVERE, null, ex);
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
}
} catch (IOException ex) {
Logger.getLogger(SettingsDialog.class.getName()).log(Level.SEVERE, null, ex);
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
}
}
@ -2292,11 +2308,11 @@ public final class SettingsDialog extends javax.swing.JDialog {
setVisible(false);
} catch (SQLException ex) {
Logger.getLogger(SettingsDialog.class.getName()).log(Level.SEVERE, null, ex);
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
}
} catch (IOException ex) {
Logger.getLogger(SettingsDialog.class.getName()).log(Level.SEVERE, null, ex);
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
}
}
}//GEN-LAST:event_export_settings_buttonActionPerformed

View File

@ -165,7 +165,7 @@ public class SmartMegaProxyManager implements Runnable {
}
}
Logger.getLogger(SmartMegaProxyManager.class.getName()).log(Level.INFO, "{0} Smart Proxy Manager: proxy list refreshed ({1})", new Object[]{Thread.currentThread().getName(), _proxy_list.size()});
Logger.getLogger(getClass().getName()).log(Level.INFO, "{0} Smart Proxy Manager: proxy list refreshed ({1})", new Object[]{Thread.currentThread().getName(), _proxy_list.size()});
if (_enabled) {
@ -176,16 +176,16 @@ public class SmartMegaProxyManager implements Runnable {
}
} catch (MalformedURLException ex) {
Logger.getLogger(SmartMegaProxyManager.class.getName()).log(Level.SEVERE, null, ex);
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
} catch (IOException | URISyntaxException ex) {
Logger.getLogger(SmartMegaProxyManager.class.getName()).log(Level.SEVERE, null, ex);
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
}
}
@Override
public void run() {
Logger.getLogger(SmartMegaProxyManager.class.getName()).log(Level.INFO, "{0} Smart Proxy Manager: hello!", new Object[]{Thread.currentThread().getName()});
Logger.getLogger(getClass().getName()).log(Level.INFO, "{0} Smart Proxy Manager: hello!", new Object[]{Thread.currentThread().getName()});
_main_panel.getView().updateSmartProxyStatus("");
@ -198,14 +198,14 @@ public class SmartMegaProxyManager implements Runnable {
try {
_refresh_lock.wait(1000 * REFRESH_PROXY_LIST_TIMEOUT);
} catch (InterruptedException ex) {
Logger.getLogger(SmartMegaProxyManager.class.getName()).log(Level.SEVERE, null, ex);
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
}
}
}
_main_panel.getView().updateSmartProxyStatus("");
Logger.getLogger(SmartMegaProxyManager.class.getName()).log(Level.INFO, "{0} Smart Proxy Manager: bye bye", new Object[]{Thread.currentThread().getName()});
Logger.getLogger(getClass().getName()).log(Level.INFO, "{0} Smart Proxy Manager: bye bye", new Object[]{Thread.currentThread().getName()});
}

View File

@ -79,7 +79,7 @@ public class StreamChunkDownloader implements Runnable {
try {
httpclient.close();
} catch (IOException ex) {
Logger.getLogger(StreamChunkDownloader.class.getName()).log(Level.SEVERE, null, ex);
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
}
}
@ -184,13 +184,13 @@ public class StreamChunkDownloader implements Runnable {
} catch (IOException | URISyntaxException | ChunkInvalidException | InterruptedException ex) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
} catch (Exception ex) {
Logger.getLogger(StreamChunkDownloader.class.getName()).log(Level.SEVERE, null, ex);
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
} finally {
if (httpclient != null) {
try {
httpclient.close();
} catch (IOException ex) {
Logger.getLogger(StreamChunkDownloader.class.getName()).log(Level.SEVERE, null, ex);
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
}
}
}

View File

@ -243,7 +243,7 @@ public final class StreamerDialog extends javax.swing.JDialog implements Clipboa
getParent().dispatchEvent(new WindowEvent(tthis, WINDOW_CLOSING));
}
} catch (UnsupportedEncodingException ex) {
Logger.getLogger(StreamerDialog.class.getName()).log(Level.SEVERE, null, ex);
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
}
}

View File

@ -31,30 +31,23 @@ public final class ThrottledInputStream extends InputStream {
@Override
public int read() throws IOException {
int r;
if (_stream_supervisor.getMaxBytesPerSecInput() > 0) {
if (!_stream_finish) {
int r;
throttle(1);
if (_slice_size != null) {
r = _rawStream.read();
r = _rawStream.read();
if (r == -1) {
if (r == -1) {
_stream_finish = true;
}
return r;
} else {
return _rawStream.read();
_stream_finish = true;
}
return r;
} else {
return -1;
@ -62,7 +55,14 @@ public final class ThrottledInputStream extends InputStream {
} else {
return _rawStream.read();
r = _rawStream.read();
if (r == -1) {
_stream_finish = true;
}
return r;
}
}
@ -70,42 +70,26 @@ public final class ThrottledInputStream extends InputStream {
@Override
public int read(byte[] b) throws IOException {
int readLen, len = b.length;
if (_stream_supervisor.getMaxBytesPerSecInput() > 0) {
if (!_stream_finish) {
int readLen = 0, readSlice, len = b.length, r = 0;
throttle(len);
do {
readLen = _rawStream.read(b, 0, _slice_size != null ? _slice_size : len);
throttle(len - readLen);
if (readLen == -1) {
if (_slice_size != null) {
_stream_finish = true;
readSlice = 0;
} else if (_slice_size != null && readLen < _slice_size && !_stream_supervisor.isQueue_swapping()) {
do {
r = _rawStream.read(b, readLen + readSlice, _slice_size - readSlice);
_stream_supervisor.getInput_slice_queue().add(_slice_size - readLen);
if (r != -1) {
readSlice += r;
} else {
_stream_finish = true;
}
} while (r != -1 && readSlice < _slice_size);
readLen += readSlice;
} else {
return _rawStream.read(b);
}
} while (r != -1 && readLen < len);
_stream_supervisor.secureNotifyAll();
}
return readLen;
@ -123,51 +107,26 @@ public final class ThrottledInputStream extends InputStream {
@Override
public int read(byte[] b, int off, int len) throws IOException {
int readLen;
if (_stream_supervisor.getMaxBytesPerSecInput() > 0) {
if (!_stream_finish) {
int readLen = 0, r = 0;
throttle(len);
do {
readLen = _rawStream.read(b, off, _slice_size != null ? _slice_size : len);
throttle(len - readLen);
if (readLen == -1) {
if (_slice_size != null) {
_stream_finish = true;
int readSlice = 0;
} else if (_slice_size != null && readLen < _slice_size && !_stream_supervisor.isQueue_swapping()) {
do {
r = _rawStream.read(b, off + readSlice + readLen, _slice_size - readSlice);
_stream_supervisor.getInput_slice_queue().add(_slice_size - readLen);
if (r != -1) {
readSlice += r;
} else {
_stream_finish = true;
}
} while (r != -1 && readSlice < _slice_size);
readLen += readSlice;
} else {
r = _rawStream.read(b, off + readLen, len - readLen);
if (r != -1) {
readLen += r;
} else {
_stream_finish = true;
}
}
} while (r != -1 && readLen < len);
_stream_supervisor.secureNotifyAll();
}
return readLen;
@ -180,7 +139,6 @@ public final class ThrottledInputStream extends InputStream {
return _rawStream.read(b, off, len);
}
}
@Override
@ -189,10 +147,9 @@ public final class ThrottledInputStream extends InputStream {
_stream_finish = false;
_rawStream.reset();
}
private void throttle(int size) throws IOException {
private void throttle(int req_slice_size) throws IOException {
_slice_size = null;
@ -201,16 +158,16 @@ public final class ThrottledInputStream extends InputStream {
_stream_supervisor.secureWait();
}
if (_slice_size != null && size < _slice_size) {
if (_slice_size != null && req_slice_size < _slice_size) {
if (!_stream_supervisor.isQueue_swapping()) {
_stream_supervisor.getInput_slice_queue().add(_slice_size - size);
_stream_supervisor.getInput_slice_queue().add(_slice_size - req_slice_size);
_stream_supervisor.secureNotifyAll();
}
_slice_size = size;
_slice_size = req_slice_size;
}
}

View File

@ -13,7 +13,7 @@ public final class ThrottledOutputStream extends OutputStream {
private final StreamThrottlerSupervisor _stream_supervisor;
private Integer slice_size;
private Integer _slice_size;
public ThrottledOutputStream(OutputStream rawStream, StreamThrottlerSupervisor stream_supervisor) {
@ -21,8 +21,7 @@ public final class ThrottledOutputStream extends OutputStream {
_stream_supervisor = stream_supervisor;
slice_size = null;
_slice_size = null;
}
@Override
@ -30,31 +29,10 @@ public final class ThrottledOutputStream extends OutputStream {
if (_stream_supervisor.getMaxBytesPerSecOutput() > 0) {
int writeLen = 0;
do {
throttle(len - writeLen);
if (slice_size != null) {
_rawStream.write(b, off + writeLen, slice_size);
writeLen += slice_size;
} else {
_rawStream.write(b, off + writeLen, len - writeLen);
writeLen = len;
}
} while (writeLen < len);
} else {
_rawStream.write(b, off, len);
throttle(len);
}
_rawStream.write(b, off, _slice_size != null ? _slice_size : len);
}
@Override
@ -63,34 +41,30 @@ public final class ThrottledOutputStream extends OutputStream {
if (_stream_supervisor.getMaxBytesPerSecOutput() > 0) {
throttle(1);
_rawStream.write(i);
} else {
_rawStream.write(i);
}
_rawStream.write(i);
}
private void throttle(int size) throws IOException {
private void throttle(int req_slice_size) throws IOException {
slice_size = null;
_slice_size = null;
while (_stream_supervisor.getMaxBytesPerSecOutput() > 0 && (_stream_supervisor.isQueue_swapping() || (slice_size = _stream_supervisor.getOutput_slice_queue().poll()) == null)) {
while (_stream_supervisor.getMaxBytesPerSecOutput() > 0 && (_stream_supervisor.isQueue_swapping() || (_slice_size = _stream_supervisor.getOutput_slice_queue().poll()) == null)) {
_stream_supervisor.secureWait();
}
if (slice_size != null && size < slice_size) {
if (_slice_size != null && req_slice_size < _slice_size) {
if (!_stream_supervisor.isQueue_swapping()) {
_stream_supervisor.getOutput_slice_queue().add(slice_size - size);
_stream_supervisor.getOutput_slice_queue().add(_slice_size - req_slice_size);
_stream_supervisor.secureNotifyAll();
}
slice_size = size;
_slice_size = req_slice_size;
}
}

View File

@ -14,7 +14,7 @@ public interface Transference {
int SIM_TRANSFERENCES_DEFAULT = 4;
boolean LIMIT_TRANSFERENCE_SPEED_DEFAULT = false;
int MAX_TRANSFERENCE_SPEED_DEFAULT = 5;
int MAX_WAIT_WORKERS_SHUTDOWN = 15;
int MAX_WAIT_WORKERS_SHUTDOWN = 60;
Integer[] FATAL_ERROR_API_CODES = {-2, -8, -9, -10, -11, -12, -13, -14, -15, -16, 22, 23, 24, 25};
void start();

View File

@ -37,7 +37,6 @@ public final class Upload implements Transference, Runnable, SecureSingleThreadN
private final Object _workers_lock;
private final Object _chunkid_lock;
private byte[] _byte_file_key;
private String _fatal_error;
private volatile long _progress;
private byte[] _byte_file_iv;
private final ConcurrentLinkedQueue<Long> _rejectedChunkIds;
@ -156,10 +155,6 @@ public final class Upload implements Transference, Runnable, SecureSingleThreadN
return _byte_file_key;
}
public String getFatal_error() {
return _fatal_error;
}
@Override
public long getProgress() {
return _progress;
@ -302,7 +297,7 @@ public final class Upload implements Transference, Runnable, SecureSingleThreadN
try {
Thread.sleep(250);
} catch (InterruptedException ex) {
Logger.getLogger(Upload.class.getName()).log(Level.SEVERE, null, ex);
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
}
}
@ -316,7 +311,7 @@ public final class Upload implements Transference, Runnable, SecureSingleThreadN
try {
Thread.sleep(250);
} catch (InterruptedException ex) {
Logger.getLogger(Upload.class.getName()).log(Level.SEVERE, null, ex);
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
}
}
@ -410,11 +405,7 @@ public final class Upload implements Transference, Runnable, SecureSingleThreadN
getView().hideAllExceptStatus();
if (_fatal_error != null) {
getView().printStatusError(_fatal_error);
} else if (exit_msg != null) {
if (exit_msg != null) {
getView().printStatusError(exit_msg);
}
@ -682,7 +673,7 @@ public final class Upload implements Transference, Runnable, SecureSingleThreadN
try {
Thread.sleep(wait_time * 1000);
} catch (InterruptedException ex) {
Logger.getLogger(Upload.class.getName()).log(Level.SEVERE, null, ex);
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
}
} while (_ul_url == null && !_exit);
@ -851,6 +842,10 @@ public final class Upload implements Transference, Runnable, SecureSingleThreadN
getView().printStatusNormal("Creating new MEGA node ... ***DO NOT EXIT MEGABASTERD NOW***");
if (!getMain_panel().getUpload_manager().getFinishing_uploads_queue().contains(this)) {
getMain_panel().getUpload_manager().getFinishing_uploads_queue().add(this);
}
File f = new File(_file_name);
HashMap<String, Object> upload_res;
@ -897,14 +892,6 @@ public final class Upload implements Transference, Runnable, SecureSingleThreadN
_status_error = true;
}
} else if (_fatal_error != null) {
getView().hideAllExceptStatus();
getView().printStatusError(_fatal_error);
_status_error = true;
} else {
getView().hideAllExceptStatus();
@ -916,12 +903,6 @@ public final class Upload implements Transference, Runnable, SecureSingleThreadN
_status_error = true;
}
} else if (_fatal_error != null) {
getView().hideAllExceptStatus();
getView().printStatusError(_fatal_error);
_status_error = true;
} else {
getView().hideAllExceptStatus();
@ -932,14 +913,6 @@ public final class Upload implements Transference, Runnable, SecureSingleThreadN
_status_error = true;
}
} else if (_fatal_error != null) {
getView().hideAllExceptStatus();
_exit_message = _fatal_error;
getView().printStatusError(_fatal_error);
_status_error = true;
} else {
getView().hideAllExceptStatus();
@ -948,7 +921,6 @@ public final class Upload implements Transference, Runnable, SecureSingleThreadN
getView().printStatusError(_exit_message);
_status_error = true;
}
if (!_exit) {
@ -986,6 +958,8 @@ public final class Upload implements Transference, Runnable, SecureSingleThreadN
}
});
getMain_panel().getUpload_manager().getFinishing_uploads_queue().remove(this);
Logger.getLogger(getClass().getName()).log(Level.INFO, "{0} Uploader finished with message -> {1} {2}...", new Object[]{Thread.currentThread().getName(), _exit_message, this.getFile_name()});
Logger.getLogger(getClass().getName()).log(Level.INFO, "{0} Uploader {1} BYE BYE", new Object[]{Thread.currentThread().getName(), this.getFile_name()});
@ -1071,14 +1045,6 @@ public final class Upload implements Transference, Runnable, SecureSingleThreadN
}
}
public void emergencyStopUploader(String reason) {
if (!_exit && _fatal_error == null) {
_fatal_error = reason != null ? reason : "FATAL ERROR!";
stopUploader();
}
}
public long nextChunkId() {
synchronized (_chunkid_lock) {
@ -1100,6 +1066,7 @@ public final class Upload implements Transference, Runnable, SecureSingleThreadN
public void stopUploader() {
if (!_exit) {
_exit = true;
try {
@ -1147,8 +1114,9 @@ public final class Upload implements Transference, Runnable, SecureSingleThreadN
}
public long calculateLastUploadedChunk(long bytes_read) {
if (bytes_read > 3584 * 1024) {
return 7 + (long) Math.ceil((bytes_read - 3584 * 1024) / (1024 * 1024));
return 7 + (long) Math.ceil((float) (bytes_read - 3584 * 1024) / (1024 * 1024));
} else {
int i = 0, tot = 0;

View File

@ -128,6 +128,10 @@ public final class UploadMACGenerator implements Runnable, SecureSingleThreadNot
_upload.getView().getPause_button().setEnabled(false);
if (!_upload.getMain_panel().getUpload_manager().getFinishing_uploads_queue().contains(_upload)) {
_upload.getMain_panel().getUpload_manager().getFinishing_uploads_queue().add(_upload);
}
upload_workers_finish = true;
}
@ -174,14 +178,15 @@ public final class UploadMACGenerator implements Runnable, SecureSingleThreadNot
_chunk_queue.remove(chunk.getId());
new_chunk = true;
}
if (!upload_workers_finish && new_chunk) {
temp_file_data = (String.valueOf(_bytes_read) + "|" + Bin2BASE64(i32a2bin(file_mac)));
Logger.getLogger(getClass().getName()).log(Level.INFO, "{0} Macgenerator -> {1} {2} {3} {4}", new Object[]{Thread.currentThread().getName(), temp_file_data, _upload.calculateLastUploadedChunk(_bytes_read), _last_chunk_id_read, this.getUpload().getFile_name()});
}
if (!upload_workers_finish && new_chunk) {
DBTools.updateUploadProgres(_upload.getFile_name(), _upload.getMa().getEmail(), _bytes_read, Bin2BASE64(i32a2bin(file_mac)));
new_chunk = false;

View File

@ -6,6 +6,7 @@ import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.concurrent.ConcurrentLinkedQueue;
import static java.util.logging.Level.SEVERE;
import java.util.logging.Logger;
import static megabasterd.MiscTools.*;
@ -16,10 +17,16 @@ import static megabasterd.MiscTools.*;
*/
public final class UploadManager extends TransferenceManager {
private final ConcurrentLinkedQueue<Upload> _finishing_uploads_queue;
public ConcurrentLinkedQueue<Upload> getFinishing_uploads_queue() {
return _finishing_uploads_queue;
}
public UploadManager(MainPanel main_panel) {
super(main_panel, main_panel.getMax_ul(), main_panel.getView().getStatus_up_label(), main_panel.getView().getjPanel_scroll_up(), main_panel.getView().getClose_all_finished_up_button(), main_panel.getView().getPause_all_up_button(), main_panel.getView().getClean_all_up_menu());
_finishing_uploads_queue = new ConcurrentLinkedQueue<>();
}
@Override