Refactoring

1.5
This commit is contained in:
tonikelope 2016-10-01 16:00:53 +02:00
parent 085d11bec2
commit c8ae3bc4be
21 changed files with 286 additions and 365 deletions

View File

@ -70,7 +70,7 @@ public final class Chunk {
private long calculateSize(long file_size)
{
long chunk_size = (_id>=1 && _id<=7)?_id*128*1_024:1_024*1_024;
long chunk_size = (_id>=1 && _id<=7)?_id*128*1024:1024*1024;
if(_offset + chunk_size > file_size) {
chunk_size = file_size - _offset;
@ -81,9 +81,9 @@ public final class Chunk {
private long calculateOffset()
{
long[] offs = {0, 128, 384, 768, 1_280, 1_920, 2_688};
long[] offs = {0, 128, 384, 768, 1280, 1920, 2688};
return (_id<=7?offs[(int)_id-1]:(3_584 + (_id-8)*1_024))*1_024;
return (_id<=7?offs[(int)_id-1]:(3584 + (_id-8)*1024))*1024;
}
}

View File

@ -180,7 +180,7 @@ public class ChunkDownloader implements Runnable, SecureNotifiable {
conta_error++;
Thread.sleep(getWaitTimeExpBackOff(conta_error)*1_000);
Thread.sleep(getWaitTimeExpBackOff(conta_error)*1000);
} else if(!error) {

View File

@ -114,7 +114,7 @@ public class ChunkDownloaderMono extends ChunkDownloader {
conta_error++;
Thread.sleep(getWaitTimeExpBackOff(conta_error)*1_000);
Thread.sleep(getWaitTimeExpBackOff(conta_error)*1000);
} else if(!error) {

View File

@ -235,7 +235,7 @@ public final class ChunkUploader implements Runnable, SecureNotifiable {
if(!_exit) {
Thread.sleep(getWaitTimeExpBackOff(conta_error)*1_000);
Thread.sleep(getWaitTimeExpBackOff(conta_error)*1000);
}
} else if(!error) {

View File

@ -128,7 +128,7 @@ public final class ChunkWriter implements Runnable, SecureNotifiable {
{
Chunk current_chunk;
CipherInputStream cis;
byte[] buffer = new byte[16*1_024];
byte[] buffer = new byte[16*1024];
int reads;
try {
@ -186,9 +186,9 @@ public final class ChunkWriter implements Runnable, SecureNotifiable {
private long calculateLastWrittenChunk(long temp_file_size)
{
if(temp_file_size > 3_584*1_024)
if(temp_file_size > 3584*1024)
{
return 7 + (long)Math.ceil((temp_file_size - 3_584*1_024)/(1_024*1_024));
return 7 + (long)Math.ceil((temp_file_size - 3584*1024)/(1024*1024));
}
else
{
@ -197,7 +197,7 @@ public final class ChunkWriter implements Runnable, SecureNotifiable {
while(tot < temp_file_size)
{
i++;
tot+=i*128*1_024;
tot+=i*128*1024;
}
return i;

View File

@ -286,11 +286,11 @@ public final class CryptTools {
public static int[] MEGAPrepareMasterKey(int[] key) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException {
int[] pkey = {0x93C4_67E3, 0x7DB0_C7A4, 0xD1BE_3F81, 0x0152_CB56};
int[] pkey = {0x93C467E3, 0x7DB0_C7A4, 0xD1BE_3F81, 0x0152_CB56};
int[] iv = {0,0,0,0};
for(int r=0; r<0x1_0000; r++) {
for(int r=0; r<0x10000; r++) {
for(int j=0; j<key.length; j+=4) {

View File

@ -921,7 +921,7 @@ public final class Download implements Transference, Runnable, SecureNotifiable
for(long i=getWaitTimeExpBackOff(api_error_retry++); i>0 && !_exit; i--)
{
try {
sleep(1_000);
sleep(1000);
} catch (InterruptedException ex) {}
}
}
@ -1013,7 +1013,7 @@ public final class Download implements Transference, Runnable, SecureNotifiable
long chunk_id=1;
long tot=0L;
byte[] chunk_buffer = new byte[16*1_024];
byte[] chunk_buffer = new byte[16*1024];
byte[] byte_block = new byte[16];
int[] int_block;
int re, reads, to_read;
@ -1135,9 +1135,9 @@ public final class Download implements Transference, Runnable, SecureNotifiable
public long calculateMaxTempFileSize(long size)
{
if(size > 3_584*1_024)
if(size > 3584*1024)
{
long reminder = (size - 3_584*1_024)%(1_024*1_024);
long reminder = (size - 3584*1024)%(1024*1024);
return reminder==0?size:(size - reminder);
}
@ -1148,10 +1148,10 @@ public final class Download implements Transference, Runnable, SecureNotifiable
while(tot < size)
{
i++;
tot+=i*128*1_024;
tot+=i*128*1024;
}
return tot==size?size:(tot-i*128*1_024);
return tot==size?size:(tot-i*128*1024);
}
}
@ -1238,7 +1238,7 @@ public final class Download implements Transference, Runnable, SecureNotifiable
}
try {
sleep(1_000);
sleep(1000);
} catch (InterruptedException ex2) {}
}
}
@ -1325,7 +1325,7 @@ public final class Download implements Transference, Runnable, SecureNotifiable
}
try {
sleep(1_000);
sleep(1000);
} catch (InterruptedException ex2) {}
}
}

View File

@ -6,19 +6,19 @@ import static java.util.logging.Level.SEVERE;
import static java.util.logging.Logger.getLogger;
import static megabasterd.DBTools.deleteDownload;
import static megabasterd.MainPanel.THREAD_POOL;
import static megabasterd.MiscTools.swingReflectionInvoke;
public final class DownloadManager extends TransferenceManager {
public DownloadManager(MainPanel main_panel) {
super(main_panel, main_panel.getView().getjPanel_scroll_down());
super(main_panel, main_panel.getMax_dl(), main_panel.getView().getStatus_down_label(), main_panel.getView().getjPanel_scroll_down(), main_panel.getView().getClose_all_finished_down_button(), main_panel.getView().getPause_all_down_button(), main_panel.getView().getClean_all_down_menu());
}
public void remove(Download download) {
@Override
public void remove(Transference download) {
getScroll_panel().remove(download.getView());
getScroll_panel().remove(((Download)download).getView());
getTransference_start_queue().remove(download);
@ -26,10 +26,10 @@ public final class DownloadManager extends TransferenceManager {
getTransference_finished_queue().remove(download);
if(download.isProvision_ok()) {
if(((Download)download).isProvision_ok()) {
try {
deleteDownload(download.getUrl());
deleteDownload(((Download)download).getUrl());
} catch (SQLException ex) {
getLogger(DownloadManager.class.getName()).log(SEVERE, null, ex);
}
@ -38,9 +38,44 @@ public final class DownloadManager extends TransferenceManager {
secureNotify();
}
public void provision(Download download, boolean retry) throws MegaAPIException, MegaCrypterAPIException
@Override
public void provision(final Transference download)
{
getScroll_panel().add(download.getView());
getScroll_panel().add(((Download)download).getView());
try {
this._provision((Download)download, false);
secureNotify();
} catch (MegaAPIException | MegaCrypterAPIException ex) {
System.out.println("Provision failed! Retrying in separated thread...");
final DownloadManager tthis = this;
THREAD_POOL.execute(new Runnable(){
@Override
public void run(){
try {
tthis._provision((Download)download, true);
} catch (MegaAPIException | MegaCrypterAPIException ex1) {
getLogger(DownloadManager.class.getName()).log(SEVERE, null, ex1);
}
secureNotify();
}});
}
}
private void _provision(Download download, boolean retry) throws MegaAPIException, MegaCrypterAPIException {
download.provisionIt(retry);
@ -64,134 +99,11 @@ public final class DownloadManager extends TransferenceManager {
getScroll_panel().add((Component)down.getView());
}
}
} else {
getTransference_finished_queue().add(download);
}
secureNotify();
}
@Override
public void run() {
final DownloadManager tthis = this;
while(true)
{
if(!isProvisioning_transferences() && !getTransference_provision_queue().isEmpty())
{
setProvisioning_transferences(true);
THREAD_POOL.execute(new Runnable(){
@Override
public void run(){
while(!getTransference_provision_queue().isEmpty())
{
final Download download = (Download)getTransference_provision_queue().poll();
if(download != null) {
try{
provision(download, false);
}catch (MegaAPIException | MegaCrypterAPIException ex) {
System.out.println("Provision failed! Retrying in separated thread...");
getScroll_panel().remove(download.getView());
THREAD_POOL.execute(new Runnable(){
@Override
public void run(){
try {
tthis.provision(download, true);
} catch (MegaAPIException | MegaCrypterAPIException ex1) {
getLogger(DownloadManager.class.getName()).log(SEVERE, null, ex1);
}
}});
}
}
}
tthis.setProvisioning_transferences(false);
tthis.secureNotify();
}});
}
if(!isRemoving_transferences() && !getTransference_remove_queue().isEmpty()) {
setRemoving_transferences(true);
THREAD_POOL.execute(new Runnable(){
@Override
public void run(){
while(!getTransference_remove_queue().isEmpty()) {
Download download = (Download)getTransference_remove_queue().poll();
if(download != null) {
remove(download);
}
}
tthis.setRemoving_transferences(false);
tthis.secureNotify();
}});
}
if(!isStarting_transferences() && !getTransference_start_queue().isEmpty() && getTransference_running_list().size() < getMain_panel().getMax_dl())
{
setStarting_transferences(true);
THREAD_POOL.execute(new Runnable(){
@Override
public void run(){
while(!getTransference_start_queue().isEmpty() && getTransference_running_list().size() < getMain_panel().getMax_dl()) {
Download download = (Download)getTransference_start_queue().poll();
if(download != null) {
start(download);
}
}
tthis.setStarting_transferences(false);
tthis.secureNotify();
}});
}
secureWait();
checkButtonsAndMenus(getMain_panel().getView().getClose_all_finished_down_button(), getMain_panel().getView().getPause_all_down_button(), getMain_panel().getView().getClean_all_down_menu());
if(!this.getMain_panel().getView().isPre_processing_downloads()) {
swingReflectionInvoke("setText", getMain_panel().getView().getStatus_down_label(), getStatus());
}
}
}
}

View File

@ -20,7 +20,7 @@ import static megabasterd.MiscTools.swingReflectionInvoke;
public final class KissVideoStreamServer {
public static final int TIMEOUT=30_000;
public static final int TIMEOUT=30000;
public static final int EXP_BACKOFF_BASE=2;
public static final int EXP_BACKOFF_SECS_RETRY=1;
public static final int EXP_BACKOFF_MAX_WAIT_TIME=128;
@ -169,7 +169,7 @@ public final class KissVideoStreamServer {
}
try {
Thread.sleep(1_000);
Thread.sleep(1000);
} catch (InterruptedException ex) {}
}
}
@ -231,7 +231,7 @@ public final class KissVideoStreamServer {
}
try {
Thread.sleep(1_000);
Thread.sleep(1000);
} catch (InterruptedException ex) {}
}
}
@ -265,7 +265,7 @@ public final class KissVideoStreamServer {
}
try {
Thread.sleep(1_000);
Thread.sleep(1000);
} catch (InterruptedException ex) {}
}
}

View File

@ -158,7 +158,7 @@ public final class KissVideoStreamServerHandler implements HttpHandler {
resheaders.add("Connection", "close");
byte[] buffer = new byte[16*1_024];
byte[] buffer = new byte[16*1024];
int reads;
@ -287,7 +287,7 @@ public final class KissVideoStreamServerHandler implements HttpHandler {
_httpserver.getStreaming().remove(Thread.currentThread());
try {
Thread.sleep(1_000);
Thread.sleep(1000);
} catch (InterruptedException ex) {
getLogger(KissVideoStreamServerHandler.class.getName()).log(Level.SEVERE, null, ex);
}

View File

@ -57,12 +57,13 @@ import static megabasterd.Transference.MAX_TRANSFERENCE_SPEED_DEFAULT;
*/
public final class MainPanel {
public static final String VERSION="1.4";
public static final String USER_AGENT="Mozilla/5.0 (X11; Linux x86_64; rv:48.0) Gecko/20100101 Firefox/48.0";
public static final int CONNECTION_TIMEOUT = 30_000;
public static final int THROTTLE_SLICE_SIZE=16*1_024;
public static final int STREAMER_PORT = 1_337;
public static final int WATCHDOG_PORT = 1_338;
public static final String VERSION="1.5";
public static final String USER_AGENT="Mozilla/5.0 (X11; Linux x8664; rv:48.0) Gecko/20100101 Firefox/48.0";
public static final int CONNECTION_TIMEOUT = 30000;
public static final int THROTTLE_SLICE_SIZE=16*1024;
public static final int STREAMER_PORT = 1337;
public static final int WATCHDOG_PORT = 1338;
public static final String ICON_FILE = "pica_roja.png";
public static final ExecutorService THREAD_POOL = newCachedThreadPool();
public static final Font FONT_DEFAULT = createAndRegisterFont("Gochi.ttf");
@ -129,7 +130,7 @@ public final class MainPanel {
THREAD_POOL.execute((_upload_manager = new UploadManager(this)));
THREAD_POOL.execute((_stream_supervisor = new StreamThrottlerSupervisor(_limit_download_speed?_max_dl_speed*1_024:0, _limit_upload_speed?_max_up_speed*1_024:0, THROTTLE_SLICE_SIZE)));
THREAD_POOL.execute((_stream_supervisor = new StreamThrottlerSupervisor(_limit_download_speed?_max_dl_speed*1024:0, _limit_upload_speed?_max_up_speed*1024:0, THROTTLE_SLICE_SIZE)));
THREAD_POOL.execute((_clipboardspy = new ClipboardSpy()));
@ -490,7 +491,7 @@ public final class MainPanel {
Toolkit toolkit = getDefaultToolkit();
Image image = toolkit.getImage(getClass().getResource("pica_roja.png"));
Image image = toolkit.getImage(getClass().getResource(ICON_FILE));
PopupMenu menu = new PopupMenu();

View File

@ -177,7 +177,7 @@
<Group type="102" alignment="1" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="1" attributes="0">
<Component id="jTabbedPane1" pref="796" max="32767" attributes="0"/>
<Component id="jTabbedPane1" max="32767" attributes="0"/>
<Group type="102" attributes="0">
<Component id="kiss_server_status" max="32767" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
@ -250,9 +250,8 @@
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="status_down_label" max="32767" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="close_all_finished_down_button" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="6" max="-2" attributes="0"/>
</Group>
<Component id="jScrollPane_down" alignment="0" max="32767" attributes="0"/>
</Group>
@ -358,9 +357,8 @@
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="status_up_label" max="32767" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="close_all_finished_up_button" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="6" max="-2" attributes="0"/>
</Group>
<Component id="jScrollPane_up" alignment="0" max="32767" attributes="0"/>
</Group>

View File

@ -28,6 +28,7 @@ import javax.swing.JTabbedPane;
import static megabasterd.CryptTools.decryptMegaDownloaderLink;
import static megabasterd.DBTools.deleteMegaAccount;
import static megabasterd.MainPanel.FONT_DEFAULT;
import static megabasterd.MainPanel.ICON_FILE;
import static megabasterd.MainPanel.THREAD_POOL;
import static megabasterd.MainPanel.VERSION;
import static megabasterd.MiscTools.BASE642Bin;
@ -43,17 +44,8 @@ import static megabasterd.MiscTools.updateFont;
public final class MainPanelView extends javax.swing.JFrame {
private final MainPanel _main_panel;
private volatile boolean _pre_processing_downloads;
private volatile boolean _pre_processing_uploads;
public boolean isPre_processing_downloads() {
return _pre_processing_downloads;
}
public boolean isPre_processing_uploads() {
return _pre_processing_uploads;
}
public JLabel getKiss_server_status() {
return kiss_server_status;
@ -103,7 +95,7 @@ public final class MainPanelView extends javax.swing.JFrame {
return pause_all_down_button;
}
public JButton getPause_all_up() {
public JButton getPause_all_up_button() {
return pause_all_up_button;
}
@ -133,7 +125,7 @@ public final class MainPanelView extends javax.swing.JFrame {
setTitle("MegaBasterd " + VERSION);
setIconImage(new ImageIcon(getClass().getResource("pica_roja.png")).getImage());
setIconImage(new ImageIcon(getClass().getResource(ICON_FILE)).getImage());
updateFont(file_menu, FONT_DEFAULT, PLAIN);
updateFont(edit_menu, FONT_DEFAULT, PLAIN);
@ -272,9 +264,8 @@ public final class MainPanelView extends javax.swing.JFrame {
.addGroup(downloads_panelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(status_down_label, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(close_all_finished_down_button)
.addGap(6, 6, 6))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(close_all_finished_down_button))
.addComponent(jScrollPane_down)
);
downloads_panelLayout.setVerticalGroup(
@ -334,9 +325,8 @@ public final class MainPanelView extends javax.swing.JFrame {
.addGroup(uploads_panelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(status_up_label, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(close_all_finished_up_button)
.addGap(6, 6, 6))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(close_all_finished_up_button))
.addComponent(jScrollPane_up)
);
uploads_panelLayout.setVerticalGroup(
@ -470,7 +460,7 @@ public final class MainPanelView extends javax.swing.JFrame {
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 796, Short.MAX_VALUE)
.addComponent(jTabbedPane1)
.addGroup(layout.createSequentialGroup()
.addComponent(kiss_server_status, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(18, 18, 18)
@ -494,8 +484,6 @@ public final class MainPanelView extends javax.swing.JFrame {
private void new_download_menuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_new_download_menuActionPerformed
_pre_processing_downloads = true;
swingReflectionInvoke("setEnabled", new_download_menu, false);
final LinkGrabberDialog dialog = new LinkGrabberDialog(this, true, _main_panel.getDefault_download_path(), _main_panel.getClipboardspy());
@ -514,13 +502,15 @@ public final class MainPanelView extends javax.swing.JFrame {
if(dialog.isDownload()) {
final MainPanelView main = this;
getMain_panel().getDownload_manager().setPreprocessing_transferences(true);
final MainPanelView tthis = this;
THREAD_POOL.execute(new Runnable(){
@Override
public void run() {
swingReflectionInvoke("setText", main.status_down_label, "Pre-processing downloads, please wait...");
swingReflectionInvoke("setText", tthis.status_down_label, "Pre-processing downloads, please wait...");
Set<String> urls = new HashSet(findAllRegex("(?:https?|mega)://[^/]*/(#.*?)?!.+![^\r\n]+", dialog.getLinks_textarea().getText(), 0));
@ -549,11 +539,11 @@ public final class MainPanelView extends javax.swing.JFrame {
if(findFirstRegex("#F!", url, 0) != null) {
FolderLinkDialog fdialog = new FolderLinkDialog(main, true, url);
FolderLinkDialog fdialog = new FolderLinkDialog(tthis, true, url);
if(!fdialog.isMega_error()) {
swingReflectionInvokeAndWait("setLocationRelativeTo", fdialog, main);
swingReflectionInvokeAndWait("setLocationRelativeTo", fdialog, tthis);
swingReflectionInvokeAndWait("setVisible", fdialog, true);
@ -565,9 +555,9 @@ public final class MainPanelView extends javax.swing.JFrame {
for(HashMap folder_link:folder_links) {
download = new Download(main.getMain_panel(), (String)folder_link.get("url"), dl_path, (String)folder_link.get("filename"), (String)folder_link.get("filekey"), (long)folder_link.get("filesize"), null, null, main.getMain_panel().isUse_slots_down(), main.getMain_panel().getDefault_slots_down(), true);
download = new Download(tthis.getMain_panel(), (String)folder_link.get("url"), dl_path, (String)folder_link.get("filename"), (String)folder_link.get("filekey"), (long)folder_link.get("filesize"), null, null, tthis.getMain_panel().isUse_slots_down(), tthis.getMain_panel().getDefault_slots_down(), true);
main.getMain_panel().getDownload_manager().getTransference_provision_queue().add(download);
tthis.getMain_panel().getDownload_manager().getTransference_provision_queue().add(download);
conta_downloads++;
}
@ -580,9 +570,9 @@ public final class MainPanelView extends javax.swing.JFrame {
} else {
download = new Download(main.getMain_panel(), url, dl_path, null, null, null, null, null, main.getMain_panel().isUse_slots_down(), main.getMain_panel().getDefault_slots_down(), false);
download = new Download(tthis.getMain_panel(), url, dl_path, null, null, null, null, null, tthis.getMain_panel().isUse_slots_down(), tthis.getMain_panel().getDefault_slots_down(), false);
main.getMain_panel().getDownload_manager().getTransference_provision_queue().add(download);
tthis.getMain_panel().getDownload_manager().getTransference_provision_queue().add(download);
conta_downloads++;
}
@ -590,23 +580,27 @@ public final class MainPanelView extends javax.swing.JFrame {
if(conta_downloads > 0) {
swingReflectionInvoke("setText", main.status_down_label, "Starting downloads provisioning, please wait...");
swingReflectionInvoke("setText", tthis.status_down_label, "Starting downloads provisioning, please wait...");
main.getMain_panel().getDownload_manager().secureNotify();
tthis.getMain_panel().getDownload_manager().secureNotify();
}
}
swingReflectionInvoke("setText", main.status_down_label, "");
}});
}
swingReflectionInvoke("setText", tthis.status_down_label, "");
swingReflectionInvoke("setEnabled", new_download_menu, true);
dialog.dispose();
tthis.getMain_panel().getDownload_manager().setPreprocessing_transferences(false);
_pre_processing_downloads = false;
}});
} else {
swingReflectionInvoke("setEnabled", new_download_menu, true);
}
dialog.dispose();
}//GEN-LAST:event_new_download_menuActionPerformed
@ -636,9 +630,9 @@ public final class MainPanelView extends javax.swing.JFrame {
_main_panel.loadUserSettings();
_main_panel.getStream_supervisor().setMaxBytesPerSecInput(_main_panel.isLimit_download_speed()?_main_panel.getMax_dl_speed()*1_024:0);
_main_panel.getStream_supervisor().setMaxBytesPerSecInput(_main_panel.isLimit_download_speed()?_main_panel.getMax_dl_speed()*1024:0);
_main_panel.getStream_supervisor().setMaxBytesPerSecOutput( _main_panel.isLimit_upload_speed()?_main_panel.getMax_up_speed()*1_024:0);
_main_panel.getStream_supervisor().setMaxBytesPerSecOutput( _main_panel.isLimit_upload_speed()?_main_panel.getMax_up_speed()*1024:0);
swingReflectionInvoke("setForeground", global_speed_down_label, _main_panel.isLimit_download_speed()?new Color(255,0,0):new Color(0,128,255));
@ -716,19 +710,19 @@ public final class MainPanelView extends javax.swing.JFrame {
private void new_upload_menuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_new_upload_menuActionPerformed
_pre_processing_uploads = true;
final FileGrabberDialog dialog = new FileGrabberDialog(this,true);
try{
swingReflectionInvoke("setEnabled", new_upload_menu, false);
final FileGrabberDialog dialog = new FileGrabberDialog(this,true);
swingReflectionInvokeAndWait("setLocationRelativeTo", dialog, this);
swingReflectionInvokeAndWait("setVisible", dialog, true);
if(dialog.isUpload() && dialog.getFiles().size() > 0) {
try {
getMain_panel().getUpload_manager().setPreprocessing_transferences(true);
swingReflectionInvoke("setText", status_up_label, "Pre-processing uploads, please wait...");
@ -740,8 +734,10 @@ public final class MainPanelView extends javax.swing.JFrame {
final String dir_name=dialog.getDir_name_textfield().getText();
final int[] mega_aes_pass = bin2i32a(BASE642Bin((String)data_account.get("password_aes")));
final String mega_user_hash = (String)data_account.get("user_hash");
final ArrayList<File> files = dialog.getFiles();
@ -831,20 +827,22 @@ public final class MainPanelView extends javax.swing.JFrame {
getLogger(MainPanelView.class.getName()).log(SEVERE, null, ex);
}
}
});
} catch (Exception ex) {
getLogger(MainPanelView.class.getName()).log(SEVERE, null, ex);
}
}
swingReflectionInvoke("setEnabled", new_upload_menu, true);
main.getMain_panel().getUpload_manager().setPreprocessing_transferences(false);
}
});
} else {
swingReflectionInvoke("setEnabled", new_upload_menu, true);
}
}catch(Exception ex) {}
dialog.dispose();
_pre_processing_uploads = false;
}//GEN-LAST:event_new_upload_menuActionPerformed
private void close_all_finished_up_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_close_all_finished_up_buttonActionPerformed

View File

@ -342,7 +342,7 @@ public final class MegaAPI {
ByteArrayOutputStream byte_res = new ByteArrayOutputStream();
byte[] buffer = new byte[16*1_024];
byte[] buffer = new byte[16*1024];
int reads;

View File

@ -60,7 +60,7 @@ public final class MegaCrypterAPI {
ByteArrayOutputStream byte_res = new ByteArrayOutputStream();
byte[] buffer = new byte[16*1_024];
byte[] buffer = new byte[16*1024];
int reads;

View File

@ -534,7 +534,7 @@ public final class MiscTools {
ByteArrayOutputStream byte_res = new ByteArrayOutputStream();
byte[] buffer = new byte[16*1_024];
byte[] buffer = new byte[16*1024];
int reads;
@ -554,7 +554,7 @@ public final class MiscTools {
bytes = Math.max(bytes, 0L);
int pow = Math.min((int)((bytes>0L?Math.log(bytes):0) / Math.log(1_024)), units.length - 1);
int pow = Math.min((int)((bytes>0L?Math.log(bytes):0) / Math.log(1024)), units.length - 1);
Double bytes_double = (double)bytes/(1 << (10 * pow));

View File

@ -7,7 +7,7 @@ import static megabasterd.MiscTools.formatBytes;
public final class SpeedMeter implements Runnable, SecureNotifiable
{
public static final int SLEEP = 3_000;
public static final int SLEEP = 3000;
private long _progress;
private final Transference _transference;
private final GlobalSpeedMeter _gspeed;
@ -120,7 +120,7 @@ public final class SpeedMeter implements Runnable, SecureNotifiable
} else if( p > _progress) {
double sleep_time = ((double)SpeedMeter.SLEEP*(no_data_count+1))/1_000 ;
double sleep_time = ((double)SpeedMeter.SLEEP*(no_data_count+1))/1000 ;
double current_speed = (p - _progress) / sleep_time;

View File

@ -147,7 +147,7 @@ public final class StreamThrottlerSupervisor implements Runnable, SecureNotifiab
secureNotifyAll();
try {
Thread.sleep(1_000);
Thread.sleep(1000);
} catch (InterruptedException ex) {
getLogger(StreamThrottlerSupervisor.class.getName()).log(Level.SEVERE, null, ex);
}

View File

@ -7,6 +7,7 @@ import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.logging.Level;
import static java.util.logging.Logger.getLogger;
import javax.swing.JPanel;
import static megabasterd.MainPanel.THREAD_POOL;
import static megabasterd.MiscTools.swingReflectionInvoke;
/**
@ -21,12 +22,22 @@ abstract public class TransferenceManager implements Runnable, SecureNotifiable
private final ConcurrentLinkedQueue<Transference> _transference_finished_queue;
private final ConcurrentLinkedQueue<Transference> _transference_running_list;
private final javax.swing.JPanel _scroll_panel;
private final javax.swing.JLabel _status;
private final javax.swing.JButton _close_all_button;
private final javax.swing.JButton _pause_all_button;
private final javax.swing.MenuElement _clean_all_menu;
private final int _max_running_trans;
private final MainPanel _main_panel;
private final Object _secure_notify_lock;
private boolean _notified;
private volatile boolean _removing_transferences;
private volatile boolean _provisioning_transferences;
private volatile boolean _starting_transferences;
private volatile boolean _preprocessing_transferences;
abstract public void provision(Transference transference);
abstract public void remove(Transference transference);
public boolean isRemoving_transferences() {
return _removing_transferences;
@ -52,13 +63,23 @@ abstract public class TransferenceManager implements Runnable, SecureNotifiable
_starting_transferences = starting;
}
public TransferenceManager(MainPanel main_panel, javax.swing.JPanel scroll_panel) {
public void setPreprocessing_transferences(boolean preprocessing) {
_preprocessing_transferences = preprocessing;
}
public TransferenceManager(MainPanel main_panel, int max_running_trans, javax.swing.JLabel status, javax.swing.JPanel scroll_panel, javax.swing.JButton close_all_button, javax.swing.JButton pause_all_button, javax.swing.MenuElement clean_all_menu) {
_notified = false;
_removing_transferences = false;
_provisioning_transferences = false;
_starting_transferences=false;
_preprocessing_transferences=false;
_main_panel = main_panel;
_max_running_trans = max_running_trans;
_scroll_panel = scroll_panel;
_status = status;
_close_all_button = close_all_button;
_pause_all_button = pause_all_button;
_clean_all_menu = clean_all_menu;
_secure_notify_lock = new Object();
_transference_waitstart_queue = new ConcurrentLinkedQueue();
_transference_provision_queue = new ConcurrentLinkedQueue();
@ -193,8 +214,7 @@ abstract public class TransferenceManager implements Runnable, SecureNotifiable
_transference_waitstart_queue.addAll(trans_list);
}
public void checkButtonsAndMenus(javax.swing.JButton close_all_finished_button, javax.swing.JButton pause_all_button,
javax.swing.MenuElement clean_all_waiting_trans_menu) {
private void updateView() {
if(!_transference_running_list.isEmpty()) {
@ -208,29 +228,32 @@ abstract public class TransferenceManager implements Runnable, SecureNotifiable
}
}
swingReflectionInvoke("setVisible", pause_all_button, show_pause_all);
swingReflectionInvoke("setVisible", _pause_all_button, show_pause_all);
} else {
swingReflectionInvoke("setVisible", pause_all_button, false);
swingReflectionInvoke("setVisible", _pause_all_button, false);
}
swingReflectionInvoke("setEnabled", clean_all_waiting_trans_menu, !_transference_waitstart_queue.isEmpty());
swingReflectionInvoke("setEnabled", _clean_all_menu, !_transference_waitstart_queue.isEmpty());
if(!_transference_finished_queue.isEmpty()) {
swingReflectionInvoke("setText", close_all_finished_button, "Close all finished ("+_transference_finished_queue.size()+")" );
swingReflectionInvoke("setText", _close_all_button, "Close all finished ("+_transference_finished_queue.size()+")" );
swingReflectionInvoke("setVisible", close_all_finished_button, true);
swingReflectionInvoke("setVisible", _close_all_button, true);
} else {
swingReflectionInvoke("setVisible", close_all_finished_button, false);
swingReflectionInvoke("setVisible", _close_all_button, false);
}
if(!_preprocessing_transferences) {
swingReflectionInvoke("setText", _status, genStatus());
}
}
public String getStatus() {
private String genStatus() {
int prov = _transference_provision_queue.size();
@ -242,7 +265,99 @@ abstract public class TransferenceManager implements Runnable, SecureNotifiable
int finish = _transference_finished_queue.size();
return (prov+rem+wait+run+finish > 0)?"Prov("+prov+") / Rem("+rem+") / Wait("+wait+") / Run("+run+") / Finish("+finish+")":"";
return (prov+rem+wait+run+finish > 0)?"Prov: "+prov+" / Rem: "+rem+" / Wait: "+wait+" / Run: "+run+" / Finish: "+finish:"";
}
@Override
public void run() {
final TransferenceManager tthis = this;
while(true)
{
if(!isProvisioning_transferences() && !getTransference_provision_queue().isEmpty())
{
setProvisioning_transferences(true);
THREAD_POOL.execute(new Runnable(){
@Override
public void run(){
while(!getTransference_provision_queue().isEmpty())
{
final Transference transference = getTransference_provision_queue().poll();
if(transference != null) {
provision(transference);
}
}
tthis.setProvisioning_transferences(false);
tthis.secureNotify();
}});
}
if(!isRemoving_transferences() && !getTransference_remove_queue().isEmpty()) {
setRemoving_transferences(true);
THREAD_POOL.execute(new Runnable(){
@Override
public void run(){
while(!getTransference_remove_queue().isEmpty()) {
Transference transference = getTransference_remove_queue().poll();
if(transference != null) {
remove(transference);
}
}
tthis.setRemoving_transferences(false);
tthis.secureNotify();
}});
}
if(!isStarting_transferences() && !getTransference_start_queue().isEmpty() && getTransference_running_list().size() < _max_running_trans)
{
setStarting_transferences(true);
THREAD_POOL.execute(new Runnable(){
@Override
public void run(){
while(!getTransference_start_queue().isEmpty() && getTransference_running_list().size() < _max_running_trans) {
Transference transference = getTransference_start_queue().poll();
if(transference != null) {
start(transference);
}
}
tthis.setStarting_transferences(false);
tthis.secureNotify();
}});
}
secureWait();
updateView();
}
}
}

View File

@ -6,9 +6,7 @@ import java.sql.SQLException;
import static java.util.logging.Level.SEVERE;
import static java.util.logging.Logger.getLogger;
import static megabasterd.DBTools.deleteUpload;
import static megabasterd.MainPanel.THREAD_POOL;
import static megabasterd.MiscTools.HashString;
import static megabasterd.MiscTools.swingReflectionInvoke;
@ -20,16 +18,18 @@ public final class UploadManager extends TransferenceManager {
public UploadManager(MainPanel main_panel) {
super(main_panel, main_panel.getView().getjPanel_scroll_up());
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());
}
public void provision(Upload upload)
@Override
public void provision(Transference upload)
{
getScroll_panel().add(upload.getView());
getScroll_panel().add(((Upload)upload).getView());
upload.provisionIt();
((Upload)upload).provisionIt();
if(upload.isProvision_ok()) {
if(((Upload)upload).isProvision_ok()) {
getTransference_start_queue().add(upload);
@ -58,9 +58,10 @@ public final class UploadManager extends TransferenceManager {
}
public void remove(Upload upload) {
@Override
public void remove(Transference upload) {
getScroll_panel().remove(upload.getView());
getScroll_panel().remove(((Upload)upload).getView());
getTransference_start_queue().remove(upload);
@ -68,10 +69,10 @@ public final class UploadManager extends TransferenceManager {
getTransference_finished_queue().remove(upload);
if(upload.isProvision_ok()) {
if(((Upload)upload).isProvision_ok()) {
try {
deleteUpload(upload.getFile_name(), upload.getMa().getEmail());
deleteUpload(upload.getFile_name(), ((Upload)upload).getMa().getEmail());
} catch (SQLException ex) {
getLogger(UploadManager.class.getName()).log(SEVERE, null, ex);
}
@ -93,108 +94,4 @@ public final class UploadManager extends TransferenceManager {
secureNotify();
}
@Override
public void run() {
final UploadManager tthis = this;
while(true)
{
if(!isProvisioning_transferences() && !getTransference_provision_queue().isEmpty())
{
setProvisioning_transferences(true);
THREAD_POOL.execute(new Runnable(){
@Override
public void run(){
while(!getTransference_provision_queue().isEmpty())
{
Upload upload = (Upload)getTransference_provision_queue().poll();
if(upload != null) {
provision(upload);
}
}
tthis.setProvisioning_transferences(false);
tthis.secureNotify();
}});
}
if(!isRemoving_transferences() && !getTransference_remove_queue().isEmpty()){
setRemoving_transferences(true);
THREAD_POOL.execute(new Runnable(){
@Override
public void run(){
while(!getTransference_remove_queue().isEmpty()) {
Upload upload = (Upload)getTransference_remove_queue().poll();
if(upload != null) {
remove(upload);
}
}
tthis.setRemoving_transferences(false);
tthis.secureNotify();
}});
}
if(!isStarting_transferences() && !getTransference_start_queue().isEmpty() && getTransference_running_list().size() < getMain_panel().getMax_ul())
{
setStarting_transferences(true);
THREAD_POOL.execute(new Runnable(){
@Override
public void run(){
while(!getTransference_start_queue().isEmpty() && getTransference_running_list().size() < getMain_panel().getMax_ul()) {
Upload upload = (Upload)getTransference_start_queue().poll();
if(upload != null) {
start(upload);
}
}
tthis.setStarting_transferences(false);
tthis.secureNotify();
}
});
}
secureWait();
checkButtonsAndMenus(getMain_panel().getView().getClose_all_finished_up_button(), getMain_panel().getView().getPause_all_up(), getMain_panel().getView().getClean_all_up_menu());
if(!getMain_panel().getView().isPre_processing_uploads()) {
swingReflectionInvoke("setText", getMain_panel().getView().getStatus_up_label(), getStatus());
}
}
}
}

View File

@ -466,7 +466,7 @@ public final class UploadView extends javax.swing.JPanel implements Transference
swingReflectionInvoke("setText", pause_button, "PAUSE UPLOAD");
swingReflectionInvoke("setVisible", _upload.getMain_panel().getView().getPause_all_up(), true);
swingReflectionInvoke("setVisible", _upload.getMain_panel().getView().getPause_all_up_button(), true);
}
@Override