mirror of
https://github.com/tonikelope/megabasterd.git
synced 2025-05-03 08:04:27 +02:00
1.42
-Cleaning
This commit is contained in:
parent
fc274e9a1f
commit
6b5ac57673
@ -90,5 +90,5 @@
|
||||
excludes="META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA, megabasterd/screenshot*.png"/>
|
||||
</zip>
|
||||
<delete file="${store.dir}/temp_final.jar"/>
|
||||
</target>
|
||||
</target>
|
||||
</project>
|
||||
|
@ -18,7 +18,7 @@ is divided into following sections:
|
||||
- applet
|
||||
- cleanup
|
||||
|
||||
-->
|
||||
-->
|
||||
<project xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1" xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3" xmlns:jaxrpc="http://www.netbeans.org/ns/j2se-project/jax-rpc" basedir=".." default="default" name="MegaBasterd-impl">
|
||||
<fail message="Please build using Ant 1.8.0 or higher.">
|
||||
<condition>
|
||||
|
@ -6,7 +6,6 @@ import javax.swing.JOptionPane;
|
||||
import static megabasterd.MainPanel.FONT_DEFAULT;
|
||||
import static megabasterd.MainPanel.THREAD_POOL;
|
||||
import static megabasterd.MainPanel.VERSION;
|
||||
import static megabasterd.MiscTools.copyTextToClipboard;
|
||||
import static megabasterd.MiscTools.swingReflectionInvoke;
|
||||
import static megabasterd.MiscTools.updateFont;
|
||||
|
||||
@ -22,23 +21,24 @@ public final class AboutDialog extends javax.swing.JDialog {
|
||||
private static final String SPAIN_URL = "https://en.wikipedia.org/wiki/Spain";
|
||||
private static final String MEGABASTERD_GITHUB_URL = "https://github.com/tonikelope/megabasterd";
|
||||
|
||||
|
||||
public AboutDialog(MainPanelView parent, boolean modal) {
|
||||
|
||||
super(parent, modal);
|
||||
|
||||
initComponents();
|
||||
|
||||
swingReflectionInvoke("setText", title_label , "MegaBasterd "+ VERSION);
|
||||
swingReflectionInvoke("setText", title_label, "MegaBasterd " + VERSION);
|
||||
|
||||
MiscTools.swingInvokeIt(new Runnable(){
|
||||
MiscTools.swingInvokeIt(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() { updateFont(title_label, FONT_DEFAULT, Font.BOLD);
|
||||
public void run() {
|
||||
updateFont(title_label, FONT_DEFAULT, Font.BOLD);
|
||||
updateFont(subtitle_label, FONT_DEFAULT, Font.BOLD);
|
||||
updateFont(mcdown_url_button, FONT_DEFAULT, Font.PLAIN);
|
||||
updateFont(check_version_button, FONT_DEFAULT, Font.PLAIN);}}, true);
|
||||
|
||||
updateFont(check_version_button, FONT_DEFAULT, Font.PLAIN);
|
||||
}
|
||||
}, true);
|
||||
|
||||
}
|
||||
|
||||
@ -190,7 +190,7 @@ public final class AboutDialog extends javax.swing.JDialog {
|
||||
|
||||
private void mcdown_url_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mcdown_url_buttonActionPerformed
|
||||
|
||||
copyTextToClipboard(MEGA_URL);
|
||||
MiscTools.copyTextToClipboard(MEGA_URL);
|
||||
|
||||
JOptionPane.showMessageDialog(this, "MEGA URL was copied to clipboard!");
|
||||
}//GEN-LAST:event_mcdown_url_buttonActionPerformed
|
||||
@ -203,15 +203,15 @@ public final class AboutDialog extends javax.swing.JDialog {
|
||||
|
||||
final Dialog tthis = this;
|
||||
|
||||
THREAD_POOL.execute(new Runnable(){
|
||||
THREAD_POOL.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
String new_version = MiscTools.checkNewVersion("lYsRWaQB", "uVhntmyKcVECRaOxAbcL4A");
|
||||
|
||||
if(new_version != null) {
|
||||
if (new_version != null) {
|
||||
|
||||
JOptionPane.showMessageDialog(tthis, "MegaBasterd NEW VERSION ("+new_version+") is available!\n\n(HELP > ABOUT for more info)");
|
||||
JOptionPane.showMessageDialog(tthis, "MegaBasterd NEW VERSION (" + new_version + ") is available!\n\n(HELP > ABOUT for more info)");
|
||||
|
||||
} else {
|
||||
|
||||
@ -222,7 +222,8 @@ public final class AboutDialog extends javax.swing.JDialog {
|
||||
|
||||
swingReflectionInvoke("setEnabled", check_version_button, true);
|
||||
|
||||
}});
|
||||
}
|
||||
});
|
||||
|
||||
}//GEN-LAST:event_check_version_buttonActionPerformed
|
||||
|
||||
@ -250,7 +251,6 @@ public final class AboutDialog extends javax.swing.JDialog {
|
||||
MiscTools.openBrowserURL(MEGABASTERD_GITHUB_URL);
|
||||
}//GEN-LAST:event_title_labelMouseReleased
|
||||
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JLabel author_webpage_label;
|
||||
private javax.swing.JButton check_version_button;
|
||||
|
@ -16,22 +16,19 @@ public final class Chunk {
|
||||
private final ByteArrayOutputStream _data_os;
|
||||
private final String _url;
|
||||
|
||||
|
||||
public Chunk(long id, long file_size, String file_url) throws ChunkInvalidIdException
|
||||
{
|
||||
public Chunk(long id, long file_size, String file_url) throws ChunkInvalidIdException {
|
||||
_id = id;
|
||||
|
||||
_offset = calculateOffset();
|
||||
|
||||
if(file_size > 0)
|
||||
{
|
||||
if(_offset>=file_size) {
|
||||
if (file_size > 0) {
|
||||
if (_offset >= file_size) {
|
||||
throw new ChunkInvalidIdException(valueOf(id));
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if(id>1) {
|
||||
if (id > 1) {
|
||||
|
||||
throw new ChunkInvalidIdException(valueOf(id));
|
||||
}
|
||||
@ -39,9 +36,9 @@ public final class Chunk {
|
||||
|
||||
_size = calculateSize(file_size);
|
||||
|
||||
_url = file_url!=null?file_url+"/"+_offset+"-"+(_offset+_size-1):null;
|
||||
_url = file_url != null ? file_url + "/" + _offset + "-" + (_offset + _size - 1) : null;
|
||||
|
||||
_data_os = new ByteArrayOutputStream((int)_size);
|
||||
_data_os = new ByteArrayOutputStream((int) _size);
|
||||
}
|
||||
|
||||
public long getOffset() {
|
||||
@ -68,22 +65,20 @@ public final class Chunk {
|
||||
return new ByteArrayInputStream(_data_os.toByteArray());
|
||||
}
|
||||
|
||||
private long calculateSize(long file_size)
|
||||
{
|
||||
long chunk_size = (_id>=1 && _id<=7)?_id*128*1024:1024*1024;
|
||||
private long calculateSize(long file_size) {
|
||||
long chunk_size = (_id >= 1 && _id <= 7) ? _id * 128 * 1024 : 1024 * 1024;
|
||||
|
||||
if(_offset + chunk_size > file_size) {
|
||||
if (_offset + chunk_size > file_size) {
|
||||
chunk_size = file_size - _offset;
|
||||
}
|
||||
|
||||
return chunk_size;
|
||||
}
|
||||
|
||||
private long calculateOffset()
|
||||
{
|
||||
private long calculateOffset() {
|
||||
long[] offs = {0, 128, 384, 768, 1280, 1920, 2688};
|
||||
|
||||
return (_id<=7?offs[(int)_id-1]:(3584 + (_id-8)*1024))*1024;
|
||||
return (_id <= 7 ? offs[(int) _id - 1] : (3584 + (_id - 8) * 1024)) * 1024;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tonikelope
|
||||
@ -28,9 +27,7 @@ public class ChunkDownloader implements Runnable, SecureNotifiable {
|
||||
private volatile boolean _error_wait;
|
||||
private boolean _notified;
|
||||
|
||||
|
||||
public ChunkDownloader(int id, Download download)
|
||||
{
|
||||
public ChunkDownloader(int id, Download download) {
|
||||
_notified = false;
|
||||
_exit = false;
|
||||
_secure_notify_lock = new Object();
|
||||
@ -63,11 +60,9 @@ public class ChunkDownloader implements Runnable, SecureNotifiable {
|
||||
_error_wait = error_wait;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void secureNotify()
|
||||
{
|
||||
synchronized(_secure_notify_lock) {
|
||||
public void secureNotify() {
|
||||
synchronized (_secure_notify_lock) {
|
||||
|
||||
_notified = true;
|
||||
|
||||
@ -78,9 +73,8 @@ public class ChunkDownloader implements Runnable, SecureNotifiable {
|
||||
@Override
|
||||
public void secureWait() {
|
||||
|
||||
synchronized(_secure_notify_lock)
|
||||
{
|
||||
while(!_notified) {
|
||||
synchronized (_secure_notify_lock) {
|
||||
while (!_notified) {
|
||||
|
||||
try {
|
||||
_secure_notify_lock.wait();
|
||||
@ -96,7 +90,7 @@ public class ChunkDownloader implements Runnable, SecureNotifiable {
|
||||
@Override
|
||||
public void secureNotifyAll() {
|
||||
|
||||
synchronized(_secure_notify_lock) {
|
||||
synchronized (_secure_notify_lock) {
|
||||
|
||||
_notified = true;
|
||||
|
||||
@ -105,28 +99,25 @@ public class ChunkDownloader implements Runnable, SecureNotifiable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
String worker_url=null;
|
||||
public void run() {
|
||||
String worker_url = null;
|
||||
Chunk chunk;
|
||||
int reads, conta_error, http_status;
|
||||
byte[] buffer = new byte[THROTTLE_SLICE_SIZE];
|
||||
InputStream is;
|
||||
boolean error;
|
||||
|
||||
System.out.println("Worker ["+_id+"]: let's do some work!");
|
||||
System.out.println("Worker [" + _id + "]: let's do some work!");
|
||||
|
||||
try(CloseableHttpClient httpclient = MiscTools.getApacheKissHttpClient())
|
||||
{
|
||||
try (CloseableHttpClient httpclient = MiscTools.getApacheKissHttpClient()) {
|
||||
conta_error = 0;
|
||||
|
||||
error = false;
|
||||
|
||||
while(!_exit && !_download.isStopped())
|
||||
{
|
||||
if(worker_url == null || error) {
|
||||
while (!_exit && !_download.isStopped()) {
|
||||
if (worker_url == null || error) {
|
||||
|
||||
worker_url=_download.getDownloadUrlForWorker();
|
||||
worker_url = _download.getDownloadUrlForWorker();
|
||||
}
|
||||
|
||||
chunk = new Chunk(_download.nextChunkId(), _download.getFile_size(), worker_url);
|
||||
@ -137,31 +128,29 @@ public class ChunkDownloader implements Runnable, SecureNotifiable {
|
||||
|
||||
error = false;
|
||||
|
||||
try(CloseableHttpResponse httpresponse = httpclient.execute(httpget)){
|
||||
try (CloseableHttpResponse httpresponse = httpclient.execute(httpget)) {
|
||||
|
||||
if(!_exit && !_download.isStopped()) {
|
||||
if (!_exit && !_download.isStopped()) {
|
||||
|
||||
is = new ThrottledInputStream(httpresponse.getEntity().getContent(), _download.getMain_panel().getStream_supervisor());
|
||||
|
||||
http_status = httpresponse.getStatusLine().getStatusCode();
|
||||
|
||||
if ( http_status != HttpStatus.SC_OK )
|
||||
{
|
||||
if (http_status != HttpStatus.SC_OK) {
|
||||
System.out.println("Failed : HTTP error code : " + http_status);
|
||||
|
||||
error = true;
|
||||
|
||||
} else {
|
||||
|
||||
while(!_exit && !_download.isStopped() && !_download.getChunkwriter().isExit() && chunk.getOutputStream().size() < chunk.getSize() && (reads=is.read(buffer))!=-1 )
|
||||
{
|
||||
while (!_exit && !_download.isStopped() && !_download.getChunkwriter().isExit() && chunk.getOutputStream().size() < chunk.getSize() && (reads = is.read(buffer)) != -1) {
|
||||
chunk.getOutputStream().write(buffer, 0, reads);
|
||||
|
||||
_download.getPartialProgressQueue().add(reads);
|
||||
|
||||
_download.getProgress_meter().secureNotify();
|
||||
|
||||
if(_download.isPaused() && !_download.isStopped()) {
|
||||
if (_download.isPaused() && !_download.isStopped()) {
|
||||
|
||||
_download.pause_worker();
|
||||
|
||||
@ -171,11 +160,10 @@ public class ChunkDownloader implements Runnable, SecureNotifiable {
|
||||
|
||||
is.close();
|
||||
|
||||
if(chunk.getOutputStream().size() < chunk.getSize()) {
|
||||
if (chunk.getOutputStream().size() < chunk.getSize()) {
|
||||
|
||||
if(chunk.getOutputStream().size() > 0)
|
||||
{
|
||||
_download.getPartialProgressQueue().add(-1*chunk.getOutputStream().size());
|
||||
if (chunk.getOutputStream().size() > 0) {
|
||||
_download.getPartialProgressQueue().add(-1 * chunk.getOutputStream().size());
|
||||
|
||||
_download.getProgress_meter().secureNotify();
|
||||
|
||||
@ -185,28 +173,28 @@ public class ChunkDownloader implements Runnable, SecureNotifiable {
|
||||
}
|
||||
}
|
||||
|
||||
if(error && !_download.isStopped()) {
|
||||
if (error && !_download.isStopped()) {
|
||||
|
||||
_download.rejectChunkId(chunk.getId());
|
||||
|
||||
conta_error++;
|
||||
|
||||
if(!_exit) {
|
||||
if (!_exit) {
|
||||
|
||||
_error_wait = true;
|
||||
|
||||
_download.getView().updateSlotsStatus();
|
||||
|
||||
Thread.sleep(getWaitTimeExpBackOff(conta_error)*1000);
|
||||
Thread.sleep(getWaitTimeExpBackOff(conta_error) * 1000);
|
||||
|
||||
_error_wait = false;
|
||||
|
||||
_download.getView().updateSlotsStatus();
|
||||
}
|
||||
|
||||
} else if(!error) {
|
||||
} else if (!error) {
|
||||
|
||||
System.out.println("Worker ["+_id+"] has downloaded chunk ["+chunk.getId()+"]!");
|
||||
System.out.println("Worker [" + _id + "] has downloaded chunk [" + chunk.getId() + "]!");
|
||||
|
||||
_download.getChunkwriter().getChunk_queue().put(chunk.getId(), chunk);
|
||||
|
||||
@ -215,20 +203,17 @@ public class ChunkDownloader implements Runnable, SecureNotifiable {
|
||||
conta_error = 0;
|
||||
}
|
||||
|
||||
} else if(_exit) {
|
||||
} else if (_exit) {
|
||||
|
||||
_download.rejectChunkId(chunk.getId());
|
||||
}
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
} catch (IOException ex) {
|
||||
error = true;
|
||||
|
||||
_download.rejectChunkId(chunk.getId());
|
||||
|
||||
if(chunk.getOutputStream().size() > 0)
|
||||
{
|
||||
_download.getPartialProgressQueue().add(-1*chunk.getOutputStream().size());
|
||||
if (chunk.getOutputStream().size() > 0) {
|
||||
_download.getPartialProgressQueue().add(-1 * chunk.getOutputStream().size());
|
||||
|
||||
_download.getProgress_meter().secureNotify();
|
||||
}
|
||||
@ -241,9 +226,9 @@ public class ChunkDownloader implements Runnable, SecureNotifiable {
|
||||
}
|
||||
}
|
||||
|
||||
}catch(ChunkInvalidIdException e) {
|
||||
} catch (ChunkInvalidIdException e) {
|
||||
|
||||
}catch (IOException ex) {
|
||||
} catch (IOException ex) {
|
||||
_download.emergencyStopDownloader(ex.getMessage());
|
||||
getLogger(ChunkDownloader.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (URISyntaxException ex) {
|
||||
@ -254,9 +239,7 @@ public class ChunkDownloader implements Runnable, SecureNotifiable {
|
||||
|
||||
_download.getChunkwriter().secureNotify();
|
||||
|
||||
System.out.println("Worker ["+_id+"]: bye bye");
|
||||
System.out.println("Worker [" + _id + "]: bye bye");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tonikelope
|
||||
@ -26,42 +25,39 @@ public class ChunkDownloaderMono extends ChunkDownloader {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
String worker_url=null;
|
||||
public void run() {
|
||||
String worker_url = null;
|
||||
Chunk chunk;
|
||||
int reads, max_reads, conta_error, http_status=200;
|
||||
int reads, max_reads, conta_error, http_status = 200;
|
||||
byte[] buffer = new byte[THROTTLE_SLICE_SIZE];
|
||||
boolean error;
|
||||
HttpGet httpget = null;
|
||||
CloseableHttpResponse httpresponse=null;
|
||||
CloseableHttpResponse httpresponse = null;
|
||||
|
||||
System.out.println("Worker ["+getId()+"]: let's do some work!");
|
||||
System.out.println("Worker [" + getId() + "]: let's do some work!");
|
||||
|
||||
try(CloseableHttpClient httpclient = MiscTools.getApacheKissHttpClient())
|
||||
{
|
||||
try (CloseableHttpClient httpclient = MiscTools.getApacheKissHttpClient()) {
|
||||
conta_error = 0;
|
||||
|
||||
error = false;
|
||||
|
||||
InputStream is=null;
|
||||
InputStream is = null;
|
||||
|
||||
while(!isExit() && !getDownload().isStopped())
|
||||
{
|
||||
if(worker_url == null || error) {
|
||||
while (!isExit() && !getDownload().isStopped()) {
|
||||
if (worker_url == null || error) {
|
||||
|
||||
worker_url=getDownload().getDownloadUrlForWorker();
|
||||
worker_url = getDownload().getDownloadUrlForWorker();
|
||||
|
||||
if(httpresponse != null) {
|
||||
if (httpresponse != null) {
|
||||
httpresponse.close();
|
||||
}
|
||||
}
|
||||
|
||||
chunk = new Chunk(getDownload().nextChunkId(), getDownload().getFile_size(), null);
|
||||
|
||||
if(httpget == null || error) {
|
||||
if (httpget == null || error) {
|
||||
|
||||
httpget = new HttpGet(new URI(worker_url+"/"+chunk.getOffset()));
|
||||
httpget = new HttpGet(new URI(worker_url + "/" + chunk.getOffset()));
|
||||
|
||||
httpget.addHeader("Connection", "close");
|
||||
|
||||
@ -74,7 +70,7 @@ public class ChunkDownloaderMono extends ChunkDownloader {
|
||||
|
||||
error = false;
|
||||
|
||||
if(http_status != HttpStatus.SC_OK){
|
||||
if (http_status != HttpStatus.SC_OK) {
|
||||
|
||||
System.out.println("Failed : HTTP error code : " + http_status);
|
||||
|
||||
@ -82,19 +78,18 @@ public class ChunkDownloaderMono extends ChunkDownloader {
|
||||
|
||||
} else {
|
||||
|
||||
try{
|
||||
try {
|
||||
|
||||
if(!isExit() && !getDownload().isStopped()) {
|
||||
if (!isExit() && !getDownload().isStopped() && is != null) {
|
||||
|
||||
while(!getDownload().isStopped() && !getDownload().getChunkwriter().isExit() && chunk.getOutputStream().size() < chunk.getSize() && (reads=is.read(buffer, 0, (max_reads=(int)(chunk.getSize() - chunk.getOutputStream().size())) <= buffer.length?max_reads:buffer.length))!=-1 )
|
||||
{
|
||||
while (!getDownload().isStopped() && !getDownload().getChunkwriter().isExit() && chunk.getOutputStream().size() < chunk.getSize() && (reads = is.read(buffer, 0, (max_reads = (int) (chunk.getSize() - chunk.getOutputStream().size())) <= buffer.length ? max_reads : buffer.length)) != -1) {
|
||||
chunk.getOutputStream().write(buffer, 0, reads);
|
||||
|
||||
getDownload().getPartialProgressQueue().add(reads);
|
||||
|
||||
getDownload().getProgress_meter().secureNotify();
|
||||
|
||||
if(getDownload().isPaused() && !getDownload().isStopped()) {
|
||||
if (getDownload().isPaused() && !getDownload().isStopped()) {
|
||||
|
||||
getDownload().pause_worker_mono();
|
||||
|
||||
@ -102,11 +97,10 @@ public class ChunkDownloaderMono extends ChunkDownloader {
|
||||
}
|
||||
}
|
||||
|
||||
if(chunk.getOutputStream().size() < chunk.getSize()) {
|
||||
if (chunk.getOutputStream().size() < chunk.getSize()) {
|
||||
|
||||
if(chunk.getOutputStream().size() > 0)
|
||||
{
|
||||
getDownload().getPartialProgressQueue().add(-1*chunk.getOutputStream().size());
|
||||
if (chunk.getOutputStream().size() > 0) {
|
||||
getDownload().getPartialProgressQueue().add(-1 * chunk.getOutputStream().size());
|
||||
|
||||
getDownload().getProgress_meter().secureNotify();
|
||||
}
|
||||
@ -114,22 +108,22 @@ public class ChunkDownloaderMono extends ChunkDownloader {
|
||||
error = true;
|
||||
}
|
||||
|
||||
if(error && !getDownload().isStopped()) {
|
||||
if (error && !getDownload().isStopped()) {
|
||||
|
||||
getDownload().rejectChunkId(chunk.getId());
|
||||
|
||||
conta_error++;
|
||||
|
||||
if(!isExit()) {
|
||||
if (!isExit()) {
|
||||
|
||||
setError_wait(true);
|
||||
|
||||
Thread.sleep(getWaitTimeExpBackOff(conta_error)*1000);
|
||||
Thread.sleep(getWaitTimeExpBackOff(conta_error) * 1000);
|
||||
|
||||
setError_wait(false);
|
||||
}
|
||||
|
||||
} else if(!error) {
|
||||
} else if (!error) {
|
||||
|
||||
getDownload().getChunkwriter().getChunk_queue().put(chunk.getId(), chunk);
|
||||
|
||||
@ -138,20 +132,17 @@ public class ChunkDownloaderMono extends ChunkDownloader {
|
||||
conta_error = 0;
|
||||
}
|
||||
|
||||
} else if(isExit()) {
|
||||
} else if (isExit()) {
|
||||
|
||||
getDownload().rejectChunkId(chunk.getId());
|
||||
}
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
} catch (IOException ex) {
|
||||
error = true;
|
||||
|
||||
getDownload().rejectChunkId(chunk.getId());
|
||||
|
||||
if(chunk.getOutputStream().size() > 0)
|
||||
{
|
||||
getDownload().getPartialProgressQueue().add(-1*chunk.getOutputStream().size());
|
||||
if (chunk.getOutputStream().size() > 0) {
|
||||
getDownload().getPartialProgressQueue().add(-1 * chunk.getOutputStream().size());
|
||||
|
||||
getDownload().getProgress_meter().secureNotify();
|
||||
}
|
||||
@ -164,7 +155,7 @@ public class ChunkDownloaderMono extends ChunkDownloader {
|
||||
}
|
||||
}
|
||||
|
||||
}catch(ChunkInvalidIdException e) {
|
||||
} catch (ChunkInvalidIdException e) {
|
||||
|
||||
} catch (IOException ex) {
|
||||
|
||||
@ -180,7 +171,7 @@ public class ChunkDownloaderMono extends ChunkDownloader {
|
||||
|
||||
getDownload().getChunkwriter().secureNotify();
|
||||
|
||||
System.out.println("Worker ["+getId()+"]: bye bye");
|
||||
System.out.println("Worker [" + getId() + "]: bye bye");
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,12 @@
|
||||
package megabasterd;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tonikelope
|
||||
*/
|
||||
public final class ChunkInvalidIdException extends Exception {
|
||||
|
||||
public ChunkInvalidIdException(String message)
|
||||
{
|
||||
public ChunkInvalidIdException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
|
@ -28,8 +28,6 @@ import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.InputStreamEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tonikelope
|
||||
@ -43,8 +41,7 @@ public class ChunkUploader implements Runnable, SecureNotifiable {
|
||||
private volatile boolean _error_wait;
|
||||
private boolean _notified;
|
||||
|
||||
public ChunkUploader(int id, Upload upload)
|
||||
{
|
||||
public ChunkUploader(int id, Upload upload) {
|
||||
_notified = false;
|
||||
_secure_notify_lock = new Object();
|
||||
_id = id;
|
||||
@ -62,9 +59,8 @@ public class ChunkUploader implements Runnable, SecureNotifiable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void secureNotify()
|
||||
{
|
||||
synchronized(_secure_notify_lock) {
|
||||
public void secureNotify() {
|
||||
synchronized (_secure_notify_lock) {
|
||||
|
||||
_notified = true;
|
||||
|
||||
@ -75,9 +71,8 @@ public class ChunkUploader implements Runnable, SecureNotifiable {
|
||||
@Override
|
||||
public void secureWait() {
|
||||
|
||||
synchronized(_secure_notify_lock)
|
||||
{
|
||||
while(!_notified) {
|
||||
synchronized (_secure_notify_lock) {
|
||||
while (!_notified) {
|
||||
|
||||
try {
|
||||
_secure_notify_lock.wait();
|
||||
@ -93,7 +88,7 @@ public class ChunkUploader implements Runnable, SecureNotifiable {
|
||||
@Override
|
||||
public void secureNotifyAll() {
|
||||
|
||||
synchronized(_secure_notify_lock) {
|
||||
synchronized (_secure_notify_lock) {
|
||||
|
||||
_notified = true;
|
||||
|
||||
@ -117,41 +112,35 @@ public class ChunkUploader implements Runnable, SecureNotifiable {
|
||||
this._error_wait = _error_wait;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
System.out.println("ChunkUploader "+_id+" hello!");
|
||||
public void run() {
|
||||
System.out.println("ChunkUploader " + _id + " hello!");
|
||||
|
||||
String worker_url=_upload.getUl_url();
|
||||
String worker_url = _upload.getUl_url();
|
||||
Chunk chunk;
|
||||
int reads, to_read, conta_error, re, http_status, tot_bytes_up;
|
||||
byte[] buffer = new byte[MainPanel.THROTTLE_SLICE_SIZE];
|
||||
boolean error;
|
||||
OutputStream out;
|
||||
|
||||
try(final CloseableHttpClient httpclient = MiscTools.getApacheKissHttpClient())
|
||||
{
|
||||
try (final CloseableHttpClient httpclient = MiscTools.getApacheKissHttpClient()) {
|
||||
RandomAccessFile f = new RandomAccessFile(_upload.getFile_name(), "r");
|
||||
|
||||
conta_error = 0;
|
||||
|
||||
while(!_exit && !_upload.isStopped())
|
||||
{
|
||||
while (!_exit && !_upload.isStopped()) {
|
||||
chunk = new Chunk(_upload.nextChunkId(), _upload.getFile_size(), worker_url);
|
||||
|
||||
f.seek(chunk.getOffset());
|
||||
|
||||
do
|
||||
{
|
||||
to_read = chunk.getSize() - chunk.getOutputStream().size() >= buffer.length?buffer.length:(int)(chunk.getSize() - chunk.getOutputStream().size());
|
||||
do {
|
||||
to_read = chunk.getSize() - chunk.getOutputStream().size() >= buffer.length ? buffer.length : (int) (chunk.getSize() - chunk.getOutputStream().size());
|
||||
|
||||
re=f.read(buffer, 0, to_read);
|
||||
re = f.read(buffer, 0, to_read);
|
||||
|
||||
chunk.getOutputStream().write(buffer, 0, re);
|
||||
|
||||
}while(!_exit && !_upload.isStopped() && chunk.getOutputStream().size()<chunk.getSize());
|
||||
} while (!_exit && !_upload.isStopped() && chunk.getOutputStream().size() < chunk.getSize());
|
||||
|
||||
final HttpPost httppost = new HttpPost(new URI(chunk.getUrl()));
|
||||
|
||||
@ -159,15 +148,15 @@ public class ChunkUploader implements Runnable, SecureNotifiable {
|
||||
|
||||
httppost.addHeader("Connection", "close");
|
||||
|
||||
tot_bytes_up=0;
|
||||
tot_bytes_up = 0;
|
||||
|
||||
error = false;
|
||||
|
||||
CloseableHttpResponse httpresponse = null;
|
||||
|
||||
try{
|
||||
try {
|
||||
|
||||
if(!_exit && !_upload.isStopped()) {
|
||||
if (!_exit && !_upload.isStopped()) {
|
||||
|
||||
CipherInputStream cis = new CipherInputStream(chunk.getInputStream(), CryptTools.genCrypter("AES", "AES/CTR/NoPadding", _upload.getByte_file_key(), CryptTools.forwardMEGALinkKeyIV(_upload.getByte_file_iv(), chunk.getOffset())));
|
||||
|
||||
@ -189,19 +178,18 @@ public class ChunkUploader implements Runnable, SecureNotifiable {
|
||||
|
||||
out = new ThrottledOutputStream(pipeout, _upload.getMain_panel().getStream_supervisor());
|
||||
|
||||
System.out.println(" Subiendo chunk "+chunk.getId()+" desde worker "+ _id +"...");
|
||||
System.out.println(" Subiendo chunk " + chunk.getId() + " desde worker " + _id + "...");
|
||||
|
||||
while( !_exit && !_upload.isStopped() && (reads=cis.read(buffer))!=-1 )
|
||||
{
|
||||
while (!_exit && !_upload.isStopped() && (reads = cis.read(buffer)) != -1) {
|
||||
out.write(buffer, 0, reads);
|
||||
|
||||
_upload.getPartialProgress().add(reads);
|
||||
|
||||
_upload.getProgress_meter().secureNotify();
|
||||
|
||||
tot_bytes_up+=reads;
|
||||
tot_bytes_up += reads;
|
||||
|
||||
if(_upload.isPaused() && !_upload.isStopped()) {
|
||||
if (_upload.isPaused() && !_upload.isStopped()) {
|
||||
|
||||
_upload.pause_worker();
|
||||
|
||||
@ -211,11 +199,11 @@ public class ChunkUploader implements Runnable, SecureNotifiable {
|
||||
|
||||
out.close();
|
||||
|
||||
if(!_upload.isStopped()) {
|
||||
if (!_upload.isStopped()) {
|
||||
|
||||
try{
|
||||
try {
|
||||
|
||||
if(!_exit) {
|
||||
if (!_exit) {
|
||||
|
||||
httpresponse = futureTask.get();
|
||||
|
||||
@ -226,19 +214,17 @@ public class ChunkUploader implements Runnable, SecureNotifiable {
|
||||
httpresponse = null;
|
||||
}
|
||||
|
||||
if (httpresponse != null && (http_status = httpresponse.getStatusLine().getStatusCode()) != HttpStatus.SC_OK )
|
||||
{
|
||||
if (httpresponse != null && (http_status = httpresponse.getStatusLine().getStatusCode()) != HttpStatus.SC_OK) {
|
||||
System.out.println("Failed : HTTP error code : " + http_status);
|
||||
|
||||
error = true;
|
||||
|
||||
} else {
|
||||
|
||||
if(tot_bytes_up < chunk.getSize())
|
||||
{
|
||||
if(tot_bytes_up > 0) {
|
||||
if (tot_bytes_up < chunk.getSize()) {
|
||||
if (tot_bytes_up > 0) {
|
||||
|
||||
_upload.getPartialProgress().add(-1*tot_bytes_up);
|
||||
_upload.getPartialProgress().add(-1 * tot_bytes_up);
|
||||
|
||||
_upload.getProgress_meter().secureNotify();
|
||||
}
|
||||
@ -247,28 +233,27 @@ public class ChunkUploader implements Runnable, SecureNotifiable {
|
||||
|
||||
} else {
|
||||
|
||||
if(httpresponse != null && _upload.getCompletion_handle() == null) {
|
||||
if (httpresponse != null && _upload.getCompletion_handle() == null) {
|
||||
|
||||
InputStream is=httpresponse.getEntity().getContent();
|
||||
InputStream is = httpresponse.getEntity().getContent();
|
||||
|
||||
ByteArrayOutputStream byte_res = new ByteArrayOutputStream();
|
||||
|
||||
while( (reads=is.read(buffer)) != -1 ) {
|
||||
while ((reads = is.read(buffer)) != -1) {
|
||||
|
||||
byte_res.write(buffer, 0, reads);
|
||||
}
|
||||
|
||||
String response = new String(byte_res.toByteArray());
|
||||
|
||||
if(response.length() > 0) {
|
||||
if (response.length() > 0) {
|
||||
|
||||
if( MegaAPI.checkMEGAError(response) != 0 )
|
||||
{
|
||||
if (MegaAPI.checkMEGAError(response) != 0) {
|
||||
error = true;
|
||||
|
||||
} else {
|
||||
|
||||
System.out.println("Completion handle -> "+response);
|
||||
System.out.println("Completion handle -> " + response);
|
||||
|
||||
_upload.setCompletion_handle(response);
|
||||
}
|
||||
@ -277,28 +262,28 @@ public class ChunkUploader implements Runnable, SecureNotifiable {
|
||||
}
|
||||
}
|
||||
|
||||
if(error && !_upload.isStopped()) {
|
||||
if (error && !_upload.isStopped()) {
|
||||
|
||||
_upload.rejectChunkId(chunk.getId());
|
||||
|
||||
conta_error++;
|
||||
|
||||
if(!_exit) {
|
||||
if (!_exit) {
|
||||
|
||||
_error_wait = true;
|
||||
|
||||
_upload.getView().updateSlotsStatus();
|
||||
|
||||
Thread.sleep(getWaitTimeExpBackOff(conta_error)*1000);
|
||||
Thread.sleep(getWaitTimeExpBackOff(conta_error) * 1000);
|
||||
|
||||
_error_wait = false;
|
||||
|
||||
_upload.getView().updateSlotsStatus();
|
||||
}
|
||||
|
||||
} else if(!error) {
|
||||
} else if (!error) {
|
||||
|
||||
System.out.println(" Worker "+_id+" ha subido chunk "+chunk.getId());
|
||||
System.out.println(" Worker " + _id + " ha subido chunk " + chunk.getId());
|
||||
|
||||
_upload.getMac_generator().getChunk_queue().put(chunk.getId(), chunk);
|
||||
|
||||
@ -307,10 +292,10 @@ public class ChunkUploader implements Runnable, SecureNotifiable {
|
||||
conta_error = 0;
|
||||
}
|
||||
|
||||
}catch(ExecutionException exception){}
|
||||
finally{
|
||||
} catch (ExecutionException exception) {
|
||||
} finally {
|
||||
|
||||
if(httpresponse != null) {
|
||||
if (httpresponse != null) {
|
||||
|
||||
httpresponse.close();
|
||||
}
|
||||
@ -318,19 +303,16 @@ public class ChunkUploader implements Runnable, SecureNotifiable {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} else if(_exit) {
|
||||
} else if (_exit) {
|
||||
|
||||
_upload.rejectChunkId(chunk.getId());
|
||||
}
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
} catch (IOException ex) {
|
||||
_upload.rejectChunkId(chunk.getId());
|
||||
|
||||
if(tot_bytes_up > 0) {
|
||||
if (tot_bytes_up > 0) {
|
||||
|
||||
_upload.getPartialProgress().add(-1*tot_bytes_up);
|
||||
_upload.getPartialProgress().add(-1 * tot_bytes_up);
|
||||
|
||||
_upload.getProgress_meter().secureNotify();
|
||||
}
|
||||
@ -342,7 +324,7 @@ public class ChunkUploader implements Runnable, SecureNotifiable {
|
||||
|
||||
} finally {
|
||||
|
||||
if( httpresponse != null ) {
|
||||
if (httpresponse != null) {
|
||||
httpresponse.close();
|
||||
}
|
||||
|
||||
@ -350,7 +332,7 @@ public class ChunkUploader implements Runnable, SecureNotifiable {
|
||||
|
||||
}
|
||||
|
||||
}catch(ChunkInvalidIdException e) {
|
||||
} catch (ChunkInvalidIdException e) {
|
||||
|
||||
} catch (IOException ex) {
|
||||
|
||||
@ -365,7 +347,7 @@ public class ChunkUploader implements Runnable, SecureNotifiable {
|
||||
|
||||
_upload.getMac_generator().secureNotify();
|
||||
|
||||
System.out.println("ChunkUploader "+_id+" bye bye...");
|
||||
System.out.println("ChunkUploader " + _id + " bye bye...");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -44,49 +44,45 @@ public class ChunkUploaderMono extends ChunkUploader {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
System.out.println("ChunkUploader "+getId()+" hello!");
|
||||
public void run() {
|
||||
System.out.println("ChunkUploader " + getId() + " hello!");
|
||||
|
||||
String worker_url=getUpload().getUl_url();
|
||||
String worker_url = getUpload().getUl_url();
|
||||
Chunk chunk;
|
||||
int reads, to_read, conta_error, re, http_status, tot_bytes_up=-1;
|
||||
int reads, to_read, conta_error, re, http_status, tot_bytes_up = -1;
|
||||
byte[] buffer = new byte[MainPanel.THROTTLE_SLICE_SIZE];
|
||||
boolean error = false;
|
||||
|
||||
try(CloseableHttpClient httpclient = MiscTools.getApacheKissHttpClient())
|
||||
{
|
||||
try (CloseableHttpClient httpclient = MiscTools.getApacheKissHttpClient()) {
|
||||
RandomAccessFile f = new RandomAccessFile(getUpload().getFile_name(), "r");
|
||||
|
||||
conta_error = 0;
|
||||
|
||||
OutputStream out=null;
|
||||
OutputStream out = null;
|
||||
|
||||
FutureTask<CloseableHttpResponse> futureTask = null;
|
||||
|
||||
while(!isExit() && !getUpload().isStopped())
|
||||
{
|
||||
CloseableHttpResponse httpresponse=null;
|
||||
while (!isExit() && !getUpload().isStopped()) {
|
||||
CloseableHttpResponse httpresponse = null;
|
||||
|
||||
chunk = new Chunk(getUpload().nextChunkId(), getUpload().getFile_size(), null);
|
||||
|
||||
f.seek(chunk.getOffset());
|
||||
|
||||
do
|
||||
{
|
||||
to_read = chunk.getSize() - chunk.getOutputStream().size() >= buffer.length?buffer.length:(int)(chunk.getSize() - chunk.getOutputStream().size());
|
||||
do {
|
||||
to_read = chunk.getSize() - chunk.getOutputStream().size() >= buffer.length ? buffer.length : (int) (chunk.getSize() - chunk.getOutputStream().size());
|
||||
|
||||
re=f.read(buffer, 0, to_read);
|
||||
re = f.read(buffer, 0, to_read);
|
||||
|
||||
chunk.getOutputStream().write(buffer, 0, re);
|
||||
|
||||
}while(!isExit() && !getUpload().isStopped() && chunk.getOutputStream().size()<chunk.getSize());
|
||||
} while (!isExit() && !getUpload().isStopped() && chunk.getOutputStream().size() < chunk.getSize());
|
||||
|
||||
if(tot_bytes_up == -1 || error) {
|
||||
if (tot_bytes_up == -1 || error) {
|
||||
|
||||
final HttpPost httppost = new HttpPost(new URI(worker_url+"/"+chunk.getOffset()));
|
||||
final HttpPost httppost = new HttpPost(new URI(worker_url + "/" + chunk.getOffset()));
|
||||
|
||||
final long postdata_length = getUpload().getFile_size()-chunk.getOffset();
|
||||
final long postdata_length = getUpload().getFile_size() - chunk.getOffset();
|
||||
|
||||
httppost.addHeader("Connection", "close");
|
||||
|
||||
@ -110,29 +106,28 @@ public class ChunkUploaderMono extends ChunkUploader {
|
||||
|
||||
}
|
||||
|
||||
tot_bytes_up=0;
|
||||
tot_bytes_up = 0;
|
||||
|
||||
error = false;
|
||||
|
||||
try{
|
||||
try {
|
||||
|
||||
if(!isExit() && !getUpload().isStopped()) {
|
||||
if (!isExit() && !getUpload().isStopped()) {
|
||||
|
||||
CipherInputStream cis = new CipherInputStream(chunk.getInputStream(), CryptTools.genCrypter("AES", "AES/CTR/NoPadding", getUpload().getByte_file_key(), CryptTools.forwardMEGALinkKeyIV(getUpload().getByte_file_iv(), chunk.getOffset())));
|
||||
|
||||
System.out.println(" Subiendo chunk "+chunk.getId()+" desde worker "+ getId() +"...");
|
||||
System.out.println(" Subiendo chunk " + chunk.getId() + " desde worker " + getId() + "...");
|
||||
|
||||
while( !isExit() && !getUpload().isStopped() && (reads=cis.read(buffer))!=-1 && out != null )
|
||||
{
|
||||
while (!isExit() && !getUpload().isStopped() && (reads = cis.read(buffer)) != -1 && out != null) {
|
||||
out.write(buffer, 0, reads);
|
||||
|
||||
getUpload().getPartialProgress().add(reads);
|
||||
|
||||
getUpload().getProgress_meter().secureNotify();
|
||||
|
||||
tot_bytes_up+=reads;
|
||||
tot_bytes_up += reads;
|
||||
|
||||
if(getUpload().isPaused() && !getUpload().isStopped()) {
|
||||
if (getUpload().isPaused() && !getUpload().isStopped()) {
|
||||
|
||||
getUpload().pause_worker();
|
||||
|
||||
@ -140,13 +135,12 @@ public class ChunkUploaderMono extends ChunkUploader {
|
||||
}
|
||||
}
|
||||
|
||||
if(!getUpload().isStopped()) {
|
||||
if (!getUpload().isStopped()) {
|
||||
|
||||
if(tot_bytes_up < chunk.getSize())
|
||||
{
|
||||
if(tot_bytes_up > 0) {
|
||||
if (tot_bytes_up < chunk.getSize()) {
|
||||
if (tot_bytes_up > 0) {
|
||||
|
||||
getUpload().getPartialProgress().add(-1*tot_bytes_up);
|
||||
getUpload().getPartialProgress().add(-1 * tot_bytes_up);
|
||||
|
||||
getUpload().getProgress_meter().secureNotify();
|
||||
}
|
||||
@ -154,24 +148,24 @@ public class ChunkUploaderMono extends ChunkUploader {
|
||||
error = true;
|
||||
}
|
||||
|
||||
if(error && !getUpload().isStopped()) {
|
||||
if (error && !getUpload().isStopped()) {
|
||||
|
||||
getUpload().rejectChunkId(chunk.getId());
|
||||
|
||||
conta_error++;
|
||||
|
||||
if(!isExit()) {
|
||||
if (!isExit()) {
|
||||
|
||||
setError_wait(true);
|
||||
|
||||
Thread.sleep(getWaitTimeExpBackOff(conta_error)*1000);
|
||||
Thread.sleep(getWaitTimeExpBackOff(conta_error) * 1000);
|
||||
|
||||
setError_wait(false);
|
||||
}
|
||||
|
||||
} else if(!error) {
|
||||
} else if (!error) {
|
||||
|
||||
System.out.println(" Worker "+getId()+" ha subido chunk "+chunk.getId());
|
||||
System.out.println(" Worker " + getId() + " ha subido chunk " + chunk.getId());
|
||||
|
||||
getUpload().getMac_generator().getChunk_queue().put(chunk.getId(), chunk);
|
||||
|
||||
@ -182,21 +176,19 @@ public class ChunkUploaderMono extends ChunkUploader {
|
||||
|
||||
}
|
||||
|
||||
} else if(isExit()) {
|
||||
} else if (isExit()) {
|
||||
|
||||
getUpload().rejectChunkId(chunk.getId());
|
||||
}
|
||||
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
} catch (IOException ex) {
|
||||
error = true;
|
||||
|
||||
getUpload().rejectChunkId(chunk.getId());
|
||||
|
||||
if(tot_bytes_up > 0) {
|
||||
if (tot_bytes_up > 0) {
|
||||
|
||||
getUpload().getPartialProgress().add(-1*tot_bytes_up);
|
||||
getUpload().getPartialProgress().add(-1 * tot_bytes_up);
|
||||
|
||||
getUpload().getProgress_meter().secureNotify();
|
||||
}
|
||||
@ -208,7 +200,7 @@ public class ChunkUploaderMono extends ChunkUploader {
|
||||
|
||||
}
|
||||
|
||||
if(!error && chunk.getOffset() + tot_bytes_up == getUpload().getFile_size() && futureTask != null) {
|
||||
if (!error && chunk.getOffset() + tot_bytes_up == getUpload().getFile_size() && futureTask != null) {
|
||||
|
||||
try {
|
||||
|
||||
@ -216,65 +208,63 @@ 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+")");
|
||||
if (http_status != HttpStatus.SC_OK) {
|
||||
throw new IOException("UPLOAD FAILED! (HTTP STATUS: " + http_status + ")");
|
||||
|
||||
} else {
|
||||
|
||||
InputStream is=httpresponse.getEntity().getContent();
|
||||
InputStream is = httpresponse.getEntity().getContent();
|
||||
|
||||
ByteArrayOutputStream byte_res = new ByteArrayOutputStream();
|
||||
|
||||
while( (reads=is.read(buffer)) != -1 ) {
|
||||
while ((reads = is.read(buffer)) != -1) {
|
||||
|
||||
byte_res.write(buffer, 0, reads);
|
||||
}
|
||||
|
||||
String response = new String(byte_res.toByteArray());
|
||||
|
||||
if(response.length() > 0) {
|
||||
if (response.length() > 0) {
|
||||
|
||||
if( MegaAPI.checkMEGAError(response) != 0 )
|
||||
{
|
||||
throw new IOException("UPLOAD FAILED! (MEGA ERROR: "+ MegaAPI.checkMEGAError(response)+")");
|
||||
if (MegaAPI.checkMEGAError(response) != 0) {
|
||||
throw new IOException("UPLOAD FAILED! (MEGA ERROR: " + MegaAPI.checkMEGAError(response) + ")");
|
||||
|
||||
} else {
|
||||
|
||||
System.out.println("Completion handle -> "+response);
|
||||
System.out.println("Completion handle -> " + response);
|
||||
|
||||
getUpload().setCompletion_handle(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}catch(ExecutionException exception) {}
|
||||
finally{
|
||||
} catch (ExecutionException exception) {
|
||||
} finally {
|
||||
|
||||
if(out != null) {
|
||||
if (out != null) {
|
||||
out.close();
|
||||
}
|
||||
|
||||
if(httpresponse != null) {
|
||||
if (httpresponse != null) {
|
||||
|
||||
httpresponse.close();
|
||||
}
|
||||
}
|
||||
|
||||
} else if(error) {
|
||||
} else if (error) {
|
||||
|
||||
if(out != null) {
|
||||
if (out != null) {
|
||||
|
||||
out.close();
|
||||
}
|
||||
|
||||
if(futureTask != null) {
|
||||
if (futureTask != null) {
|
||||
futureTask.cancel(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}catch(ChunkInvalidIdException e) {
|
||||
} catch (ChunkInvalidIdException e) {
|
||||
|
||||
} catch (IOException ex) {
|
||||
|
||||
@ -290,7 +280,7 @@ public class ChunkUploaderMono extends ChunkUploader {
|
||||
|
||||
getUpload().getMac_generator().secureNotify();
|
||||
|
||||
System.out.println("ChunkUploader "+getId()+" bye bye...");
|
||||
System.out.println("ChunkUploader " + getId() + " bye bye...");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,13 +11,12 @@ import static java.util.logging.Logger.getLogger;
|
||||
import javax.crypto.CipherInputStream;
|
||||
import javax.crypto.NoSuchPaddingException;
|
||||
|
||||
|
||||
public final class ChunkWriter implements Runnable, SecureNotifiable {
|
||||
|
||||
private long _last_chunk_id_written;
|
||||
private long _bytes_written;
|
||||
private final long _file_size;
|
||||
private final ConcurrentHashMap<Long,Chunk> _chunk_queue;
|
||||
private final ConcurrentHashMap<Long, Chunk> _chunk_queue;
|
||||
private final Download _download;
|
||||
private final byte[] _byte_file_key;
|
||||
private final byte[] _byte_iv;
|
||||
@ -25,8 +24,8 @@ public final class ChunkWriter implements Runnable, SecureNotifiable {
|
||||
private final ConcurrentLinkedQueue<Long> _rejectedChunkIds;
|
||||
private final Object _secure_notify_lock;
|
||||
private boolean _notified;
|
||||
public ChunkWriter(Download downloader) throws Exception
|
||||
{
|
||||
|
||||
public ChunkWriter(Download downloader) throws Exception {
|
||||
_notified = false;
|
||||
_exit = false;
|
||||
_download = downloader;
|
||||
@ -37,16 +36,13 @@ public final class ChunkWriter implements Runnable, SecureNotifiable {
|
||||
_chunk_queue = new ConcurrentHashMap();
|
||||
_rejectedChunkIds = new ConcurrentLinkedQueue<>();
|
||||
|
||||
if(_download.getProgress() == 0)
|
||||
{
|
||||
if (_download.getProgress() == 0) {
|
||||
_download.setLast_chunk_id_dispatched(0);
|
||||
|
||||
_last_chunk_id_written = 0;
|
||||
|
||||
_bytes_written = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
_last_chunk_id_written = calculateLastWrittenChunk(_download.getProgress());
|
||||
|
||||
_download.setLast_chunk_id_dispatched(_last_chunk_id_written);
|
||||
@ -55,11 +51,9 @@ public final class ChunkWriter implements Runnable, SecureNotifiable {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void secureNotify()
|
||||
{
|
||||
synchronized(_secure_notify_lock) {
|
||||
public void secureNotify() {
|
||||
synchronized (_secure_notify_lock) {
|
||||
|
||||
_notified = true;
|
||||
|
||||
@ -70,9 +64,8 @@ public final class ChunkWriter implements Runnable, SecureNotifiable {
|
||||
@Override
|
||||
public void secureWait() {
|
||||
|
||||
synchronized(_secure_notify_lock)
|
||||
{
|
||||
while(!_notified) {
|
||||
synchronized (_secure_notify_lock) {
|
||||
while (!_notified) {
|
||||
|
||||
try {
|
||||
_secure_notify_lock.wait();
|
||||
@ -88,7 +81,7 @@ public final class ChunkWriter implements Runnable, SecureNotifiable {
|
||||
@Override
|
||||
public void secureNotifyAll() {
|
||||
|
||||
synchronized(_secure_notify_lock) {
|
||||
synchronized (_secure_notify_lock) {
|
||||
|
||||
_notified = true;
|
||||
|
||||
@ -104,7 +97,6 @@ public final class ChunkWriter implements Runnable, SecureNotifiable {
|
||||
return _rejectedChunkIds;
|
||||
}
|
||||
|
||||
|
||||
public boolean isExit() {
|
||||
return _exit;
|
||||
}
|
||||
@ -117,42 +109,35 @@ public final class ChunkWriter implements Runnable, SecureNotifiable {
|
||||
return _last_chunk_id_written;
|
||||
}
|
||||
|
||||
|
||||
public ConcurrentHashMap getChunk_queue()
|
||||
{
|
||||
public ConcurrentHashMap getChunk_queue() {
|
||||
return _chunk_queue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
public void run() {
|
||||
Chunk current_chunk;
|
||||
CipherInputStream cis;
|
||||
byte[] buffer = new byte[16*1024];
|
||||
byte[] buffer = new byte[16 * 1024];
|
||||
int reads;
|
||||
|
||||
try {
|
||||
|
||||
System.out.println("Filewriter: let's do some work!");
|
||||
|
||||
if(_file_size > 0)
|
||||
{
|
||||
while(!_exit && (!_download.isStopped() || !_download.getChunkworkers().isEmpty()) && _bytes_written < _file_size)
|
||||
{
|
||||
while(_chunk_queue.containsKey(_last_chunk_id_written+1))
|
||||
{
|
||||
current_chunk = _chunk_queue.get(_last_chunk_id_written+1);
|
||||
if (_file_size > 0) {
|
||||
while (!_exit && (!_download.isStopped() || !_download.getChunkworkers().isEmpty()) && _bytes_written < _file_size) {
|
||||
while (_chunk_queue.containsKey(_last_chunk_id_written + 1)) {
|
||||
current_chunk = _chunk_queue.get(_last_chunk_id_written + 1);
|
||||
|
||||
cis = new CipherInputStream(current_chunk.getInputStream(), CryptTools.genDecrypter("AES", "AES/CTR/NoPadding", _byte_file_key, CryptTools.forwardMEGALinkKeyIV(_byte_iv, _bytes_written)));
|
||||
|
||||
while((reads=cis.read(buffer))!=-1)
|
||||
{
|
||||
while ((reads = cis.read(buffer)) != -1) {
|
||||
_download.getOutput_stream().write(buffer, 0, reads);
|
||||
}
|
||||
|
||||
cis.close();
|
||||
|
||||
_bytes_written+=current_chunk.getSize();
|
||||
_bytes_written += current_chunk.getSize();
|
||||
|
||||
_chunk_queue.remove(current_chunk.getId());
|
||||
|
||||
@ -160,10 +145,9 @@ public final class ChunkWriter implements Runnable, SecureNotifiable {
|
||||
|
||||
}
|
||||
|
||||
if(!_exit && (!_download.isStopped() || !_download.getChunkworkers().isEmpty()) && _bytes_written < _file_size)
|
||||
{
|
||||
if (!_exit && (!_download.isStopped() || !_download.getChunkworkers().isEmpty()) && _bytes_written < _file_size) {
|
||||
|
||||
System.out.println("Filewriter waiting for chunk ["+(_last_chunk_id_written+1)+"]...");
|
||||
System.out.println("Filewriter waiting for chunk [" + (_last_chunk_id_written + 1) + "]...");
|
||||
|
||||
secureWait();
|
||||
}
|
||||
@ -181,23 +165,18 @@ public final class ChunkWriter implements Runnable, SecureNotifiable {
|
||||
|
||||
_download.secureNotify();
|
||||
|
||||
System.out.println("Filewriter: bye bye"+_download.getFile().getName());
|
||||
System.out.println("Filewriter: bye bye" + _download.getFile().getName());
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
else
|
||||
{
|
||||
int i=0, tot=0;
|
||||
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));
|
||||
} else {
|
||||
int i = 0, tot = 0;
|
||||
|
||||
while(tot < temp_file_size)
|
||||
{
|
||||
while (tot < temp_file_size) {
|
||||
i++;
|
||||
tot+=i*128*1024;
|
||||
tot += i * 128 * 1024;
|
||||
}
|
||||
|
||||
return i;
|
||||
|
@ -9,8 +9,11 @@ import java.awt.datatransfer.Transferable;
|
||||
public interface ClipboardChangeObservable {
|
||||
|
||||
void attachObserver(ClipboardChangeObserver observer);
|
||||
|
||||
void detachObserver(ClipboardChangeObserver observer);
|
||||
|
||||
Transferable getContents();
|
||||
|
||||
void notifyChangeToMyObservers();
|
||||
|
||||
}
|
||||
|
@ -4,13 +4,11 @@ import static java.awt.Toolkit.getDefaultToolkit;
|
||||
import java.awt.datatransfer.Clipboard;
|
||||
import java.awt.datatransfer.ClipboardOwner;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
import static java.lang.System.out;
|
||||
import static java.lang.Thread.sleep;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import static java.util.logging.Level.SEVERE;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
|
||||
|
||||
public final class ClipboardSpy implements Runnable, ClipboardOwner, SecureNotifiable, ClipboardChangeObservable {
|
||||
|
||||
private static final int SLEEP = 50;
|
||||
@ -25,8 +23,6 @@ public final class ClipboardSpy implements Runnable, ClipboardOwner, SecureNotif
|
||||
|
||||
private final Object _secure_notify_lock;
|
||||
|
||||
|
||||
|
||||
public ClipboardSpy() {
|
||||
_sysClip = getDefaultToolkit().getSystemClipboard();
|
||||
_notified = false;
|
||||
@ -34,15 +30,15 @@ public final class ClipboardSpy implements Runnable, ClipboardOwner, SecureNotif
|
||||
_secure_notify_lock = new Object();
|
||||
_observers = new ConcurrentLinkedQueue<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Transferable getContents() {
|
||||
return _contents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void secureNotify()
|
||||
{
|
||||
synchronized(_secure_notify_lock) {
|
||||
public void secureNotify() {
|
||||
synchronized (_secure_notify_lock) {
|
||||
|
||||
_notified = true;
|
||||
|
||||
@ -53,9 +49,8 @@ public final class ClipboardSpy implements Runnable, ClipboardOwner, SecureNotif
|
||||
@Override
|
||||
public void secureWait() {
|
||||
|
||||
synchronized(_secure_notify_lock)
|
||||
{
|
||||
while(!_notified) {
|
||||
synchronized (_secure_notify_lock) {
|
||||
while (!_notified) {
|
||||
|
||||
try {
|
||||
_secure_notify_lock.wait();
|
||||
@ -71,7 +66,7 @@ public final class ClipboardSpy implements Runnable, ClipboardOwner, SecureNotif
|
||||
@Override
|
||||
public void secureNotifyAll() {
|
||||
|
||||
synchronized(_secure_notify_lock) {
|
||||
synchronized (_secure_notify_lock) {
|
||||
|
||||
_notified = true;
|
||||
|
||||
@ -79,7 +74,6 @@ public final class ClipboardSpy implements Runnable, ClipboardOwner, SecureNotif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
@ -87,12 +81,11 @@ public final class ClipboardSpy implements Runnable, ClipboardOwner, SecureNotif
|
||||
|
||||
gainOwnership(_contents);
|
||||
|
||||
out.println("Spying clipboard...");
|
||||
System.out.println("Spying clipboard...");
|
||||
|
||||
secureWait();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void lostOwnership(Clipboard c, Transferable t) {
|
||||
|
||||
@ -103,21 +96,20 @@ public final class ClipboardSpy implements Runnable, ClipboardOwner, SecureNotif
|
||||
gainOwnership(_contents);
|
||||
}
|
||||
|
||||
|
||||
private Transferable getClipboardContents() {
|
||||
|
||||
boolean error;
|
||||
|
||||
Transferable c = null;
|
||||
|
||||
do{
|
||||
do {
|
||||
error = false;
|
||||
|
||||
try{
|
||||
try {
|
||||
|
||||
c = _sysClip.getContents(null);
|
||||
|
||||
} catch(Exception ex) {
|
||||
} catch (Exception ex) {
|
||||
|
||||
error = true;
|
||||
|
||||
@ -128,24 +120,23 @@ public final class ClipboardSpy implements Runnable, ClipboardOwner, SecureNotif
|
||||
}
|
||||
}
|
||||
|
||||
}while(error);
|
||||
} while (error);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
private void gainOwnership(Transferable t) {
|
||||
|
||||
boolean error;
|
||||
|
||||
do{
|
||||
do {
|
||||
error = false;
|
||||
|
||||
try{
|
||||
try {
|
||||
|
||||
_sysClip.setContents(t,this);
|
||||
_sysClip.setContents(t, this);
|
||||
|
||||
} catch(Exception ex) {
|
||||
} catch (Exception ex) {
|
||||
|
||||
error = true;
|
||||
|
||||
@ -156,14 +147,14 @@ public final class ClipboardSpy implements Runnable, ClipboardOwner, SecureNotif
|
||||
}
|
||||
}
|
||||
|
||||
}while(error);
|
||||
} while (error);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attachObserver(ClipboardChangeObserver observer) {
|
||||
|
||||
if(!_observers.contains(observer)) {
|
||||
if (!_observers.contains(observer)) {
|
||||
|
||||
_observers.add(observer);
|
||||
}
|
||||
@ -179,7 +170,7 @@ public final class ClipboardSpy implements Runnable, ClipboardOwner, SecureNotif
|
||||
@Override
|
||||
public void notifyChangeToMyObservers() {
|
||||
|
||||
for(ClipboardChangeObserver o:_observers) {
|
||||
for (ClipboardChangeObserver o : _observers) {
|
||||
|
||||
o.notifyClipboardChange();
|
||||
}
|
||||
|
@ -4,8 +4,7 @@ import java.util.HashMap;
|
||||
|
||||
public final class ContentType {
|
||||
|
||||
private final HashMap<String,String> _content_type;
|
||||
|
||||
private final HashMap<String, String> _content_type;
|
||||
|
||||
public ContentType() {
|
||||
|
||||
@ -48,12 +47,12 @@ public final class ContentType {
|
||||
_content_type.put("mov", "video/quicktime");
|
||||
_content_type.put("qt", "video/quicktime");
|
||||
}
|
||||
|
||||
public HashMap<String, String> getContent_type() {
|
||||
return _content_type;
|
||||
}
|
||||
|
||||
public String getMIME(String ext)
|
||||
{
|
||||
public String getMIME(String ext) {
|
||||
return _content_type.get(ext);
|
||||
}
|
||||
}
|
||||
|
@ -23,8 +23,6 @@ public final class ContextMenuMouseListener extends MouseAdapter {
|
||||
private String _savedString;
|
||||
private _Actions _lastActionSelected;
|
||||
|
||||
|
||||
|
||||
public ContextMenuMouseListener() {
|
||||
_savedString = "";
|
||||
_popup = new JPopupMenu();
|
||||
@ -121,5 +119,8 @@ public final class ContextMenuMouseListener extends MouseAdapter {
|
||||
_popup.show(e.getComponent(), nx, e.getY() - _popup.getSize().height);
|
||||
}
|
||||
}
|
||||
private enum _Actions { UNDO, CUT, COPY, PASTE, SELECT_ALL }
|
||||
|
||||
private enum _Actions {
|
||||
UNDO, CUT, COPY, PASTE, SELECT_ALL
|
||||
}
|
||||
}
|
||||
|
@ -26,10 +26,9 @@ import static megabasterd.MiscTools.hex2bin;
|
||||
import static megabasterd.MiscTools.i32a2bin;
|
||||
import static megabasterd.MiscTools.long2bytearray;
|
||||
|
||||
|
||||
public final class CryptTools {
|
||||
|
||||
public static final int[] AES_ZERO_IV_I32A = {0,0,0,0};
|
||||
public static final int[] AES_ZERO_IV_I32A = {0, 0, 0, 0};
|
||||
|
||||
public static final byte[] AES_ZERO_IV = i32a2bin(AES_ZERO_IV_I32A);
|
||||
|
||||
@ -37,13 +36,12 @@ public final class CryptTools {
|
||||
|
||||
public static final int PBKDF2_ITERATIONS = 0x10000;
|
||||
|
||||
public static Cipher genDecrypter(String algo, String mode, byte[] key, byte[] iv) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException
|
||||
{
|
||||
public static Cipher genDecrypter(String algo, String mode, byte[] key, byte[] iv) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException {
|
||||
SecretKeySpec skeySpec = new SecretKeySpec(key, algo);
|
||||
|
||||
Cipher decryptor = Cipher.getInstance(mode);
|
||||
|
||||
if(iv != null) {
|
||||
if (iv != null) {
|
||||
|
||||
IvParameterSpec ivParameterSpec = new IvParameterSpec(iv);
|
||||
|
||||
@ -57,13 +55,12 @@ public final class CryptTools {
|
||||
return decryptor;
|
||||
}
|
||||
|
||||
public static Cipher genCrypter(String algo, String mode, byte[] key, byte[] iv) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException
|
||||
{
|
||||
public static Cipher genCrypter(String algo, String mode, byte[] key, byte[] iv) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException {
|
||||
SecretKeySpec skeySpec = new SecretKeySpec(key, algo);
|
||||
|
||||
Cipher cryptor = Cipher.getInstance(mode);
|
||||
|
||||
if(iv != null) {
|
||||
if (iv != null) {
|
||||
|
||||
IvParameterSpec ivParameterSpec = new IvParameterSpec(iv);
|
||||
|
||||
@ -189,25 +186,24 @@ public final class CryptTools {
|
||||
|
||||
byte[] enc_data_byte = enc_data.toByteArray();
|
||||
|
||||
if(enc_data_byte[0] == 0) {
|
||||
if (enc_data_byte[0] == 0) {
|
||||
|
||||
enc_data_byte=Arrays.copyOfRange(enc_data_byte, 1, enc_data_byte.length);
|
||||
enc_data_byte = Arrays.copyOfRange(enc_data_byte, 1, enc_data_byte.length);
|
||||
}
|
||||
|
||||
byte[] plainText = cipher.doFinal(enc_data_byte);
|
||||
|
||||
if(plainText[0] == 0) {
|
||||
if (plainText[0] == 0) {
|
||||
|
||||
plainText=Arrays.copyOfRange(plainText, 1, plainText.length);
|
||||
plainText = Arrays.copyOfRange(plainText, 1, plainText.length);
|
||||
}
|
||||
|
||||
return plainText;
|
||||
}
|
||||
|
||||
public static byte[] initMEGALinkKey(String key_string) throws Exception
|
||||
{
|
||||
public static byte[] initMEGALinkKey(String key_string) throws Exception {
|
||||
int[] int_key = bin2i32a(UrlBASE642Bin(key_string));
|
||||
int[] k=new int[4];
|
||||
int[] k = new int[4];
|
||||
|
||||
k[0] = int_key[0] ^ int_key[4];
|
||||
k[1] = int_key[1] ^ int_key[5];
|
||||
@ -217,9 +213,8 @@ public final class CryptTools {
|
||||
return i32a2bin(k);
|
||||
}
|
||||
|
||||
public static byte[] initMEGALinkKeyIV(String key_string) throws Exception
|
||||
{
|
||||
int[] int_key =bin2i32a(UrlBASE642Bin(key_string));
|
||||
public static byte[] initMEGALinkKeyIV(String key_string) throws Exception {
|
||||
int[] int_key = bin2i32a(UrlBASE642Bin(key_string));
|
||||
int[] iv = new int[4];
|
||||
|
||||
iv[0] = int_key[4];
|
||||
@ -230,31 +225,28 @@ public final class CryptTools {
|
||||
return i32a2bin(iv);
|
||||
}
|
||||
|
||||
public static byte[] forwardMEGALinkKeyIV(byte[] iv, long forward_bytes)
|
||||
{
|
||||
public static byte[] forwardMEGALinkKeyIV(byte[] iv, long forward_bytes) {
|
||||
byte[] new_iv = new byte[iv.length];
|
||||
|
||||
System.arraycopy(iv, 0, new_iv, 0, iv.length/2);
|
||||
System.arraycopy(iv, 0, new_iv, 0, iv.length / 2);
|
||||
|
||||
byte[] ctr = long2bytearray(forward_bytes/iv.length);
|
||||
byte[] ctr = long2bytearray(forward_bytes / iv.length);
|
||||
|
||||
System.arraycopy(ctr, 0, new_iv, iv.length/2, ctr.length);
|
||||
System.arraycopy(ctr, 0, new_iv, iv.length / 2, ctr.length);
|
||||
|
||||
return new_iv;
|
||||
}
|
||||
|
||||
public static String decryptMegaDownloaderLink(String link) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, Exception, IllegalBlockSizeException, BadPaddingException
|
||||
{
|
||||
String[] keys = {"6B316F36416C2D316B7A3F217A30357958585858585858585858585858585858","ED1F4C200B35139806B260563B3D3876F011B4750F3A1A4A5EFD0BBE67554B44"};
|
||||
String iv="79F10A01844A0B27FF5B2D4E0ED3163E";
|
||||
public static String decryptMegaDownloaderLink(String link) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, Exception, IllegalBlockSizeException, BadPaddingException {
|
||||
String[] keys = {"6B316F36416C2D316B7A3F217A30357958585858585858585858585858585858", "ED1F4C200B35139806B260563B3D3876F011B4750F3A1A4A5EFD0BBE67554B44"};
|
||||
String iv = "79F10A01844A0B27FF5B2D4E0ED3163E";
|
||||
|
||||
String enc_type, folder, dec_link;
|
||||
|
||||
if((enc_type=findFirstRegex("mega://f?(enc[0-9]*)\\?", link, 1)) != null)
|
||||
{
|
||||
if ((enc_type = findFirstRegex("mega://f?(enc[0-9]*)\\?", link, 1)) != null) {
|
||||
Cipher decrypter;
|
||||
|
||||
String the_key=null;
|
||||
String the_key = null;
|
||||
|
||||
switch (enc_type.toLowerCase()) {
|
||||
case "enc":
|
||||
@ -265,15 +257,15 @@ public final class CryptTools {
|
||||
break;
|
||||
}
|
||||
|
||||
folder=findFirstRegex("mega://(f)?enc[0-9]*\\?", link, 1);
|
||||
folder = findFirstRegex("mega://(f)?enc[0-9]*\\?", link, 1);
|
||||
|
||||
decrypter = CryptTools.genDecrypter("AES", "AES/CBC/NoPadding", hex2bin(the_key), hex2bin(iv));
|
||||
|
||||
byte[] decrypted_data = decrypter.doFinal(UrlBASE642Bin(findFirstRegex("mega://f?enc[0-9]*\\?([\\da-zA-Z_,-]*)", link, 1)));
|
||||
|
||||
dec_link=new String(decrypted_data).trim();
|
||||
dec_link = new String(decrypted_data).trim();
|
||||
|
||||
return "https://mega.nz/#"+(folder!=null?"f":"")+dec_link;
|
||||
return "https://mega.nz/#" + (folder != null ? "f" : "") + dec_link;
|
||||
|
||||
} else {
|
||||
return link;
|
||||
@ -284,16 +276,16 @@ public final class CryptTools {
|
||||
|
||||
int[] s32 = bin2i32a(str);
|
||||
|
||||
int[] h32 = {0,0,0,0};
|
||||
int[] h32 = {0, 0, 0, 0};
|
||||
|
||||
int[] iv = {0,0,0,0};
|
||||
int[] iv = {0, 0, 0, 0};
|
||||
|
||||
for(int i=0; i<s32.length; i++) {
|
||||
for (int i = 0; i < s32.length; i++) {
|
||||
|
||||
h32[i%4]^=s32[i];
|
||||
h32[i % 4] ^= s32[i];
|
||||
}
|
||||
|
||||
for(int i=0; i<0x4000; i++) {
|
||||
for (int i = 0; i < 0x4000; i++) {
|
||||
|
||||
h32 = CryptTools.aes_cbc_encrypt_ia32(h32, aeskey, iv);
|
||||
}
|
||||
@ -307,19 +299,19 @@ public final class CryptTools {
|
||||
|
||||
int[] pkey = {0x93C467E3, 0x7DB0_C7A4, 0xD1BE_3F81, 0x0152_CB56};
|
||||
|
||||
int[] iv = {0,0,0,0};
|
||||
int[] iv = {0, 0, 0, 0};
|
||||
|
||||
for(int r=0; r<0x10000; r++) {
|
||||
for (int r = 0; r < 0x10000; r++) {
|
||||
|
||||
for(int j=0; j<key.length; j+=4) {
|
||||
for (int j = 0; j < key.length; j += 4) {
|
||||
|
||||
int[] k = {0,0,0,0};
|
||||
int[] k = {0, 0, 0, 0};
|
||||
|
||||
for(int i=0; i<4; i++) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
|
||||
if(i+j < key.length) {
|
||||
if (i + j < key.length) {
|
||||
|
||||
k[i] = key[i+j];
|
||||
k[i] = key[i + j];
|
||||
}
|
||||
}
|
||||
|
||||
@ -339,7 +331,6 @@ public final class CryptTools {
|
||||
return f.generateSecret(ks).getEncoded();
|
||||
}
|
||||
|
||||
|
||||
private CryptTools() {
|
||||
}
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ public final class DBTools {
|
||||
|
||||
public static String selectSettingValueFromDB(String key) {
|
||||
|
||||
String value=null;
|
||||
String value = null;
|
||||
|
||||
try (Connection conn = SqliteSingleton.getInstance().getConn(); PreparedStatement ps = conn.prepareStatement("SELECT value from settings WHERE key=?")) {
|
||||
|
||||
@ -113,7 +113,7 @@ public final class DBTools {
|
||||
|
||||
ResultSet res = ps.executeQuery();
|
||||
|
||||
if(res.next()) {
|
||||
if (res.next()) {
|
||||
value = res.getString(1);
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
@ -135,9 +135,9 @@ public final class DBTools {
|
||||
}
|
||||
}
|
||||
|
||||
public static ArrayList<HashMap<String,Object>> selectDownloads() throws SQLException {
|
||||
public static ArrayList<HashMap<String, Object>> selectDownloads() throws SQLException {
|
||||
|
||||
ArrayList<HashMap<String,Object>> downloads = new ArrayList<>();
|
||||
ArrayList<HashMap<String, Object>> downloads = new ArrayList<>();
|
||||
|
||||
ResultSet res;
|
||||
|
||||
@ -145,9 +145,9 @@ public final class DBTools {
|
||||
|
||||
res = stat.executeQuery("SELECT * FROM downloads");
|
||||
|
||||
while(res.next()) {
|
||||
while (res.next()) {
|
||||
|
||||
HashMap<String,Object> download = new HashMap<>();
|
||||
HashMap<String, Object> download = new HashMap<>();
|
||||
|
||||
download.put("url", res.getString("url"));
|
||||
download.put("path", res.getString("path"));
|
||||
@ -164,9 +164,9 @@ public final class DBTools {
|
||||
return downloads;
|
||||
}
|
||||
|
||||
public static ArrayList<HashMap<String,Object>> selectUploads() throws SQLException {
|
||||
public static ArrayList<HashMap<String, Object>> selectUploads() throws SQLException {
|
||||
|
||||
ArrayList<HashMap<String,Object>> uploads = new ArrayList<>();
|
||||
ArrayList<HashMap<String, Object>> uploads = new ArrayList<>();
|
||||
|
||||
ResultSet res;
|
||||
|
||||
@ -174,9 +174,9 @@ public final class DBTools {
|
||||
|
||||
res = stat.executeQuery("SELECT * FROM uploads");
|
||||
|
||||
while(res.next()) {
|
||||
while (res.next()) {
|
||||
|
||||
HashMap<String,Object> upload = new HashMap<>();
|
||||
HashMap<String, Object> upload = new HashMap<>();
|
||||
|
||||
upload.put("filename", res.getString("filename"));
|
||||
upload.put("email", res.getString("email"));
|
||||
@ -193,7 +193,7 @@ public final class DBTools {
|
||||
return uploads;
|
||||
}
|
||||
|
||||
public static HashMap<String,Object> selectMegaAccounts() throws SQLException {
|
||||
public static HashMap<String, Object> selectMegaAccounts() throws SQLException {
|
||||
|
||||
HashMap<String, Object> accounts = new HashMap<>();
|
||||
|
||||
@ -203,9 +203,9 @@ public final class DBTools {
|
||||
|
||||
res = stat.executeQuery("SELECT * FROM mega_accounts");
|
||||
|
||||
while(res.next()) {
|
||||
while (res.next()) {
|
||||
|
||||
HashMap<String,Object> account_data = new HashMap<>();
|
||||
HashMap<String, Object> account_data = new HashMap<>();
|
||||
|
||||
account_data.put("password", res.getString("password"));
|
||||
account_data.put("password_aes", res.getString("password_aes"));
|
||||
@ -218,7 +218,6 @@ public final class DBTools {
|
||||
return accounts;
|
||||
}
|
||||
|
||||
|
||||
public static void insertMegaAccount(String email, String password, String password_aes, String user_hash) throws SQLException {
|
||||
|
||||
try (Connection conn = SqliteSingleton.getInstance().getConn(); PreparedStatement ps = conn.prepareStatement("INSERT OR REPLACE INTO mega_accounts (email,password,password_aes,user_hash) VALUES (?, ?, ?, ?)")) {
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -7,7 +7,6 @@ import static java.util.logging.Logger.getLogger;
|
||||
import static megabasterd.DBTools.deleteDownload;
|
||||
import static megabasterd.MainPanel.THREAD_POOL;
|
||||
|
||||
|
||||
public final class DownloadManager extends TransferenceManager {
|
||||
|
||||
public DownloadManager(MainPanel main_panel) {
|
||||
@ -18,7 +17,7 @@ public final class DownloadManager extends TransferenceManager {
|
||||
@Override
|
||||
public void remove(Transference download) {
|
||||
|
||||
getScroll_panel().remove(((Download)download).getView());
|
||||
getScroll_panel().remove(((Download) download).getView());
|
||||
|
||||
getTransference_waitstart_queue().remove(download);
|
||||
|
||||
@ -26,10 +25,10 @@ public final class DownloadManager extends TransferenceManager {
|
||||
|
||||
getTransference_finished_queue().remove(download);
|
||||
|
||||
if(((Download)download).isProvision_ok()) {
|
||||
if (((Download) download).isProvision_ok()) {
|
||||
|
||||
try {
|
||||
deleteDownload(((Download)download).getUrl());
|
||||
deleteDownload(((Download) download).getUrl());
|
||||
} catch (SQLException ex) {
|
||||
getLogger(DownloadManager.class.getName()).log(SEVERE, null, ex);
|
||||
}
|
||||
@ -39,13 +38,12 @@ public final class DownloadManager extends TransferenceManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void provision(final Transference download)
|
||||
{
|
||||
getScroll_panel().add(((Download)download).getView());
|
||||
public void provision(final Transference download) {
|
||||
getScroll_panel().add(((Download) download).getView());
|
||||
|
||||
try {
|
||||
|
||||
_provision((Download)download, false);
|
||||
_provision((Download) download, false);
|
||||
|
||||
secureNotify();
|
||||
|
||||
@ -53,13 +51,13 @@ public final class DownloadManager extends TransferenceManager {
|
||||
|
||||
System.out.println("Provision failed! Retrying in separated thread...");
|
||||
|
||||
THREAD_POOL.execute(new Runnable(){
|
||||
THREAD_POOL.execute(new Runnable() {
|
||||
@Override
|
||||
public void run(){
|
||||
public void run() {
|
||||
|
||||
try {
|
||||
|
||||
_provision((Download)download, true);
|
||||
_provision((Download) download, true);
|
||||
|
||||
} catch (MegaAPIException | MegaCrypterAPIException ex1) {
|
||||
|
||||
@ -68,7 +66,8 @@ public final class DownloadManager extends TransferenceManager {
|
||||
|
||||
secureNotify();
|
||||
|
||||
}});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@ -77,24 +76,24 @@ public final class DownloadManager extends TransferenceManager {
|
||||
|
||||
download.provisionIt(retry);
|
||||
|
||||
if(download.isProvision_ok()) {
|
||||
if (download.isProvision_ok()) {
|
||||
|
||||
getTransference_waitstart_queue().add(download);
|
||||
|
||||
if(getTransference_provision_queue().isEmpty()) {
|
||||
if (getTransference_provision_queue().isEmpty()) {
|
||||
|
||||
sortTransferenceStartQueue();
|
||||
|
||||
for(Transference down:getTransference_waitstart_queue()) {
|
||||
for (Transference down : getTransference_waitstart_queue()) {
|
||||
|
||||
getScroll_panel().remove((Component)down.getView());
|
||||
getScroll_panel().add((Component)down.getView());
|
||||
getScroll_panel().remove((Component) down.getView());
|
||||
getScroll_panel().add((Component) down.getView());
|
||||
}
|
||||
|
||||
for(Transference down:getTransference_finished_queue()) {
|
||||
for (Transference down : getTransference_finished_queue()) {
|
||||
|
||||
getScroll_panel().remove((Component)down.getView());
|
||||
getScroll_panel().add((Component)down.getView());
|
||||
getScroll_panel().remove((Component) down.getView());
|
||||
getScroll_panel().add((Component) down.getView());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,12 +11,10 @@ import javax.swing.JSpinner;
|
||||
import javax.swing.SpinnerNumberModel;
|
||||
import static megabasterd.MainPanel.FONT_DEFAULT;
|
||||
import static megabasterd.MainPanel.THREAD_POOL;
|
||||
import static megabasterd.MiscTools.copyTextToClipboard;
|
||||
import static megabasterd.MiscTools.swingReflectionInvoke;
|
||||
import static megabasterd.MiscTools.swingReflectionInvokeAndWait;
|
||||
import static megabasterd.MiscTools.updateFont;
|
||||
|
||||
|
||||
public final class DownloadView extends javax.swing.JPanel implements TransferenceView {
|
||||
|
||||
private final Download _download;
|
||||
@ -87,7 +85,7 @@ public final class DownloadView extends javax.swing.JPanel implements Transferen
|
||||
|
||||
_download = download;
|
||||
|
||||
MiscTools.swingInvokeIt(new Runnable(){
|
||||
MiscTools.swingInvokeIt(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
@ -105,22 +103,22 @@ public final class DownloadView extends javax.swing.JPanel implements Transferen
|
||||
updateFont(close_button, FONT_DEFAULT, Font.PLAIN);
|
||||
updateFont(copy_link_button, FONT_DEFAULT, Font.PLAIN);
|
||||
updateFont(restart_button, FONT_DEFAULT, Font.PLAIN);
|
||||
updateFont(slot_status_label, FONT_DEFAULT, Font.BOLD);}}, true);
|
||||
|
||||
updateFont(slot_status_label, FONT_DEFAULT, Font.BOLD);
|
||||
}
|
||||
}, true);
|
||||
|
||||
swingReflectionInvokeAndWait("setModel", slots_spinner, new SpinnerNumberModel(_download.getMain_panel().getDefault_slots_down(), Download.MIN_WORKERS, Download.MAX_WORKERS, 1));
|
||||
|
||||
swingReflectionInvoke("setEditable", ((JSpinner.DefaultEditor)slots_spinner.getEditor()).getTextField(), false);
|
||||
swingReflectionInvoke("setEditable", ((JSpinner.DefaultEditor) slots_spinner.getEditor()).getTextField(), false);
|
||||
|
||||
swingReflectionInvoke("setForeground", speed_label, new Color(0,128,255));
|
||||
swingReflectionInvoke("setForeground", speed_label, new Color(0, 128, 255));
|
||||
|
||||
swingReflectionInvoke("setVisible", new Object[]{slots_spinner, slots_label, pause_button, stop_button, speed_label, remtime_label,progress_pbar,keep_temp_checkbox,file_name_label,close_button,copy_link_button,restart_button,file_size_label}, false);
|
||||
swingReflectionInvoke("setVisible", new Object[]{slots_spinner, slots_label, pause_button, stop_button, speed_label, remtime_label, progress_pbar, keep_temp_checkbox, file_name_label, close_button, copy_link_button, restart_button, file_size_label}, false);
|
||||
|
||||
}
|
||||
|
||||
public void hideAllExceptStatus()
|
||||
{
|
||||
swingReflectionInvoke("setVisible", new Object[]{speed_label, remtime_label, slots_spinner,slots_label,slot_status_label,slot_status_label,pause_button,stop_button,progress_pbar,keep_temp_checkbox}, false);
|
||||
public void hideAllExceptStatus() {
|
||||
swingReflectionInvoke("setVisible", new Object[]{speed_label, remtime_label, slots_spinner, slots_label, slot_status_label, slot_status_label, pause_button, stop_button, progress_pbar, keep_temp_checkbox}, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -325,7 +323,7 @@ public final class DownloadView extends javax.swing.JPanel implements Transferen
|
||||
|
||||
private void slots_spinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_slots_spinnerStateChanged
|
||||
|
||||
THREAD_POOL.execute(new Runnable(){
|
||||
THREAD_POOL.execute(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
@ -335,7 +333,6 @@ public final class DownloadView extends javax.swing.JPanel implements Transferen
|
||||
});
|
||||
}//GEN-LAST:event_slots_spinnerStateChanged
|
||||
|
||||
|
||||
private void close_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_close_buttonActionPerformed
|
||||
|
||||
_download.close();
|
||||
@ -343,7 +340,7 @@ public final class DownloadView extends javax.swing.JPanel implements Transferen
|
||||
|
||||
private void copy_link_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_copy_link_buttonActionPerformed
|
||||
|
||||
copyTextToClipboard(_download.getUrl());
|
||||
MiscTools.copyTextToClipboard(_download.getUrl());
|
||||
|
||||
JOptionPane.showMessageDialog(_download.getMain_panel().getView(), "Link was copied to clipboard!");
|
||||
}//GEN-LAST:event_copy_link_buttonActionPerformed
|
||||
@ -368,7 +365,7 @@ public final class DownloadView extends javax.swing.JPanel implements Transferen
|
||||
|
||||
printStatusNormal("Pausing download ...");
|
||||
|
||||
swingReflectionInvoke("setEnabled", new Object[]{pause_button,speed_label,slots_label,slots_spinner}, false);
|
||||
swingReflectionInvoke("setEnabled", new Object[]{pause_button, speed_label, slots_label, slots_spinner}, false);
|
||||
swingReflectionInvoke("setVisible", new Object[]{stop_button, keep_temp_checkbox}, true);
|
||||
|
||||
}
|
||||
@ -378,7 +375,7 @@ public final class DownloadView extends javax.swing.JPanel implements Transferen
|
||||
|
||||
printStatusNormal("Downloading file from mega ...");
|
||||
|
||||
swingReflectionInvoke("setEnabled", new Object[]{pause_button,speed_label,slots_label,slots_spinner}, true);
|
||||
swingReflectionInvoke("setEnabled", new Object[]{pause_button, speed_label, slots_label, slots_spinner}, true);
|
||||
swingReflectionInvoke("setVisible", new Object[]{stop_button, keep_temp_checkbox}, false);
|
||||
swingReflectionInvoke("setText", pause_button, "PAUSE DOWNLOAD");
|
||||
swingReflectionInvoke("setVisible", _download.getMain_panel().getView().getPause_all_down_button(), true);
|
||||
@ -390,19 +387,18 @@ public final class DownloadView extends javax.swing.JPanel implements Transferen
|
||||
|
||||
printStatusNormal("Stopping download safely, please wait...");
|
||||
|
||||
swingReflectionInvoke("setEnabled", new Object[]{pause_button,keep_temp_checkbox,stop_button,speed_label,slots_label,slots_spinner}, false);
|
||||
swingReflectionInvoke("setEnabled", new Object[]{pause_button, keep_temp_checkbox, stop_button, speed_label, slots_label, slots_spinner}, false);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void updateSpeed(String speed, Boolean visible) {
|
||||
|
||||
if(speed != null) {
|
||||
if (speed != null) {
|
||||
|
||||
swingReflectionInvoke("setText", speed_label, speed);
|
||||
}
|
||||
|
||||
if(visible != null) {
|
||||
if (visible != null) {
|
||||
|
||||
swingReflectionInvoke("setVisible", speed_label, visible);
|
||||
}
|
||||
@ -411,12 +407,12 @@ public final class DownloadView extends javax.swing.JPanel implements Transferen
|
||||
@Override
|
||||
public void updateRemainingTime(String rem_time, Boolean visible) {
|
||||
|
||||
if(speed_label != null) {
|
||||
if (speed_label != null) {
|
||||
|
||||
swingReflectionInvoke("setText", remtime_label, rem_time);
|
||||
}
|
||||
|
||||
if(visible != null) {
|
||||
if (visible != null) {
|
||||
|
||||
swingReflectionInvoke("setVisible", remtime_label, visible);
|
||||
}
|
||||
@ -425,27 +421,24 @@ public final class DownloadView extends javax.swing.JPanel implements Transferen
|
||||
@Override
|
||||
public void updateProgressBar(long progress, double bar_rate) {
|
||||
|
||||
swingReflectionInvoke("setValue", progress_pbar, (int)Math.ceil(bar_rate*progress));
|
||||
swingReflectionInvoke("setValue", progress_pbar, (int) Math.ceil(bar_rate * progress));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printStatusError(String message)
|
||||
{
|
||||
public void printStatusError(String message) {
|
||||
swingReflectionInvoke("setForeground", status_label, Color.red);
|
||||
swingReflectionInvoke("setText", status_label, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printStatusOK(String message)
|
||||
{
|
||||
swingReflectionInvoke("setForeground", status_label, new Color(0,128,0));
|
||||
public void printStatusOK(String message) {
|
||||
swingReflectionInvoke("setForeground", status_label, new Color(0, 128, 0));
|
||||
swingReflectionInvoke("setText", status_label, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printStatusNormal(String message)
|
||||
{
|
||||
public void printStatusNormal(String message) {
|
||||
swingReflectionInvoke("setForeground", status_label, Color.BLACK);
|
||||
swingReflectionInvoke("setText", status_label, message);
|
||||
}
|
||||
@ -455,9 +448,9 @@ public final class DownloadView extends javax.swing.JPanel implements Transferen
|
||||
|
||||
int conta_exit = 0;
|
||||
|
||||
for(ChunkDownloader c:_download.getChunkworkers()) {
|
||||
for (ChunkDownloader c : _download.getChunkworkers()) {
|
||||
|
||||
if(c.isExit()) {
|
||||
if (c.isExit()) {
|
||||
|
||||
conta_exit++;
|
||||
}
|
||||
@ -465,15 +458,15 @@ public final class DownloadView extends javax.swing.JPanel implements Transferen
|
||||
|
||||
int conta_error = 0;
|
||||
|
||||
for(ChunkDownloader c:_download.getChunkworkers()) {
|
||||
for (ChunkDownloader c : _download.getChunkworkers()) {
|
||||
|
||||
if(c.isError_wait()) {
|
||||
if (c.isError_wait()) {
|
||||
|
||||
conta_error++;
|
||||
}
|
||||
}
|
||||
|
||||
if(conta_error > 0) {
|
||||
if (conta_error > 0) {
|
||||
|
||||
swingReflectionInvoke("setForeground", slot_status_label, Color.red);
|
||||
|
||||
@ -482,7 +475,7 @@ public final class DownloadView extends javax.swing.JPanel implements Transferen
|
||||
swingReflectionInvoke("setForeground", slot_status_label, Color.black);
|
||||
}
|
||||
|
||||
swingReflectionInvoke("setText", slot_status_label, (conta_exit>0?"Removing: "+conta_exit:"") + (conta_error>0?((conta_exit>0?" / ":"")+"Error: " + conta_error):""));
|
||||
swingReflectionInvoke("setText", slot_status_label, (conta_exit > 0 ? "Removing: " + conta_exit : "") + (conta_error > 0 ? ((conta_exit > 0 ? " / " : "") + "Error: " + conta_error) : ""));
|
||||
|
||||
}
|
||||
|
||||
@ -504,6 +497,4 @@ public final class DownloadView extends javax.swing.JPanel implements Transferen
|
||||
private javax.swing.JButton stop_button;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -15,6 +15,8 @@ import javax.swing.JFileChooser;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.DefaultTreeModel;
|
||||
import javax.swing.tree.TreeModel;
|
||||
import javax.swing.tree.TreeNode;
|
||||
import static megabasterd.MainPanel.FONT_DEFAULT;
|
||||
import static megabasterd.MainPanel.THREAD_POOL;
|
||||
import static megabasterd.MiscTools.BASE642Bin;
|
||||
@ -70,6 +72,7 @@ public final class FileGrabberDialog extends javax.swing.JDialog {
|
||||
|
||||
/**
|
||||
* Creates new form FileGrabber
|
||||
*
|
||||
* @param parent
|
||||
* @param modal
|
||||
*/
|
||||
@ -86,10 +89,11 @@ public final class FileGrabberDialog extends javax.swing.JDialog {
|
||||
_remember_master_pass = true;
|
||||
_files = new ArrayList<>();
|
||||
|
||||
MiscTools.swingInvokeIt(new Runnable(){
|
||||
MiscTools.swingInvokeIt(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {updateFont(dance_button, FONT_DEFAULT, Font.PLAIN);
|
||||
public void run() {
|
||||
updateFont(dance_button, FONT_DEFAULT, Font.PLAIN);
|
||||
updateFont(add_files_button, FONT_DEFAULT, Font.PLAIN);
|
||||
updateFont(add_folder_button, FONT_DEFAULT, Font.PLAIN);
|
||||
updateFont(account_combobox, FONT_DEFAULT, Font.PLAIN);
|
||||
@ -101,17 +105,19 @@ public final class FileGrabberDialog extends javax.swing.JDialog {
|
||||
updateFont(warning_label, FONT_DEFAULT, Font.PLAIN);
|
||||
updateFont(dir_name_textfield, FONT_DEFAULT, Font.PLAIN);
|
||||
updateFont(skip_button, FONT_DEFAULT, Font.PLAIN);
|
||||
updateFont(skip_rest_button, FONT_DEFAULT, Font.PLAIN);}}, true);
|
||||
updateFont(skip_rest_button, FONT_DEFAULT, Font.PLAIN);
|
||||
}
|
||||
}, true);
|
||||
|
||||
swingReflectionInvokeAndWait("addMouseListener", dir_name_textfield, new ContextMenuMouseListener());
|
||||
|
||||
_main_panel = ((MainPanelView)parent).getMain_panel();
|
||||
_main_panel = ((MainPanelView) parent).getMain_panel();
|
||||
|
||||
if( _main_panel.getMega_accounts().size() > 0) {
|
||||
if (_main_panel.getMega_accounts().size() > 0) {
|
||||
|
||||
for (Object o:_main_panel.getMega_accounts().keySet()) {
|
||||
for (Object o : _main_panel.getMega_accounts().keySet()) {
|
||||
|
||||
swingReflectionInvoke("addItem", account_combobox, (String)o);
|
||||
swingReflectionInvoke("addItem", account_combobox, o);
|
||||
}
|
||||
|
||||
} else {
|
||||
@ -356,7 +362,6 @@ public final class FileGrabberDialog extends javax.swing.JDialog {
|
||||
dir_name_textfield.setEnabled(false);
|
||||
dir_name_label.setEnabled(false);
|
||||
|
||||
|
||||
JFileChooser filechooser = new javax.swing.JFileChooser();
|
||||
|
||||
filechooser.setDialogTitle("Add files");
|
||||
@ -365,7 +370,7 @@ public final class FileGrabberDialog extends javax.swing.JDialog {
|
||||
|
||||
filechooser.setMultiSelectionEnabled(true);
|
||||
|
||||
if( filechooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION ) {
|
||||
if (filechooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
|
||||
|
||||
total_file_size_label.setText("[0 B]");
|
||||
|
||||
@ -375,7 +380,7 @@ public final class FileGrabberDialog extends javax.swing.JDialog {
|
||||
|
||||
System.out.println(_base_path);
|
||||
|
||||
dir_name_textfield.setText(files_selected[0].getParentFile().getName()+"_"+genID(10));
|
||||
dir_name_textfield.setText(files_selected[0].getParentFile().getName() + "_" + genID(10));
|
||||
|
||||
dir_name_textfield.setEnabled(true);
|
||||
|
||||
@ -383,9 +388,9 @@ public final class FileGrabberDialog extends javax.swing.JDialog {
|
||||
|
||||
DefaultMutableTreeNode root = new DefaultMutableTreeNode(filechooser.getSelectedFile().getParent());
|
||||
|
||||
for(File file:files_selected) {
|
||||
for (File file : files_selected) {
|
||||
|
||||
DefaultMutableTreeNode current_file = new DefaultMutableTreeNode( file.getName() + (file.isFile()?" ["+ formatBytes(file.length())+"]":"") );
|
||||
DefaultMutableTreeNode current_file = new DefaultMutableTreeNode(file.getName() + (file.isFile() ? " [" + formatBytes(file.length()) + "]" : ""));
|
||||
|
||||
root.add(current_file);
|
||||
}
|
||||
@ -402,7 +407,7 @@ public final class FileGrabberDialog extends javax.swing.JDialog {
|
||||
|
||||
add_files_button.setText("Add files");
|
||||
|
||||
boolean root_childs = ((DefaultMutableTreeNode)tree_model.getRoot()).getChildCount()>0;
|
||||
boolean root_childs = ((TreeNode) tree_model.getRoot()).getChildCount() > 0;
|
||||
|
||||
file_tree.setRootVisible(root_childs);
|
||||
file_tree.setEnabled(root_childs);
|
||||
@ -447,7 +452,7 @@ public final class FileGrabberDialog extends javax.swing.JDialog {
|
||||
|
||||
filechooser.setAcceptAllFileFilterUsed(false);
|
||||
|
||||
if( filechooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION ) {
|
||||
if (filechooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
|
||||
|
||||
total_file_size_label.setText("[0 B]");
|
||||
|
||||
@ -455,7 +460,7 @@ public final class FileGrabberDialog extends javax.swing.JDialog {
|
||||
|
||||
System.out.println(_base_path);
|
||||
|
||||
dir_name_textfield.setText(filechooser.getSelectedFile().getName()+"_"+genID(10));
|
||||
dir_name_textfield.setText(filechooser.getSelectedFile().getName() + "_" + genID(10));
|
||||
|
||||
dir_name_textfield.setEnabled(true);
|
||||
|
||||
@ -477,7 +482,7 @@ public final class FileGrabberDialog extends javax.swing.JDialog {
|
||||
|
||||
add_folder_button.setText("Add folder");
|
||||
|
||||
boolean root_childs = ((DefaultMutableTreeNode)tree_model.getRoot()).getChildCount()>0;
|
||||
boolean root_childs = ((TreeNode) tree_model.getRoot()).getChildCount() > 0;
|
||||
|
||||
file_tree.setRootVisible(root_childs);
|
||||
|
||||
@ -513,9 +518,9 @@ public final class FileGrabberDialog extends javax.swing.JDialog {
|
||||
|
||||
private void account_comboboxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_account_comboboxItemStateChanged
|
||||
|
||||
String selected_item = (String)account_combobox.getSelectedItem();
|
||||
String selected_item = (String) account_combobox.getSelectedItem();
|
||||
|
||||
if(selected_item != null && !selected_item.equals(_last_selected_account)) {
|
||||
if (selected_item != null && !selected_item.equals(_last_selected_account)) {
|
||||
|
||||
_last_selected_account = selected_item;
|
||||
|
||||
@ -525,7 +530,6 @@ public final class FileGrabberDialog extends javax.swing.JDialog {
|
||||
|
||||
used_space_label.setForeground(Color.black);
|
||||
|
||||
|
||||
used_space_label.setText("Checking account quota, please wait...");
|
||||
|
||||
account_combobox.setEnabled(false);
|
||||
@ -540,18 +544,17 @@ public final class FileGrabberDialog extends javax.swing.JDialog {
|
||||
warning_label.setEnabled(false);
|
||||
file_tree.setEnabled(false);
|
||||
|
||||
|
||||
THREAD_POOL.execute(new Runnable(){
|
||||
THREAD_POOL.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
HashMap<String,Object> account_info = (HashMap)_main_panel.getMega_accounts().get(email);
|
||||
HashMap<String, Object> account_info = (HashMap) _main_panel.getMega_accounts().get(email);
|
||||
|
||||
Long[] quota = null;
|
||||
|
||||
MegaAPI ma = _main_panel.getMega_active_accounts().get((String)account_combobox.getSelectedItem());
|
||||
MegaAPI ma = _main_panel.getMega_active_accounts().get(account_combobox.getSelectedItem());
|
||||
|
||||
if(ma == null) {
|
||||
if (ma == null) {
|
||||
|
||||
ma = new MegaAPI();
|
||||
|
||||
@ -559,17 +562,17 @@ public final class FileGrabberDialog extends javax.swing.JDialog {
|
||||
|
||||
try {
|
||||
|
||||
if(_main_panel.getMega_master_pass_hash() != null) {
|
||||
if (_main_panel.getMega_master_pass_hash() != null) {
|
||||
|
||||
if(_main_panel.getMega_master_pass() == null) {
|
||||
if (_main_panel.getMega_master_pass() == null) {
|
||||
|
||||
GetMegaMasterPasswordDialog dialog = new GetMegaMasterPasswordDialog((Frame)getParent(), true, _main_panel.getMega_master_pass_hash(), _main_panel.getMega_master_pass_salt());
|
||||
GetMegaMasterPasswordDialog dialog = new GetMegaMasterPasswordDialog((Frame) getParent(), true, _main_panel.getMega_master_pass_hash(), _main_panel.getMega_master_pass_salt());
|
||||
|
||||
swingReflectionInvokeAndWait("setLocationRelativeTo", dialog, tthis);
|
||||
|
||||
swingReflectionInvokeAndWait("setVisible", dialog, true);
|
||||
|
||||
if(dialog.isPass_ok()) {
|
||||
if (dialog.isPass_ok()) {
|
||||
|
||||
_main_panel.setMega_master_pass(dialog.getPass());
|
||||
|
||||
@ -579,9 +582,9 @@ public final class FileGrabberDialog extends javax.swing.JDialog {
|
||||
|
||||
dialog.dispose();
|
||||
|
||||
password_aes = Bin2BASE64(CryptTools.aes_cbc_decrypt_pkcs7(BASE642Bin((String)account_info.get("password_aes")), _main_panel.getMega_master_pass(), CryptTools.AES_ZERO_IV));
|
||||
password_aes = Bin2BASE64(CryptTools.aes_cbc_decrypt_pkcs7(BASE642Bin((String) account_info.get("password_aes")), _main_panel.getMega_master_pass(), CryptTools.AES_ZERO_IV));
|
||||
|
||||
user_hash = Bin2BASE64(CryptTools.aes_cbc_decrypt_pkcs7(BASE642Bin((String)account_info.get("user_hash")), _main_panel.getMega_master_pass(), CryptTools.AES_ZERO_IV));
|
||||
user_hash = Bin2BASE64(CryptTools.aes_cbc_decrypt_pkcs7(BASE642Bin((String) account_info.get("user_hash")), _main_panel.getMega_master_pass(), CryptTools.AES_ZERO_IV));
|
||||
|
||||
} else {
|
||||
|
||||
@ -592,20 +595,20 @@ public final class FileGrabberDialog extends javax.swing.JDialog {
|
||||
|
||||
} else {
|
||||
|
||||
password_aes = Bin2BASE64(CryptTools.aes_cbc_decrypt_pkcs7(BASE642Bin((String)account_info.get("password_aes")), _main_panel.getMega_master_pass(), CryptTools.AES_ZERO_IV));
|
||||
password_aes = Bin2BASE64(CryptTools.aes_cbc_decrypt_pkcs7(BASE642Bin((String) account_info.get("password_aes")), _main_panel.getMega_master_pass(), CryptTools.AES_ZERO_IV));
|
||||
|
||||
user_hash = Bin2BASE64(CryptTools.aes_cbc_decrypt_pkcs7(BASE642Bin((String)account_info.get("user_hash")), _main_panel.getMega_master_pass(), CryptTools.AES_ZERO_IV));
|
||||
user_hash = Bin2BASE64(CryptTools.aes_cbc_decrypt_pkcs7(BASE642Bin((String) account_info.get("user_hash")), _main_panel.getMega_master_pass(), CryptTools.AES_ZERO_IV));
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
password_aes = (String)account_info.get("password_aes");
|
||||
password_aes = (String) account_info.get("password_aes");
|
||||
|
||||
user_hash = (String)account_info.get("user_hash");
|
||||
user_hash = (String) account_info.get("user_hash");
|
||||
}
|
||||
|
||||
ma.fastLogin(email,bin2i32a(BASE642Bin(password_aes)), user_hash);
|
||||
ma.fastLogin(email, bin2i32a(BASE642Bin(password_aes)), user_hash);
|
||||
|
||||
_main_panel.getMega_active_accounts().put(email, ma);
|
||||
|
||||
@ -616,36 +619,34 @@ public final class FileGrabberDialog extends javax.swing.JDialog {
|
||||
getLogger(FileGrabberDialog.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
quota = ma.getQuota();
|
||||
}
|
||||
|
||||
if(quota != null) {
|
||||
if (quota != null) {
|
||||
|
||||
if(quota[0] <= Math.round((double)quota[1]/2)) {
|
||||
if (quota[0] <= Math.round((double) quota[1] / 2)) {
|
||||
|
||||
swingReflectionInvoke("setForeground", used_space_label, new Color(0,128,0));
|
||||
swingReflectionInvoke("setForeground", used_space_label, new Color(0, 128, 0));
|
||||
|
||||
} else if(quota[0] < quota[1]) {
|
||||
} else if (quota[0] < quota[1]) {
|
||||
|
||||
swingReflectionInvoke("setForeground", used_space_label, new Color(230,115,0));
|
||||
swingReflectionInvoke("setForeground", used_space_label, new Color(230, 115, 0));
|
||||
|
||||
} else {
|
||||
|
||||
swingReflectionInvoke("setForeground", used_space_label, Color.red);
|
||||
}
|
||||
|
||||
boolean root_childs = ((DefaultMutableTreeNode)((DefaultTreeModel)swingReflectionInvokeAndWaitForReturn("getModel", file_tree)).getRoot()).getChildCount()>0;
|
||||
boolean root_childs = ((TreeNode) ((TreeModel) swingReflectionInvokeAndWaitForReturn("getModel", file_tree)).getRoot()).getChildCount() > 0;
|
||||
|
||||
swingReflectionInvoke("setText", used_space_label, formatBytes(quota[0])+" / "+formatBytes(quota[1]));
|
||||
swingReflectionInvoke("setText", used_space_label, formatBytes(quota[0]) + " / " + formatBytes(quota[1]));
|
||||
|
||||
swingReflectionInvoke("setEnabled", new Object[]{add_files_button,add_folder_button, account_combobox, account_label}, true);
|
||||
swingReflectionInvoke("setEnabled", new Object[]{add_files_button, add_folder_button, account_combobox, account_label}, true);
|
||||
|
||||
swingReflectionInvoke("setEnabled", new Object[]{dir_name_textfield, dir_name_label, warning_label, dance_button, file_tree, total_file_size_label, skip_button, skip_rest_button}, root_childs);
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
_last_selected_account = null;
|
||||
@ -661,7 +662,8 @@ public final class FileGrabberDialog extends javax.swing.JDialog {
|
||||
swingReflectionInvoke("setText", used_space_label, "ERROR checking account quota!");
|
||||
}
|
||||
|
||||
} });
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@ -669,11 +671,11 @@ public final class FileGrabberDialog extends javax.swing.JDialog {
|
||||
|
||||
private void skip_rest_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_skip_rest_buttonActionPerformed
|
||||
|
||||
if( deleteAllExceptSelectedTreeItems(file_tree)) {
|
||||
if (deleteAllExceptSelectedTreeItems(file_tree)) {
|
||||
|
||||
_genFileList();
|
||||
|
||||
boolean root_childs = ((DefaultMutableTreeNode)file_tree.getModel().getRoot()).getChildCount()>0;
|
||||
boolean root_childs = ((TreeNode) file_tree.getModel().getRoot()).getChildCount() > 0;
|
||||
|
||||
warning_label.setEnabled(root_childs);
|
||||
dance_button.setEnabled(root_childs);
|
||||
@ -683,7 +685,7 @@ public final class FileGrabberDialog extends javax.swing.JDialog {
|
||||
dir_name_textfield.setEnabled(root_childs);
|
||||
dir_name_label.setEnabled(root_childs);
|
||||
|
||||
if(!root_childs) {
|
||||
if (!root_childs) {
|
||||
|
||||
dir_name_textfield.setText("");
|
||||
}
|
||||
@ -693,11 +695,11 @@ public final class FileGrabberDialog extends javax.swing.JDialog {
|
||||
|
||||
private void skip_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_skip_buttonActionPerformed
|
||||
|
||||
if(deleteSelectedTreeItems(file_tree)) {
|
||||
if (deleteSelectedTreeItems(file_tree)) {
|
||||
|
||||
_genFileList();
|
||||
|
||||
boolean root_childs = ((DefaultMutableTreeNode)file_tree.getModel().getRoot()).getChildCount()>0;
|
||||
boolean root_childs = ((TreeNode) file_tree.getModel().getRoot()).getChildCount() > 0;
|
||||
|
||||
warning_label.setEnabled(root_childs);
|
||||
dance_button.setEnabled(root_childs);
|
||||
@ -707,7 +709,7 @@ public final class FileGrabberDialog extends javax.swing.JDialog {
|
||||
dir_name_textfield.setEnabled(root_childs);
|
||||
dir_name_label.setEnabled(root_childs);
|
||||
|
||||
if(!root_childs) {
|
||||
if (!root_childs) {
|
||||
|
||||
dir_name_textfield.setText("");
|
||||
}
|
||||
@ -720,19 +722,19 @@ public final class FileGrabberDialog extends javax.swing.JDialog {
|
||||
|
||||
File[] fList = directory.listFiles();
|
||||
|
||||
if(fList != null) {
|
||||
if (fList != null) {
|
||||
|
||||
for (File file : fList) {
|
||||
|
||||
if (file.isFile()) {
|
||||
|
||||
DefaultMutableTreeNode current_file = new DefaultMutableTreeNode( file.getName() + " ["+formatBytes(file.length())+"]" );
|
||||
DefaultMutableTreeNode current_file = new DefaultMutableTreeNode(file.getName() + " [" + formatBytes(file.length()) + "]");
|
||||
|
||||
root.add(current_file);
|
||||
|
||||
} else if (file.isDirectory() && file.listFiles().length > 0) {
|
||||
|
||||
DefaultMutableTreeNode current_dir = new DefaultMutableTreeNode( file.getName() );
|
||||
DefaultMutableTreeNode current_dir = new DefaultMutableTreeNode(file.getName());
|
||||
|
||||
root.add(current_dir);
|
||||
|
||||
@ -749,44 +751,43 @@ public final class FileGrabberDialog extends javax.swing.JDialog {
|
||||
|
||||
_total_space = 0L;
|
||||
|
||||
DefaultTreeModel tree_model = (DefaultTreeModel)file_tree.getModel();
|
||||
DefaultTreeModel tree_model = (DefaultTreeModel) file_tree.getModel();
|
||||
|
||||
DefaultMutableTreeNode root = (DefaultMutableTreeNode)tree_model.getRoot();
|
||||
DefaultMutableTreeNode root = (DefaultMutableTreeNode) tree_model.getRoot();
|
||||
|
||||
Enumeration files_tree = root.depthFirstEnumeration();
|
||||
|
||||
while(files_tree.hasMoreElements()) {
|
||||
while (files_tree.hasMoreElements()) {
|
||||
|
||||
DefaultMutableTreeNode node = (DefaultMutableTreeNode)files_tree.nextElement();
|
||||
DefaultMutableTreeNode node = (DefaultMutableTreeNode) files_tree.nextElement();
|
||||
|
||||
if(node.isLeaf() && node!=root) {
|
||||
if (node.isLeaf() && node != root) {
|
||||
|
||||
String path = "";
|
||||
|
||||
Object[] object_path = node.getUserObjectPath();
|
||||
|
||||
for(Object p:object_path) {
|
||||
for (Object p : object_path) {
|
||||
|
||||
path+="/"+p;
|
||||
path += "/" + p;
|
||||
}
|
||||
|
||||
path = path.replaceAll("^//", "/").trim().replaceAll(" \\[[0-9,]+ [A-Z]+\\]$", "");
|
||||
|
||||
File file = new File(path);
|
||||
|
||||
if(file.isFile()) {
|
||||
if (file.isFile()) {
|
||||
|
||||
_total_space+=file.length();
|
||||
_total_space += file.length();
|
||||
|
||||
_files.add(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
total_file_size_label.setText("["+formatBytes(_total_space)+"]");
|
||||
total_file_size_label.setText("[" + formatBytes(_total_space) + "]");
|
||||
}
|
||||
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JComboBox<String> account_combobox;
|
||||
private javax.swing.JLabel account_label;
|
||||
|
@ -11,6 +11,8 @@ import static java.util.logging.Level.SEVERE;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.DefaultTreeModel;
|
||||
import javax.swing.tree.TreeModel;
|
||||
import javax.swing.tree.TreeNode;
|
||||
import static megabasterd.MainPanel.FONT_DEFAULT;
|
||||
import static megabasterd.MainPanel.THREAD_POOL;
|
||||
import static megabasterd.MiscTools.deleteAllExceptSelectedTreeItems;
|
||||
@ -51,9 +53,9 @@ public final class FolderLinkDialog extends javax.swing.JDialog {
|
||||
return _mega_error;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates new form FolderLink
|
||||
*
|
||||
* @param parent
|
||||
* @param link
|
||||
*/
|
||||
@ -69,10 +71,11 @@ public final class FolderLinkDialog extends javax.swing.JDialog {
|
||||
_download_links = new ArrayList<>();
|
||||
_link = link;
|
||||
|
||||
MiscTools.swingInvokeIt(new Runnable(){
|
||||
MiscTools.swingInvokeIt(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {updateFont(file_tree, FONT_DEFAULT, PLAIN);
|
||||
public void run() {
|
||||
updateFont(file_tree, FONT_DEFAULT, PLAIN);
|
||||
updateFont(link_detected_label, FONT_DEFAULT, PLAIN);
|
||||
updateFont(warning_label, FONT_DEFAULT, PLAIN);
|
||||
updateFont(skip_button, FONT_DEFAULT, PLAIN);
|
||||
@ -80,9 +83,9 @@ public final class FolderLinkDialog extends javax.swing.JDialog {
|
||||
updateFont(restore_button, FONT_DEFAULT, PLAIN);
|
||||
updateFont(skip_rest_button, FONT_DEFAULT, PLAIN);
|
||||
updateFont(total_space_label, FONT_DEFAULT, BOLD);
|
||||
updateFont(folder_link_label, FONT_DEFAULT, PLAIN);}}, true);
|
||||
|
||||
|
||||
updateFont(folder_link_label, FONT_DEFAULT, PLAIN);
|
||||
}
|
||||
}, true);
|
||||
|
||||
swingReflectionInvoke("setText", folder_link_label, link);
|
||||
|
||||
@ -90,7 +93,7 @@ public final class FolderLinkDialog extends javax.swing.JDialog {
|
||||
|
||||
_loadMegaDirTree();
|
||||
|
||||
if(!_mega_error) {
|
||||
if (!_mega_error) {
|
||||
|
||||
_genDownloadLiks();
|
||||
}
|
||||
@ -243,13 +246,13 @@ public final class FolderLinkDialog extends javax.swing.JDialog {
|
||||
|
||||
private void skip_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_skip_buttonActionPerformed
|
||||
|
||||
if(deleteSelectedTreeItems(file_tree)) {
|
||||
if (deleteSelectedTreeItems(file_tree)) {
|
||||
|
||||
_genDownloadLiks();
|
||||
|
||||
restore_button.setVisible(true);
|
||||
|
||||
boolean root_childs = ((DefaultMutableTreeNode)file_tree.getModel().getRoot()).getChildCount()>0;
|
||||
boolean root_childs = ((TreeNode) file_tree.getModel().getRoot()).getChildCount() > 0;
|
||||
|
||||
dance_button.setEnabled(root_childs);
|
||||
|
||||
@ -269,13 +272,13 @@ public final class FolderLinkDialog extends javax.swing.JDialog {
|
||||
|
||||
private void skip_rest_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_skip_rest_buttonActionPerformed
|
||||
|
||||
if(deleteAllExceptSelectedTreeItems(file_tree)) {
|
||||
if (deleteAllExceptSelectedTreeItems(file_tree)) {
|
||||
|
||||
_genDownloadLiks();
|
||||
|
||||
restore_button.setVisible(true);
|
||||
|
||||
boolean root_childs = ((DefaultMutableTreeNode)file_tree.getModel().getRoot()).getChildCount()>0;
|
||||
boolean root_childs = ((TreeNode) file_tree.getModel().getRoot()).getChildCount() > 0;
|
||||
|
||||
dance_button.setEnabled(root_childs);
|
||||
|
||||
@ -295,7 +298,7 @@ public final class FolderLinkDialog extends javax.swing.JDialog {
|
||||
|
||||
dance_button.setEnabled(false);
|
||||
|
||||
THREAD_POOL.execute(new Runnable(){
|
||||
THREAD_POOL.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
@ -307,20 +310,19 @@ public final class FolderLinkDialog extends javax.swing.JDialog {
|
||||
|
||||
swingReflectionInvoke("setText", restore_button, "Restore folder data");
|
||||
|
||||
boolean root_childs = ((DefaultMutableTreeNode)((DefaultTreeModel)swingReflectionInvokeAndWaitForReturn("getModel", file_tree)).getRoot()).getChildCount()>0;
|
||||
boolean root_childs = ((TreeNode) ((TreeModel) swingReflectionInvokeAndWaitForReturn("getModel", file_tree)).getRoot()).getChildCount() > 0;
|
||||
|
||||
swingReflectionInvoke("setEnabled", new Object[]{restore_button,dance_button, skip_button, skip_rest_button, file_tree}, root_childs);
|
||||
swingReflectionInvoke("setEnabled", new Object[]{restore_button, dance_button, skip_button, skip_rest_button, file_tree}, root_childs);
|
||||
|
||||
|
||||
|
||||
}});
|
||||
}
|
||||
});
|
||||
|
||||
}//GEN-LAST:event_restore_buttonActionPerformed
|
||||
|
||||
private void _loadMegaDirTree() {
|
||||
|
||||
try {
|
||||
HashMap<String,Object> folder_nodes;
|
||||
HashMap<String, Object> folder_nodes;
|
||||
|
||||
MegaAPI ma = new MegaAPI();
|
||||
|
||||
@ -330,15 +332,15 @@ public final class FolderLinkDialog extends javax.swing.JDialog {
|
||||
|
||||
folder_nodes = ma.getFolderNodes(folder_id, folder_key);
|
||||
|
||||
MegaMutableTreeNode root=null;
|
||||
MegaMutableTreeNode root = null;
|
||||
|
||||
for(Object o:folder_nodes.values()) {
|
||||
for (Object o : folder_nodes.values()) {
|
||||
|
||||
HashMap<String,Object> current_hashmap_node = (HashMap<String,Object>)o;
|
||||
HashMap<String, Object> current_hashmap_node = (HashMap<String, Object>) o;
|
||||
|
||||
MegaMutableTreeNode current_node;
|
||||
|
||||
if(current_hashmap_node.get("jtree_node") == null) {
|
||||
if (current_hashmap_node.get("jtree_node") == null) {
|
||||
|
||||
current_node = new MegaMutableTreeNode(current_hashmap_node);
|
||||
|
||||
@ -346,22 +348,22 @@ public final class FolderLinkDialog extends javax.swing.JDialog {
|
||||
|
||||
} else {
|
||||
|
||||
current_node = (MegaMutableTreeNode)current_hashmap_node.get("jtree_node");
|
||||
current_node = (MegaMutableTreeNode) current_hashmap_node.get("jtree_node");
|
||||
}
|
||||
|
||||
String parent_id=(String)current_hashmap_node.get("parent");
|
||||
String parent_id = (String) current_hashmap_node.get("parent");
|
||||
|
||||
root=null;
|
||||
root = null;
|
||||
|
||||
do{
|
||||
do {
|
||||
|
||||
if(folder_nodes.get(parent_id) != null) {
|
||||
if (folder_nodes.get(parent_id) != null) {
|
||||
|
||||
HashMap<String,Object> parent_hashmap_node = (HashMap)folder_nodes.get(parent_id);
|
||||
HashMap<String, Object> parent_hashmap_node = (HashMap) folder_nodes.get(parent_id);
|
||||
|
||||
MegaMutableTreeNode parent_node;
|
||||
|
||||
if(parent_hashmap_node.get("jtree_node") == null) {
|
||||
if (parent_hashmap_node.get("jtree_node") == null) {
|
||||
|
||||
parent_node = new MegaMutableTreeNode(parent_hashmap_node);
|
||||
|
||||
@ -369,12 +371,12 @@ public final class FolderLinkDialog extends javax.swing.JDialog {
|
||||
|
||||
} else {
|
||||
|
||||
parent_node = (MegaMutableTreeNode)parent_hashmap_node.get("jtree_node");
|
||||
parent_node = (MegaMutableTreeNode) parent_hashmap_node.get("jtree_node");
|
||||
}
|
||||
|
||||
parent_node.add(current_node);
|
||||
|
||||
parent_id = (String)parent_hashmap_node.get("parent");
|
||||
parent_id = (String) parent_hashmap_node.get("parent");
|
||||
|
||||
current_node = parent_node;
|
||||
|
||||
@ -383,16 +385,15 @@ public final class FolderLinkDialog extends javax.swing.JDialog {
|
||||
root = current_node;
|
||||
}
|
||||
|
||||
}while(current_node != root);
|
||||
} while (current_node != root);
|
||||
}
|
||||
|
||||
swingReflectionInvokeAndWait("setModel", file_tree, new DefaultTreeModel(sortTree(root)));
|
||||
|
||||
swingReflectionInvoke("setRootVisible", file_tree, root!=null?root.getChildCount() > 0:false);
|
||||
swingReflectionInvoke("setRootVisible", file_tree, root != null ? root.getChildCount() > 0 : false);
|
||||
|
||||
swingReflectionInvoke("setEnabled", file_tree, true);
|
||||
|
||||
|
||||
} catch (Exception ex) {
|
||||
|
||||
getLogger(FolderLinkDialog.class.getName()).log(SEVERE, null, ex);
|
||||
@ -402,38 +403,38 @@ public final class FolderLinkDialog extends javax.swing.JDialog {
|
||||
|
||||
}
|
||||
|
||||
private void _genDownloadLiks(){
|
||||
private void _genDownloadLiks() {
|
||||
|
||||
String folder_id = findFirstRegex("#F!([^!]+)", _link, 1);
|
||||
|
||||
_download_links.clear();
|
||||
|
||||
MegaMutableTreeNode root = (MegaMutableTreeNode)((DefaultTreeModel)swingReflectionInvokeAndWaitForReturn("getModel", file_tree)).getRoot();
|
||||
MegaMutableTreeNode root = (MegaMutableTreeNode) ((TreeModel) swingReflectionInvokeAndWaitForReturn("getModel", file_tree)).getRoot();
|
||||
|
||||
Enumeration files_tree = root.depthFirstEnumeration();
|
||||
|
||||
_total_space = 0L;
|
||||
|
||||
while(files_tree.hasMoreElements()) {
|
||||
while (files_tree.hasMoreElements()) {
|
||||
|
||||
MegaMutableTreeNode node = (MegaMutableTreeNode)files_tree.nextElement();
|
||||
MegaMutableTreeNode node = (MegaMutableTreeNode) files_tree.nextElement();
|
||||
|
||||
if(node.isLeaf() && node!=root && ((HashMap<String,Object>)node.getUserObject()).get("size") != null) {
|
||||
if (node.isLeaf() && node != root && ((HashMap<String, Object>) node.getUserObject()).get("size") != null) {
|
||||
|
||||
String path = "";
|
||||
|
||||
Object[] object_path = node.getUserObjectPath();
|
||||
|
||||
for(Object p:object_path) {
|
||||
for (Object p : object_path) {
|
||||
|
||||
path+="/"+((Map<String,Object>)p).get("name");
|
||||
path += "/" + ((Map<String, Object>) p).get("name");
|
||||
}
|
||||
|
||||
path = path.replaceAll("^/+", "").trim();
|
||||
|
||||
String url = "https://mega.nz/#N!" + ((Map<String, Object>) node.getUserObject()).get("h") + "!" + ((Map<String, Object>) node.getUserObject()).get("key") + "###n=" + folder_id ;
|
||||
String url = "https://mega.nz/#N!" + ((Map<String, Object>) node.getUserObject()).get("h") + "!" + ((Map<String, Object>) node.getUserObject()).get("key") + "###n=" + folder_id;
|
||||
|
||||
HashMap<String,Object> download_link = new HashMap<>();
|
||||
HashMap<String, Object> download_link = new HashMap<>();
|
||||
|
||||
download_link.put("url", url);
|
||||
|
||||
@ -441,17 +442,17 @@ public final class FolderLinkDialog extends javax.swing.JDialog {
|
||||
|
||||
download_link.put("filekey", ((Map<String, Object>) node.getUserObject()).get("key"));
|
||||
|
||||
download_link.put("filesize", ((Map<String,Object>)node.getUserObject()).get("size"));
|
||||
download_link.put("filesize", ((Map<String, Object>) node.getUserObject()).get("size"));
|
||||
|
||||
_total_space+=(long)download_link.get("filesize");
|
||||
_total_space += (long) download_link.get("filesize");
|
||||
|
||||
_download_links.add(download_link);
|
||||
}
|
||||
}
|
||||
|
||||
swingReflectionInvoke("setText", total_space_label, "["+formatBytes(_total_space)+"]");
|
||||
swingReflectionInvoke("setText", total_space_label, "[" + formatBytes(_total_space) + "]");
|
||||
|
||||
swingReflectionInvoke("setEnabled", new Object[]{dance_button, warning_label, skip_button,skip_rest_button, total_space_label}, root.getChildCount() > 0);
|
||||
swingReflectionInvoke("setEnabled", new Object[]{dance_button, warning_label, skip_button, skip_rest_button, total_space_label}, root.getChildCount() > 0);
|
||||
}
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
|
@ -16,7 +16,6 @@ import static megabasterd.MiscTools.HashBin;
|
||||
import static megabasterd.MiscTools.swingReflectionInvoke;
|
||||
import static megabasterd.MiscTools.updateFont;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tonikelope
|
||||
@ -49,9 +48,9 @@ public class GetMegaMasterPasswordDialog extends javax.swing.JDialog {
|
||||
|
||||
public void deletePass() {
|
||||
|
||||
if(_pass != null) {
|
||||
if (_pass != null) {
|
||||
|
||||
Arrays.fill(_pass, (byte)0);
|
||||
Arrays.fill(_pass, (byte) 0);
|
||||
}
|
||||
|
||||
_pass = null;
|
||||
@ -64,15 +63,17 @@ public class GetMegaMasterPasswordDialog extends javax.swing.JDialog {
|
||||
super(parent, modal);
|
||||
initComponents();
|
||||
|
||||
MiscTools.swingInvokeIt(new Runnable(){
|
||||
MiscTools.swingInvokeIt(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() { updateFont(ok_button, FONT_DEFAULT, Font.PLAIN);
|
||||
public void run() {
|
||||
updateFont(ok_button, FONT_DEFAULT, Font.PLAIN);
|
||||
updateFont(cancel_button, FONT_DEFAULT, Font.PLAIN);
|
||||
updateFont(please_label, FONT_DEFAULT, Font.PLAIN);
|
||||
updateFont(status_label, FONT_DEFAULT, Font.PLAIN);
|
||||
updateFont(remember_checkbox, FONT_DEFAULT, Font.PLAIN);}}, true);
|
||||
|
||||
updateFont(remember_checkbox, FONT_DEFAULT, Font.PLAIN);
|
||||
}
|
||||
}, true);
|
||||
|
||||
_current_pass_hash = current_pass_hash;
|
||||
|
||||
@ -203,15 +204,16 @@ public class GetMegaMasterPasswordDialog extends javax.swing.JDialog {
|
||||
|
||||
final Dialog tthis = this;
|
||||
|
||||
THREAD_POOL.execute(new Runnable(){
|
||||
THREAD_POOL.execute(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {try {
|
||||
public void run() {
|
||||
try {
|
||||
byte[] pass = CryptTools.PBKDF2HMACSHA256(new String(current_pass_textfield.getPassword()), MiscTools.BASE642Bin(_salt), CryptTools.PBKDF2_ITERATIONS);
|
||||
|
||||
String pass_hash = Bin2BASE64(HashBin("SHA-1", pass));
|
||||
|
||||
if(!pass_hash.equals(_current_pass_hash)) {
|
||||
if (!pass_hash.equals(_current_pass_hash)) {
|
||||
|
||||
JOptionPane.showMessageDialog(tthis, "BAD PASSWORD!", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
|
||||
@ -221,7 +223,6 @@ public class GetMegaMasterPasswordDialog extends javax.swing.JDialog {
|
||||
|
||||
swingReflectionInvoke("grabFocus", current_pass_textfield);
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
_pass = pass;
|
||||
@ -235,19 +236,20 @@ public class GetMegaMasterPasswordDialog extends javax.swing.JDialog {
|
||||
|
||||
} catch (Exception ex) {
|
||||
Logger.getLogger(GetMegaMasterPasswordDialog.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}}});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}//GEN-LAST:event_ok_buttonActionPerformed
|
||||
|
||||
private void current_pass_textfieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_current_pass_textfieldKeyPressed
|
||||
|
||||
if(evt.getKeyCode() == KeyEvent.VK_ENTER) {
|
||||
if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
|
||||
|
||||
ok_buttonActionPerformed(null);
|
||||
}
|
||||
}//GEN-LAST:event_current_pass_textfieldKeyPressed
|
||||
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JButton cancel_button;
|
||||
private javax.swing.JPasswordField current_pass_textfield;
|
||||
|
@ -7,16 +7,14 @@ import javax.swing.JLabel;
|
||||
import static megabasterd.MiscTools.formatBytes;
|
||||
import static megabasterd.MiscTools.swingReflectionInvoke;
|
||||
|
||||
public final class GlobalSpeedMeter implements Runnable, SecureNotifiable
|
||||
{
|
||||
public final class GlobalSpeedMeter implements Runnable, SecureNotifiable {
|
||||
|
||||
private final JLabel _speed_label;
|
||||
private final ConcurrentLinkedQueue<SpeedMeter> _speedmeters;
|
||||
private final Object _secure_notify_lock;
|
||||
private boolean _notified;
|
||||
|
||||
|
||||
GlobalSpeedMeter(JLabel sp_label)
|
||||
{
|
||||
GlobalSpeedMeter(JLabel sp_label) {
|
||||
_notified = false;
|
||||
_secure_notify_lock = new Object();
|
||||
_speed_label = sp_label;
|
||||
@ -24,9 +22,8 @@ public final class GlobalSpeedMeter implements Runnable, SecureNotifiable
|
||||
}
|
||||
|
||||
@Override
|
||||
public void secureNotify()
|
||||
{
|
||||
synchronized(_secure_notify_lock) {
|
||||
public void secureNotify() {
|
||||
synchronized (_secure_notify_lock) {
|
||||
|
||||
_notified = true;
|
||||
|
||||
@ -37,9 +34,8 @@ public final class GlobalSpeedMeter implements Runnable, SecureNotifiable
|
||||
@Override
|
||||
public void secureWait() {
|
||||
|
||||
synchronized(_secure_notify_lock)
|
||||
{
|
||||
while(!_notified) {
|
||||
synchronized (_secure_notify_lock) {
|
||||
while (!_notified) {
|
||||
|
||||
try {
|
||||
_secure_notify_lock.wait();
|
||||
@ -55,7 +51,7 @@ public final class GlobalSpeedMeter implements Runnable, SecureNotifiable
|
||||
@Override
|
||||
public void secureNotifyAll() {
|
||||
|
||||
synchronized(_secure_notify_lock) {
|
||||
synchronized (_secure_notify_lock) {
|
||||
|
||||
_notified = true;
|
||||
|
||||
@ -75,36 +71,30 @@ public final class GlobalSpeedMeter implements Runnable, SecureNotifiable
|
||||
|
||||
long sp = 0;
|
||||
|
||||
for(SpeedMeter speed:_speedmeters)
|
||||
{
|
||||
sp+=speed.getLastSpeed();
|
||||
for (SpeedMeter speed : _speedmeters) {
|
||||
sp += speed.getLastSpeed();
|
||||
}
|
||||
|
||||
return sp;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
public void run() {
|
||||
long sp;
|
||||
|
||||
swingReflectionInvoke("setText", _speed_label, "------");
|
||||
swingReflectionInvoke("setVisible", _speed_label, true);
|
||||
|
||||
while(true)
|
||||
{
|
||||
while (true) {
|
||||
secureWait();
|
||||
|
||||
sp = calcSpeed();
|
||||
|
||||
if(sp > 0) {
|
||||
if (sp > 0) {
|
||||
|
||||
swingReflectionInvoke("setText", _speed_label, formatBytes(sp)+"/s");
|
||||
swingReflectionInvoke("setText", _speed_label, formatBytes(sp) + "/s");
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
swingReflectionInvoke("setText", _speed_label, "------");
|
||||
|
||||
}
|
||||
|
@ -32,14 +32,13 @@ import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
|
||||
|
||||
public final class KissVideoStreamServer implements HttpHandler, SecureNotifiable {
|
||||
|
||||
public static final int WORKER_STATUS_FILE_INFO=0x01;
|
||||
public static final int WORKER_STATUS_CONNECT=0x02;
|
||||
public static final int WORKER_STATUS_STREAM=0x03;
|
||||
public static final int WORKER_STATUS_RETRY=0x04;
|
||||
public static final int WORKER_STATUS_EXIT=0x05;
|
||||
public static final int WORKER_STATUS_FILE_INFO = 0x01;
|
||||
public static final int WORKER_STATUS_CONNECT = 0x02;
|
||||
public static final int WORKER_STATUS_STREAM = 0x03;
|
||||
public static final int WORKER_STATUS_RETRY = 0x04;
|
||||
public static final int WORKER_STATUS_EXIT = 0x05;
|
||||
|
||||
private final MainPanel _main_panel;
|
||||
private final ConcurrentHashMap<String, String[]> _link_cache;
|
||||
@ -53,7 +52,7 @@ public final class KissVideoStreamServer implements HttpHandler, SecureNotifiabl
|
||||
_link_cache = new ConcurrentHashMap();
|
||||
_working_threads = new ConcurrentHashMap();
|
||||
_ctype = new ContentType();
|
||||
_notified=false;
|
||||
_notified = false;
|
||||
_secure_notify_lock = new Object();
|
||||
}
|
||||
|
||||
@ -74,9 +73,8 @@ public final class KissVideoStreamServer implements HttpHandler, SecureNotifiabl
|
||||
}
|
||||
|
||||
@Override
|
||||
public void secureNotify()
|
||||
{
|
||||
synchronized(_secure_notify_lock) {
|
||||
public void secureNotify() {
|
||||
synchronized (_secure_notify_lock) {
|
||||
|
||||
_notified = true;
|
||||
|
||||
@ -87,9 +85,8 @@ public final class KissVideoStreamServer implements HttpHandler, SecureNotifiabl
|
||||
@Override
|
||||
public void secureWait() {
|
||||
|
||||
synchronized(_secure_notify_lock)
|
||||
{
|
||||
while(!_notified) {
|
||||
synchronized (_secure_notify_lock) {
|
||||
while (!_notified) {
|
||||
|
||||
try {
|
||||
_secure_notify_lock.wait();
|
||||
@ -105,7 +102,7 @@ public final class KissVideoStreamServer implements HttpHandler, SecureNotifiabl
|
||||
@Override
|
||||
public void secureNotifyAll() {
|
||||
|
||||
synchronized(_secure_notify_lock) {
|
||||
synchronized (_secure_notify_lock) {
|
||||
|
||||
_notified = true;
|
||||
|
||||
@ -113,11 +110,10 @@ public final class KissVideoStreamServer implements HttpHandler, SecureNotifiabl
|
||||
}
|
||||
}
|
||||
|
||||
public void start(int port, String context) throws IOException
|
||||
{
|
||||
swingReflectionInvoke("setForeground", _main_panel.getView().getKiss_server_status(), new Color(0,128,0));
|
||||
public void start(int port, String context) throws IOException {
|
||||
swingReflectionInvoke("setForeground", _main_panel.getView().getKiss_server_status(), new Color(0, 128, 0));
|
||||
|
||||
swingReflectionInvoke("setText", _main_panel.getView().getKiss_server_status(), "Kissvideostreamer on localhost:"+STREAMER_PORT+" (Waiting for request...)");
|
||||
swingReflectionInvoke("setText", _main_panel.getView().getKiss_server_status(), "Kissvideostreamer on localhost:" + STREAMER_PORT + " (Waiting for request...)");
|
||||
|
||||
HttpServer httpserver = HttpServer.create(new InetSocketAddress(InetAddress.getLoopbackAddress(), port), 0);
|
||||
|
||||
@ -131,7 +127,7 @@ public final class KissVideoStreamServer implements HttpHandler, SecureNotifiabl
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
while(true) {
|
||||
while (true) {
|
||||
|
||||
secureWait();
|
||||
|
||||
@ -141,9 +137,9 @@ public final class KissVideoStreamServer implements HttpHandler, SecureNotifiabl
|
||||
Logger.getLogger(KissVideoStreamServer.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
|
||||
if(_working_threads.isEmpty()) {
|
||||
if (_working_threads.isEmpty()) {
|
||||
|
||||
swingReflectionInvoke("setText", _main_panel.getView().getKiss_server_status(), "Kissvideostreamer on localhost:"+STREAMER_PORT+" (Waiting for request...)");
|
||||
swingReflectionInvoke("setText", _main_panel.getView().getKiss_server_status(), "Kissvideostreamer on localhost:" + STREAMER_PORT + " (Waiting for request...)");
|
||||
|
||||
swingReflectionInvoke("setExtendedState", _main_panel.getView(), NORMAL);
|
||||
|
||||
@ -156,7 +152,7 @@ public final class KissVideoStreamServer implements HttpHandler, SecureNotifiabl
|
||||
|
||||
private void updateStatus(Integer new_status) {
|
||||
|
||||
if(new_status != WORKER_STATUS_EXIT) {
|
||||
if (new_status != WORKER_STATUS_EXIT) {
|
||||
|
||||
getWorking_threads().put(Thread.currentThread(), new_status);
|
||||
|
||||
@ -165,11 +161,11 @@ public final class KissVideoStreamServer implements HttpHandler, SecureNotifiabl
|
||||
getWorking_threads().remove(Thread.currentThread());
|
||||
}
|
||||
|
||||
int conta_info=0, conta_connect=0, conta_stream=0, conta_retry=0;
|
||||
int conta_info = 0, conta_connect = 0, conta_stream = 0, conta_retry = 0;
|
||||
|
||||
for(Integer thread_status:getWorking_threads().values()) {
|
||||
for (Integer thread_status : getWorking_threads().values()) {
|
||||
|
||||
switch(thread_status) {
|
||||
switch (thread_status) {
|
||||
|
||||
case WORKER_STATUS_FILE_INFO:
|
||||
conta_info++;
|
||||
@ -189,43 +185,34 @@ public final class KissVideoStreamServer implements HttpHandler, SecureNotifiabl
|
||||
}
|
||||
}
|
||||
|
||||
String status="Kissvideostreamer on localhost:"+STREAMER_PORT+" Info: "+conta_info+" / Conn: "+conta_connect+" / Stream: "+conta_stream+" / Retry: "+conta_retry;
|
||||
String status = "Kissvideostreamer on localhost:" + STREAMER_PORT + " Info: " + conta_info + " / Conn: " + conta_connect + " / Stream: " + conta_stream + " / Retry: " + conta_retry;
|
||||
|
||||
swingReflectionInvoke("setText", _main_panel.getView().getKiss_server_status(), status);
|
||||
}
|
||||
|
||||
private String[] getMegaFileMetadata(String link, MainPanelView panel) throws IOException, InterruptedException
|
||||
{
|
||||
String[] file_info=null;
|
||||
int retry=0;
|
||||
private String[] getMegaFileMetadata(String link, MainPanelView panel) throws IOException, InterruptedException {
|
||||
String[] file_info = null;
|
||||
int retry = 0;
|
||||
boolean error;
|
||||
|
||||
do
|
||||
{
|
||||
do {
|
||||
updateStatus(WORKER_STATUS_FILE_INFO);
|
||||
|
||||
error=false;
|
||||
error = false;
|
||||
|
||||
try
|
||||
{
|
||||
if( findFirstRegex("://mega(\\.co)?\\.nz/", link, 0) != null)
|
||||
{
|
||||
try {
|
||||
if (findFirstRegex("://mega(\\.co)?\\.nz/", link, 0) != null) {
|
||||
MegaAPI ma = new MegaAPI();
|
||||
|
||||
file_info = ma.getMegaFileMetadata(link);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
file_info = MegaCrypterAPI.getMegaFileMetadata(link, panel);
|
||||
}
|
||||
|
||||
}
|
||||
catch(MegaAPIException | MegaCrypterAPIException e)
|
||||
{
|
||||
error=true;
|
||||
} catch (MegaAPIException | MegaCrypterAPIException e) {
|
||||
error = true;
|
||||
|
||||
switch(Integer.parseInt(e.getMessage()))
|
||||
{
|
||||
switch (Integer.parseInt(e.getMessage())) {
|
||||
case -2:
|
||||
throw new IOException("Mega link is not valid!");
|
||||
|
||||
@ -245,55 +232,45 @@ public final class KissVideoStreamServer implements HttpHandler, SecureNotifiabl
|
||||
|
||||
updateStatus(WORKER_STATUS_RETRY);
|
||||
|
||||
for(long i=getWaitTimeExpBackOff(retry++); i>0; i--)
|
||||
{
|
||||
for (long i = getWaitTimeExpBackOff(retry++); i > 0; i--) {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException ex) {}
|
||||
} catch (InterruptedException ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch(Exception ex) {
|
||||
} catch (Exception ex) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}while(error);
|
||||
} while (error);
|
||||
|
||||
return file_info;
|
||||
}
|
||||
|
||||
private String getMegaFileDownloadUrl(String link, String pass_hash, String noexpire_token) throws IOException, InterruptedException
|
||||
{
|
||||
String dl_url=null;
|
||||
int retry=0;
|
||||
private String getMegaFileDownloadUrl(String link, String pass_hash, String noexpire_token) throws IOException, InterruptedException {
|
||||
String dl_url = null;
|
||||
int retry = 0;
|
||||
boolean error;
|
||||
|
||||
do
|
||||
{
|
||||
do {
|
||||
updateStatus(WORKER_STATUS_FILE_INFO);
|
||||
|
||||
error=false;
|
||||
error = false;
|
||||
|
||||
try
|
||||
{
|
||||
if( findFirstRegex("://mega(\\.co)?\\.nz/", link, 0) != null)
|
||||
{
|
||||
try {
|
||||
if (findFirstRegex("://mega(\\.co)?\\.nz/", link, 0) != null) {
|
||||
MegaAPI ma = new MegaAPI();
|
||||
|
||||
dl_url = ma.getMegaFileDownloadUrl(link);
|
||||
} else {
|
||||
dl_url = MegaCrypterAPI.getMegaFileDownloadUrl(link, pass_hash, noexpire_token);
|
||||
}
|
||||
else
|
||||
{
|
||||
dl_url = MegaCrypterAPI.getMegaFileDownloadUrl(link,pass_hash,noexpire_token);
|
||||
}
|
||||
}
|
||||
catch(MegaAPIException | MegaCrypterAPIException e)
|
||||
{
|
||||
error=true;
|
||||
} catch (MegaAPIException | MegaCrypterAPIException e) {
|
||||
error = true;
|
||||
|
||||
switch(Integer.parseInt(e.getMessage()))
|
||||
{
|
||||
switch (Integer.parseInt(e.getMessage())) {
|
||||
case 22:
|
||||
throw new IOException("MegaCrypter link is not valid!");
|
||||
|
||||
@ -307,46 +284,42 @@ public final class KissVideoStreamServer implements HttpHandler, SecureNotifiabl
|
||||
|
||||
updateStatus(WORKER_STATUS_RETRY);
|
||||
|
||||
for(long i=getWaitTimeExpBackOff(retry++); i>0; i--)
|
||||
{
|
||||
for (long i = getWaitTimeExpBackOff(retry++); i > 0; i--) {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException ex) {}
|
||||
} catch (InterruptedException ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}while(error);
|
||||
} while (error);
|
||||
|
||||
return dl_url;
|
||||
}
|
||||
|
||||
private long[] parseRangeHeader(String header)
|
||||
{
|
||||
private long[] parseRangeHeader(String header) {
|
||||
Pattern pattern = Pattern.compile("bytes\\=([0-9]+)\\-([0-9]+)?");
|
||||
|
||||
Matcher matcher = pattern.matcher(header);
|
||||
|
||||
long[] ranges=new long[2];
|
||||
long[] ranges = new long[2];
|
||||
|
||||
if(matcher.find())
|
||||
{
|
||||
if (matcher.find()) {
|
||||
ranges[0] = Long.valueOf(matcher.group(1));
|
||||
|
||||
if(matcher.group(2)!=null) {
|
||||
if (matcher.group(2) != null) {
|
||||
ranges[1] = Long.valueOf(matcher.group(2));
|
||||
} else
|
||||
{
|
||||
ranges[1]=-1;
|
||||
} else {
|
||||
ranges[1] = -1;
|
||||
}
|
||||
}
|
||||
|
||||
return ranges;
|
||||
}
|
||||
|
||||
private String cookRangeUrl(String url, long[] ranges, int sync_bytes)
|
||||
{
|
||||
return url+"/"+String.valueOf(ranges[0]-sync_bytes)+(ranges[1]>=0?"-"+String.valueOf(ranges[1]):"");
|
||||
private String cookRangeUrl(String url, long[] ranges, int sync_bytes) {
|
||||
return url + "/" + String.valueOf(ranges[0] - sync_bytes) + (ranges[1] >= 0 ? "-" + String.valueOf(ranges[1]) : "");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -362,22 +335,19 @@ public final class KissVideoStreamServer implements HttpHandler, SecureNotifiabl
|
||||
|
||||
HttpGet httpget;
|
||||
|
||||
try(CloseableHttpClient httpclient = MiscTools.getApacheKissHttpClient()){
|
||||
try (CloseableHttpClient httpclient = MiscTools.getApacheKissHttpClient()) {
|
||||
|
||||
Headers reqheaders=xchg.getRequestHeaders();
|
||||
Headers reqheaders = xchg.getRequestHeaders();
|
||||
|
||||
Headers resheaders = xchg.getResponseHeaders();
|
||||
|
||||
String url_path = xchg.getRequestURI().getPath();
|
||||
|
||||
String link = url_path.substring(url_path.indexOf("/video/")+7);
|
||||
String link = url_path.substring(url_path.indexOf("/video/") + 7);
|
||||
|
||||
if(link.indexOf("mega/") == 0)
|
||||
{
|
||||
if (link.indexOf("mega/") == 0) {
|
||||
link = link.replaceAll("mega/", "https://mega.co.nz/#");
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
String mc_host = findFirstRegex("^[^/]+/", link, 0);
|
||||
|
||||
link = "http://" + mc_host + link;
|
||||
@ -387,11 +357,11 @@ public final class KissVideoStreamServer implements HttpHandler, SecureNotifiabl
|
||||
|
||||
cache_info = getLink_cache().get(link);
|
||||
|
||||
if(cache_info!=null) {
|
||||
if (cache_info != null) {
|
||||
|
||||
file_info = new String[6];
|
||||
|
||||
System.arraycopy( cache_info, 0, file_info, 0, cache_info.length );
|
||||
System.arraycopy(cache_info, 0, file_info, 0, cache_info.length);
|
||||
|
||||
} else {
|
||||
|
||||
@ -399,9 +369,9 @@ public final class KissVideoStreamServer implements HttpHandler, SecureNotifiabl
|
||||
|
||||
cache_info = new String[6];
|
||||
|
||||
System.arraycopy( file_info, 0, cache_info, 0, file_info.length );
|
||||
System.arraycopy(file_info, 0, cache_info, 0, file_info.length);
|
||||
|
||||
cache_info[5]=null;
|
||||
cache_info[5] = null;
|
||||
|
||||
}
|
||||
|
||||
@ -413,8 +383,7 @@ public final class KissVideoStreamServer implements HttpHandler, SecureNotifiabl
|
||||
|
||||
String pass_hash, noexpire_token;
|
||||
|
||||
if(file_info.length >= 5)
|
||||
{
|
||||
if (file_info.length >= 5) {
|
||||
pass_hash = file_info[3];
|
||||
|
||||
noexpire_token = file_info[4];
|
||||
@ -425,11 +394,9 @@ public final class KissVideoStreamServer implements HttpHandler, SecureNotifiabl
|
||||
noexpire_token = null;
|
||||
}
|
||||
|
||||
String file_ext = file_name.substring(file_name.lastIndexOf('.')+1).toLowerCase();
|
||||
String file_ext = file_name.substring(file_name.lastIndexOf('.') + 1).toLowerCase();
|
||||
|
||||
|
||||
|
||||
if(httpmethod.equals("HEAD")) {
|
||||
if (httpmethod.equals("HEAD")) {
|
||||
|
||||
resheaders.add("Accept-Ranges", "bytes");
|
||||
|
||||
@ -445,7 +412,7 @@ public final class KissVideoStreamServer implements HttpHandler, SecureNotifiabl
|
||||
|
||||
xchg.sendResponseHeaders(HttpStatus.SC_OK, 0);
|
||||
|
||||
} else if(httpmethod.equals("GET")) {
|
||||
} else if (httpmethod.equals("GET")) {
|
||||
|
||||
resheaders.add("Accept-Ranges", "bytes");
|
||||
|
||||
@ -457,19 +424,19 @@ public final class KissVideoStreamServer implements HttpHandler, SecureNotifiabl
|
||||
|
||||
resheaders.add("Connection", "close");
|
||||
|
||||
byte[] buffer = new byte[16*1024];
|
||||
byte[] buffer = new byte[16 * 1024];
|
||||
|
||||
int reads;
|
||||
|
||||
String temp_url;
|
||||
|
||||
if(cache_info[5]!=null) {
|
||||
if (cache_info[5] != null) {
|
||||
|
||||
temp_url = cache_info[5];
|
||||
|
||||
if(!checkMegaDownloadUrl(temp_url)) {
|
||||
if (!checkMegaDownloadUrl(temp_url)) {
|
||||
|
||||
temp_url = getMegaFileDownloadUrl(link,pass_hash,noexpire_token);
|
||||
temp_url = getMegaFileDownloadUrl(link, pass_hash, noexpire_token);
|
||||
|
||||
cache_info[5] = temp_url;
|
||||
|
||||
@ -477,52 +444,50 @@ public final class KissVideoStreamServer implements HttpHandler, SecureNotifiabl
|
||||
}
|
||||
|
||||
} else {
|
||||
temp_url = getMegaFileDownloadUrl(link,pass_hash,noexpire_token);
|
||||
temp_url = getMegaFileDownloadUrl(link, pass_hash, noexpire_token);
|
||||
|
||||
cache_info[5] = temp_url;
|
||||
|
||||
getLink_cache().put(link, cache_info);
|
||||
}
|
||||
|
||||
long[] ranges=new long[2];
|
||||
long[] ranges = new long[2];
|
||||
|
||||
int sync_bytes=0;
|
||||
int sync_bytes = 0;
|
||||
|
||||
String header_range=null;
|
||||
String header_range = null;
|
||||
|
||||
InputStream is;
|
||||
|
||||
URL url;
|
||||
|
||||
if(reqheaders.containsKey("Range"))
|
||||
{
|
||||
if (reqheaders.containsKey("Range")) {
|
||||
header_range = "Range";
|
||||
|
||||
} else if(reqheaders.containsKey("range")) {
|
||||
} else if (reqheaders.containsKey("range")) {
|
||||
|
||||
header_range = "range";
|
||||
}
|
||||
|
||||
if(header_range != null)
|
||||
{
|
||||
if (header_range != null) {
|
||||
List<String> ranges_raw = reqheaders.get(header_range);
|
||||
|
||||
String range_header=ranges_raw.get(0);
|
||||
String range_header = ranges_raw.get(0);
|
||||
|
||||
ranges = parseRangeHeader(range_header);
|
||||
|
||||
sync_bytes = (int)ranges[0] % 16;
|
||||
sync_bytes = (int) ranges[0] % 16;
|
||||
|
||||
if(ranges[1]>=0 && ranges[1]>=ranges[0]) {
|
||||
if (ranges[1] >= 0 && ranges[1] >= ranges[0]) {
|
||||
|
||||
clength = ranges[1]-ranges[0]+1;
|
||||
clength = ranges[1] - ranges[0] + 1;
|
||||
|
||||
} else {
|
||||
|
||||
clength = file_size - ranges[0];
|
||||
}
|
||||
|
||||
resheaders.add("Content-Range", "bytes "+ranges[0]+"-"+(ranges[1]>=0?ranges[1]:(file_size-1))+"/"+file_size);
|
||||
resheaders.add("Content-Range", "bytes " + ranges[0] + "-" + (ranges[1] >= 0 ? ranges[1] : (file_size - 1)) + "/" + file_size);
|
||||
|
||||
xchg.sendResponseHeaders(HttpStatus.SC_PARTIAL_CONTENT, clength);
|
||||
|
||||
@ -541,13 +506,13 @@ public final class KissVideoStreamServer implements HttpHandler, SecureNotifiabl
|
||||
|
||||
httpget.addHeader("Connection", "close");
|
||||
|
||||
try(CloseableHttpResponse httpresponse = httpclient.execute(httpget)) {
|
||||
try (CloseableHttpResponse httpresponse = httpclient.execute(httpget)) {
|
||||
|
||||
is = httpresponse.getEntity().getContent();
|
||||
|
||||
byte[] iv = CryptTools.initMEGALinkKeyIV(file_key);
|
||||
|
||||
cis = new CipherInputStream(is, CryptTools.genDecrypter("AES", "AES/CTR/NoPadding", CryptTools.initMEGALinkKey(file_key), (header_range!=null && (ranges[0]-sync_bytes)>0)?CryptTools.forwardMEGALinkKeyIV(iv, ranges[0]-sync_bytes):iv));
|
||||
cis = new CipherInputStream(is, CryptTools.genDecrypter("AES", "AES/CTR/NoPadding", CryptTools.initMEGALinkKey(file_key), (header_range != null && (ranges[0] - sync_bytes) > 0) ? CryptTools.forwardMEGALinkKeyIV(iv, ranges[0] - sync_bytes) : iv));
|
||||
|
||||
os = xchg.getResponseBody();
|
||||
|
||||
@ -555,16 +520,14 @@ public final class KissVideoStreamServer implements HttpHandler, SecureNotifiabl
|
||||
|
||||
updateStatus(WORKER_STATUS_STREAM);
|
||||
|
||||
while((reads=cis.read(buffer))!=-1) {
|
||||
while ((reads = cis.read(buffer)) != -1) {
|
||||
|
||||
os.write(buffer, 0, reads);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Exception ex){ }
|
||||
finally
|
||||
{
|
||||
} catch (Exception ex) {
|
||||
} finally {
|
||||
xchg.close();
|
||||
|
||||
updateStatus(WORKER_STATUS_EXIT);
|
||||
@ -574,4 +537,3 @@ public final class KissVideoStreamServer implements HttpHandler, SecureNotifiabl
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,6 @@ import static megabasterd.MiscTools.swingReflectionInvoke;
|
||||
import static megabasterd.MiscTools.truncateText;
|
||||
import static megabasterd.MiscTools.updateFont;
|
||||
|
||||
|
||||
public final class LinkGrabberDialog extends javax.swing.JDialog implements ClipboardChangeObserver {
|
||||
|
||||
private boolean _download;
|
||||
@ -30,8 +29,6 @@ public final class LinkGrabberDialog extends javax.swing.JDialog implements Clip
|
||||
return links_textarea;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public LinkGrabberDialog(java.awt.Frame parent, boolean modal, String download_path, ClipboardSpy clipboardspy) {
|
||||
|
||||
super(parent, modal);
|
||||
@ -39,26 +36,27 @@ public final class LinkGrabberDialog extends javax.swing.JDialog implements Clip
|
||||
|
||||
initComponents();
|
||||
|
||||
MiscTools.swingInvokeIt(new Runnable(){
|
||||
MiscTools.swingInvokeIt(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {updateFont(links_label, FONT_DEFAULT, Font.PLAIN);
|
||||
public void run() {
|
||||
updateFont(links_label, FONT_DEFAULT, Font.PLAIN);
|
||||
updateFont(dance_button, FONT_DEFAULT, Font.PLAIN);
|
||||
updateFont(down_dir_to_label, FONT_DEFAULT, Font.PLAIN);
|
||||
updateFont(change_dir_button, FONT_DEFAULT, Font.PLAIN);
|
||||
updateFont(download_dir_label, FONT_DEFAULT, Font.PLAIN);}}, true);
|
||||
|
||||
updateFont(download_dir_label, FONT_DEFAULT, Font.PLAIN);
|
||||
}
|
||||
}, true);
|
||||
|
||||
_download_path = download_path;
|
||||
|
||||
_clipboardpy = clipboardspy;
|
||||
|
||||
swingReflectionInvoke("setText", download_dir_label, truncateText(download_path,80));
|
||||
swingReflectionInvoke("setText", download_dir_label, truncateText(download_path, 80));
|
||||
|
||||
notifyClipboardChange();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method is called from within the constructor to initialize the form.
|
||||
* WARNING: Do NOT modify this code. The content of this method is always
|
||||
@ -163,7 +161,7 @@ public final class LinkGrabberDialog extends javax.swing.JDialog implements Clip
|
||||
|
||||
private void dance_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dance_buttonActionPerformed
|
||||
|
||||
_download=true;
|
||||
_download = true;
|
||||
|
||||
this.setVisible(false);
|
||||
}//GEN-LAST:event_dance_buttonActionPerformed
|
||||
@ -177,17 +175,16 @@ public final class LinkGrabberDialog extends javax.swing.JDialog implements Clip
|
||||
filechooser.setFileSelectionMode(javax.swing.JFileChooser.DIRECTORIES_ONLY);
|
||||
filechooser.setAcceptAllFileFilterUsed(false);
|
||||
|
||||
if( filechooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION ) {
|
||||
if (filechooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
|
||||
|
||||
File file = filechooser.getSelectedFile();
|
||||
|
||||
_download_path = file.getAbsolutePath();
|
||||
|
||||
download_dir_label.setText(truncateText(_download_path,80));
|
||||
download_dir_label.setText(truncateText(_download_path, 80));
|
||||
}
|
||||
}//GEN-LAST:event_change_dir_buttonActionPerformed
|
||||
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JButton change_dir_button;
|
||||
private javax.swing.JButton dance_button;
|
||||
@ -201,6 +198,6 @@ public final class LinkGrabberDialog extends javax.swing.JDialog implements Clip
|
||||
@Override
|
||||
public void notifyClipboardChange() {
|
||||
|
||||
swingReflectionInvoke("setText", links_textarea,extractMegaLinksFromString(extractStringFromClipboardContents(_clipboardpy.getContents())));
|
||||
swingReflectionInvoke("setText", links_textarea, extractMegaLinksFromString(extractStringFromClipboardContents(_clipboardpy.getContents())));
|
||||
}
|
||||
}
|
||||
|
@ -52,15 +52,14 @@ import static megabasterd.MiscTools.swingReflectionInvokeAndWaitForReturn;
|
||||
import static megabasterd.Transference.LIMIT_TRANSFERENCE_SPEED_DEFAULT;
|
||||
import static megabasterd.Transference.MAX_TRANSFERENCE_SPEED_DEFAULT;
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
*
|
||||
* @author tonikelope
|
||||
*/
|
||||
public final class MainPanel {
|
||||
|
||||
public static final String VERSION="1.41";
|
||||
public static final int THROTTLE_SLICE_SIZE=16*1024;
|
||||
public static final String VERSION = "1.42";
|
||||
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 DEFAULT_USER_AGENT = "Mozilla/5.0 (X11; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0";
|
||||
@ -82,7 +81,7 @@ public final class MainPanel {
|
||||
});
|
||||
}
|
||||
|
||||
private volatile MainPanelView _view=null; //lazy init
|
||||
private volatile MainPanelView _view = null; //lazy init
|
||||
private final GlobalSpeedMeter _global_dl_speed, _global_up_speed;
|
||||
private final DownloadManager _download_manager;
|
||||
private final UploadManager _upload_manager;
|
||||
@ -101,7 +100,7 @@ public final class MainPanel {
|
||||
|
||||
public MainPanel() {
|
||||
|
||||
if(checkAppIsRunning()) {
|
||||
if (checkAppIsRunning()) {
|
||||
|
||||
System.exit(0);
|
||||
}
|
||||
@ -136,13 +135,13 @@ 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*1024:0, _limit_upload_speed?_max_up_speed*1024: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()));
|
||||
|
||||
swingReflectionInvoke("setForeground", getView().getGlobal_speed_down_label(), _limit_download_speed?new Color(255,0,0):new Color(0,128,255));
|
||||
swingReflectionInvoke("setForeground", getView().getGlobal_speed_down_label(), _limit_download_speed ? new Color(255, 0, 0) : new Color(0, 128, 255));
|
||||
|
||||
swingReflectionInvoke("setForeground", getView().getGlobal_speed_up_label(), _limit_upload_speed?new Color(255,0,0):new Color(0,128,255));
|
||||
swingReflectionInvoke("setForeground", getView().getGlobal_speed_up_label(), _limit_upload_speed ? new Color(255, 0, 0) : new Color(0, 128, 255));
|
||||
|
||||
resumeDownloads();
|
||||
|
||||
@ -156,17 +155,18 @@ public final class MainPanel {
|
||||
getLogger(MainPanel.class.getName()).log(SEVERE, null, ex);
|
||||
}
|
||||
|
||||
THREAD_POOL.execute(new Runnable(){
|
||||
THREAD_POOL.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
String new_version = MiscTools.checkNewVersion("lYsRWaQB", "uVhntmyKcVECRaOxAbcL4A");
|
||||
|
||||
if(new_version != null) {
|
||||
if (new_version != null) {
|
||||
|
||||
JOptionPane.showMessageDialog(getView(), "MegaBasterd NEW VERSION ("+new_version+") is available!\n\n(HELP > ABOUT for more info)");
|
||||
JOptionPane.showMessageDialog(getView(), "MegaBasterd NEW VERSION (" + new_version + ") is available!\n\n(HELP > ABOUT for more info)");
|
||||
}
|
||||
}});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public TrayIcon getTrayicon() {
|
||||
@ -185,21 +185,20 @@ public final class MainPanel {
|
||||
return _mega_master_pass_salt;
|
||||
}
|
||||
|
||||
|
||||
public byte[] getMega_master_pass() {
|
||||
return _mega_master_pass;
|
||||
}
|
||||
|
||||
public void setMega_master_pass(byte[] pass) {
|
||||
|
||||
if(_mega_master_pass != null) {
|
||||
if (_mega_master_pass != null) {
|
||||
|
||||
Arrays.fill(_mega_master_pass, (byte)0);
|
||||
Arrays.fill(_mega_master_pass, (byte) 0);
|
||||
|
||||
_mega_master_pass = null;
|
||||
}
|
||||
|
||||
if(pass != null) {
|
||||
if (pass != null) {
|
||||
|
||||
_mega_master_pass = new byte[pass.length];
|
||||
|
||||
@ -213,7 +212,7 @@ public final class MainPanel {
|
||||
|
||||
if (result == null) {
|
||||
|
||||
synchronized(this) {
|
||||
synchronized (this) {
|
||||
|
||||
result = _view;
|
||||
|
||||
@ -312,12 +311,10 @@ public final class MainPanel {
|
||||
return _limit_upload_speed;
|
||||
}
|
||||
|
||||
|
||||
public void loadUserSettings()
|
||||
{
|
||||
public void loadUserSettings() {
|
||||
String def_slots = selectSettingValueFromDB("default_slots_down");
|
||||
|
||||
if(def_slots != null) {
|
||||
if (def_slots != null) {
|
||||
_default_slots_down = parseInt(def_slots);
|
||||
} else {
|
||||
_default_slots_down = Download.WORKERS_DEFAULT;
|
||||
@ -325,7 +322,7 @@ public final class MainPanel {
|
||||
|
||||
def_slots = selectSettingValueFromDB("default_slots_up");
|
||||
|
||||
if(def_slots != null) {
|
||||
if (def_slots != null) {
|
||||
_default_slots_up = parseInt(def_slots);
|
||||
} else {
|
||||
_default_slots_up = Upload.WORKERS_DEFAULT;
|
||||
@ -333,7 +330,7 @@ public final class MainPanel {
|
||||
|
||||
String use_slots = selectSettingValueFromDB("use_slots_down");
|
||||
|
||||
if(use_slots != null) {
|
||||
if (use_slots != null) {
|
||||
_use_slots_down = use_slots.equals("yes");
|
||||
} else {
|
||||
_use_slots_down = Download.USE_SLOTS_DEFAULT;
|
||||
@ -341,7 +338,7 @@ public final class MainPanel {
|
||||
|
||||
use_slots = selectSettingValueFromDB("use_slots_up");
|
||||
|
||||
if(use_slots != null) {
|
||||
if (use_slots != null) {
|
||||
_use_slots_up = use_slots.equals("yes");
|
||||
} else {
|
||||
_use_slots_up = Upload.USE_SLOTS_DEFAULT;
|
||||
@ -349,29 +346,29 @@ public final class MainPanel {
|
||||
|
||||
String max_downloads = selectSettingValueFromDB("max_downloads");
|
||||
|
||||
if(max_downloads != null) {
|
||||
if (max_downloads != null) {
|
||||
_max_dl = parseInt(max_downloads);
|
||||
} else {
|
||||
_max_dl=Download.SIM_TRANSFERENCES_DEFAULT;
|
||||
_max_dl = Download.SIM_TRANSFERENCES_DEFAULT;
|
||||
}
|
||||
|
||||
String max_uploads = selectSettingValueFromDB("max_uploads");
|
||||
|
||||
if(max_uploads != null) {
|
||||
if (max_uploads != null) {
|
||||
_max_ul = parseInt(max_uploads);
|
||||
} else {
|
||||
_max_ul=Upload.SIM_TRANSFERENCES_DEFAULT;
|
||||
_max_ul = Upload.SIM_TRANSFERENCES_DEFAULT;
|
||||
}
|
||||
|
||||
_default_download_path = selectSettingValueFromDB("default_down_dir");
|
||||
|
||||
if(_default_download_path == null) {
|
||||
if (_default_download_path == null) {
|
||||
_default_download_path = ".";
|
||||
}
|
||||
|
||||
String limit_dl_speed = selectSettingValueFromDB("limit_download_speed");
|
||||
|
||||
if(limit_dl_speed != null) {
|
||||
if (limit_dl_speed != null) {
|
||||
|
||||
_limit_download_speed = limit_dl_speed.equals("yes");
|
||||
|
||||
@ -382,7 +379,7 @@ public final class MainPanel {
|
||||
|
||||
String limit_ul_speed = selectSettingValueFromDB("limit_upload_speed");
|
||||
|
||||
if(limit_ul_speed != null) {
|
||||
if (limit_ul_speed != null) {
|
||||
|
||||
_limit_upload_speed = limit_ul_speed.equals("yes");
|
||||
|
||||
@ -391,21 +388,20 @@ public final class MainPanel {
|
||||
_limit_upload_speed = LIMIT_TRANSFERENCE_SPEED_DEFAULT;
|
||||
}
|
||||
|
||||
|
||||
String max_download_speed = selectSettingValueFromDB("max_download_speed");
|
||||
|
||||
if(max_download_speed != null) {
|
||||
if (max_download_speed != null) {
|
||||
_max_dl_speed = parseInt(max_download_speed);
|
||||
} else {
|
||||
_max_dl_speed=MAX_TRANSFERENCE_SPEED_DEFAULT;
|
||||
_max_dl_speed = MAX_TRANSFERENCE_SPEED_DEFAULT;
|
||||
}
|
||||
|
||||
String max_upload_speed = selectSettingValueFromDB("max_upload_speed");
|
||||
|
||||
if(max_upload_speed != null) {
|
||||
if (max_upload_speed != null) {
|
||||
_max_up_speed = parseInt(max_upload_speed);
|
||||
} else {
|
||||
_max_up_speed=MAX_TRANSFERENCE_SPEED_DEFAULT;
|
||||
_max_up_speed = MAX_TRANSFERENCE_SPEED_DEFAULT;
|
||||
}
|
||||
|
||||
try {
|
||||
@ -418,7 +414,7 @@ public final class MainPanel {
|
||||
|
||||
_mega_master_pass_salt = DBTools.selectSettingValueFromDB("mega_master_pass_salt");
|
||||
|
||||
if(_mega_master_pass_salt == null) {
|
||||
if (_mega_master_pass_salt == null) {
|
||||
|
||||
try {
|
||||
|
||||
@ -437,7 +433,7 @@ public final class MainPanel {
|
||||
|
||||
boolean exit = true;
|
||||
|
||||
if(!_streamserver.getWorking_threads().isEmpty()) {
|
||||
if (!_streamserver.getWorking_threads().isEmpty()) {
|
||||
|
||||
Object[] options = {"No",
|
||||
"Yes"};
|
||||
@ -449,12 +445,12 @@ public final class MainPanel {
|
||||
options,
|
||||
options[0]);
|
||||
|
||||
if(n==0) {
|
||||
if (n == 0) {
|
||||
|
||||
exit=false;
|
||||
exit = false;
|
||||
}
|
||||
|
||||
} else if(!getDownload_manager().getTransference_provision_queue().isEmpty() || !getUpload_manager().getTransference_provision_queue().isEmpty()) {
|
||||
} else if (!getDownload_manager().getTransference_provision_queue().isEmpty() || !getUpload_manager().getTransference_provision_queue().isEmpty()) {
|
||||
|
||||
Object[] options = {"No",
|
||||
"Yes"};
|
||||
@ -466,14 +462,14 @@ public final class MainPanel {
|
||||
options,
|
||||
options[0]);
|
||||
|
||||
if(n==0) {
|
||||
if (n == 0) {
|
||||
|
||||
exit=false;
|
||||
exit = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(exit) {
|
||||
if (exit) {
|
||||
|
||||
try {
|
||||
DBTools.vaccum();
|
||||
@ -485,22 +481,21 @@ public final class MainPanel {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkAppIsRunning()
|
||||
{
|
||||
private boolean checkAppIsRunning() {
|
||||
boolean app_is_running = false;
|
||||
|
||||
try {
|
||||
|
||||
final ServerSocket serverSocket = new ServerSocket(WATCHDOG_PORT, 0, InetAddress.getLoopbackAddress());
|
||||
|
||||
THREAD_POOL.execute(new Runnable(){
|
||||
THREAD_POOL.execute(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
final ServerSocket socket = serverSocket;
|
||||
|
||||
while(true) {
|
||||
while (true) {
|
||||
|
||||
try {
|
||||
socket.accept();
|
||||
@ -514,7 +509,8 @@ public final class MainPanel {
|
||||
}
|
||||
}
|
||||
|
||||
}});
|
||||
}
|
||||
});
|
||||
|
||||
} catch (IOException ex) {
|
||||
|
||||
@ -539,9 +535,9 @@ public final class MainPanel {
|
||||
|
||||
swingReflectionInvoke("setText", getView().getStatus_down_label(), "Resuming previous downloads, please wait...");
|
||||
|
||||
final MainPanel tthis =this;
|
||||
final MainPanel tthis = this;
|
||||
|
||||
THREAD_POOL.execute(new Runnable(){
|
||||
THREAD_POOL.execute(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
@ -550,11 +546,11 @@ public final class MainPanel {
|
||||
|
||||
try {
|
||||
|
||||
ArrayList<HashMap<String,Object>> res = selectDownloads();
|
||||
ArrayList<HashMap<String, Object>> res = selectDownloads();
|
||||
|
||||
for(HashMap<String,Object> o:res) {
|
||||
for (HashMap<String, Object> o : res) {
|
||||
|
||||
Download download = new Download(tthis, (String)o.get("url"), (String)o.get("path"), (String)o.get("filename"), (String)o.get("filekey"), (Long)o.get("filesize"), (String)o.get("filepass"), (String)o.get("filenoexpire"), _use_slots_down, _default_slots_down, false);
|
||||
Download download = new Download(tthis, (String) o.get("url"), (String) o.get("path"), (String) o.get("filename"), (String) o.get("filekey"), (Long) o.get("filesize"), (String) o.get("filepass"), (String) o.get("filenoexpire"), _use_slots_down, _default_slots_down, false);
|
||||
|
||||
getDownload_manager().getTransference_provision_queue().add(download);
|
||||
|
||||
@ -566,7 +562,7 @@ public final class MainPanel {
|
||||
getLogger(MainPanelView.class.getName()).log(SEVERE, null, ex);
|
||||
}
|
||||
|
||||
if(conta_downloads>0) {
|
||||
if (conta_downloads > 0) {
|
||||
|
||||
getDownload_manager().secureNotify();
|
||||
|
||||
@ -576,8 +572,8 @@ public final class MainPanel {
|
||||
|
||||
swingReflectionInvoke("setText", getView().getStatus_down_label(), "");
|
||||
|
||||
|
||||
}});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@ -626,16 +622,13 @@ public final class MainPanel {
|
||||
ActionListener actionListener = new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed( ActionEvent e ) {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
||||
if(!(boolean)swingReflectionInvokeAndWaitForReturn("isVisible", getView()))
|
||||
{
|
||||
if (!(boolean) swingReflectionInvokeAndWaitForReturn("isVisible", getView())) {
|
||||
swingReflectionInvoke("setExtendedState", getView(), NORMAL);
|
||||
|
||||
swingReflectionInvoke("setVisible", getView(), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
swingReflectionInvoke("dispatchEvent", getView(), new WindowEvent(getView(), WINDOW_CLOSING));
|
||||
}
|
||||
}
|
||||
@ -654,16 +647,15 @@ public final class MainPanel {
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void resumeUploads() {
|
||||
|
||||
swingReflectionInvoke("setText", getView().getStatus_up_label(), "Resuming previous uploads, please wait...");
|
||||
|
||||
final MainPanel tthis =this;
|
||||
final MainPanel tthis = this;
|
||||
|
||||
THREAD_POOL.execute(new Runnable(){
|
||||
THREAD_POOL.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
@ -673,33 +665,31 @@ public final class MainPanel {
|
||||
|
||||
boolean remember_pass = true;
|
||||
|
||||
ArrayList<HashMap<String,Object>> res = selectUploads();
|
||||
ArrayList<HashMap<String, Object>> res = selectUploads();
|
||||
|
||||
for(HashMap<String,Object> o:res) {
|
||||
for (HashMap<String, Object> o : res) {
|
||||
|
||||
try{
|
||||
try {
|
||||
|
||||
|
||||
String email = (String)o.get("email");
|
||||
String email = (String) o.get("email");
|
||||
|
||||
MegaAPI ma;
|
||||
|
||||
if(_mega_accounts.get(email) != null) {
|
||||
if (_mega_accounts.get(email) != null) {
|
||||
|
||||
final HashMap<String,Object> account_info = (HashMap)_mega_accounts.get(email);
|
||||
final HashMap<String, Object> account_info = (HashMap) _mega_accounts.get(email);
|
||||
|
||||
ma = _mega_active_accounts.get(email);
|
||||
|
||||
if(ma == null) {
|
||||
|
||||
if (ma == null) {
|
||||
|
||||
ma = new MegaAPI();
|
||||
|
||||
String password_aes, user_hash;
|
||||
|
||||
if(getMega_master_pass_hash() != null) {
|
||||
if (getMega_master_pass_hash() != null) {
|
||||
|
||||
if(getMega_master_pass() == null) {
|
||||
if (getMega_master_pass() == null) {
|
||||
|
||||
getView().getjTabbedPane1().setSelectedIndex(1);
|
||||
|
||||
@ -709,7 +699,7 @@ public final class MainPanel {
|
||||
|
||||
swingReflectionInvokeAndWait("setVisible", dialog, true);
|
||||
|
||||
if(dialog.isPass_ok()) {
|
||||
if (dialog.isPass_ok()) {
|
||||
|
||||
setMega_master_pass(dialog.getPass());
|
||||
|
||||
@ -719,9 +709,9 @@ public final class MainPanel {
|
||||
|
||||
dialog.dispose();
|
||||
|
||||
password_aes =Bin2BASE64(CryptTools.aes_cbc_decrypt_pkcs7(BASE642Bin((String)account_info.get("password_aes")), getMega_master_pass(), CryptTools.AES_ZERO_IV));
|
||||
password_aes = Bin2BASE64(CryptTools.aes_cbc_decrypt_pkcs7(BASE642Bin((String) account_info.get("password_aes")), getMega_master_pass(), CryptTools.AES_ZERO_IV));
|
||||
|
||||
user_hash =Bin2BASE64(CryptTools.aes_cbc_decrypt_pkcs7(BASE642Bin((String)account_info.get("user_hash")), getMega_master_pass(), CryptTools.AES_ZERO_IV));
|
||||
user_hash = Bin2BASE64(CryptTools.aes_cbc_decrypt_pkcs7(BASE642Bin((String) account_info.get("user_hash")), getMega_master_pass(), CryptTools.AES_ZERO_IV));
|
||||
|
||||
} else {
|
||||
|
||||
@ -732,27 +722,26 @@ public final class MainPanel {
|
||||
|
||||
} else {
|
||||
|
||||
password_aes =Bin2BASE64(CryptTools.aes_cbc_decrypt_pkcs7(BASE642Bin((String)account_info.get("password_aes")), getMega_master_pass(), CryptTools.AES_ZERO_IV));
|
||||
password_aes = Bin2BASE64(CryptTools.aes_cbc_decrypt_pkcs7(BASE642Bin((String) account_info.get("password_aes")), getMega_master_pass(), CryptTools.AES_ZERO_IV));
|
||||
|
||||
user_hash =Bin2BASE64(CryptTools.aes_cbc_decrypt_pkcs7(BASE642Bin((String)account_info.get("user_hash")), getMega_master_pass(), CryptTools.AES_ZERO_IV));
|
||||
user_hash = Bin2BASE64(CryptTools.aes_cbc_decrypt_pkcs7(BASE642Bin((String) account_info.get("user_hash")), getMega_master_pass(), CryptTools.AES_ZERO_IV));
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
password_aes = (String)account_info.get("password_aes");
|
||||
password_aes = (String) account_info.get("password_aes");
|
||||
|
||||
user_hash = (String)account_info.get("user_hash");
|
||||
user_hash = (String) account_info.get("user_hash");
|
||||
}
|
||||
|
||||
ma.fastLogin(email,bin2i32a(BASE642Bin(password_aes)), user_hash);
|
||||
ma.fastLogin(email, bin2i32a(BASE642Bin(password_aes)), user_hash);
|
||||
|
||||
_mega_active_accounts.put(email, ma);
|
||||
|
||||
|
||||
}
|
||||
|
||||
Upload upload = new Upload(tthis, ma, (String)o.get("filename"), (String)o.get("parent_node"), (String)o.get("ul_key")!=null?bin2i32a(BASE642Bin((String)o.get("ul_key"))):null, (String)o.get("url"), (String)o.get("root_node"), BASE642Bin((String)o.get("share_key")), (String)o.get("folder_link"), _use_slots_up, _default_slots_up, false);
|
||||
Upload upload = new Upload(tthis, ma, (String) o.get("filename"), (String) o.get("parent_node"), (String) o.get("ul_key") != null ? bin2i32a(BASE642Bin((String) o.get("ul_key"))) : null, (String) o.get("url"), (String) o.get("root_node"), BASE642Bin((String) o.get("share_key")), (String) o.get("folder_link"), _use_slots_up, _default_slots_up, false);
|
||||
|
||||
getUpload_manager().getTransference_provision_queue().add(upload);
|
||||
|
||||
@ -760,7 +749,7 @@ public final class MainPanel {
|
||||
|
||||
} else {
|
||||
|
||||
deleteUpload((String)o.get("filename"), email);
|
||||
deleteUpload((String) o.get("filename"), email);
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
@ -768,7 +757,7 @@ public final class MainPanel {
|
||||
}
|
||||
}
|
||||
|
||||
if(conta_uploads>0) {
|
||||
if (conta_uploads > 0) {
|
||||
|
||||
getUpload_manager().secureNotify();
|
||||
|
||||
@ -776,7 +765,7 @@ public final class MainPanel {
|
||||
|
||||
}
|
||||
|
||||
if(!remember_pass) {
|
||||
if (!remember_pass) {
|
||||
|
||||
setMega_master_pass(null);
|
||||
}
|
||||
@ -787,9 +776,9 @@ public final class MainPanel {
|
||||
getLogger(MainPanel.class.getName()).log(SEVERE, null, ex);
|
||||
}
|
||||
|
||||
}});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package megabasterd;
|
||||
|
||||
|
||||
import java.awt.Color;
|
||||
import static java.awt.Font.BOLD;
|
||||
import static java.awt.Font.PLAIN;
|
||||
@ -37,10 +36,8 @@ import static megabasterd.MiscTools.swingReflectionInvoke;
|
||||
import static megabasterd.MiscTools.swingReflectionInvokeAndWait;
|
||||
import static megabasterd.MiscTools.updateFont;
|
||||
|
||||
|
||||
public final class MainPanelView extends javax.swing.JFrame {
|
||||
|
||||
|
||||
private final MainPanel _main_panel;
|
||||
|
||||
public JLabel getKiss_server_status() {
|
||||
@ -111,8 +108,6 @@ public final class MainPanelView extends javax.swing.JFrame {
|
||||
return jTabbedPane1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public MainPanelView(MainPanel main_panel) {
|
||||
|
||||
_main_panel = main_panel;
|
||||
@ -123,10 +118,11 @@ public final class MainPanelView extends javax.swing.JFrame {
|
||||
|
||||
setIconImage(new ImageIcon(getClass().getResource(ICON_FILE)).getImage());
|
||||
|
||||
MiscTools.swingInvokeIt(new Runnable(){
|
||||
MiscTools.swingInvokeIt(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {updateFont(file_menu, FONT_DEFAULT, PLAIN);
|
||||
public void run() {
|
||||
updateFont(file_menu, FONT_DEFAULT, PLAIN);
|
||||
updateFont(edit_menu, FONT_DEFAULT, PLAIN);
|
||||
updateFont(help_menu, FONT_DEFAULT, PLAIN);
|
||||
updateFont(new_download_menu, FONT_DEFAULT, PLAIN);
|
||||
@ -147,9 +143,9 @@ public final class MainPanelView extends javax.swing.JFrame {
|
||||
updateFont(close_all_finished_up_button, FONT_DEFAULT, BOLD);
|
||||
updateFont(pause_all_down_button, FONT_DEFAULT, BOLD);
|
||||
updateFont(pause_all_up_button, FONT_DEFAULT, BOLD);
|
||||
updateFont(jTabbedPane1, FONT_DEFAULT, PLAIN);}}, true);
|
||||
|
||||
|
||||
updateFont(jTabbedPane1, FONT_DEFAULT, PLAIN);
|
||||
}
|
||||
}, true);
|
||||
|
||||
swingReflectionInvoke("setVisible", global_speed_down_label, false);
|
||||
swingReflectionInvoke("setVisible", global_speed_up_label, false);
|
||||
@ -489,9 +485,9 @@ public final class MainPanelView extends javax.swing.JFrame {
|
||||
|
||||
jTabbedPane1.setSelectedIndex(0);
|
||||
|
||||
if(dialog.isDownload()) {
|
||||
if (dialog.isDownload()) {
|
||||
|
||||
Runnable run = new Runnable(){
|
||||
Runnable run = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
@ -499,7 +495,7 @@ public final class MainPanelView extends javax.swing.JFrame {
|
||||
|
||||
Set<String> megadownloader = new HashSet(findAllRegex("mega://enc.*?[^\r\n]+", dialog.getLinks_textarea().getText(), 0));
|
||||
|
||||
for (String link : megadownloader ) {
|
||||
for (String link : megadownloader) {
|
||||
|
||||
try {
|
||||
|
||||
@ -510,39 +506,38 @@ public final class MainPanelView extends javax.swing.JFrame {
|
||||
}
|
||||
}
|
||||
|
||||
if(!urls.isEmpty()) {
|
||||
if (!urls.isEmpty()) {
|
||||
|
||||
getMain_panel().getDownload_manager().addPre_count(urls.size());
|
||||
|
||||
getMain_panel().getDownload_manager().secureNotify();
|
||||
|
||||
for (String url : urls ) {
|
||||
for (String url : urls) {
|
||||
|
||||
if(getMain_panel().getDownload_manager().getPre_count() > 0)
|
||||
{
|
||||
if (getMain_panel().getDownload_manager().getPre_count() > 0) {
|
||||
url = url.replaceAll("^mega://", "https://mega.nz");
|
||||
|
||||
Download download;
|
||||
|
||||
if(findFirstRegex("#F!", url, 0) != null) {
|
||||
if (findFirstRegex("#F!", url, 0) != null) {
|
||||
|
||||
FolderLinkDialog fdialog = new FolderLinkDialog(_main_panel.getView(), true, url);
|
||||
|
||||
if(!fdialog.isMega_error()) {
|
||||
if (!fdialog.isMega_error()) {
|
||||
|
||||
swingReflectionInvokeAndWait("setLocationRelativeTo", fdialog, _main_panel.getView());
|
||||
|
||||
swingReflectionInvokeAndWait("setVisible", fdialog, true);
|
||||
|
||||
if(fdialog.isDownload()) {
|
||||
if (fdialog.isDownload()) {
|
||||
|
||||
List<HashMap> folder_links = fdialog.getDownload_links();
|
||||
|
||||
fdialog.dispose();
|
||||
|
||||
for(HashMap folder_link:folder_links) {
|
||||
for (HashMap folder_link : folder_links) {
|
||||
|
||||
download = new Download(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, getMain_panel().isUse_slots_down(), getMain_panel().getDefault_slots_down(), true);
|
||||
download = new Download(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, getMain_panel().isUse_slots_down(), getMain_panel().getDefault_slots_down(), true);
|
||||
|
||||
getMain_panel().getDownload_manager().getTransference_provision_queue().add(download);
|
||||
}
|
||||
@ -567,7 +562,8 @@ public final class MainPanelView extends javax.swing.JFrame {
|
||||
}
|
||||
}
|
||||
|
||||
}};
|
||||
}
|
||||
};
|
||||
|
||||
getMain_panel().getDownload_manager().getTransference_preprocess_queue().add(run);
|
||||
|
||||
@ -592,9 +588,9 @@ public final class MainPanelView extends javax.swing.JFrame {
|
||||
|
||||
dialog.setVisible(true);
|
||||
|
||||
if(dialog.isSettings_ok()) {
|
||||
if (dialog.isSettings_ok()) {
|
||||
|
||||
for(String email:dialog.getDeleted_accounts()) {
|
||||
for (String email : dialog.getDeleted_accounts()) {
|
||||
|
||||
try {
|
||||
deleteMegaAccount(email);
|
||||
@ -609,31 +605,31 @@ public final class MainPanelView extends javax.swing.JFrame {
|
||||
|
||||
_main_panel.loadUserSettings();
|
||||
|
||||
if(_main_panel.isLimit_download_speed()) {
|
||||
if (_main_panel.isLimit_download_speed()) {
|
||||
|
||||
_main_panel.getStream_supervisor().setMaxBytesPerSecInput(_main_panel.getMax_dl_speed()*1024);
|
||||
_main_panel.getStream_supervisor().setMaxBytesPerSecInput(_main_panel.getMax_dl_speed() * 1024);
|
||||
|
||||
global_speed_down_label.setForeground(new Color(255,0,0));
|
||||
global_speed_down_label.setForeground(new Color(255, 0, 0));
|
||||
|
||||
} else {
|
||||
|
||||
_main_panel.getStream_supervisor().setMaxBytesPerSecInput(0);
|
||||
|
||||
global_speed_down_label.setForeground(new Color(0,128,255));
|
||||
global_speed_down_label.setForeground(new Color(0, 128, 255));
|
||||
|
||||
}
|
||||
|
||||
if(_main_panel.isLimit_upload_speed()) {
|
||||
if (_main_panel.isLimit_upload_speed()) {
|
||||
|
||||
_main_panel.getStream_supervisor().setMaxBytesPerSecOutput(_main_panel.getMax_up_speed()*1024);
|
||||
_main_panel.getStream_supervisor().setMaxBytesPerSecOutput(_main_panel.getMax_up_speed() * 1024);
|
||||
|
||||
global_speed_up_label.setForeground(new Color(255,0,0));
|
||||
global_speed_up_label.setForeground(new Color(255, 0, 0));
|
||||
|
||||
} else {
|
||||
|
||||
_main_panel.getStream_supervisor().setMaxBytesPerSecOutput(0);
|
||||
|
||||
global_speed_up_label.setForeground(new Color(0,128,255));
|
||||
global_speed_up_label.setForeground(new Color(0, 128, 255));
|
||||
|
||||
}
|
||||
|
||||
@ -646,7 +642,7 @@ public final class MainPanelView extends javax.swing.JFrame {
|
||||
_main_panel.getUpload_manager().secureNotify();
|
||||
}
|
||||
|
||||
if(!dialog.isRemember_master_pass()) {
|
||||
if (!dialog.isRemember_master_pass()) {
|
||||
|
||||
_main_panel.setMega_master_pass(null);
|
||||
}
|
||||
@ -690,7 +686,7 @@ public final class MainPanelView extends javax.swing.JFrame {
|
||||
options,
|
||||
options[0]);
|
||||
|
||||
if(n==1) {
|
||||
if (n == 1) {
|
||||
_main_panel.getDownload_manager().closeAllPreProWaiting();
|
||||
}
|
||||
}//GEN-LAST:event_clean_all_down_menuActionPerformed
|
||||
@ -715,9 +711,9 @@ public final class MainPanelView extends javax.swing.JFrame {
|
||||
|
||||
private void new_upload_menuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_new_upload_menuActionPerformed
|
||||
|
||||
final FileGrabberDialog dialog = new FileGrabberDialog(this,true);
|
||||
final FileGrabberDialog dialog = new FileGrabberDialog(this, true);
|
||||
|
||||
try{
|
||||
try {
|
||||
|
||||
new_upload_menu.setEnabled(false);
|
||||
|
||||
@ -725,25 +721,25 @@ public final class MainPanelView extends javax.swing.JFrame {
|
||||
|
||||
dialog.setVisible(true);
|
||||
|
||||
if(dialog.isUpload() && dialog.getFiles().size() > 0) {
|
||||
if (dialog.isUpload() && dialog.getFiles().size() > 0) {
|
||||
|
||||
getMain_panel().getUpload_manager().addPre_count(dialog.getFiles().size());
|
||||
|
||||
getMain_panel().getUpload_manager().secureNotify();
|
||||
|
||||
final String mega_account = (String)dialog.getAccount_combobox().getSelectedItem();
|
||||
final String mega_account = (String) dialog.getAccount_combobox().getSelectedItem();
|
||||
|
||||
final String base_path = dialog.getBase_path();
|
||||
|
||||
final String dir_name=dialog.getDir_name_textfield().getText();
|
||||
final String dir_name = dialog.getDir_name_textfield().getText();
|
||||
|
||||
jTabbedPane1.setSelectedIndex(1);
|
||||
|
||||
Runnable run = new Runnable(){
|
||||
Runnable run = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
MegaAPI ma=getMain_panel().getMega_active_accounts().get(mega_account);
|
||||
MegaAPI ma = getMain_panel().getMega_active_accounts().get(mega_account);
|
||||
|
||||
try {
|
||||
|
||||
@ -751,11 +747,11 @@ public final class MainPanelView extends javax.swing.JFrame {
|
||||
|
||||
byte[] share_key = ma.genShareKey();
|
||||
|
||||
HashMap<String,Object> res = ma.createDir(dir_name!=null?dir_name:dialog.getFiles().get(0).getName()+"_"+genID(10), ma.getRoot_id(), parent_key, i32a2bin(ma.getMaster_key()));
|
||||
HashMap<String, Object> res = ma.createDir(dir_name != null ? dir_name : dialog.getFiles().get(0).getName() + "_" + genID(10), ma.getRoot_id(), parent_key, i32a2bin(ma.getMaster_key()));
|
||||
|
||||
String parent_node = (String)((Map)((List)res.get("f")).get(0)).get("h");
|
||||
String parent_node = (String) ((Map) ((List) res.get("f")).get(0)).get("h");
|
||||
|
||||
System.out.println("Dir "+ parent_node+" created");
|
||||
System.out.println("Dir " + parent_node + " created");
|
||||
|
||||
ma.shareFolder(parent_node, parent_key, share_key);
|
||||
|
||||
@ -763,10 +759,9 @@ public final class MainPanelView extends javax.swing.JFrame {
|
||||
|
||||
MegaDirNode file_paths = new MegaDirNode(parent_node);
|
||||
|
||||
for(File f:dialog.getFiles()) {
|
||||
for (File f : dialog.getFiles()) {
|
||||
|
||||
if(getMain_panel().getUpload_manager().getPre_count() > 0)
|
||||
{
|
||||
if (getMain_panel().getUpload_manager().getPre_count() > 0) {
|
||||
String file_path = f.getParentFile().getAbsolutePath().replace(base_path, "");
|
||||
|
||||
String[] dirs = file_path.split("/");
|
||||
@ -777,11 +772,11 @@ public final class MainPanelView extends javax.swing.JFrame {
|
||||
|
||||
String file_parent = current_node.getNode_id();
|
||||
|
||||
for(String d:dirs) {
|
||||
for (String d : dirs) {
|
||||
|
||||
if(!d.isEmpty()) {
|
||||
if (!d.isEmpty()) {
|
||||
|
||||
if(current_node.getChildren().get(d) != null) {
|
||||
if (current_node.getChildren().get(d) != null) {
|
||||
|
||||
current_node = current_node.getChildren().get(d);
|
||||
|
||||
@ -791,7 +786,7 @@ public final class MainPanelView extends javax.swing.JFrame {
|
||||
|
||||
res = ma.createDirInsideAnotherSharedDir(d, current_node.getNode_id(), ma.genFolderKey(), i32a2bin(ma.getMaster_key()), parent_node, share_key);
|
||||
|
||||
file_parent = (String)((Map)((List)res.get("f")).get(0)).get("h");
|
||||
file_parent = (String) ((Map) ((List) res.get("f")).get(0)).get("h");
|
||||
|
||||
current_node.getChildren().put(d, new MegaDirNode(file_parent));
|
||||
|
||||
@ -825,14 +820,14 @@ public final class MainPanelView extends javax.swing.JFrame {
|
||||
|
||||
new_upload_menu.setEnabled(true);
|
||||
|
||||
|
||||
} else {
|
||||
new_upload_menu.setEnabled(true);
|
||||
}
|
||||
|
||||
}catch(Exception ex) {}
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
|
||||
if(!dialog.isRemember_master_pass()) {
|
||||
if (!dialog.isRemember_master_pass()) {
|
||||
|
||||
_main_panel.setMega_master_pass(null);
|
||||
}
|
||||
@ -863,7 +858,7 @@ public final class MainPanelView extends javax.swing.JFrame {
|
||||
options,
|
||||
options[0]);
|
||||
|
||||
if(n==1) {
|
||||
if (n == 1) {
|
||||
_main_panel.getUpload_manager().closeAllPreProWaiting();
|
||||
}
|
||||
}//GEN-LAST:event_clean_all_up_menuActionPerformed
|
||||
@ -903,8 +898,4 @@ public final class MainPanelView extends javax.swing.JFrame {
|
||||
private javax.swing.JPanel uploads_panel;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -32,20 +32,16 @@ import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.codehaus.jackson.map.ObjectMapper;
|
||||
|
||||
|
||||
|
||||
public final class MegaAPI {
|
||||
|
||||
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 int checkMEGAError(String data)
|
||||
{
|
||||
public static int checkMEGAError(String data) {
|
||||
String error = findFirstRegex("^\\[?(\\-[0-9]+)\\]?$", data, 1);
|
||||
|
||||
return error != null?Integer.parseInt(error):0;
|
||||
return error != null ? Integer.parseInt(error) : 0;
|
||||
}
|
||||
|
||||
private long _seqno;
|
||||
@ -70,9 +66,7 @@ public final class MegaAPI {
|
||||
|
||||
private String _req_id;
|
||||
|
||||
|
||||
public MegaAPI()
|
||||
{
|
||||
public MegaAPI() {
|
||||
_req_id = null;
|
||||
_trashbin_id = null;
|
||||
_email = null;
|
||||
@ -87,15 +81,18 @@ public final class MegaAPI {
|
||||
|
||||
Random randomno = new Random();
|
||||
|
||||
_seqno=randomno.nextLong() & 0xffffffffL;
|
||||
_seqno = randomno.nextLong() & 0xffffffffL;
|
||||
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return _email;
|
||||
}
|
||||
|
||||
public int[] getPassword_aes() {
|
||||
return _password_aes;
|
||||
}
|
||||
|
||||
public String getUser_hash() {
|
||||
return _user_hash;
|
||||
}
|
||||
@ -124,13 +121,11 @@ public final class MegaAPI {
|
||||
return _trashbin_id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void _realLogin() throws Exception, MegaAPIException {
|
||||
|
||||
String request = "[{\"a\":\"us\", \"user\":\""+_email+"\", \"uh\":\""+_user_hash+"\"}]";
|
||||
String request = "[{\"a\":\"us\", \"user\":\"" + _email + "\", \"uh\":\"" + _user_hash + "\"}]";
|
||||
|
||||
URL url_api = new URL(API_URL+"/cs?id="+String.valueOf(_seqno)+(API_KEY!=null?"&ak="+API_KEY:""));
|
||||
URL url_api = new URL(API_URL + "/cs?id=" + String.valueOf(_seqno) + (API_KEY != null ? "&ak=" + API_KEY : ""));
|
||||
|
||||
String res = _rawRequest(request, url_api);
|
||||
|
||||
@ -138,15 +133,15 @@ public final class MegaAPI {
|
||||
|
||||
HashMap[] res_map = objectMapper.readValue(res, HashMap[].class);
|
||||
|
||||
String k = (String)res_map[0].get("k");
|
||||
String k = (String) res_map[0].get("k");
|
||||
|
||||
String privk = (String)res_map[0].get("privk");
|
||||
String privk = (String) res_map[0].get("privk");
|
||||
|
||||
_master_key = bin2i32a(decryptKey(UrlBASE642Bin(k), i32a2bin(_password_aes)));
|
||||
|
||||
String csid = (String)res_map[0].get("csid");
|
||||
String csid = (String) res_map[0].get("csid");
|
||||
|
||||
if(csid != null) {
|
||||
if (csid != null) {
|
||||
|
||||
int[] enc_rsa_priv_key = bin2i32a(UrlBASE642Bin(privk));
|
||||
|
||||
@ -154,7 +149,6 @@ public final class MegaAPI {
|
||||
|
||||
_rsa_priv_key = _extractRSAPrivKey(privk_byte);
|
||||
|
||||
|
||||
byte[] raw_sid = CryptTools.rsaDecrypt(mpi2big(UrlBASE642Bin(csid)), _rsa_priv_key[0], _rsa_priv_key[1], _rsa_priv_key[2]);
|
||||
|
||||
_sid = Bin2UrlBASE64(Arrays.copyOfRange(raw_sid, 0, 43));
|
||||
@ -194,7 +188,7 @@ public final class MegaAPI {
|
||||
|
||||
URL url_api;
|
||||
|
||||
url_api = new URL(API_URL+"/cs?id="+String.valueOf(_seqno)+"&sid="+_sid+(API_KEY!=null?"&ak="+API_KEY:""));
|
||||
url_api = new URL(API_URL + "/cs?id=" + String.valueOf(_seqno) + "&sid=" + _sid + (API_KEY != null ? "&ak=" + API_KEY : ""));
|
||||
|
||||
String res = _rawRequest(request, url_api);
|
||||
|
||||
@ -204,22 +198,22 @@ public final class MegaAPI {
|
||||
|
||||
quota = new Long[2];
|
||||
|
||||
if(res_map[0].get("cstrg") instanceof Integer) {
|
||||
if (res_map[0].get("cstrg") instanceof Integer) {
|
||||
|
||||
quota[0] = ((Number)res_map[0].get("cstrg")).longValue();
|
||||
quota[0] = ((Number) res_map[0].get("cstrg")).longValue();
|
||||
|
||||
} else if(res_map[0].get("cstrg") instanceof Long) {
|
||||
} else if (res_map[0].get("cstrg") instanceof Long) {
|
||||
|
||||
quota[0] = (Long)res_map[0].get("cstrg");
|
||||
quota[0] = (Long) res_map[0].get("cstrg");
|
||||
}
|
||||
|
||||
if(res_map[0].get("mstrg") instanceof Integer) {
|
||||
if (res_map[0].get("mstrg") instanceof Integer) {
|
||||
|
||||
quota[1] = ((Number)res_map[0].get("mstrg")).longValue();
|
||||
quota[1] = ((Number) res_map[0].get("mstrg")).longValue();
|
||||
|
||||
} else if(res_map[0].get("mstrg") instanceof Long) {
|
||||
} else if (res_map[0].get("mstrg") instanceof Long) {
|
||||
|
||||
quota[1] = (Long)res_map[0].get("mstrg");
|
||||
quota[1] = (Long) res_map[0].get("mstrg");
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
@ -238,7 +232,7 @@ public final class MegaAPI {
|
||||
|
||||
try {
|
||||
|
||||
url_api = new URL(API_URL+"/cs?id="+String.valueOf(_seqno)+"&sid="+_sid+(API_KEY!=null?"&ak="+API_KEY:""));
|
||||
url_api = new URL(API_URL + "/cs?id=" + String.valueOf(_seqno) + "&sid=" + _sid + (API_KEY != null ? "&ak=" + API_KEY : ""));
|
||||
|
||||
String res = _rawRequest(request, url_api);
|
||||
|
||||
@ -248,22 +242,22 @@ public final class MegaAPI {
|
||||
|
||||
HashMap[] res_map = objectMapper.readValue(res, HashMap[].class);
|
||||
|
||||
for(Object o:(Iterable<? extends Object>)res_map[0].get("f")) {
|
||||
for (Object o : (Iterable<? extends Object>) res_map[0].get("f")) {
|
||||
|
||||
HashMap element = (HashMap<String,Object>)o;
|
||||
HashMap element = (HashMap<String, Object>) o;
|
||||
|
||||
int file_type = (int)element.get("t");
|
||||
int file_type = (int) element.get("t");
|
||||
|
||||
switch (file_type) {
|
||||
|
||||
case 2:
|
||||
_root_id = (String)element.get("h");
|
||||
_root_id = (String) element.get("h");
|
||||
break;
|
||||
case 3:
|
||||
_inbox_id = (String)element.get("h");
|
||||
_inbox_id = (String) element.get("h");
|
||||
break;
|
||||
case 4:
|
||||
_trashbin_id = (String)element.get("h");
|
||||
_trashbin_id = (String) element.get("h");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -278,17 +272,17 @@ public final class MegaAPI {
|
||||
|
||||
private String _rawRequest(String request, URL url_api) throws IOException, MegaAPIException {
|
||||
|
||||
String response=null;
|
||||
String response = null;
|
||||
|
||||
try(CloseableHttpClient httpclient = MiscTools.getApacheKissHttpClient()) {
|
||||
try (CloseableHttpClient httpclient = MiscTools.getApacheKissHttpClient()) {
|
||||
|
||||
boolean error;
|
||||
|
||||
int conta_error=0;
|
||||
int conta_error = 0;
|
||||
|
||||
HttpPost httppost;
|
||||
|
||||
do{
|
||||
do {
|
||||
error = true;
|
||||
|
||||
try {
|
||||
@ -301,36 +295,34 @@ public final class MegaAPI {
|
||||
|
||||
httppost.setEntity(new StringEntity(request));
|
||||
|
||||
try(CloseableHttpResponse httpresponse = httpclient.execute(httppost)) {
|
||||
try (CloseableHttpResponse httpresponse = httpclient.execute(httppost)) {
|
||||
|
||||
if (httpresponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK)
|
||||
{
|
||||
if (httpresponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
|
||||
System.out.println("Failed : HTTP error code : " + httpresponse.getStatusLine().getStatusCode());
|
||||
|
||||
} else {
|
||||
|
||||
InputStream is=httpresponse.getEntity().getContent();
|
||||
InputStream is = httpresponse.getEntity().getContent();
|
||||
|
||||
ByteArrayOutputStream byte_res = new ByteArrayOutputStream();
|
||||
|
||||
byte[] buffer = new byte[16*1024];
|
||||
byte[] buffer = new byte[16 * 1024];
|
||||
|
||||
int reads;
|
||||
|
||||
while( (reads=is.read(buffer)) != -1 ) {
|
||||
while ((reads = is.read(buffer)) != -1) {
|
||||
|
||||
byte_res.write(buffer, 0, reads);
|
||||
}
|
||||
|
||||
response = new String(byte_res.toByteArray());
|
||||
|
||||
if(response.length() > 0) {
|
||||
if (response.length() > 0) {
|
||||
|
||||
int mega_error;
|
||||
|
||||
if( (mega_error=checkMEGAError(response))!=0 )
|
||||
{
|
||||
if(mega_error != -3) {
|
||||
if ((mega_error = checkMEGAError(response)) != 0) {
|
||||
if (mega_error != -3) {
|
||||
throw new MegaAPIException(String.valueOf(mega_error));
|
||||
}
|
||||
|
||||
@ -346,10 +338,10 @@ public final class MegaAPI {
|
||||
Logger.getLogger(MegaAPI.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
|
||||
if(error) {
|
||||
if (error) {
|
||||
|
||||
try {
|
||||
Thread.sleep( getWaitTimeExpBackOff(conta_error++) );
|
||||
Thread.sleep(getWaitTimeExpBackOff(conta_error++));
|
||||
} catch (InterruptedException ex) {
|
||||
getLogger(MegaAPI.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
@ -359,7 +351,7 @@ public final class MegaAPI {
|
||||
conta_error = 0;
|
||||
}
|
||||
|
||||
}while(error);
|
||||
} while (error);
|
||||
|
||||
}
|
||||
|
||||
@ -369,9 +361,8 @@ public final class MegaAPI {
|
||||
|
||||
}
|
||||
|
||||
public String getMegaFileDownloadUrl(String link) throws IOException, MegaAPIException
|
||||
{
|
||||
link=link.replace("/#!N?", "/#N!");
|
||||
public String getMegaFileDownloadUrl(String link) throws IOException, MegaAPIException {
|
||||
link = link.replace("/#!N?", "/#N!");
|
||||
|
||||
String file_id = findFirstRegex("#.*?!([^!]+)", link, 1);
|
||||
|
||||
@ -379,18 +370,17 @@ public final class MegaAPI {
|
||||
|
||||
URL url_api;
|
||||
|
||||
if(findFirstRegex("#N!", link, 0) != null)
|
||||
{
|
||||
if (findFirstRegex("#N!", link, 0) != null) {
|
||||
String folder_id = findFirstRegex("###n=(.+)$", link, 1);
|
||||
|
||||
request = "[{\"a\":\"g\", \"g\":\"1\", \"n\":\""+file_id+"\"}]";
|
||||
request = "[{\"a\":\"g\", \"g\":\"1\", \"n\":\"" + file_id + "\"}]";
|
||||
|
||||
url_api = new URL(API_URL+"/cs?id="+String.valueOf(_seqno)+(API_KEY!=null?"&ak="+API_KEY:"")+"&n="+folder_id);
|
||||
url_api = new URL(API_URL + "/cs?id=" + String.valueOf(_seqno) + (API_KEY != null ? "&ak=" + API_KEY : "") + "&n=" + folder_id);
|
||||
|
||||
} else {
|
||||
|
||||
request = "[{\"a\":\"g\", \"g\":\"1\", \"p\":\""+file_id+"\"}]";
|
||||
url_api = new URL(API_URL+"/cs?id="+String.valueOf(_seqno)+(API_KEY!=null?"&ak="+API_KEY:""));
|
||||
request = "[{\"a\":\"g\", \"g\":\"1\", \"p\":\"" + file_id + "\"}]";
|
||||
url_api = new URL(API_URL + "/cs?id=" + String.valueOf(_seqno) + (API_KEY != null ? "&ak=" + API_KEY : ""));
|
||||
}
|
||||
|
||||
String data = _rawRequest(request, url_api);
|
||||
@ -399,14 +389,12 @@ public final class MegaAPI {
|
||||
|
||||
HashMap[] res_map = objectMapper.readValue(data, HashMap[].class);
|
||||
|
||||
return (String)res_map[0].get("g");
|
||||
return (String) res_map[0].get("g");
|
||||
}
|
||||
|
||||
public String[] getMegaFileMetadata(String link) throws Exception, MegaAPIException {
|
||||
|
||||
public String[] getMegaFileMetadata(String link) throws Exception, MegaAPIException
|
||||
{
|
||||
|
||||
link=link.replace("/#!N?", "/#N!");
|
||||
link = link.replace("/#!N?", "/#N!");
|
||||
|
||||
String file_id = findFirstRegex("#.*?!([^!]+)", link, 1);
|
||||
|
||||
@ -416,19 +404,18 @@ public final class MegaAPI {
|
||||
|
||||
URL url_api;
|
||||
|
||||
if(findFirstRegex("#N!", link, 0) != null)
|
||||
{
|
||||
if (findFirstRegex("#N!", link, 0) != null) {
|
||||
String folder_id = findFirstRegex("###n=(.+)$", link, 1);
|
||||
|
||||
request = "[{\"a\":\"g\", \"g\":\"1\", \"n\":\""+file_id+"\"}]";
|
||||
request = "[{\"a\":\"g\", \"g\":\"1\", \"n\":\"" + file_id + "\"}]";
|
||||
|
||||
url_api = new URL(API_URL+"/cs?id="+String.valueOf(_seqno)+(API_KEY!=null?"&ak="+API_KEY:"")+"&n="+folder_id);
|
||||
url_api = new URL(API_URL + "/cs?id=" + String.valueOf(_seqno) + (API_KEY != null ? "&ak=" + API_KEY : "") + "&n=" + folder_id);
|
||||
|
||||
} else {
|
||||
|
||||
request = "[{\"a\":\"g\", \"p\":\""+file_id+"\"}]";
|
||||
request = "[{\"a\":\"g\", \"p\":\"" + file_id + "\"}]";
|
||||
|
||||
url_api = new URL(API_URL+"/cs?id="+String.valueOf(_seqno)+(API_KEY!=null?"&ak="+API_KEY:""));
|
||||
url_api = new URL(API_URL + "/cs?id=" + String.valueOf(_seqno) + (API_KEY != null ? "&ak=" + API_KEY : ""));
|
||||
}
|
||||
|
||||
String data = _rawRequest(request, url_api);
|
||||
@ -439,15 +426,15 @@ public final class MegaAPI {
|
||||
|
||||
String fsize = String.valueOf(res_map[0].get("s"));
|
||||
|
||||
String at = (String)res_map[0].get("at");
|
||||
String at = (String) res_map[0].get("at");
|
||||
|
||||
String[] file_data = null;
|
||||
|
||||
HashMap att_map = _decAttr(at, CryptTools.initMEGALinkKey(file_key));
|
||||
|
||||
if(att_map != null) {
|
||||
if (att_map != null) {
|
||||
|
||||
String fname = cleanFilename((String)att_map.get("n"));
|
||||
String fname = cleanFilename((String) att_map.get("n"));
|
||||
|
||||
file_data = new String[]{fname, fsize, file_key};
|
||||
|
||||
@ -459,12 +446,11 @@ public final class MegaAPI {
|
||||
return file_data;
|
||||
}
|
||||
|
||||
|
||||
private byte[] _encAttr(String attr, byte[] key) {
|
||||
|
||||
byte[] attr_byte = ("MEGA"+attr).getBytes();
|
||||
byte[] attr_byte = ("MEGA" + attr).getBytes();
|
||||
|
||||
int l = (int)(16 * Math.ceil((double)attr_byte.length/16));
|
||||
int l = (int) (16 * Math.ceil((double) attr_byte.length / 16));
|
||||
|
||||
byte[] new_attr_byte = Arrays.copyOfRange(attr_byte, 0, l);
|
||||
|
||||
@ -493,14 +479,13 @@ public final class MegaAPI {
|
||||
|
||||
decrypted_at = decrypter.doFinal(UrlBASE642Bin(encAttr));
|
||||
|
||||
String att = new String(decrypted_at).replaceAll("[\0]+$","").replaceAll("^MEGA", "");
|
||||
String att = new String(decrypted_at).replaceAll("[\0]+$", "").replaceAll("^MEGA", "");
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
res_map = objectMapper.readValue(att, HashMap.class);
|
||||
|
||||
}
|
||||
catch (Exception ex) {
|
||||
} catch (Exception ex) {
|
||||
getLogger(MegaAPI.class.getName()).log(Level.SEVERE, null, ex);
|
||||
|
||||
}
|
||||
@ -516,9 +501,9 @@ public final class MegaAPI {
|
||||
|
||||
File f = new File(filename);
|
||||
|
||||
String request = "[{\"a\":\"u\", \"s\":"+String.valueOf(f.length())+"}]";
|
||||
String request = "[{\"a\":\"u\", \"s\":" + String.valueOf(f.length()) + "}]";
|
||||
|
||||
URL url_api = new URL(API_URL+"/cs?id="+String.valueOf(_seqno)+"&sid="+_sid+(API_KEY!=null?"&ak="+API_KEY:""));
|
||||
URL url_api = new URL(API_URL + "/cs?id=" + String.valueOf(_seqno) + "&sid=" + _sid + (API_KEY != null ? "&ak=" + API_KEY : ""));
|
||||
|
||||
String res = _rawRequest(request, url_api);
|
||||
|
||||
@ -526,7 +511,7 @@ public final class MegaAPI {
|
||||
|
||||
HashMap[] res_map = objectMapper.readValue(res, HashMap[].class);
|
||||
|
||||
ul_url = (String)res_map[0].get("p");
|
||||
ul_url = (String) res_map[0].get("p");
|
||||
|
||||
} catch (Exception ex) {
|
||||
getLogger(MegaAPI.class.getName()).log(Level.SEVERE, null, ex);
|
||||
@ -535,17 +520,17 @@ public final class MegaAPI {
|
||||
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) {
|
||||
|
||||
HashMap[] res_map = null;
|
||||
|
||||
try {
|
||||
|
||||
byte[] enc_att = _encAttr("{\"n\":\""+fbasename+"\"}", i32a2bin(Arrays.copyOfRange(ul_key, 0, 4)));
|
||||
byte[] enc_att = _encAttr("{\"n\":\"" + fbasename + "\"}", i32a2bin(Arrays.copyOfRange(ul_key, 0, 4)));
|
||||
|
||||
URL url_api = new URL(API_URL+"/cs?id="+String.valueOf(_seqno)+"&sid="+_sid+(API_KEY!=null?"&ak="+API_KEY:""));
|
||||
URL url_api = new URL(API_URL + "/cs?id=" + String.valueOf(_seqno) + "&sid=" + _sid + (API_KEY != null ? "&ak=" + API_KEY : ""));
|
||||
|
||||
String request = "[{\"a\":\"p\", \"t\":\""+mega_parent+"\", \"n\":[{\"h\":\""+completion_handle+"\", \"t\":0, \"a\":\""+Bin2UrlBASE64(enc_att)+"\", \"k\":\""+Bin2UrlBASE64(encryptKey(i32a2bin(fkey), master_key))+"\"}], \"i\":\""+_req_id+"\", \"cr\" : [ [\"" + root_node + "\"] , [\""+completion_handle+"\"] , [0,0, \""+Bin2UrlBASE64(encryptKey(i32a2bin(fkey), share_key))+"\"]]}]";
|
||||
String request = "[{\"a\":\"p\", \"t\":\"" + mega_parent + "\", \"n\":[{\"h\":\"" + completion_handle + "\", \"t\":0, \"a\":\"" + Bin2UrlBASE64(enc_att) + "\", \"k\":\"" + Bin2UrlBASE64(encryptKey(i32a2bin(fkey), master_key)) + "\"}], \"i\":\"" + _req_id + "\", \"cr\" : [ [\"" + root_node + "\"] , [\"" + completion_handle + "\"] , [0,0, \"" + Bin2UrlBASE64(encryptKey(i32a2bin(fkey), share_key)) + "\"]]}]";
|
||||
|
||||
String res = _rawRequest(request, url_api);
|
||||
|
||||
@ -574,33 +559,33 @@ public final class MegaAPI {
|
||||
|
||||
BigInteger[] rsa_key = new BigInteger[4];
|
||||
|
||||
for(int i=0, offset=0; i<4; i++) {
|
||||
for (int i = 0, offset = 0; i < 4; i++) {
|
||||
|
||||
int l = ( ( 256*( (((int)rsa_data[offset]) & 0xFF )) + ( ((int)rsa_data[offset+1]) & 0xFF ) + 7 ) /8 ) + 2;
|
||||
int l = ((256 * ((((int) rsa_data[offset]) & 0xFF)) + (((int) rsa_data[offset + 1]) & 0xFF) + 7) / 8) + 2;
|
||||
|
||||
rsa_key[i] = mpi2big(Arrays.copyOfRange(rsa_data, offset, offset+l));
|
||||
rsa_key[i] = mpi2big(Arrays.copyOfRange(rsa_data, offset, offset + l));
|
||||
|
||||
offset+=l;
|
||||
offset += l;
|
||||
}
|
||||
|
||||
return rsa_key;
|
||||
}
|
||||
|
||||
public HashMap<String,Object> createDir(String name, String parent_node, byte[] node_key, byte[] master_key) {
|
||||
public HashMap<String, Object> createDir(String name, String parent_node, byte[] node_key, byte[] master_key) {
|
||||
|
||||
HashMap[] res_map=null;
|
||||
HashMap[] res_map = null;
|
||||
|
||||
try {
|
||||
|
||||
byte[] enc_att = _encAttr("{\"n\":\""+name+"\"}", node_key);
|
||||
byte[] enc_att = _encAttr("{\"n\":\"" + name + "\"}", node_key);
|
||||
|
||||
byte[] enc_node_key = encryptKey(node_key, master_key);
|
||||
|
||||
URL url_api = new URL(API_URL+"/cs?id="+String.valueOf(_seqno)+"&sid="+_sid+(API_KEY!=null?"&ak="+API_KEY:""));
|
||||
URL url_api = new URL(API_URL + "/cs?id=" + String.valueOf(_seqno) + "&sid=" + _sid + (API_KEY != null ? "&ak=" + API_KEY : ""));
|
||||
|
||||
String request="[{\"a\":\"p\", \"t\":\""+parent_node+"\", \"n\":[{\"h\":\"xxxxxxxx\",\"t\":1,\"a\":\""+Bin2UrlBASE64(enc_att)+"\",\"k\":\""+Bin2UrlBASE64(enc_node_key)+"\"}],\"i\":\""+_req_id+"\"}]";
|
||||
String request = "[{\"a\":\"p\", \"t\":\"" + parent_node + "\", \"n\":[{\"h\":\"xxxxxxxx\",\"t\":1,\"a\":\"" + Bin2UrlBASE64(enc_att) + "\",\"k\":\"" + Bin2UrlBASE64(enc_node_key) + "\"}],\"i\":\"" + _req_id + "\"}]";
|
||||
|
||||
String res=_rawRequest(request, url_api);
|
||||
String res = _rawRequest(request, url_api);
|
||||
|
||||
System.out.println(res);
|
||||
|
||||
@ -616,24 +601,23 @@ public final class MegaAPI {
|
||||
|
||||
}
|
||||
|
||||
public HashMap<String, Object> createDirInsideAnotherSharedDir(String name, String parent_node, byte[] node_key, byte[] master_key, String root_node, byte[] share_key) {
|
||||
|
||||
public HashMap<String,Object> createDirInsideAnotherSharedDir(String name, String parent_node, byte[] node_key, byte[] master_key, String root_node, byte[] share_key) {
|
||||
|
||||
HashMap[] res_map=null;
|
||||
HashMap[] res_map = null;
|
||||
|
||||
try {
|
||||
|
||||
byte[] enc_att = _encAttr("{\"n\":\""+name+"\"}", node_key);
|
||||
byte[] enc_att = _encAttr("{\"n\":\"" + name + "\"}", node_key);
|
||||
|
||||
byte[] enc_node_key = encryptKey(node_key, master_key);
|
||||
|
||||
byte[] enc_node_key_s = encryptKey(node_key, share_key);
|
||||
|
||||
URL url_api = new URL(API_URL+"/cs?id="+String.valueOf(_seqno)+"&sid="+_sid+(API_KEY!=null?"&ak="+API_KEY:""));
|
||||
URL url_api = new URL(API_URL + "/cs?id=" + String.valueOf(_seqno) + "&sid=" + _sid + (API_KEY != null ? "&ak=" + API_KEY : ""));
|
||||
|
||||
String request="[{\"a\":\"p\", \"t\":\""+parent_node+"\", \"n\":[{\"h\":\"xxxxxxxx\",\"t\":1,\"a\":\""+Bin2UrlBASE64(enc_att)+"\",\"k\":\""+Bin2UrlBASE64(enc_node_key)+"\"}],\"i\":\""+_req_id+"\", \"cr\" : [ [\"" + root_node + "\"] , [\"xxxxxxxx\"] , [0,0, \""+Bin2UrlBASE64(enc_node_key_s)+"\"]]}]";
|
||||
String request = "[{\"a\":\"p\", \"t\":\"" + parent_node + "\", \"n\":[{\"h\":\"xxxxxxxx\",\"t\":1,\"a\":\"" + Bin2UrlBASE64(enc_att) + "\",\"k\":\"" + Bin2UrlBASE64(enc_node_key) + "\"}],\"i\":\"" + _req_id + "\", \"cr\" : [ [\"" + root_node + "\"] , [\"xxxxxxxx\"] , [0,0, \"" + Bin2UrlBASE64(enc_node_key_s) + "\"]]}]";
|
||||
|
||||
String res=_rawRequest(request, url_api);
|
||||
String res = _rawRequest(request, url_api);
|
||||
|
||||
System.out.println(res);
|
||||
|
||||
@ -649,10 +633,9 @@ public final class MegaAPI {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public String getPublicFileLink(String node, byte[] node_key) {
|
||||
|
||||
String public_link=null;
|
||||
String public_link = null;
|
||||
|
||||
try {
|
||||
|
||||
@ -660,11 +643,11 @@ public final class MegaAPI {
|
||||
|
||||
List res_map;
|
||||
|
||||
String request = "[{\"a\":\"l\", \"n\":\""+node+"\"}]";
|
||||
String request = "[{\"a\":\"l\", \"n\":\"" + node + "\"}]";
|
||||
|
||||
URL url_api = new URL(API_URL+"/cs?id="+String.valueOf(_seqno)+"&sid="+_sid+(API_KEY!=null?"&ak="+API_KEY:""));
|
||||
URL url_api = new URL(API_URL + "/cs?id=" + String.valueOf(_seqno) + "&sid=" + _sid + (API_KEY != null ? "&ak=" + API_KEY : ""));
|
||||
|
||||
String res=_rawRequest(request, url_api);
|
||||
String res = _rawRequest(request, url_api);
|
||||
|
||||
System.out.println(res);
|
||||
|
||||
@ -672,9 +655,9 @@ public final class MegaAPI {
|
||||
|
||||
res_map = objectMapper.readValue(res, List.class);
|
||||
|
||||
file_id = (String)res_map.get(0);
|
||||
file_id = (String) res_map.get(0);
|
||||
|
||||
public_link = "https://mega.nz/#!"+file_id+"!"+Bin2UrlBASE64(node_key);
|
||||
public_link = "https://mega.nz/#!" + file_id + "!" + Bin2UrlBASE64(node_key);
|
||||
|
||||
} catch (Exception ex) {
|
||||
getLogger(MegaAPI.class.getName()).log(Level.SEVERE, null, ex);
|
||||
@ -685,7 +668,7 @@ public final class MegaAPI {
|
||||
|
||||
public String getPublicFolderLink(String node, byte[] node_key) {
|
||||
|
||||
String public_link=null;
|
||||
String public_link = null;
|
||||
|
||||
try {
|
||||
|
||||
@ -693,11 +676,11 @@ public final class MegaAPI {
|
||||
|
||||
List res_map;
|
||||
|
||||
String request = "[{\"a\":\"l\", \"n\":\""+node+"\", \"i\":\""+_req_id+"\"}]";
|
||||
String request = "[{\"a\":\"l\", \"n\":\"" + node + "\", \"i\":\"" + _req_id + "\"}]";
|
||||
|
||||
URL url_api = new URL(API_URL+"/cs?id="+String.valueOf(_seqno)+"&sid="+_sid+(API_KEY!=null?"&ak="+API_KEY:""));
|
||||
URL url_api = new URL(API_URL + "/cs?id=" + String.valueOf(_seqno) + "&sid=" + _sid + (API_KEY != null ? "&ak=" + API_KEY : ""));
|
||||
|
||||
String res=_rawRequest(request, url_api);
|
||||
String res = _rawRequest(request, url_api);
|
||||
|
||||
System.out.println(res);
|
||||
|
||||
@ -705,11 +688,11 @@ public final class MegaAPI {
|
||||
|
||||
res_map = objectMapper.readValue(res, List.class);
|
||||
|
||||
folder_id = (String)res_map.get(0);
|
||||
folder_id = (String) res_map.get(0);
|
||||
|
||||
public_link = "https://mega.nz/#F!"+folder_id+"!"+Bin2UrlBASE64(node_key);
|
||||
public_link = "https://mega.nz/#F!" + folder_id + "!" + Bin2UrlBASE64(node_key);
|
||||
|
||||
}catch (Exception ex) {
|
||||
} catch (Exception ex) {
|
||||
getLogger(MegaAPI.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
|
||||
@ -731,24 +714,23 @@ public final class MegaAPI {
|
||||
return genRandomByteArray(16);
|
||||
}
|
||||
|
||||
|
||||
public void shareFolder(String node, byte[] node_key, byte[] share_key) {
|
||||
|
||||
try {
|
||||
|
||||
String ok=Bin2UrlBASE64(encryptKey(share_key, i32a2bin(getMaster_key())));
|
||||
String ok = Bin2UrlBASE64(encryptKey(share_key, i32a2bin(getMaster_key())));
|
||||
|
||||
String enc_nk = Bin2UrlBASE64(encryptKey(node_key, share_key));
|
||||
|
||||
String ha=cryptoHandleauth(node);
|
||||
String ha = cryptoHandleauth(node);
|
||||
|
||||
String request = "[{\"a\":\"s2\",\"n\":\""+node+"\",\"s\":[{\"u\":\"EXP\",\"r\":0}],\"i\":\""+_req_id+"\",\"ok\":\""+ok+"\",\"ha\":\""+ha+"\",\"cr\":[[\""+node+"\"],[\""+node+"\"],[0,0,\""+enc_nk+"\"]]}]";
|
||||
String request = "[{\"a\":\"s2\",\"n\":\"" + node + "\",\"s\":[{\"u\":\"EXP\",\"r\":0}],\"i\":\"" + _req_id + "\",\"ok\":\"" + ok + "\",\"ha\":\"" + ha + "\",\"cr\":[[\"" + node + "\"],[\"" + node + "\"],[0,0,\"" + enc_nk + "\"]]}]";
|
||||
|
||||
System.out.println(request);
|
||||
|
||||
URL url_api = new URL(API_URL+"/cs?id="+String.valueOf(_seqno)+"&sid="+_sid+(API_KEY!=null?"&ak="+API_KEY:""));
|
||||
URL url_api = new URL(API_URL + "/cs?id=" + String.valueOf(_seqno) + "&sid=" + _sid + (API_KEY != null ? "&ak=" + API_KEY : ""));
|
||||
|
||||
String res=_rawRequest(request, url_api);
|
||||
String res = _rawRequest(request, url_api);
|
||||
|
||||
System.out.println(res);
|
||||
|
||||
@ -757,14 +739,13 @@ public final class MegaAPI {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String cryptoHandleauth(String h) {
|
||||
|
||||
String ch = null;
|
||||
|
||||
try {
|
||||
|
||||
ch = Bin2UrlBASE64(encryptKey((h+h).getBytes(), i32a2bin(getMaster_key())));
|
||||
ch = Bin2UrlBASE64(encryptKey((h + h).getBytes(), i32a2bin(getMaster_key())));
|
||||
|
||||
} catch (Exception ex) {
|
||||
getLogger(MegaAPI.class.getName()).log(Level.SEVERE, null, ex);
|
||||
@ -773,16 +754,15 @@ public final class MegaAPI {
|
||||
return ch;
|
||||
}
|
||||
|
||||
public HashMap<String, Object> getFolderNodes(String folder_id, String folder_key) throws Exception {
|
||||
|
||||
public HashMap<String,Object> getFolderNodes(String folder_id, String folder_key) throws Exception {
|
||||
|
||||
HashMap<String,Object> folder_nodes;
|
||||
HashMap<String, Object> folder_nodes;
|
||||
|
||||
String request = "[{\"a\":\"f\", \"c\":\"1\", \"r\":\"1\"}]";
|
||||
|
||||
URL url_api = new URL(API_URL+"/cs?id="+String.valueOf(_seqno)+(API_KEY!=null?"&ak="+API_KEY:"")+"&n="+folder_id);
|
||||
URL url_api = new URL(API_URL + "/cs?id=" + String.valueOf(_seqno) + (API_KEY != null ? "&ak=" + API_KEY : "") + "&n=" + folder_id);
|
||||
|
||||
String res=_rawRequest(request, url_api);
|
||||
String res = _rawRequest(request, url_api);
|
||||
|
||||
System.out.println(res);
|
||||
|
||||
@ -792,17 +772,17 @@ public final class MegaAPI {
|
||||
|
||||
folder_nodes = new HashMap<>();
|
||||
|
||||
for(Object o:(Iterable<? extends Object>)res_map[0].get("f")) {
|
||||
for (Object o : (Iterable<? extends Object>) res_map[0].get("f")) {
|
||||
|
||||
HashMap<String,Object> node = (HashMap<String,Object>)o;
|
||||
HashMap<String, Object> node = (HashMap<String, Object>) o;
|
||||
|
||||
String[] node_k = ((String)node.get("k")).split(":");
|
||||
String[] node_k = ((String) node.get("k")).split(":");
|
||||
|
||||
String dec_node_k = Bin2UrlBASE64(decryptKey(UrlBASE642Bin(node_k[1]), _urlBase64KeyDecode(folder_key)));
|
||||
|
||||
HashMap at = _decAttr((String)node.get("a"), _urlBase64KeyDecode(dec_node_k));
|
||||
HashMap at = _decAttr((String) node.get("a"), _urlBase64KeyDecode(dec_node_k));
|
||||
|
||||
HashMap<String,Object> the_node = new HashMap<>();
|
||||
HashMap<String, Object> the_node = new HashMap<>();
|
||||
|
||||
the_node.put("type", node.get("t"));
|
||||
|
||||
@ -810,16 +790,16 @@ public final class MegaAPI {
|
||||
|
||||
the_node.put("key", dec_node_k);
|
||||
|
||||
if(node.get("s") != null) {
|
||||
if (node.get("s") != null) {
|
||||
|
||||
if(node.get("s") instanceof Integer) {
|
||||
if (node.get("s") instanceof Integer) {
|
||||
|
||||
long size = ((Number)node.get("s")).longValue();
|
||||
long size = ((Number) node.get("s")).longValue();
|
||||
the_node.put("size", size);
|
||||
|
||||
} else if(node.get("s") instanceof Long) {
|
||||
} else if (node.get("s") instanceof Long) {
|
||||
|
||||
long size = (Long)node.get("s");
|
||||
long size = (Long) node.get("s");
|
||||
the_node.put("size", size);
|
||||
}
|
||||
}
|
||||
@ -828,7 +808,7 @@ public final class MegaAPI {
|
||||
|
||||
the_node.put("h", node.get("h"));
|
||||
|
||||
folder_nodes.put((String)node.get("h"), the_node);
|
||||
folder_nodes.put((String) node.get("h"), the_node);
|
||||
}
|
||||
|
||||
return folder_nodes;
|
||||
@ -839,7 +819,7 @@ public final class MegaAPI {
|
||||
try {
|
||||
byte[] key_bin = UrlBASE642Bin(key);
|
||||
|
||||
if(key_bin.length < 32) {
|
||||
if (key_bin.length < 32) {
|
||||
|
||||
return Arrays.copyOfRange(key_bin, 0, 16);
|
||||
|
||||
|
@ -1,10 +1,8 @@
|
||||
package megabasterd;
|
||||
|
||||
|
||||
public final class MegaAPIException extends Exception {
|
||||
|
||||
public MegaAPIException(String message)
|
||||
{
|
||||
public MegaAPIException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,6 @@ import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.codehaus.jackson.map.ObjectMapper;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tonikelope
|
||||
@ -44,17 +43,16 @@ public final class MegaCrypterAPI {
|
||||
|
||||
private static String _rawRequest(String request, URL url_api) throws IOException, MegaCrypterAPIException {
|
||||
|
||||
String response=null;
|
||||
String response = null;
|
||||
|
||||
try(CloseableHttpClient httpclient = MiscTools.getApacheKissHttpClient())
|
||||
{
|
||||
try (CloseableHttpClient httpclient = MiscTools.getApacheKissHttpClient()) {
|
||||
boolean error;
|
||||
|
||||
int conta_error=0;
|
||||
int conta_error = 0;
|
||||
|
||||
HttpPost httppost;
|
||||
|
||||
do{
|
||||
do {
|
||||
|
||||
error = true;
|
||||
|
||||
@ -69,35 +67,33 @@ public final class MegaCrypterAPI {
|
||||
|
||||
httppost.setEntity(new StringEntity(request));
|
||||
|
||||
try(CloseableHttpResponse httpresponse = httpclient.execute(httppost)) {
|
||||
try (CloseableHttpResponse httpresponse = httpclient.execute(httppost)) {
|
||||
|
||||
if (httpresponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK)
|
||||
{
|
||||
if (httpresponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
|
||||
System.out.println("Failed : HTTP error code : " + httpresponse.getStatusLine().getStatusCode());
|
||||
|
||||
} else {
|
||||
|
||||
InputStream is=httpresponse.getEntity().getContent();
|
||||
InputStream is = httpresponse.getEntity().getContent();
|
||||
|
||||
ByteArrayOutputStream byte_res = new ByteArrayOutputStream();
|
||||
|
||||
byte[] buffer = new byte[16*1024];
|
||||
byte[] buffer = new byte[16 * 1024];
|
||||
|
||||
int reads;
|
||||
|
||||
while( (reads=is.read(buffer)) != -1 ) {
|
||||
while ((reads = is.read(buffer)) != -1) {
|
||||
|
||||
byte_res.write(buffer, 0, reads);
|
||||
}
|
||||
|
||||
response = new String(byte_res.toByteArray());
|
||||
|
||||
if(response.length() > 0) {
|
||||
if (response.length() > 0) {
|
||||
|
||||
int mc_error;
|
||||
|
||||
if( (mc_error=MegaCrypterAPI.checkMCError(response))!=0 )
|
||||
{
|
||||
if ((mc_error = MegaCrypterAPI.checkMCError(response)) != 0) {
|
||||
throw new MegaCrypterAPIException(String.valueOf(mc_error));
|
||||
|
||||
} else {
|
||||
@ -112,10 +108,10 @@ public final class MegaCrypterAPI {
|
||||
Logger.getLogger(MegaCrypterAPI.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
|
||||
if(error) {
|
||||
if (error) {
|
||||
|
||||
try {
|
||||
Thread.sleep( getWaitTimeExpBackOff(conta_error++) );
|
||||
Thread.sleep(getWaitTimeExpBackOff(conta_error++));
|
||||
} catch (InterruptedException ex) {
|
||||
getLogger(MegaAPI.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
@ -124,18 +120,17 @@ public final class MegaCrypterAPI {
|
||||
conta_error = 0;
|
||||
}
|
||||
|
||||
}while(error);
|
||||
} while (error);
|
||||
}
|
||||
|
||||
return response;
|
||||
|
||||
}
|
||||
|
||||
public static String getMegaFileDownloadUrl(String link, String pass_hash, String noexpire_token) throws IOException, MegaCrypterAPIException
|
||||
{
|
||||
String request = noexpire_token != null?"{\"m\":\"dl\", \"link\": \""+link+"\", \"noexpire\": \""+noexpire_token+"\"}":"{\"m\":\"dl\", \"link\": \""+link+"\"}";
|
||||
public static String getMegaFileDownloadUrl(String link, String pass_hash, String noexpire_token) throws IOException, MegaCrypterAPIException {
|
||||
String request = noexpire_token != null ? "{\"m\":\"dl\", \"link\": \"" + link + "\", \"noexpire\": \"" + noexpire_token + "\"}" : "{\"m\":\"dl\", \"link\": \"" + link + "\"}";
|
||||
|
||||
URL url_api = new URL(findFirstRegex("https?://[^/]+", link, 0)+"/api");
|
||||
URL url_api = new URL(findFirstRegex("https?://[^/]+", link, 0) + "/api");
|
||||
|
||||
String res = MegaCrypterAPI._rawRequest(request, url_api);
|
||||
|
||||
@ -143,16 +138,15 @@ public final class MegaCrypterAPI {
|
||||
|
||||
HashMap res_map = objectMapper.readValue(res, HashMap.class);
|
||||
|
||||
String dl_url = (String)res_map.get("url");
|
||||
String dl_url = (String) res_map.get("url");
|
||||
|
||||
if(pass_hash != null)
|
||||
{
|
||||
if (pass_hash != null) {
|
||||
try {
|
||||
String pass = (String)res_map.get("pass");
|
||||
String pass = (String) res_map.get("pass");
|
||||
|
||||
byte[] iv = BASE642Bin(pass);
|
||||
|
||||
Cipher decrypter = CryptTools.genDecrypter("AES", "AES/CBC/PKCS5Padding", BASE642Bin(pass_hash),iv);
|
||||
Cipher decrypter = CryptTools.genDecrypter("AES", "AES/CBC/PKCS5Padding", BASE642Bin(pass_hash), iv);
|
||||
|
||||
byte[] decrypted_url = decrypter.doFinal(BASE642Bin(dl_url));
|
||||
|
||||
@ -166,11 +160,10 @@ public final class MegaCrypterAPI {
|
||||
return dl_url;
|
||||
}
|
||||
|
||||
public static String[] getMegaFileMetadata(String link, MainPanelView panel) throws Exception, MegaCrypterAPIException
|
||||
{
|
||||
String request = "{\"m\":\"info\", \"link\": \""+link+"\"}";
|
||||
public static String[] getMegaFileMetadata(String link, MainPanelView panel) throws Exception, MegaCrypterAPIException {
|
||||
String request = "{\"m\":\"info\", \"link\": \"" + link + "\"}";
|
||||
|
||||
URL url_api = new URL(findFirstRegex("https?://[^/]+", link, 0)+"/api");
|
||||
URL url_api = new URL(findFirstRegex("https?://[^/]+", link, 0) + "/api");
|
||||
|
||||
String res = MegaCrypterAPI._rawRequest(request, url_api);
|
||||
|
||||
@ -178,19 +171,19 @@ public final class MegaCrypterAPI {
|
||||
|
||||
HashMap res_map = objectMapper.readValue(res, HashMap.class);
|
||||
|
||||
String fname = cleanFilename((String)res_map.get("name"));
|
||||
String fname = cleanFilename((String) res_map.get("name"));
|
||||
|
||||
String fpath=null;
|
||||
String fpath = null;
|
||||
|
||||
Object fpath_val = res_map.get("path");
|
||||
|
||||
if(fpath_val instanceof Boolean) {
|
||||
if (fpath_val instanceof Boolean) {
|
||||
|
||||
fpath = null;
|
||||
|
||||
} else if (fpath_val instanceof String) {
|
||||
|
||||
fpath = cleanFilePath((String)fpath_val);
|
||||
fpath = cleanFilePath((String) fpath_val);
|
||||
}
|
||||
|
||||
String file_size;
|
||||
@ -199,18 +192,18 @@ public final class MegaCrypterAPI {
|
||||
|
||||
file_size = String.valueOf(res_map.get("size"));
|
||||
|
||||
} catch(java.lang.ClassCastException ex) {
|
||||
} catch (java.lang.ClassCastException ex) {
|
||||
|
||||
file_size = String.valueOf(res_map.get("size"));
|
||||
}
|
||||
|
||||
String fkey = (String)res_map.get("key");
|
||||
String fkey = (String) res_map.get("key");
|
||||
|
||||
String noexpire_token=null;
|
||||
String noexpire_token = null;
|
||||
|
||||
Object expire_val = res_map.get("expire");
|
||||
|
||||
if(expire_val instanceof Boolean) {
|
||||
if (expire_val instanceof Boolean) {
|
||||
|
||||
noexpire_token = null;
|
||||
|
||||
@ -221,27 +214,25 @@ public final class MegaCrypterAPI {
|
||||
noexpire_token = aux[1];
|
||||
}
|
||||
|
||||
String pass=null;
|
||||
String pass = null;
|
||||
|
||||
Object pass_val = res_map.get("pass");
|
||||
|
||||
if(pass_val instanceof Boolean) {
|
||||
if (pass_val instanceof Boolean) {
|
||||
|
||||
pass = null;
|
||||
|
||||
} else if (expire_val instanceof String) {
|
||||
|
||||
pass = (String)pass_val;
|
||||
pass = (String) pass_val;
|
||||
}
|
||||
|
||||
System.out.println(noexpire_token);
|
||||
|
||||
if(pass != null)
|
||||
{
|
||||
if (pass != null) {
|
||||
String[] pass_items = pass.split("#");
|
||||
|
||||
if(pass_items.length != 4)
|
||||
{
|
||||
if (pass_items.length != 4) {
|
||||
throw new MegaCrypterAPIException("Bad password data!");
|
||||
}
|
||||
|
||||
@ -261,24 +252,23 @@ public final class MegaCrypterAPI {
|
||||
|
||||
Cipher decrypter;
|
||||
|
||||
synchronized(PASS_LOCK) {
|
||||
synchronized (PASS_LOCK) {
|
||||
|
||||
LinkedList<String> pass_list = new LinkedList(PASS_CACHE);
|
||||
|
||||
do
|
||||
{
|
||||
do {
|
||||
bad_pass = true;
|
||||
|
||||
if((password = pass_list.poll()) == null) {
|
||||
if ((password = pass_list.poll()) == null) {
|
||||
|
||||
password = JOptionPane.showInputDialog(panel, "Enter password for MegaCrypter link:");
|
||||
}
|
||||
|
||||
if(password != null) {
|
||||
if (password != null) {
|
||||
|
||||
try {
|
||||
|
||||
info_key=CryptTools.PBKDF2HMACSHA256(password, salt, (int)Math.pow(2, iterations));
|
||||
info_key = CryptTools.PBKDF2HMACSHA256(password, salt, (int) Math.pow(2, iterations));
|
||||
|
||||
decrypter = CryptTools.genDecrypter("AES", "AES/CBC/PKCS5Padding", info_key, iv);
|
||||
|
||||
@ -286,25 +276,24 @@ public final class MegaCrypterAPI {
|
||||
|
||||
bad_pass = !Arrays.equals(info_key, decrypter.doFinal(key_check));
|
||||
|
||||
if(!bad_pass) {
|
||||
if (!bad_pass) {
|
||||
|
||||
PASS_CACHE.add(password);
|
||||
}
|
||||
|
||||
} catch (IllegalBlockSizeException | BadPaddingException ex) {}
|
||||
|
||||
} catch (InvalidKeySpecException ex) {}
|
||||
} catch (IllegalBlockSizeException | BadPaddingException ex) {
|
||||
}
|
||||
|
||||
}while(password!=null && bad_pass);
|
||||
} catch (InvalidKeySpecException ex) {
|
||||
}
|
||||
}
|
||||
|
||||
if(bad_pass)
|
||||
{
|
||||
} while (password != null && bad_pass);
|
||||
}
|
||||
|
||||
if (bad_pass) {
|
||||
throw new MegaCrypterAPIException("25");
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
decrypter = CryptTools.genDecrypter("AES", "AES/CBC/PKCS5Padding", info_key, iv);
|
||||
|
||||
byte[] decrypted_key = decrypter.doFinal(BASE642Bin(fkey));
|
||||
@ -317,22 +306,20 @@ public final class MegaCrypterAPI {
|
||||
|
||||
fname = new String(decrypted_name);
|
||||
|
||||
if(fpath != null)
|
||||
{
|
||||
if (fpath != null) {
|
||||
byte[] decrypted_fpath = decrypter.doFinal(BASE642Bin(fpath));
|
||||
|
||||
fpath = new String(decrypted_fpath);
|
||||
}
|
||||
|
||||
pass=Bin2BASE64(info_key);
|
||||
pass = Bin2BASE64(info_key);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(fpath != null)
|
||||
{
|
||||
fname = fpath+fname;
|
||||
if (fpath != null) {
|
||||
fname = fpath + fname;
|
||||
}
|
||||
|
||||
String file_data[] = {fname, file_size, fkey, pass, noexpire_token};
|
||||
@ -340,11 +327,10 @@ public final class MegaCrypterAPI {
|
||||
return file_data;
|
||||
}
|
||||
|
||||
private static int checkMCError(String data)
|
||||
{
|
||||
private static int checkMCError(String data) {
|
||||
String error = findFirstRegex("\"error\" *: *([0-9-]+)", data, 1);
|
||||
|
||||
return error != null?Integer.parseInt(error):0;
|
||||
return error != null ? Integer.parseInt(error) : 0;
|
||||
}
|
||||
|
||||
private MegaCrypterAPI() {
|
||||
|
@ -2,8 +2,7 @@ package megabasterd;
|
||||
|
||||
public final class MegaCrypterAPIException extends Exception {
|
||||
|
||||
public MegaCrypterAPIException(String message)
|
||||
{
|
||||
public MegaCrypterAPIException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ public final class MegaDirNode {
|
||||
|
||||
private final String _node_id;
|
||||
|
||||
private final HashMap <String,MegaDirNode> _children;
|
||||
private final HashMap<String, MegaDirNode> _children;
|
||||
|
||||
public MegaDirNode(String node_id) {
|
||||
|
||||
|
@ -21,13 +21,13 @@ public final class MegaMutableTreeNode extends DefaultMutableTreeNode {
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
if(userObject instanceof HashMap) {
|
||||
if (userObject instanceof HashMap) {
|
||||
|
||||
HashMap<String,Object> user_object = (HashMap<String,Object>)userObject;
|
||||
HashMap<String, Object> user_object = (HashMap<String, Object>) userObject;
|
||||
|
||||
return user_object.get("name") + ((isLeaf() && user_object.get("size")!=null)?" ["+formatBytes((long)user_object.get("size"))+"]":"");
|
||||
return user_object.get("name") + ((isLeaf() && user_object.get("size") != null) ? " [" + formatBytes((long) user_object.get("size")) + "]" : "");
|
||||
|
||||
} else if(userObject instanceof Object) {
|
||||
} else if (userObject instanceof Object) {
|
||||
|
||||
return userObject.toString();
|
||||
|
||||
|
@ -48,6 +48,7 @@ import javax.swing.SwingUtilities;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.DefaultTreeModel;
|
||||
import javax.swing.tree.MutableTreeNode;
|
||||
import javax.swing.tree.TreeNode;
|
||||
import javax.swing.tree.TreePath;
|
||||
import javax.xml.bind.DatatypeConverter;
|
||||
import static megabasterd.MainPanel.VERSION;
|
||||
@ -70,16 +71,16 @@ import org.apache.http.protocol.RequestTargetHost;
|
||||
|
||||
public final class MiscTools {
|
||||
|
||||
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;
|
||||
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;
|
||||
|
||||
private static final ConcurrentHashMap<String, Method> REFLECTION_METHOD_CACHE = new ConcurrentHashMap<>();
|
||||
|
||||
private static final Comparator<DefaultMutableTreeNode> TREE_NODE_COMPARATOR = new Comparator< DefaultMutableTreeNode>() {
|
||||
|
||||
@Override public int compare(DefaultMutableTreeNode a, DefaultMutableTreeNode b) {
|
||||
|
||||
@Override
|
||||
public int compare(DefaultMutableTreeNode a, DefaultMutableTreeNode b) {
|
||||
|
||||
if (a.isLeaf() && !b.isLeaf()) {
|
||||
return 1;
|
||||
@ -126,9 +127,8 @@ public final class MiscTools {
|
||||
}
|
||||
}
|
||||
|
||||
public static int[] bin2i32a(byte[] bin)
|
||||
{
|
||||
int l = (int)(4 * Math.ceil((double)bin.length/4));
|
||||
public static int[] bin2i32a(byte[] bin) {
|
||||
int l = (int) (4 * Math.ceil((double) bin.length / 4));
|
||||
|
||||
byte[] new_bin = Arrays.copyOfRange(bin, 0, l);
|
||||
|
||||
@ -137,20 +137,18 @@ public final class MiscTools {
|
||||
ByteBuffer bin_buffer = ByteBuffer.wrap(bin);
|
||||
IntBuffer int_buffer = bin_buffer.asIntBuffer();
|
||||
|
||||
if(int_buffer.hasArray()) {
|
||||
if (int_buffer.hasArray()) {
|
||||
return int_buffer.array();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
ArrayList<Integer> list = new ArrayList<>();
|
||||
|
||||
while(int_buffer.hasRemaining()) {
|
||||
while (int_buffer.hasRemaining()) {
|
||||
list.add(int_buffer.get());
|
||||
}
|
||||
|
||||
int[] aux = new int[list.size()];
|
||||
|
||||
for(int i=0; i<aux.length; i++) {
|
||||
for (int i = 0; i < aux.length; i++) {
|
||||
aux[i] = list.get(i);
|
||||
}
|
||||
|
||||
@ -158,26 +156,23 @@ public final class MiscTools {
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] i32a2bin(int[] i32a)
|
||||
{
|
||||
public static byte[] i32a2bin(int[] i32a) {
|
||||
ByteBuffer bin_buffer = ByteBuffer.allocate(i32a.length * 4);
|
||||
IntBuffer int_buffer = bin_buffer.asIntBuffer();
|
||||
int_buffer.put(i32a);
|
||||
|
||||
if(bin_buffer.hasArray()) {
|
||||
if (bin_buffer.hasArray()) {
|
||||
return bin_buffer.array();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
ArrayList<Byte> list = new ArrayList<>();
|
||||
|
||||
while(int_buffer.hasRemaining()) {
|
||||
while (int_buffer.hasRemaining()) {
|
||||
list.add(bin_buffer.get());
|
||||
}
|
||||
|
||||
byte[] aux = new byte[list.size()];
|
||||
|
||||
for(int i=0; i<aux.length; i++) {
|
||||
for (int i = 0; i < aux.length; i++) {
|
||||
aux[i] = list.get(i);
|
||||
}
|
||||
|
||||
@ -185,12 +180,11 @@ public final class MiscTools {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static BigInteger mpi2big(byte[] s) {
|
||||
|
||||
byte[] ns = Arrays.copyOfRange(s, 2, s.length);
|
||||
|
||||
BigInteger bigi = new BigInteger(1,ns);
|
||||
BigInteger bigi = new BigInteger(1, ns);
|
||||
|
||||
return bigi;
|
||||
}
|
||||
@ -199,13 +193,13 @@ public final class MiscTools {
|
||||
|
||||
String pos = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
|
||||
String res="";
|
||||
String res = "";
|
||||
|
||||
Random randomno = new Random();
|
||||
|
||||
for(int i=0; i<length; i++) {
|
||||
for (int i = 0; i < length; i++) {
|
||||
|
||||
res+=pos.charAt(randomno.nextInt(pos.length()));
|
||||
res += pos.charAt(randomno.nextInt(pos.length()));
|
||||
}
|
||||
|
||||
return res;
|
||||
@ -213,7 +207,7 @@ public final class MiscTools {
|
||||
|
||||
public static byte[] long2bytearray(long val) {
|
||||
|
||||
byte [] b = new byte[8];
|
||||
byte[] b = new byte[8];
|
||||
|
||||
for (int i = 7; i >= 0; i--) {
|
||||
b[i] = (byte) val;
|
||||
@ -225,48 +219,43 @@ public final class MiscTools {
|
||||
|
||||
public static long bytearray2long(byte[] val) {
|
||||
|
||||
long l=0;
|
||||
long l = 0;
|
||||
|
||||
for (int i = 0; i <=7; i++) {
|
||||
l+=val[i];
|
||||
l<<=8;
|
||||
for (int i = 0; i <= 7; i++) {
|
||||
l += val[i];
|
||||
l <<= 8;
|
||||
}
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
public static String findFirstRegex(String regex, String data, int group)
|
||||
{
|
||||
public static String findFirstRegex(String regex, String data, int group) {
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
|
||||
Matcher matcher = pattern.matcher(data);
|
||||
|
||||
return matcher.find()?matcher.group(group):null;
|
||||
return matcher.find() ? matcher.group(group) : null;
|
||||
}
|
||||
|
||||
public static ArrayList<String> findAllRegex(String regex, String data, int group)
|
||||
{
|
||||
public static ArrayList<String> findAllRegex(String regex, String data, int group) {
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
|
||||
Matcher matcher = pattern.matcher(data);
|
||||
|
||||
ArrayList<String> matches = new ArrayList<>();
|
||||
|
||||
while(matcher.find()) {
|
||||
while (matcher.find()) {
|
||||
matches.add(matcher.group(group));
|
||||
}
|
||||
|
||||
return matches;
|
||||
}
|
||||
|
||||
public static void updateFont(javax.swing.JComponent label, Font font, int layout)
|
||||
{
|
||||
public static void updateFont(javax.swing.JComponent label, Font font, int layout) {
|
||||
label.setFont(font.deriveFont(layout, label.getFont().getSize()));
|
||||
}
|
||||
|
||||
|
||||
public static String HashString(String algo, String data) throws NoSuchAlgorithmException, UnsupportedEncodingException
|
||||
{
|
||||
public static String HashString(String algo, String data) throws NoSuchAlgorithmException, UnsupportedEncodingException {
|
||||
MessageDigest md = MessageDigest.getInstance(algo);
|
||||
|
||||
byte[] thedigest = md.digest(data.getBytes("UTF-8"));
|
||||
@ -274,8 +263,7 @@ public final class MiscTools {
|
||||
return bin2hex(thedigest);
|
||||
}
|
||||
|
||||
public static String HashString(String algo, byte[] data) throws NoSuchAlgorithmException
|
||||
{
|
||||
public static String HashString(String algo, byte[] data) throws NoSuchAlgorithmException {
|
||||
MessageDigest md = MessageDigest.getInstance(algo);
|
||||
|
||||
byte[] thedigest = md.digest(data);
|
||||
@ -283,41 +271,34 @@ public final class MiscTools {
|
||||
return bin2hex(thedigest);
|
||||
}
|
||||
|
||||
public static byte[] HashBin(String algo, String data) throws NoSuchAlgorithmException, UnsupportedEncodingException
|
||||
{
|
||||
public static byte[] HashBin(String algo, String data) throws NoSuchAlgorithmException, UnsupportedEncodingException {
|
||||
MessageDigest md = MessageDigest.getInstance(algo);
|
||||
|
||||
return md.digest(data.getBytes("UTF-8"));
|
||||
}
|
||||
|
||||
public static byte[] HashBin(String algo, byte[] data) throws NoSuchAlgorithmException
|
||||
{
|
||||
public static byte[] HashBin(String algo, byte[] data) throws NoSuchAlgorithmException {
|
||||
MessageDigest md = MessageDigest.getInstance(algo);
|
||||
|
||||
return md.digest(data);
|
||||
}
|
||||
|
||||
public static byte[] BASE642Bin(String data) throws Exception
|
||||
{
|
||||
public static byte[] BASE642Bin(String data) throws Exception {
|
||||
return Base64.getDecoder().decode(data);
|
||||
}
|
||||
|
||||
public static String Bin2BASE64(byte[] data) throws Exception
|
||||
{
|
||||
public static String Bin2BASE64(byte[] data) throws Exception {
|
||||
return Base64.getEncoder().encodeToString(data);
|
||||
}
|
||||
|
||||
public static byte[] UrlBASE642Bin(String data) throws Exception
|
||||
{
|
||||
public static byte[] UrlBASE642Bin(String data) throws Exception {
|
||||
return Base64.getUrlDecoder().decode(data);
|
||||
}
|
||||
|
||||
public static String Bin2UrlBASE64(byte[] data) throws Exception
|
||||
{
|
||||
public static String Bin2UrlBASE64(byte[] data) throws Exception {
|
||||
return Base64.getUrlEncoder().withoutPadding().encodeToString(data);
|
||||
}
|
||||
|
||||
|
||||
public static long getWaitTimeExpBackOff(int retryCount) {
|
||||
|
||||
long waitTime = ((long) Math.pow(EXP_BACKOFF_BASE, retryCount) * EXP_BACKOFF_SECS_RETRY);
|
||||
@ -332,7 +313,7 @@ public final class MiscTools {
|
||||
|
||||
public static void swingReflectionInvoke(final String method_name, final Object[] obj, final Object... params) {
|
||||
|
||||
for(Object o:obj) {
|
||||
for (Object o : obj) {
|
||||
_swingReflectionInvoke(method_name, o, false, params);
|
||||
}
|
||||
}
|
||||
@ -344,59 +325,59 @@ public final class MiscTools {
|
||||
|
||||
public static void swingReflectionInvokeAndWait(final String method_name, final Object[] obj, final Object... params) {
|
||||
|
||||
for(Object o:obj) {
|
||||
for (Object o : obj) {
|
||||
_swingReflectionInvoke(method_name, o, true, params);
|
||||
}
|
||||
}
|
||||
|
||||
private static void _swingReflectionInvoke(final String method_name, final Object obj, final boolean wait, final Object... params) {
|
||||
|
||||
Runnable r = new Runnable(){
|
||||
Runnable r = new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
if(obj != null) {
|
||||
if (obj != null) {
|
||||
|
||||
Method method;
|
||||
|
||||
try {
|
||||
|
||||
if( (method=REFLECTION_METHOD_CACHE.get( method_name+"#"+obj.getClass().toString()+"#"+String.valueOf(params.length))) != null) {
|
||||
if ((method = REFLECTION_METHOD_CACHE.get(method_name + "#" + obj.getClass().toString() + "#" + String.valueOf(params.length))) != null) {
|
||||
|
||||
try {
|
||||
|
||||
method.invoke(obj, params);
|
||||
|
||||
} catch(SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
|
||||
} catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
|
||||
|
||||
method = null;
|
||||
}
|
||||
}
|
||||
|
||||
if(method == null) {
|
||||
if (method == null) {
|
||||
|
||||
for(Method m:obj.getClass().getMethods()) {
|
||||
for (Method m : obj.getClass().getMethods()) {
|
||||
|
||||
if(m.getName().equals(method_name) && m.getParameterCount() == params.length) {
|
||||
if (m.getName().equals(method_name) && m.getParameterCount() == params.length) {
|
||||
|
||||
try {
|
||||
|
||||
m.invoke(obj, params);
|
||||
|
||||
REFLECTION_METHOD_CACHE.put(method_name+"#"+obj.getClass().toString()+"#"+String.valueOf(params.length), m);
|
||||
REFLECTION_METHOD_CACHE.put(method_name + "#" + obj.getClass().toString() + "#" + String.valueOf(params.length), m);
|
||||
|
||||
method = m;
|
||||
|
||||
break;
|
||||
|
||||
}catch(SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex2) {
|
||||
} catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex2) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(method == null) {
|
||||
if (method == null) {
|
||||
|
||||
throw new NoSuchMethodException();
|
||||
|
||||
@ -407,7 +388,7 @@ public final class MiscTools {
|
||||
|
||||
getLogger(MiscTools.class.getName()).log(Level.SEVERE, null, ex);
|
||||
|
||||
System.out.println("REFLECTION METHOD NOT FOUND -> "+method_name+"#"+obj.getClass().toString()+"#"+String.valueOf(params.length));
|
||||
System.out.println("REFLECTION METHOD NOT FOUND -> " + method_name + "#" + obj.getClass().toString() + "#" + String.valueOf(params.length));
|
||||
}
|
||||
|
||||
}
|
||||
@ -421,67 +402,66 @@ public final class MiscTools {
|
||||
|
||||
Object[] ret = new Object[obj.length];
|
||||
|
||||
int i=0;
|
||||
int i = 0;
|
||||
|
||||
for(Object o:obj) {
|
||||
for (Object o : obj) {
|
||||
|
||||
ret[i++]=swingReflectionInvokeAndWaitForReturn(method_name, o, params);
|
||||
ret[i++] = swingReflectionInvokeAndWaitForReturn(method_name, o, params);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
public static Object swingReflectionInvokeAndWaitForReturn(final String method_name, final Object obj, final Object... params) {
|
||||
|
||||
Callable c = new Callable(){
|
||||
Callable c = new Callable() {
|
||||
|
||||
@Override
|
||||
public Object call() {
|
||||
|
||||
Object ret = null;
|
||||
|
||||
if(obj != null) {
|
||||
if (obj != null) {
|
||||
|
||||
Method method;
|
||||
|
||||
try {
|
||||
|
||||
if( (method=REFLECTION_METHOD_CACHE.get( method_name+"#"+obj.getClass().toString()+"#"+String.valueOf(params.length))) != null) {
|
||||
if ((method = REFLECTION_METHOD_CACHE.get(method_name + "#" + obj.getClass().toString() + "#" + String.valueOf(params.length))) != null) {
|
||||
|
||||
try {
|
||||
|
||||
ret = method.invoke(obj, params);
|
||||
|
||||
} catch(SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
|
||||
} catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
|
||||
|
||||
method = null;
|
||||
}
|
||||
}
|
||||
|
||||
if(method == null) {
|
||||
if (method == null) {
|
||||
|
||||
for(Method m:obj.getClass().getMethods()) {
|
||||
for (Method m : obj.getClass().getMethods()) {
|
||||
|
||||
if(m.getName().equals(method_name) && m.getParameterCount() == params.length) {
|
||||
if (m.getName().equals(method_name) && m.getParameterCount() == params.length) {
|
||||
|
||||
try {
|
||||
|
||||
ret = m.invoke(obj, params);
|
||||
|
||||
REFLECTION_METHOD_CACHE.put(method_name+"#"+obj.getClass().toString()+"#"+String.valueOf(params.length), m);
|
||||
REFLECTION_METHOD_CACHE.put(method_name + "#" + obj.getClass().toString() + "#" + String.valueOf(params.length), m);
|
||||
|
||||
method = m;
|
||||
|
||||
break;
|
||||
|
||||
}catch(SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex2) {
|
||||
} catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex2) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(method == null) {
|
||||
if (method == null) {
|
||||
|
||||
throw new NoSuchMethodException();
|
||||
}
|
||||
@ -490,7 +470,7 @@ public final class MiscTools {
|
||||
} catch (SecurityException | IllegalArgumentException | NoSuchMethodException ex) {
|
||||
getLogger(MiscTools.class.getName()).log(Level.SEVERE, null, ex);
|
||||
|
||||
System.out.println("REFLECTION METHOD NOT FOUND -> "+method_name+"#"+obj.getClass().toString()+"#"+String.valueOf(params.length));
|
||||
System.out.println("REFLECTION METHOD NOT FOUND -> " + method_name + "#" + obj.getClass().toString() + "#" + String.valueOf(params.length));
|
||||
}
|
||||
|
||||
}
|
||||
@ -502,12 +482,11 @@ public final class MiscTools {
|
||||
return swingInvokeItAndWaitForReturn(c);
|
||||
}
|
||||
|
||||
|
||||
public static void swingInvokeIt(Runnable r, boolean wait) {
|
||||
|
||||
if(wait) {
|
||||
if (wait) {
|
||||
|
||||
if(SwingUtilities.isEventDispatchThread()) {
|
||||
if (SwingUtilities.isEventDispatchThread()) {
|
||||
|
||||
r.run();
|
||||
|
||||
@ -522,17 +501,16 @@ public final class MiscTools {
|
||||
}
|
||||
}
|
||||
|
||||
}else{
|
||||
} else {
|
||||
|
||||
SwingUtilities.invokeLater(r);
|
||||
}
|
||||
}
|
||||
|
||||
public static Object swingInvokeItAndWaitForReturn(Callable c)
|
||||
{
|
||||
Object ret=null;
|
||||
public static Object swingInvokeItAndWaitForReturn(Callable c) {
|
||||
Object ret = null;
|
||||
|
||||
if(SwingUtilities.isEventDispatchThread()) {
|
||||
if (SwingUtilities.isEventDispatchThread()) {
|
||||
|
||||
try {
|
||||
ret = c.call();
|
||||
@ -556,7 +534,7 @@ public final class MiscTools {
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static String bin2hex(byte[] b){
|
||||
public static String bin2hex(byte[] b) {
|
||||
|
||||
BigInteger bi = new BigInteger(1, b);
|
||||
|
||||
@ -569,9 +547,9 @@ public final class MiscTools {
|
||||
|
||||
public static void copyTextToClipboard(String text) {
|
||||
|
||||
StringSelection stringSelection = new StringSelection (text);
|
||||
Clipboard clpbrd = Toolkit.getDefaultToolkit ().getSystemClipboard ();
|
||||
clpbrd.setContents (stringSelection, null);
|
||||
StringSelection stringSelection = new StringSelection(text);
|
||||
Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||
clpbrd.setContents(stringSelection, null);
|
||||
|
||||
}
|
||||
|
||||
@ -579,25 +557,25 @@ public final class MiscTools {
|
||||
|
||||
String response = null;
|
||||
|
||||
try(CloseableHttpClient httpclient = MiscTools.getApacheKissHttpClient()) {
|
||||
try (CloseableHttpClient httpclient = MiscTools.getApacheKissHttpClient()) {
|
||||
|
||||
HttpGet httpget = new HttpGet(new URI("http://tinyurl.com/api-create.php?url="+URLEncoder.encode(link.trim(), "UTF-8")));
|
||||
HttpGet httpget = new HttpGet(new URI("http://tinyurl.com/api-create.php?url=" + URLEncoder.encode(link.trim(), "UTF-8")));
|
||||
|
||||
httpget.addHeader("Custom-User-Agent", MainPanel.DEFAULT_USER_AGENT);
|
||||
|
||||
httpget.addHeader("Connection", "close");
|
||||
|
||||
try(CloseableHttpResponse httpresponse = httpclient.execute(httpget)) {
|
||||
try (CloseableHttpResponse httpresponse = httpclient.execute(httpget)) {
|
||||
|
||||
InputStream is=httpresponse.getEntity().getContent();
|
||||
InputStream is = httpresponse.getEntity().getContent();
|
||||
|
||||
ByteArrayOutputStream byte_res = new ByteArrayOutputStream();
|
||||
|
||||
byte[] buffer = new byte[16*1024];
|
||||
byte[] buffer = new byte[16 * 1024];
|
||||
|
||||
int reads;
|
||||
|
||||
while( (reads=is.read(buffer)) != -1 ) {
|
||||
while ((reads = is.read(buffer)) != -1) {
|
||||
|
||||
byte_res.write(buffer, 0, reads);
|
||||
}
|
||||
@ -611,7 +589,7 @@ public final class MiscTools {
|
||||
Logger.getLogger(MiscTools.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
|
||||
return findFirstRegex("http", response, 0)!=null?response:link;
|
||||
return findFirstRegex("http", response, 0) != null ? response : link;
|
||||
}
|
||||
|
||||
public static String formatBytes(Long bytes) {
|
||||
@ -620,9 +598,9 @@ public final class MiscTools {
|
||||
|
||||
bytes = Math.max(bytes, 0L);
|
||||
|
||||
int pow = Math.min((int)((bytes>0L?Math.log(bytes):0) / Math.log(1024)), 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));
|
||||
Double bytes_double = (double) bytes / (1 << (10 * pow));
|
||||
|
||||
DecimalFormat df = new DecimalFormat("#.##");
|
||||
|
||||
@ -663,7 +641,7 @@ public final class MiscTools {
|
||||
|
||||
parent.removeAllChildren();
|
||||
|
||||
for (DefaultMutableTreeNode node: children) {
|
||||
for (DefaultMutableTreeNode node : children) {
|
||||
|
||||
parent.add(node);
|
||||
|
||||
@ -672,31 +650,31 @@ public final class MiscTools {
|
||||
|
||||
public static boolean deleteSelectedTreeItems(JTree tree) {
|
||||
|
||||
TreePath[] paths = (TreePath[])swingReflectionInvokeAndWaitForReturn("getSelectionPaths", tree);
|
||||
TreePath[] paths = (TreePath[]) swingReflectionInvokeAndWaitForReturn("getSelectionPaths", tree);
|
||||
|
||||
if(paths != null) {
|
||||
if (paths != null) {
|
||||
|
||||
DefaultTreeModel tree_model = (DefaultTreeModel)swingReflectionInvokeAndWaitForReturn("getModel", tree);
|
||||
DefaultTreeModel tree_model = (DefaultTreeModel) swingReflectionInvokeAndWaitForReturn("getModel", tree);
|
||||
|
||||
MutableTreeNode node;
|
||||
|
||||
for (TreePath path : paths) {
|
||||
|
||||
node = (MutableTreeNode)path.getLastPathComponent();
|
||||
node = (MutableTreeNode) path.getLastPathComponent();
|
||||
|
||||
if(node != null) {
|
||||
if (node != null) {
|
||||
|
||||
if(node != tree_model.getRoot()) {
|
||||
if (node != tree_model.getRoot()) {
|
||||
|
||||
MutableTreeNode parent = (MutableTreeNode)node.getParent();
|
||||
MutableTreeNode parent = (MutableTreeNode) node.getParent();
|
||||
|
||||
tree_model.removeNodeFromParent(node);
|
||||
|
||||
while(parent != null && parent.isLeaf()) {
|
||||
while (parent != null && parent.isLeaf()) {
|
||||
|
||||
if(parent != tree_model.getRoot()) {
|
||||
if (parent != tree_model.getRoot()) {
|
||||
|
||||
MutableTreeNode parent_aux = (MutableTreeNode)parent.getParent();
|
||||
MutableTreeNode parent_aux = (MutableTreeNode) parent.getParent();
|
||||
|
||||
tree_model.removeNodeFromParent(parent);
|
||||
|
||||
@ -714,7 +692,7 @@ public final class MiscTools {
|
||||
|
||||
try {
|
||||
|
||||
new_root = (MutableTreeNode)tree_model.getRoot().getClass().newInstance();
|
||||
new_root = (MutableTreeNode) tree_model.getRoot().getClass().newInstance();
|
||||
|
||||
swingReflectionInvokeAndWait("setModel", tree, new DefaultTreeModel(new_root));
|
||||
|
||||
@ -731,7 +709,7 @@ public final class MiscTools {
|
||||
}
|
||||
}
|
||||
|
||||
swingReflectionInvoke("setRootVisible", tree, ((MutableTreeNode)tree_model.getRoot()).getChildCount() > 0 );
|
||||
swingReflectionInvoke("setRootVisible", tree, ((TreeNode) tree_model.getRoot()).getChildCount() > 0);
|
||||
|
||||
swingReflectionInvoke("setEnabled", tree, true);
|
||||
|
||||
@ -743,13 +721,13 @@ public final class MiscTools {
|
||||
|
||||
public static boolean deleteAllExceptSelectedTreeItems(JTree tree) {
|
||||
|
||||
TreePath[] paths = (TreePath[])swingReflectionInvokeAndWaitForReturn("getSelectionPaths", tree);
|
||||
TreePath[] paths = (TreePath[]) swingReflectionInvokeAndWaitForReturn("getSelectionPaths", tree);
|
||||
|
||||
HashMap<MutableTreeNode,MutableTreeNode> hashmap_old = new HashMap<>();
|
||||
HashMap<MutableTreeNode, MutableTreeNode> hashmap_old = new HashMap<>();
|
||||
|
||||
DefaultTreeModel tree_model = (DefaultTreeModel)swingReflectionInvokeAndWaitForReturn("getModel", tree);
|
||||
DefaultTreeModel tree_model = (DefaultTreeModel) swingReflectionInvokeAndWaitForReturn("getModel", tree);
|
||||
|
||||
if(paths != null) {
|
||||
if (paths != null) {
|
||||
|
||||
Class node_class = tree_model.getRoot().getClass();
|
||||
|
||||
@ -759,7 +737,7 @@ public final class MiscTools {
|
||||
|
||||
new_root = node_class.newInstance();
|
||||
|
||||
((MutableTreeNode)new_root).setUserObject( ((DefaultMutableTreeNode)tree_model.getRoot()).getUserObject() );
|
||||
((MutableTreeNode) new_root).setUserObject(((DefaultMutableTreeNode) tree_model.getRoot()).getUserObject());
|
||||
|
||||
} catch (InstantiationException | IllegalAccessException ex) {
|
||||
getLogger(MiscTools.class.getName()).log(Level.SEVERE, null, ex);
|
||||
@ -767,19 +745,18 @@ public final class MiscTools {
|
||||
|
||||
for (TreePath path : paths) {
|
||||
|
||||
if((MutableTreeNode)path.getLastPathComponent() != (MutableTreeNode)tree_model.getRoot())
|
||||
{
|
||||
if ((MutableTreeNode) path.getLastPathComponent() != (MutableTreeNode) tree_model.getRoot()) {
|
||||
Object parent = new_root;
|
||||
|
||||
for(Object path_element:path.getPath()) {
|
||||
for (Object path_element : path.getPath()) {
|
||||
|
||||
if((MutableTreeNode)path_element != (MutableTreeNode)tree_model.getRoot()) {
|
||||
if ((MutableTreeNode) path_element != (MutableTreeNode) tree_model.getRoot()) {
|
||||
|
||||
if(hashmap_old.get((MutableTreeNode)path_element) == null) {
|
||||
if (hashmap_old.get(path_element) == null) {
|
||||
|
||||
Object node=null;
|
||||
Object node = null;
|
||||
|
||||
if((MutableTreeNode)path_element == (MutableTreeNode)path.getLastPathComponent()) {
|
||||
if ((MutableTreeNode) path_element == (MutableTreeNode) path.getLastPathComponent()) {
|
||||
|
||||
node = path_element;
|
||||
|
||||
@ -789,20 +766,20 @@ public final class MiscTools {
|
||||
|
||||
node = node_class.newInstance();
|
||||
|
||||
((MutableTreeNode)node).setUserObject( ((DefaultMutableTreeNode)path_element).getUserObject() );
|
||||
((MutableTreeNode) node).setUserObject(((DefaultMutableTreeNode) path_element).getUserObject());
|
||||
|
||||
} catch (InstantiationException | IllegalAccessException ex) {
|
||||
getLogger(MiscTools.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
if(parent != null) {
|
||||
if (parent != null) {
|
||||
|
||||
((DefaultMutableTreeNode)parent).add((MutableTreeNode)node);
|
||||
((DefaultMutableTreeNode) parent).add((MutableTreeNode) node);
|
||||
|
||||
if(!((MutableTreeNode)path_element).isLeaf()) {
|
||||
if (!((TreeNode) path_element).isLeaf()) {
|
||||
|
||||
hashmap_old.put((MutableTreeNode)path_element, (MutableTreeNode)node);
|
||||
hashmap_old.put((MutableTreeNode) path_element, (MutableTreeNode) node);
|
||||
|
||||
parent = node;
|
||||
}
|
||||
@ -810,7 +787,7 @@ public final class MiscTools {
|
||||
|
||||
} else {
|
||||
|
||||
parent = hashmap_old.get((MutableTreeNode)path_element);
|
||||
parent = hashmap_old.get(path_element);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -821,9 +798,9 @@ public final class MiscTools {
|
||||
}
|
||||
}
|
||||
|
||||
swingReflectionInvokeAndWait("setModel", tree, new DefaultTreeModel(sortTree((DefaultMutableTreeNode)new_root)));
|
||||
swingReflectionInvokeAndWait("setModel", tree, new DefaultTreeModel(sortTree((DefaultMutableTreeNode) new_root)));
|
||||
|
||||
swingReflectionInvoke("setRootVisible", tree, new_root!=null?((DefaultMutableTreeNode)new_root).getChildCount() > 0:false);
|
||||
swingReflectionInvoke("setRootVisible", tree, new_root != null ? ((TreeNode) new_root).getChildCount() > 0 : false);
|
||||
|
||||
swingReflectionInvoke("setEnabled", tree, true);
|
||||
|
||||
@ -837,24 +814,24 @@ public final class MiscTools {
|
||||
|
||||
String separator = " ... ";
|
||||
|
||||
max_length-=separator.length();
|
||||
max_length -= separator.length();
|
||||
|
||||
if(max_length %2 != 0) {
|
||||
if (max_length % 2 != 0) {
|
||||
|
||||
max_length--;
|
||||
}
|
||||
|
||||
return (text.length() > max_length)?text.replaceAll("^(.{1,"+(max_length/2)+"}).*?(.{1,"+(max_length/2)+"})$", "$1"+separator+"$2"):text;
|
||||
return (text.length() > max_length) ? text.replaceAll("^(.{1," + (max_length / 2) + "}).*?(.{1," + (max_length / 2) + "})$", "$1" + separator + "$2") : text;
|
||||
}
|
||||
|
||||
public static String cleanFilename(String filename) {
|
||||
|
||||
return (System.getProperty("os.name").toLowerCase().contains("win")?filename.replaceAll("[<>:\"/\\\\\\|\\?\\*]+", "").replaceAll("[ \\.]{1,}/{1,}", "/"):filename).replaceAll("[\\.]{1,}$", "").trim();
|
||||
return (System.getProperty("os.name").toLowerCase().contains("win") ? filename.replaceAll("[<>:\"/\\\\\\|\\?\\*]+", "").replaceAll("[ \\.]{1,}/{1,}", "/") : filename).replaceAll("[\\.]{1,}$", "").trim();
|
||||
}
|
||||
|
||||
public static String cleanFilePath(String path) {
|
||||
|
||||
return path.equals(".")?((System.getProperty("os.name").toLowerCase().contains("win")?path.replaceAll("[<>:\"\\|\\?\\*]+", "").replaceAll("[ \\.]{1,}/{1,}", "/"):path).replaceAll("[\\.]{1,}$", "").trim()):path;
|
||||
return path.equals(".") ? ((System.getProperty("os.name").toLowerCase().contains("win") ? path.replaceAll("[<>:\"\\|\\?\\*]+", "").replaceAll("[ \\.]{1,}/{1,}", "/") : path).replaceAll("[\\.]{1,}$", "").trim()) : path;
|
||||
}
|
||||
|
||||
public static byte[] genRandomByteArray(int length) {
|
||||
@ -872,18 +849,19 @@ public final class MiscTools {
|
||||
|
||||
String ret = null;
|
||||
|
||||
if(contents != null) {
|
||||
if (contents != null) {
|
||||
|
||||
try {
|
||||
|
||||
Object o = contents.getTransferData(DataFlavor.stringFlavor);
|
||||
|
||||
if(o instanceof String) {
|
||||
if (o instanceof String) {
|
||||
|
||||
ret = (String)o;
|
||||
ret = (String) o;
|
||||
}
|
||||
|
||||
} catch (Exception ex) {}
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
@ -894,15 +872,15 @@ public final class MiscTools {
|
||||
|
||||
String res = "";
|
||||
|
||||
if(data != null) {
|
||||
if (data != null) {
|
||||
|
||||
ArrayList<String> links = findAllRegex("(?:https?|mega)://[^/]*/(#.*?)?!.+![^\r\n]+", data, 0);
|
||||
|
||||
links.addAll(findAllRegex("mega://enc.*?[^\r\n]+", data, 0));
|
||||
|
||||
for(String s:links) {
|
||||
for (String s : links) {
|
||||
|
||||
res+=s+"\n";
|
||||
res += s + "\n";
|
||||
}
|
||||
}
|
||||
|
||||
@ -913,13 +891,13 @@ public final class MiscTools {
|
||||
|
||||
String res = "";
|
||||
|
||||
if(data != null) {
|
||||
if (data != null) {
|
||||
|
||||
ArrayList<String> links = findAllRegex("(?:https?|mega)://[^/]*/(#.*?)?!.+![^\r\n]+", data, 0);
|
||||
|
||||
links.addAll(findAllRegex("mega://enc.*?[^\r\n]+", data, 0));
|
||||
|
||||
if(links.size()>0) {
|
||||
if (links.size() > 0) {
|
||||
|
||||
res = links.get(0);
|
||||
}
|
||||
@ -930,16 +908,15 @@ public final class MiscTools {
|
||||
|
||||
public static boolean checkMegaDownloadUrl(String string_url) {
|
||||
|
||||
boolean url_ok=false;
|
||||
boolean url_ok = false;
|
||||
|
||||
try (CloseableHttpClient httpclient = MiscTools.getApacheKissHttpClient()) {
|
||||
|
||||
try(CloseableHttpClient httpclient = MiscTools.getApacheKissHttpClient()) {
|
||||
|
||||
HttpGet httpget = new HttpGet(new URI(string_url+"/0"));
|
||||
HttpGet httpget = new HttpGet(new URI(string_url + "/0"));
|
||||
|
||||
httpget.addHeader("Connection", "close");
|
||||
|
||||
try(CloseableHttpResponse httpresponse = httpclient.execute(httpget)) {
|
||||
try (CloseableHttpResponse httpresponse = httpclient.execute(httpget)) {
|
||||
|
||||
url_ok = (httpresponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK);
|
||||
}
|
||||
@ -953,7 +930,6 @@ public final class MiscTools {
|
||||
return url_ok;
|
||||
}
|
||||
|
||||
|
||||
private MiscTools() {
|
||||
}
|
||||
|
||||
@ -966,15 +942,15 @@ public final class MiscTools {
|
||||
|
||||
HashMap<String, Object> folder_nodes = ma.getFolderNodes(folder_node, folder_key);
|
||||
|
||||
if(folder_nodes != null && !folder_nodes.isEmpty()) {
|
||||
if (folder_nodes != null && !folder_nodes.isEmpty()) {
|
||||
|
||||
for(Object o:folder_nodes.values()) {
|
||||
for (Object o : folder_nodes.values()) {
|
||||
|
||||
HashMap<String,Object> current_node = (HashMap<String,Object>)o;
|
||||
HashMap<String, Object> current_node = (HashMap<String, Object>) o;
|
||||
|
||||
new_version = MiscTools.findFirstRegex("([0-9\\.]+)\\.run", (String)current_node.get("name"), 1);
|
||||
new_version = MiscTools.findFirstRegex("([0-9\\.]+)\\.run", (String) current_node.get("name"), 1);
|
||||
|
||||
if(new_version!=null && Double.parseDouble(new_version) > Double.parseDouble(VERSION)) {
|
||||
if (new_version != null && Double.parseDouble(new_version) > Double.parseDouble(VERSION)) {
|
||||
|
||||
break;
|
||||
|
||||
@ -1001,8 +977,7 @@ public final class MiscTools {
|
||||
}
|
||||
}
|
||||
|
||||
public static CloseableHttpClient getApacheKissHttpClient()
|
||||
{
|
||||
public static CloseableHttpClient getApacheKissHttpClient() {
|
||||
return HttpClients.custom()
|
||||
.addInterceptorFirst(new RequestDefaultHeaders())
|
||||
.addInterceptorFirst(new RequestContent())
|
||||
@ -1034,5 +1009,4 @@ public final class MiscTools {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -3,16 +3,15 @@ package megabasterd;
|
||||
import static java.util.logging.Level.SEVERE;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
|
||||
public final class ProgressMeter implements Runnable, SecureNotifiable
|
||||
{
|
||||
public final class ProgressMeter implements Runnable, SecureNotifiable {
|
||||
|
||||
private final Transference _transference;
|
||||
private volatile boolean _exit;
|
||||
private final Object _secure_notify_lock;
|
||||
private boolean _notified;
|
||||
private long _progress;
|
||||
|
||||
ProgressMeter(Transference transference)
|
||||
{
|
||||
ProgressMeter(Transference transference) {
|
||||
_notified = false;
|
||||
_secure_notify_lock = new Object();
|
||||
_transference = transference;
|
||||
@ -20,15 +19,13 @@ public final class ProgressMeter implements Runnable, SecureNotifiable
|
||||
_exit = false;
|
||||
}
|
||||
|
||||
public void setExit(boolean value)
|
||||
{
|
||||
public void setExit(boolean value) {
|
||||
_exit = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void secureNotify()
|
||||
{
|
||||
synchronized(_secure_notify_lock) {
|
||||
public void secureNotify() {
|
||||
synchronized (_secure_notify_lock) {
|
||||
|
||||
_notified = true;
|
||||
|
||||
@ -39,9 +36,8 @@ public final class ProgressMeter implements Runnable, SecureNotifiable
|
||||
@Override
|
||||
public void secureWait() {
|
||||
|
||||
synchronized(_secure_notify_lock)
|
||||
{
|
||||
while(!_notified) {
|
||||
synchronized (_secure_notify_lock) {
|
||||
while (!_notified) {
|
||||
|
||||
try {
|
||||
_secure_notify_lock.wait();
|
||||
@ -57,7 +53,7 @@ public final class ProgressMeter implements Runnable, SecureNotifiable
|
||||
@Override
|
||||
public void secureNotifyAll() {
|
||||
|
||||
synchronized(_secure_notify_lock) {
|
||||
synchronized (_secure_notify_lock) {
|
||||
|
||||
_notified = true;
|
||||
|
||||
@ -66,23 +62,19 @@ public final class ProgressMeter implements Runnable, SecureNotifiable
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
public void run() {
|
||||
System.out.println("ProgressMeter hello!");
|
||||
|
||||
while(!_exit || !_transference.getPartialProgress().isEmpty())
|
||||
{
|
||||
while (!_exit || !_transference.getPartialProgress().isEmpty()) {
|
||||
Integer reads;
|
||||
|
||||
while( (reads=_transference.getPartialProgress().poll()) !=null )
|
||||
{
|
||||
_progress+=reads;
|
||||
while ((reads = _transference.getPartialProgress().poll()) != null) {
|
||||
_progress += reads;
|
||||
}
|
||||
|
||||
_transference.setProgress(_progress);
|
||||
|
||||
if(!_exit)
|
||||
{
|
||||
if (!_exit) {
|
||||
secureWait();
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ import static megabasterd.MiscTools.HashBin;
|
||||
import static megabasterd.MiscTools.swingReflectionInvoke;
|
||||
import static megabasterd.MiscTools.updateFont;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tonikelope
|
||||
@ -39,9 +38,9 @@ public class SetMegaMasterPasswordDialog extends javax.swing.JDialog {
|
||||
|
||||
public void deleteNewPass() {
|
||||
|
||||
if(_new_pass != null) {
|
||||
if (_new_pass != null) {
|
||||
|
||||
Arrays.fill(_new_pass, (byte)0);
|
||||
Arrays.fill(_new_pass, (byte) 0);
|
||||
}
|
||||
|
||||
_new_pass = null;
|
||||
@ -58,17 +57,18 @@ public class SetMegaMasterPasswordDialog extends javax.swing.JDialog {
|
||||
super(parent, modal);
|
||||
initComponents();
|
||||
|
||||
MiscTools.swingInvokeIt(new Runnable(){
|
||||
MiscTools.swingInvokeIt(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {updateFont(new_pass_label, FONT_DEFAULT, Font.PLAIN);
|
||||
public void run() {
|
||||
updateFont(new_pass_label, FONT_DEFAULT, Font.PLAIN);
|
||||
updateFont(confirm_pass_label, FONT_DEFAULT, Font.PLAIN);
|
||||
updateFont(ok_button, FONT_DEFAULT, Font.PLAIN);
|
||||
updateFont(cancel_button, FONT_DEFAULT, Font.PLAIN);
|
||||
updateFont(warning_label, FONT_DEFAULT, Font.PLAIN);
|
||||
updateFont(status_label, FONT_DEFAULT, Font.PLAIN);}}, true);
|
||||
|
||||
|
||||
updateFont(status_label, FONT_DEFAULT, Font.PLAIN);
|
||||
}
|
||||
}, true);
|
||||
|
||||
_pass_ok = false;
|
||||
|
||||
@ -217,22 +217,22 @@ public class SetMegaMasterPasswordDialog extends javax.swing.JDialog {
|
||||
|
||||
final Dialog tthis = this;
|
||||
|
||||
THREAD_POOL.execute(new Runnable(){
|
||||
THREAD_POOL.execute(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
try {
|
||||
|
||||
if(Arrays.equals(new_pass_textfield.getPassword(), confirm_pass_textfield.getPassword())) {
|
||||
if (Arrays.equals(new_pass_textfield.getPassword(), confirm_pass_textfield.getPassword())) {
|
||||
|
||||
swingReflectionInvoke("setText", status_label, "Processing your password, please wait...");
|
||||
|
||||
if(new_pass_textfield.getPassword().length > 0) {
|
||||
if (new_pass_textfield.getPassword().length > 0) {
|
||||
|
||||
_new_pass = CryptTools.PBKDF2HMACSHA256(new String(new_pass_textfield.getPassword()), MiscTools.BASE642Bin(_salt), CryptTools.PBKDF2_ITERATIONS);
|
||||
|
||||
_new_pass_hash =Bin2BASE64(HashBin("SHA-1", _new_pass));
|
||||
_new_pass_hash = Bin2BASE64(HashBin("SHA-1", _new_pass));
|
||||
}
|
||||
|
||||
_pass_ok = true;
|
||||
@ -255,18 +255,18 @@ public class SetMegaMasterPasswordDialog extends javax.swing.JDialog {
|
||||
} catch (Exception ex) {
|
||||
Logger.getLogger(SetMegaMasterPasswordDialog.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}});
|
||||
}
|
||||
});
|
||||
}//GEN-LAST:event_ok_buttonActionPerformed
|
||||
|
||||
private void confirm_pass_textfieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_confirm_pass_textfieldKeyPressed
|
||||
|
||||
if(evt.getKeyCode() == KeyEvent.VK_ENTER) {
|
||||
if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
|
||||
|
||||
ok_buttonActionPerformed(null);
|
||||
}
|
||||
}//GEN-LAST:event_confirm_pass_textfieldKeyPressed
|
||||
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JButton cancel_button;
|
||||
private javax.swing.JLabel confirm_pass_label;
|
||||
|
@ -38,7 +38,6 @@ import static megabasterd.MiscTools.swingReflectionInvokeAndWaitForReturn;
|
||||
import static megabasterd.MiscTools.truncateText;
|
||||
import static megabasterd.MiscTools.updateFont;
|
||||
|
||||
|
||||
public final class SettingsDialog extends javax.swing.JDialog {
|
||||
|
||||
private String _download_path;
|
||||
@ -61,6 +60,7 @@ public final class SettingsDialog extends javax.swing.JDialog {
|
||||
|
||||
/**
|
||||
* Creates new form Settings
|
||||
*
|
||||
* @param parent
|
||||
* @param modal
|
||||
*/
|
||||
@ -68,10 +68,11 @@ public final class SettingsDialog extends javax.swing.JDialog {
|
||||
super(parent, modal);
|
||||
initComponents();
|
||||
|
||||
MiscTools.swingInvokeIt(new Runnable(){
|
||||
MiscTools.swingInvokeIt(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {updateFont(change_download_dir_button, FONT_DEFAULT, Font.PLAIN);
|
||||
public void run() {
|
||||
updateFont(change_download_dir_button, FONT_DEFAULT, Font.PLAIN);
|
||||
updateFont(down_dir_label, FONT_DEFAULT, Font.PLAIN);
|
||||
updateFont(ok_button, FONT_DEFAULT, Font.PLAIN);
|
||||
updateFont(cancel_button, FONT_DEFAULT, Font.PLAIN);
|
||||
@ -100,15 +101,15 @@ public final class SettingsDialog extends javax.swing.JDialog {
|
||||
updateFont(default_dir_label, FONT_DEFAULT, Font.PLAIN);
|
||||
updateFont(encrypt_pass_checkbox, FONT_DEFAULT, Font.PLAIN);
|
||||
updateFont(unlock_accounts_button, FONT_DEFAULT, Font.PLAIN);
|
||||
updateFont(delete_all_accounts_button, FONT_DEFAULT, Font.PLAIN);}}, true);
|
||||
updateFont(delete_all_accounts_button, FONT_DEFAULT, Font.PLAIN);
|
||||
}
|
||||
}, true);
|
||||
|
||||
|
||||
|
||||
_main_panel = ((MainPanelView)parent).getMain_panel();
|
||||
_main_panel = ((MainPanelView) parent).getMain_panel();
|
||||
|
||||
String default_download_dir = DBTools.selectSettingValueFromDB("default_down_dir");
|
||||
|
||||
if(default_download_dir == null) {
|
||||
if (default_download_dir == null) {
|
||||
default_download_dir = ".";
|
||||
}
|
||||
|
||||
@ -118,66 +119,61 @@ public final class SettingsDialog extends javax.swing.JDialog {
|
||||
|
||||
String slots = DBTools.selectSettingValueFromDB("default_slots_down");
|
||||
|
||||
int default_slots=Download.WORKERS_DEFAULT;
|
||||
int default_slots = Download.WORKERS_DEFAULT;
|
||||
|
||||
if(slots != null) {
|
||||
if (slots != null) {
|
||||
default_slots = Integer.parseInt(slots);
|
||||
}
|
||||
|
||||
swingReflectionInvokeAndWait("setModel", default_slots_down_spinner, new SpinnerNumberModel(default_slots, Download.MIN_WORKERS, Download.MAX_WORKERS, 1));
|
||||
|
||||
swingReflectionInvoke("setEditable", ((JSpinner.DefaultEditor)default_slots_down_spinner.getEditor()).getTextField(), false);
|
||||
swingReflectionInvoke("setEditable", ((JSpinner.DefaultEditor) default_slots_down_spinner.getEditor()).getTextField(), false);
|
||||
|
||||
slots = DBTools.selectSettingValueFromDB("default_slots_up");
|
||||
|
||||
default_slots=Upload.WORKERS_DEFAULT;
|
||||
default_slots = Upload.WORKERS_DEFAULT;
|
||||
|
||||
if(slots != null) {
|
||||
if (slots != null) {
|
||||
default_slots = Integer.parseInt(slots);
|
||||
}
|
||||
|
||||
swingReflectionInvokeAndWait("setModel", default_slots_up_spinner, new SpinnerNumberModel(default_slots, Upload.MIN_WORKERS, Upload.MAX_WORKERS, 1));
|
||||
|
||||
swingReflectionInvoke("setEditable", ((JSpinner.DefaultEditor)default_slots_up_spinner.getEditor()).getTextField(), false);
|
||||
|
||||
swingReflectionInvoke("setEditable", ((JSpinner.DefaultEditor) default_slots_up_spinner.getEditor()).getTextField(), false);
|
||||
|
||||
String max_down = DBTools.selectSettingValueFromDB("max_downloads");
|
||||
|
||||
int max_dl = Download.SIM_TRANSFERENCES_DEFAULT;
|
||||
|
||||
if(max_down != null) {
|
||||
if (max_down != null) {
|
||||
max_dl = Integer.parseInt(max_down);
|
||||
}
|
||||
|
||||
|
||||
swingReflectionInvokeAndWait("setModel", max_downloads_spinner, new SpinnerNumberModel(max_dl, 1, Download.MAX_SIM_TRANSFERENCES, 1));
|
||||
swingReflectionInvoke("setEditable",((JSpinner.DefaultEditor)max_downloads_spinner.getEditor()).getTextField(), false);
|
||||
|
||||
swingReflectionInvoke("setEditable", ((JSpinner.DefaultEditor) max_downloads_spinner.getEditor()).getTextField(), false);
|
||||
|
||||
String max_up = DBTools.selectSettingValueFromDB("max_uploads");
|
||||
|
||||
int max_ul = Upload.SIM_TRANSFERENCES_DEFAULT;
|
||||
|
||||
if(max_up != null) {
|
||||
if (max_up != null) {
|
||||
max_ul = Integer.parseInt(max_up);
|
||||
}
|
||||
|
||||
|
||||
swingReflectionInvokeAndWait("setModel",max_uploads_spinner, new SpinnerNumberModel(max_ul, 1, Upload.MAX_SIM_TRANSFERENCES, 1));
|
||||
swingReflectionInvoke("setEditable",((JSpinner.DefaultEditor)max_uploads_spinner.getEditor()).getTextField(), false);
|
||||
|
||||
swingReflectionInvokeAndWait("setModel", max_uploads_spinner, new SpinnerNumberModel(max_ul, 1, Upload.MAX_SIM_TRANSFERENCES, 1));
|
||||
swingReflectionInvoke("setEditable", ((JSpinner.DefaultEditor) max_uploads_spinner.getEditor()).getTextField(), false);
|
||||
|
||||
boolean limit_dl_speed = Download.LIMIT_TRANSFERENCE_SPEED_DEFAULT;
|
||||
|
||||
String limit_download_speed = DBTools.selectSettingValueFromDB("limit_download_speed");
|
||||
|
||||
if(limit_download_speed != null) {
|
||||
if (limit_download_speed != null) {
|
||||
limit_dl_speed = limit_download_speed.equals("yes");
|
||||
}
|
||||
|
||||
limit_download_speed_checkbox.setSelected(limit_dl_speed);
|
||||
|
||||
if(!limit_dl_speed) {
|
||||
if (!limit_dl_speed) {
|
||||
|
||||
swingReflectionInvoke("setEnabled", max_down_speed_label, false);
|
||||
swingReflectionInvoke("setEnabled", max_down_speed_spinner, false);
|
||||
@ -190,27 +186,25 @@ public final class SettingsDialog extends javax.swing.JDialog {
|
||||
|
||||
int max_download_speed = Download.MAX_TRANSFERENCE_SPEED_DEFAULT;
|
||||
|
||||
if(max_dl_speed != null) {
|
||||
if (max_dl_speed != null) {
|
||||
max_download_speed = Integer.parseInt(max_dl_speed);
|
||||
}
|
||||
|
||||
|
||||
swingReflectionInvokeAndWait("setModel", max_down_speed_spinner, new SpinnerNumberModel(max_download_speed, 1, Integer.MAX_VALUE, 5));
|
||||
|
||||
swingReflectionInvoke("setEditable", ((JSpinner.DefaultEditor)max_down_speed_spinner.getEditor()).getTextField(), true);
|
||||
|
||||
swingReflectionInvoke("setEditable", ((JSpinner.DefaultEditor) max_down_speed_spinner.getEditor()).getTextField(), true);
|
||||
|
||||
boolean limit_ul_speed = Upload.LIMIT_TRANSFERENCE_SPEED_DEFAULT;
|
||||
|
||||
String limit_upload_speed = DBTools.selectSettingValueFromDB("limit_upload_speed");
|
||||
|
||||
if(limit_upload_speed != null) {
|
||||
if (limit_upload_speed != null) {
|
||||
limit_ul_speed = limit_upload_speed.equals("yes");
|
||||
}
|
||||
|
||||
limit_upload_speed_checkbox.setSelected(limit_ul_speed);
|
||||
|
||||
if(!limit_ul_speed) {
|
||||
if (!limit_ul_speed) {
|
||||
|
||||
swingReflectionInvoke("setEnabled", max_up_speed_label, false);
|
||||
swingReflectionInvoke("setEnabled", max_up_speed_spinner, false);
|
||||
@ -223,20 +217,19 @@ public final class SettingsDialog extends javax.swing.JDialog {
|
||||
|
||||
int max_upload_speed = Upload.MAX_TRANSFERENCE_SPEED_DEFAULT;
|
||||
|
||||
if(max_ul_speed != null) {
|
||||
if (max_ul_speed != null) {
|
||||
max_upload_speed = Integer.parseInt(max_ul_speed);
|
||||
}
|
||||
|
||||
swingReflectionInvokeAndWait("setModel", max_up_speed_spinner, new SpinnerNumberModel(max_upload_speed, 1, Integer.MAX_VALUE, 5));
|
||||
|
||||
swingReflectionInvoke("setEditable", ((JSpinner.DefaultEditor)max_up_speed_spinner.getEditor()).getTextField(), true);
|
||||
|
||||
swingReflectionInvoke("setEditable", ((JSpinner.DefaultEditor) max_up_speed_spinner.getEditor()).getTextField(), true);
|
||||
|
||||
boolean cbc_mac = Download.VERIFY_CBC_MAC_DEFAULT;
|
||||
|
||||
String verify_file = DBTools.selectSettingValueFromDB("verify_down_file");
|
||||
|
||||
if(verify_file != null) {
|
||||
if (verify_file != null) {
|
||||
cbc_mac = (verify_file.equals("yes"));
|
||||
}
|
||||
|
||||
@ -246,13 +239,13 @@ public final class SettingsDialog extends javax.swing.JDialog {
|
||||
|
||||
String use_slots_val = DBTools.selectSettingValueFromDB("use_slots_down");
|
||||
|
||||
if(use_slots_val != null) {
|
||||
if (use_slots_val != null) {
|
||||
use_slots = use_slots_val.equals("yes");
|
||||
}
|
||||
|
||||
multi_slot_down_checkbox.setSelected(use_slots);
|
||||
|
||||
if(!use_slots) {
|
||||
if (!use_slots) {
|
||||
|
||||
swingReflectionInvoke("setEnabled", default_slots_down_label, false);
|
||||
swingReflectionInvoke("setEnabled", default_slots_down_spinner, false);
|
||||
@ -261,18 +254,17 @@ public final class SettingsDialog extends javax.swing.JDialog {
|
||||
swingReflectionInvoke("setEnabled", default_slots_down_spinner, true);
|
||||
}
|
||||
|
||||
|
||||
use_slots = Upload.USE_SLOTS_DEFAULT;
|
||||
|
||||
use_slots_val = DBTools.selectSettingValueFromDB("use_slots_up");
|
||||
|
||||
if(use_slots_val != null) {
|
||||
if (use_slots_val != null) {
|
||||
use_slots = use_slots_val.equals("yes");
|
||||
}
|
||||
|
||||
multi_slot_up_checkbox.setSelected(use_slots);
|
||||
|
||||
if(!use_slots) {
|
||||
if (!use_slots) {
|
||||
|
||||
swingReflectionInvoke("setEnabled", defaut_slots_up_label, false);
|
||||
swingReflectionInvoke("setEnabled", default_slots_up_spinner, false);
|
||||
@ -283,13 +275,13 @@ public final class SettingsDialog extends javax.swing.JDialog {
|
||||
|
||||
swingReflectionInvoke("setSelected", encrypt_pass_checkbox, (_main_panel.getMega_master_pass_hash() != null));
|
||||
|
||||
swingReflectionInvoke("setEnabled", remove_account_button, (mega_accounts_table.getRowCount()>0));
|
||||
swingReflectionInvoke("setEnabled", remove_account_button, (mega_accounts_table.getRowCount() > 0));
|
||||
|
||||
DefaultTableModel model = (DefaultTableModel)mega_accounts_table.getModel();
|
||||
DefaultTableModel model = (DefaultTableModel) mega_accounts_table.getModel();
|
||||
|
||||
if(_main_panel.getMega_master_pass_hash() != null) {
|
||||
if (_main_panel.getMega_master_pass_hash() != null) {
|
||||
|
||||
if(_main_panel.getMega_master_pass() == null) {
|
||||
if (_main_panel.getMega_master_pass() == null) {
|
||||
|
||||
swingReflectionInvoke("setEnabled", encrypt_pass_checkbox, false);
|
||||
|
||||
@ -299,11 +291,11 @@ public final class SettingsDialog extends javax.swing.JDialog {
|
||||
|
||||
swingReflectionInvoke("setVisible", unlock_accounts_button, true);
|
||||
|
||||
for (Object k: _main_panel.getMega_accounts().keySet()) {
|
||||
for (Object k : _main_panel.getMega_accounts().keySet()) {
|
||||
|
||||
String[] new_row_data = {(String)k, "**************************"};
|
||||
String[] new_row_data = {(String) k, "**************************"};
|
||||
|
||||
swingReflectionInvoke("addRow", model, new Object[] {new_row_data});
|
||||
swingReflectionInvoke("addRow", model, new Object[]{new_row_data});
|
||||
}
|
||||
|
||||
swingReflectionInvoke("setEnabled", mega_accounts_table, false);
|
||||
@ -316,13 +308,13 @@ public final class SettingsDialog extends javax.swing.JDialog {
|
||||
|
||||
for (Map.Entry pair : _main_panel.getMega_accounts().entrySet()) {
|
||||
|
||||
HashMap<String,Object> data = (HashMap)pair.getValue();
|
||||
HashMap<String, Object> data = (HashMap) pair.getValue();
|
||||
|
||||
String pass = null;
|
||||
|
||||
try {
|
||||
|
||||
pass = new String(CryptTools.aes_cbc_decrypt_pkcs7(BASE642Bin((String)data.get("password")), _main_panel.getMega_master_pass(), CryptTools.AES_ZERO_IV));
|
||||
pass = new String(CryptTools.aes_cbc_decrypt_pkcs7(BASE642Bin((String) data.get("password")), _main_panel.getMega_master_pass(), CryptTools.AES_ZERO_IV));
|
||||
|
||||
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException ex) {
|
||||
Logger.getLogger(SettingsDialog.class.getName()).log(Level.SEVERE, null, ex);
|
||||
@ -330,12 +322,12 @@ public final class SettingsDialog extends javax.swing.JDialog {
|
||||
Logger.getLogger(SettingsDialog.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
|
||||
String[] new_row_data = {(String)pair.getKey(), pass};
|
||||
String[] new_row_data = {(String) pair.getKey(), pass};
|
||||
|
||||
model.addRow(new_row_data);
|
||||
}
|
||||
|
||||
swingReflectionInvoke("setEnabled", remove_account_button, (mega_accounts_table.getRowCount()>0));
|
||||
swingReflectionInvoke("setEnabled", remove_account_button, (mega_accounts_table.getRowCount() > 0));
|
||||
}
|
||||
|
||||
} else {
|
||||
@ -344,14 +336,14 @@ public final class SettingsDialog extends javax.swing.JDialog {
|
||||
|
||||
for (Map.Entry pair : _main_panel.getMega_accounts().entrySet()) {
|
||||
|
||||
HashMap<String,Object> data = (HashMap)pair.getValue();
|
||||
HashMap<String, Object> data = (HashMap) pair.getValue();
|
||||
|
||||
String[] new_row_data = {(String)pair.getKey(), (String)data.get("password")};
|
||||
String[] new_row_data = {(String) pair.getKey(), (String) data.get("password")};
|
||||
|
||||
swingReflectionInvoke("addRow", model, new Object[] {new_row_data});
|
||||
swingReflectionInvoke("addRow", model, new Object[]{new_row_data});
|
||||
}
|
||||
|
||||
swingReflectionInvoke("setEnabled", remove_account_button, (mega_accounts_table.getRowCount()>0));
|
||||
swingReflectionInvoke("setEnabled", remove_account_button, (mega_accounts_table.getRowCount() > 0));
|
||||
}
|
||||
|
||||
_remember_master_pass = true;
|
||||
@ -769,7 +761,6 @@ public final class SettingsDialog extends javax.swing.JDialog {
|
||||
|
||||
private void change_download_dir_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_change_download_dir_buttonActionPerformed
|
||||
|
||||
|
||||
javax.swing.JFileChooser filechooser = new javax.swing.JFileChooser();
|
||||
|
||||
filechooser.setCurrentDirectory(new java.io.File(_download_path));
|
||||
@ -777,7 +768,7 @@ public final class SettingsDialog extends javax.swing.JDialog {
|
||||
filechooser.setFileSelectionMode(javax.swing.JFileChooser.DIRECTORIES_ONLY);
|
||||
filechooser.setAcceptAllFileFilterUsed(false);
|
||||
|
||||
if( filechooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION ) {
|
||||
if (filechooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
|
||||
|
||||
File file = filechooser.getSelectedFile();
|
||||
|
||||
@ -800,22 +791,21 @@ public final class SettingsDialog extends javax.swing.JDialog {
|
||||
_settings_ok = true;
|
||||
|
||||
insertSettingValueInDB("default_down_dir", _download_path);
|
||||
insertSettingValueInDB("default_slots_down", String.valueOf((int)swingReflectionInvokeAndWaitForReturn("getValue", default_slots_down_spinner)));
|
||||
insertSettingValueInDB("default_slots_up", String.valueOf((int)swingReflectionInvokeAndWaitForReturn("getValue", default_slots_up_spinner)));
|
||||
insertSettingValueInDB("use_slots_down", (boolean)swingReflectionInvokeAndWaitForReturn("isSelected", multi_slot_down_checkbox)?"yes":"no");
|
||||
insertSettingValueInDB("use_slots_up", (boolean)swingReflectionInvokeAndWaitForReturn("isSelected", multi_slot_up_checkbox)?"yes":"no");
|
||||
insertSettingValueInDB("max_downloads", String.valueOf((int)swingReflectionInvokeAndWaitForReturn("getValue", max_downloads_spinner)));
|
||||
insertSettingValueInDB("max_uploads", String.valueOf((int)swingReflectionInvokeAndWaitForReturn("getValue", max_uploads_spinner)));
|
||||
insertSettingValueInDB("verify_down_file", (boolean)swingReflectionInvokeAndWaitForReturn("isSelected", verify_file_down_checkbox)?"yes":"no");
|
||||
insertSettingValueInDB("limit_download_speed", (boolean)swingReflectionInvokeAndWaitForReturn("isSelected", limit_download_speed_checkbox)?"yes":"no");
|
||||
insertSettingValueInDB("max_download_speed", String.valueOf((int)swingReflectionInvokeAndWaitForReturn("getValue", max_down_speed_spinner)));
|
||||
insertSettingValueInDB("limit_upload_speed", (boolean)swingReflectionInvokeAndWaitForReturn("isSelected", limit_upload_speed_checkbox)?"yes":"no");
|
||||
insertSettingValueInDB("max_upload_speed", String.valueOf((int)swingReflectionInvokeAndWaitForReturn("getValue", max_up_speed_spinner)));
|
||||
insertSettingValueInDB("default_slots_down", String.valueOf((int) swingReflectionInvokeAndWaitForReturn("getValue", default_slots_down_spinner)));
|
||||
insertSettingValueInDB("default_slots_up", String.valueOf((int) swingReflectionInvokeAndWaitForReturn("getValue", default_slots_up_spinner)));
|
||||
insertSettingValueInDB("use_slots_down", (boolean) swingReflectionInvokeAndWaitForReturn("isSelected", multi_slot_down_checkbox) ? "yes" : "no");
|
||||
insertSettingValueInDB("use_slots_up", (boolean) swingReflectionInvokeAndWaitForReturn("isSelected", multi_slot_up_checkbox) ? "yes" : "no");
|
||||
insertSettingValueInDB("max_downloads", String.valueOf((int) swingReflectionInvokeAndWaitForReturn("getValue", max_downloads_spinner)));
|
||||
insertSettingValueInDB("max_uploads", String.valueOf((int) swingReflectionInvokeAndWaitForReturn("getValue", max_uploads_spinner)));
|
||||
insertSettingValueInDB("verify_down_file", (boolean) swingReflectionInvokeAndWaitForReturn("isSelected", verify_file_down_checkbox) ? "yes" : "no");
|
||||
insertSettingValueInDB("limit_download_speed", (boolean) swingReflectionInvokeAndWaitForReturn("isSelected", limit_download_speed_checkbox) ? "yes" : "no");
|
||||
insertSettingValueInDB("max_download_speed", String.valueOf((int) swingReflectionInvokeAndWaitForReturn("getValue", max_down_speed_spinner)));
|
||||
insertSettingValueInDB("limit_upload_speed", (boolean) swingReflectionInvokeAndWaitForReturn("isSelected", limit_upload_speed_checkbox) ? "yes" : "no");
|
||||
insertSettingValueInDB("max_upload_speed", String.valueOf((int) swingReflectionInvokeAndWaitForReturn("getValue", max_up_speed_spinner)));
|
||||
|
||||
if (mega_accounts_table.isEnabled()) {
|
||||
|
||||
if(mega_accounts_table.isEnabled()) {
|
||||
|
||||
final DefaultTableModel model = (DefaultTableModel)mega_accounts_table.getModel();
|
||||
final DefaultTableModel model = (DefaultTableModel) mega_accounts_table.getModel();
|
||||
|
||||
status.setText("Checking your MEGA accounts, please wait...");
|
||||
|
||||
@ -835,23 +825,23 @@ public final class SettingsDialog extends javax.swing.JDialog {
|
||||
|
||||
final Dialog tthis = this;
|
||||
|
||||
THREAD_POOL.execute(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.getRowCount(); i++) {
|
||||
|
||||
String email = (String)model.getValueAt(i, 0);
|
||||
String email = (String) model.getValueAt(i, 0);
|
||||
|
||||
String pass = (String)model.getValueAt(i, 1);
|
||||
String pass = (String) model.getValueAt(i, 1);
|
||||
|
||||
if(!email.isEmpty() && !pass.isEmpty()) {
|
||||
if (!email.isEmpty() && !pass.isEmpty()) {
|
||||
|
||||
MegaAPI ma;
|
||||
|
||||
if(_main_panel.getMega_accounts().get(email) == null){
|
||||
if (_main_panel.getMega_accounts().get(email) == null) {
|
||||
|
||||
ma = new MegaAPI();
|
||||
|
||||
@ -860,20 +850,20 @@ public final class SettingsDialog extends javax.swing.JDialog {
|
||||
|
||||
_main_panel.getMega_active_accounts().put(email, ma);
|
||||
|
||||
String password=pass, password_aes=Bin2BASE64(i32a2bin(ma.getPassword_aes())), user_hash=ma.getUser_hash();
|
||||
String password = pass, password_aes = Bin2BASE64(i32a2bin(ma.getPassword_aes())), user_hash = ma.getUser_hash();
|
||||
|
||||
if(_main_panel.getMega_master_pass_hash() != null) {
|
||||
if (_main_panel.getMega_master_pass_hash() != null) {
|
||||
|
||||
password =Bin2BASE64(CryptTools.aes_cbc_encrypt_pkcs7(pass.getBytes(), _main_panel.getMega_master_pass(), CryptTools.AES_ZERO_IV));
|
||||
password = Bin2BASE64(CryptTools.aes_cbc_encrypt_pkcs7(pass.getBytes(), _main_panel.getMega_master_pass(), CryptTools.AES_ZERO_IV));
|
||||
|
||||
password_aes =Bin2BASE64(CryptTools.aes_cbc_encrypt_pkcs7(i32a2bin(ma.getPassword_aes()), _main_panel.getMega_master_pass(), CryptTools.AES_ZERO_IV));
|
||||
password_aes = Bin2BASE64(CryptTools.aes_cbc_encrypt_pkcs7(i32a2bin(ma.getPassword_aes()), _main_panel.getMega_master_pass(), CryptTools.AES_ZERO_IV));
|
||||
|
||||
user_hash =Bin2BASE64(CryptTools.aes_cbc_encrypt_pkcs7(BASE642Bin(ma.getUser_hash()), _main_panel.getMega_master_pass(), CryptTools.AES_ZERO_IV));
|
||||
user_hash = Bin2BASE64(CryptTools.aes_cbc_encrypt_pkcs7(BASE642Bin(ma.getUser_hash()), _main_panel.getMega_master_pass(), CryptTools.AES_ZERO_IV));
|
||||
}
|
||||
|
||||
DBTools.insertMegaAccount(email, password, password_aes, user_hash);
|
||||
|
||||
} catch(Exception ex) {
|
||||
} catch (Exception ex) {
|
||||
|
||||
email_error.add(email);
|
||||
getLogger(SettingsDialog.class.getName()).log(Level.SEVERE, null, ex);
|
||||
@ -881,13 +871,13 @@ public final class SettingsDialog extends javax.swing.JDialog {
|
||||
|
||||
} else {
|
||||
|
||||
HashMap<String,Object> mega_account_data = (HashMap)_main_panel.getMega_accounts().get(email);
|
||||
HashMap<String, Object> mega_account_data = (HashMap) _main_panel.getMega_accounts().get(email);
|
||||
|
||||
String password;
|
||||
|
||||
password = (String)mega_account_data.get("password");
|
||||
password = (String) mega_account_data.get("password");
|
||||
|
||||
if(_main_panel.getMega_master_pass() != null) {
|
||||
if (_main_panel.getMega_master_pass() != null) {
|
||||
|
||||
try {
|
||||
|
||||
@ -898,7 +888,7 @@ public final class SettingsDialog extends javax.swing.JDialog {
|
||||
}
|
||||
}
|
||||
|
||||
if(!password.equals(pass)) {
|
||||
if (!password.equals(pass)) {
|
||||
|
||||
ma = new MegaAPI();
|
||||
|
||||
@ -909,11 +899,11 @@ public final class SettingsDialog extends javax.swing.JDialog {
|
||||
|
||||
password = pass;
|
||||
|
||||
String password_aes=Bin2BASE64(i32a2bin(ma.getPassword_aes())), user_hash=ma.getUser_hash();
|
||||
String password_aes = Bin2BASE64(i32a2bin(ma.getPassword_aes())), user_hash = ma.getUser_hash();
|
||||
|
||||
if(_main_panel.getMega_master_pass() != null) {
|
||||
if (_main_panel.getMega_master_pass() != null) {
|
||||
|
||||
password =Bin2BASE64(CryptTools.aes_cbc_encrypt_pkcs7(pass.getBytes(), _main_panel.getMega_master_pass(), CryptTools.AES_ZERO_IV));
|
||||
password = Bin2BASE64(CryptTools.aes_cbc_encrypt_pkcs7(pass.getBytes(), _main_panel.getMega_master_pass(), CryptTools.AES_ZERO_IV));
|
||||
|
||||
password_aes = Bin2BASE64(CryptTools.aes_cbc_encrypt_pkcs7(i32a2bin(ma.getPassword_aes()), _main_panel.getMega_master_pass(), CryptTools.AES_ZERO_IV));
|
||||
|
||||
@ -933,18 +923,18 @@ public final class SettingsDialog extends javax.swing.JDialog {
|
||||
}
|
||||
}
|
||||
|
||||
if(email_error.size() > 0) {
|
||||
if (email_error.size() > 0) {
|
||||
|
||||
String email_error_s = "";
|
||||
|
||||
for(String s:email_error) {
|
||||
for (String s : email_error) {
|
||||
|
||||
email_error_s+=s+"\n";
|
||||
email_error_s += s + "\n";
|
||||
}
|
||||
|
||||
swingReflectionInvoke("setText", status, "");
|
||||
|
||||
JOptionPane.showMessageDialog(tthis, "There were errors with some accounts. Please, check them:\n\n"+email_error_s, "Error", JOptionPane.ERROR_MESSAGE);
|
||||
JOptionPane.showMessageDialog(tthis, "There were errors with some accounts. Please, check them:\n\n" + email_error_s, "Error", JOptionPane.ERROR_MESSAGE);
|
||||
|
||||
swingReflectionInvoke("setEnabled", ok_button, true);
|
||||
|
||||
@ -971,7 +961,6 @@ public final class SettingsDialog extends javax.swing.JDialog {
|
||||
this.setVisible(false);
|
||||
}
|
||||
|
||||
|
||||
} catch (SQLException ex) {
|
||||
getLogger(SettingsDialog.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
@ -979,7 +968,7 @@ public final class SettingsDialog extends javax.swing.JDialog {
|
||||
|
||||
private void multi_slot_down_checkboxStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_multi_slot_down_checkboxStateChanged
|
||||
|
||||
if(!multi_slot_down_checkbox.isSelected()) {
|
||||
if (!multi_slot_down_checkbox.isSelected()) {
|
||||
|
||||
default_slots_down_spinner.setEnabled(false);
|
||||
default_slots_down_label.setEnabled(false);
|
||||
@ -993,13 +982,13 @@ public final class SettingsDialog extends javax.swing.JDialog {
|
||||
|
||||
private void remove_account_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_remove_account_buttonActionPerformed
|
||||
|
||||
DefaultTableModel model = (DefaultTableModel)mega_accounts_table.getModel();
|
||||
DefaultTableModel model = (DefaultTableModel) mega_accounts_table.getModel();
|
||||
|
||||
int selected = mega_accounts_table.getSelectedRow();
|
||||
|
||||
while(selected >= 0) {
|
||||
while (selected >= 0) {
|
||||
|
||||
String email = (String)model.getValueAt(mega_accounts_table.convertRowIndexToModel(selected),0);
|
||||
String email = (String) model.getValueAt(mega_accounts_table.convertRowIndexToModel(selected), 0);
|
||||
|
||||
_deleted_accounts.add(email);
|
||||
|
||||
@ -1010,7 +999,7 @@ public final class SettingsDialog extends javax.swing.JDialog {
|
||||
|
||||
mega_accounts_table.clearSelection();
|
||||
|
||||
if(model.getRowCount() == 0) {
|
||||
if (model.getRowCount() == 0) {
|
||||
|
||||
remove_account_button.setEnabled(false);
|
||||
}
|
||||
@ -1018,9 +1007,9 @@ public final class SettingsDialog extends javax.swing.JDialog {
|
||||
|
||||
private void add_account_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_add_account_buttonActionPerformed
|
||||
|
||||
DefaultTableModel model = (DefaultTableModel)mega_accounts_table.getModel();
|
||||
DefaultTableModel model = (DefaultTableModel) mega_accounts_table.getModel();
|
||||
|
||||
model.addRow(new Object[]{"",""});
|
||||
model.addRow(new Object[]{"", ""});
|
||||
|
||||
mega_accounts_table.clearSelection();
|
||||
|
||||
@ -1029,7 +1018,7 @@ public final class SettingsDialog extends javax.swing.JDialog {
|
||||
|
||||
private void multi_slot_up_checkboxStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_multi_slot_up_checkboxStateChanged
|
||||
|
||||
if(!multi_slot_up_checkbox.isSelected()) {
|
||||
if (!multi_slot_up_checkbox.isSelected()) {
|
||||
|
||||
defaut_slots_up_label.setEnabled(false);
|
||||
default_slots_up_spinner.setEnabled(false);
|
||||
@ -1042,9 +1031,7 @@ public final class SettingsDialog extends javax.swing.JDialog {
|
||||
|
||||
private void limit_download_speed_checkboxStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_limit_download_speed_checkboxStateChanged
|
||||
|
||||
|
||||
if(!limit_download_speed_checkbox.isSelected()) {
|
||||
|
||||
if (!limit_download_speed_checkbox.isSelected()) {
|
||||
|
||||
max_down_speed_label.setEnabled(false);
|
||||
max_down_speed_spinner.setEnabled(false);
|
||||
@ -1056,8 +1043,7 @@ public final class SettingsDialog extends javax.swing.JDialog {
|
||||
|
||||
private void limit_upload_speed_checkboxStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_limit_upload_speed_checkboxStateChanged
|
||||
|
||||
|
||||
if(!limit_upload_speed_checkbox.isSelected()) {
|
||||
if (!limit_upload_speed_checkbox.isSelected()) {
|
||||
|
||||
max_up_speed_label.setEnabled(false);
|
||||
max_up_speed_spinner.setEnabled(false);
|
||||
@ -1074,11 +1060,11 @@ public final class SettingsDialog extends javax.swing.JDialog {
|
||||
|
||||
final Dialog tthis = this;
|
||||
|
||||
THREAD_POOL.execute(new Runnable(){
|
||||
THREAD_POOL.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
SetMegaMasterPasswordDialog dialog = new SetMegaMasterPasswordDialog((Frame)getParent(),true, _main_panel.getMega_master_pass_salt());
|
||||
SetMegaMasterPasswordDialog dialog = new SetMegaMasterPasswordDialog((Frame) getParent(), true, _main_panel.getMega_master_pass_salt());
|
||||
|
||||
swingReflectionInvokeAndWait("setLocationRelativeTo", dialog, tthis);
|
||||
|
||||
@ -1086,7 +1072,7 @@ public final class SettingsDialog extends javax.swing.JDialog {
|
||||
|
||||
byte[] old_mega_master_pass = null;
|
||||
|
||||
if(_main_panel.getMega_master_pass() != null) {
|
||||
if (_main_panel.getMega_master_pass() != null) {
|
||||
|
||||
old_mega_master_pass = new byte[_main_panel.getMega_master_pass().length];
|
||||
|
||||
@ -1095,11 +1081,11 @@ public final class SettingsDialog extends javax.swing.JDialog {
|
||||
|
||||
String old_mega_master_pass_hash = _main_panel.getMega_master_pass_hash();
|
||||
|
||||
if(dialog.isPass_ok()) {
|
||||
if (dialog.isPass_ok()) {
|
||||
|
||||
try {
|
||||
|
||||
if(dialog.getNew_pass() != null && dialog.getNew_pass().length > 0) {
|
||||
if (dialog.getNew_pass() != null && dialog.getNew_pass().length > 0) {
|
||||
|
||||
_main_panel.setMega_master_pass_hash(dialog.getNew_pass_hash());
|
||||
|
||||
@ -1118,36 +1104,36 @@ public final class SettingsDialog extends javax.swing.JDialog {
|
||||
|
||||
for (Map.Entry pair : _main_panel.getMega_accounts().entrySet()) {
|
||||
|
||||
HashMap<String,Object> data = (HashMap)pair.getValue();
|
||||
HashMap<String, Object> data = (HashMap) pair.getValue();
|
||||
|
||||
String email, password, password_aes, user_hash;
|
||||
|
||||
email = (String)pair.getKey();
|
||||
email = (String) pair.getKey();
|
||||
|
||||
if(old_mega_master_pass_hash != null) {
|
||||
if (old_mega_master_pass_hash != null) {
|
||||
|
||||
password = new String(CryptTools.aes_cbc_decrypt_pkcs7(BASE642Bin((String)data.get("password")) , old_mega_master_pass, CryptTools.AES_ZERO_IV));
|
||||
password = new String(CryptTools.aes_cbc_decrypt_pkcs7(BASE642Bin((String) data.get("password")), old_mega_master_pass, CryptTools.AES_ZERO_IV));
|
||||
|
||||
password_aes =Bin2BASE64(CryptTools.aes_cbc_decrypt_pkcs7(BASE642Bin((String)data.get("password_aes")), old_mega_master_pass, CryptTools.AES_ZERO_IV));
|
||||
password_aes = Bin2BASE64(CryptTools.aes_cbc_decrypt_pkcs7(BASE642Bin((String) data.get("password_aes")), old_mega_master_pass, CryptTools.AES_ZERO_IV));
|
||||
|
||||
user_hash =Bin2BASE64(CryptTools.aes_cbc_decrypt_pkcs7(BASE642Bin((String)data.get("user_hash")), old_mega_master_pass, CryptTools.AES_ZERO_IV));
|
||||
user_hash = Bin2BASE64(CryptTools.aes_cbc_decrypt_pkcs7(BASE642Bin((String) data.get("user_hash")), old_mega_master_pass, CryptTools.AES_ZERO_IV));
|
||||
|
||||
} else {
|
||||
|
||||
password = (String)data.get("password");
|
||||
password = (String) data.get("password");
|
||||
|
||||
password_aes = (String)data.get("password_aes");
|
||||
password_aes = (String) data.get("password_aes");
|
||||
|
||||
user_hash = (String)data.get("user_hash");
|
||||
user_hash = (String) data.get("user_hash");
|
||||
}
|
||||
|
||||
if(_main_panel.getMega_master_pass() != null) {
|
||||
if (_main_panel.getMega_master_pass() != null) {
|
||||
|
||||
password =Bin2BASE64(CryptTools.aes_cbc_encrypt_pkcs7(password.getBytes(), _main_panel.getMega_master_pass(), CryptTools.AES_ZERO_IV));
|
||||
password = Bin2BASE64(CryptTools.aes_cbc_encrypt_pkcs7(password.getBytes(), _main_panel.getMega_master_pass(), CryptTools.AES_ZERO_IV));
|
||||
|
||||
password_aes =Bin2BASE64(CryptTools.aes_cbc_encrypt_pkcs7(BASE642Bin(password_aes), _main_panel.getMega_master_pass(), CryptTools.AES_ZERO_IV));
|
||||
password_aes = Bin2BASE64(CryptTools.aes_cbc_encrypt_pkcs7(BASE642Bin(password_aes), _main_panel.getMega_master_pass(), CryptTools.AES_ZERO_IV));
|
||||
|
||||
user_hash =Bin2BASE64(CryptTools.aes_cbc_encrypt_pkcs7(BASE642Bin(user_hash), _main_panel.getMega_master_pass(), CryptTools.AES_ZERO_IV));
|
||||
user_hash = Bin2BASE64(CryptTools.aes_cbc_encrypt_pkcs7(BASE642Bin(user_hash), _main_panel.getMega_master_pass(), CryptTools.AES_ZERO_IV));
|
||||
}
|
||||
|
||||
data.put("password", password);
|
||||
@ -1171,7 +1157,8 @@ public final class SettingsDialog extends javax.swing.JDialog {
|
||||
|
||||
swingReflectionInvoke("setEnabled", encrypt_pass_checkbox, true);
|
||||
|
||||
}});
|
||||
}
|
||||
});
|
||||
|
||||
}//GEN-LAST:event_encrypt_pass_checkboxActionPerformed
|
||||
|
||||
@ -1181,23 +1168,23 @@ public final class SettingsDialog extends javax.swing.JDialog {
|
||||
|
||||
final Dialog tthis = this;
|
||||
|
||||
THREAD_POOL.execute(new Runnable(){
|
||||
THREAD_POOL.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
GetMegaMasterPasswordDialog dialog = new GetMegaMasterPasswordDialog((Frame)getParent(),true, _main_panel.getMega_master_pass_hash(), _main_panel.getMega_master_pass_salt());
|
||||
GetMegaMasterPasswordDialog dialog = new GetMegaMasterPasswordDialog((Frame) getParent(), true, _main_panel.getMega_master_pass_hash(), _main_panel.getMega_master_pass_salt());
|
||||
|
||||
swingReflectionInvokeAndWait("setLocationRelativeTo", dialog, tthis);
|
||||
|
||||
swingReflectionInvokeAndWait("setVisible", dialog, true);
|
||||
|
||||
if(dialog.isPass_ok()) {
|
||||
if (dialog.isPass_ok()) {
|
||||
|
||||
_main_panel.setMega_master_pass(dialog.getPass());
|
||||
|
||||
dialog.deletePass();
|
||||
|
||||
DefaultTableModel model = new DefaultTableModel(new Object [][] {},new String [] {"Email", "Password"});
|
||||
DefaultTableModel model = new DefaultTableModel(new Object[][]{}, new String[]{"Email", "Password"});
|
||||
|
||||
swingReflectionInvokeAndWait("setModel", mega_accounts_table, model);
|
||||
|
||||
@ -1215,13 +1202,13 @@ public final class SettingsDialog extends javax.swing.JDialog {
|
||||
|
||||
for (Map.Entry pair : _main_panel.getMega_accounts().entrySet()) {
|
||||
|
||||
HashMap<String,Object> data = (HashMap)pair.getValue();
|
||||
HashMap<String, Object> data = (HashMap) pair.getValue();
|
||||
|
||||
String pass = null;
|
||||
|
||||
try {
|
||||
|
||||
pass = new String(CryptTools.aes_cbc_decrypt_pkcs7(BASE642Bin((String)data.get("password")), _main_panel.getMega_master_pass(), CryptTools.AES_ZERO_IV));
|
||||
pass = new String(CryptTools.aes_cbc_decrypt_pkcs7(BASE642Bin((String) data.get("password")), _main_panel.getMega_master_pass(), CryptTools.AES_ZERO_IV));
|
||||
|
||||
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException ex) {
|
||||
Logger.getLogger(SettingsDialog.class.getName()).log(Level.SEVERE, null, ex);
|
||||
@ -1229,7 +1216,7 @@ public final class SettingsDialog extends javax.swing.JDialog {
|
||||
Logger.getLogger(SettingsDialog.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
|
||||
String[] new_row_data = {(String)pair.getKey(), pass};
|
||||
String[] new_row_data = {(String) pair.getKey(), pass};
|
||||
|
||||
model.addRow(new_row_data);
|
||||
}
|
||||
@ -1242,7 +1229,8 @@ public final class SettingsDialog extends javax.swing.JDialog {
|
||||
|
||||
swingReflectionInvoke("setEnabled", unlock_accounts_button, true);
|
||||
|
||||
}});
|
||||
}
|
||||
});
|
||||
|
||||
}//GEN-LAST:event_unlock_accounts_buttonActionPerformed
|
||||
|
||||
@ -1258,7 +1246,7 @@ public final class SettingsDialog extends javax.swing.JDialog {
|
||||
options,
|
||||
options[0]);
|
||||
|
||||
if(n == 1) {
|
||||
if (n == 1) {
|
||||
|
||||
try {
|
||||
encrypt_pass_checkbox.setEnabled(true);
|
||||
@ -1273,7 +1261,7 @@ public final class SettingsDialog extends javax.swing.JDialog {
|
||||
|
||||
delete_all_accounts_button.setVisible(true);
|
||||
|
||||
DefaultTableModel new_model = new DefaultTableModel(new Object [][] {},new String [] {"Email", "Password"});
|
||||
DefaultTableModel new_model = new DefaultTableModel(new Object[][]{}, new String[]{"Email", "Password"});
|
||||
|
||||
mega_accounts_table.setModel(new_model);
|
||||
|
||||
|
@ -5,8 +5,8 @@ import java.util.logging.Level;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static megabasterd.MiscTools.formatBytes;
|
||||
|
||||
public final class SpeedMeter implements Runnable, SecureNotifiable
|
||||
{
|
||||
public final class SpeedMeter implements Runnable, SecureNotifiable {
|
||||
|
||||
public static final int SLEEP = 3000;
|
||||
private long _progress;
|
||||
private final Transference _transference;
|
||||
@ -16,22 +16,19 @@ public final class SpeedMeter implements Runnable, SecureNotifiable
|
||||
private final Object _secure_notify_lock;
|
||||
private boolean _notified;
|
||||
|
||||
|
||||
SpeedMeter(Transference transference, GlobalSpeedMeter gspeed)
|
||||
{
|
||||
SpeedMeter(Transference transference, GlobalSpeedMeter gspeed) {
|
||||
_notified = false;
|
||||
_secure_notify_lock = new Object();
|
||||
_transference = transference;
|
||||
_progress = transference.getProgress();
|
||||
_lastSpeed=0;
|
||||
_lastSpeed = 0;
|
||||
_gspeed = gspeed;
|
||||
_exit=false;
|
||||
_exit = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void secureNotify()
|
||||
{
|
||||
synchronized(_secure_notify_lock) {
|
||||
public void secureNotify() {
|
||||
synchronized (_secure_notify_lock) {
|
||||
|
||||
_notified = true;
|
||||
|
||||
@ -42,9 +39,8 @@ public final class SpeedMeter implements Runnable, SecureNotifiable
|
||||
@Override
|
||||
public void secureWait() {
|
||||
|
||||
synchronized(_secure_notify_lock)
|
||||
{
|
||||
while(!_notified) {
|
||||
synchronized (_secure_notify_lock) {
|
||||
while (!_notified) {
|
||||
|
||||
try {
|
||||
_secure_notify_lock.wait();
|
||||
@ -60,7 +56,7 @@ public final class SpeedMeter implements Runnable, SecureNotifiable
|
||||
@Override
|
||||
public void secureNotifyAll() {
|
||||
|
||||
synchronized(_secure_notify_lock) {
|
||||
synchronized (_secure_notify_lock) {
|
||||
|
||||
_notified = true;
|
||||
|
||||
@ -68,18 +64,15 @@ public final class SpeedMeter implements Runnable, SecureNotifiable
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setExit(boolean exit) {
|
||||
_exit = exit;
|
||||
}
|
||||
|
||||
public long getLastSpeed()
|
||||
{
|
||||
public long getLastSpeed() {
|
||||
return _lastSpeed;
|
||||
}
|
||||
|
||||
public void setLastSpeed(long speed)
|
||||
{
|
||||
public void setLastSpeed(long speed) {
|
||||
_lastSpeed = speed;
|
||||
}
|
||||
|
||||
@ -89,29 +82,25 @@ public final class SpeedMeter implements Runnable, SecureNotifiable
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
public void run() {
|
||||
System.out.println("SpeedMeter hello!");
|
||||
|
||||
long last_progress=_progress, sp;
|
||||
long last_progress = _progress, sp;
|
||||
int no_data_count;
|
||||
|
||||
_transference.getView().updateSpeed("------", true);
|
||||
_transference.getView().updateRemainingTime("--d --:--:--", true);
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
no_data_count = 0;
|
||||
|
||||
while(!_exit)
|
||||
{
|
||||
Thread.sleep(SpeedMeter.SLEEP*(no_data_count+1));
|
||||
while (!_exit) {
|
||||
Thread.sleep(SpeedMeter.SLEEP * (no_data_count + 1));
|
||||
|
||||
if(!_exit)
|
||||
{
|
||||
if (!_exit) {
|
||||
updateProgress();
|
||||
|
||||
if(_transference.isPaused()) {
|
||||
if (_transference.isPaused()) {
|
||||
|
||||
_transference.getView().updateSpeed("------", true);
|
||||
|
||||
@ -123,9 +112,9 @@ public final class SpeedMeter implements Runnable, SecureNotifiable
|
||||
|
||||
secureWait();
|
||||
|
||||
} else if( _progress > last_progress) {
|
||||
} else if (_progress > last_progress) {
|
||||
|
||||
double sleep_time = ((double)SpeedMeter.SLEEP*(no_data_count+1))/1000 ;
|
||||
double sleep_time = ((double) SpeedMeter.SLEEP * (no_data_count + 1)) / 1000;
|
||||
|
||||
double current_speed = (_progress - last_progress) / sleep_time;
|
||||
|
||||
@ -133,18 +122,18 @@ public final class SpeedMeter implements Runnable, SecureNotifiable
|
||||
|
||||
sp = Math.round(current_speed);
|
||||
|
||||
if(sp > 0) {
|
||||
if (sp > 0) {
|
||||
|
||||
_transference.getView().updateSpeed(formatBytes(sp)+"/s", true);
|
||||
_transference.getView().updateSpeed(formatBytes(sp) + "/s", true);
|
||||
|
||||
_transference.getView().updateRemainingTime(calculateRemTime((long)Math.floor((_transference.getFile_size()-_progress)/sp ) ), true);
|
||||
_transference.getView().updateRemainingTime(calculateRemTime((long) Math.floor((_transference.getFile_size() - _progress) / sp)), true);
|
||||
|
||||
setLastSpeed(sp);
|
||||
|
||||
_gspeed.secureNotify();
|
||||
}
|
||||
|
||||
no_data_count=0;
|
||||
no_data_count = 0;
|
||||
|
||||
} else {
|
||||
|
||||
@ -160,29 +149,26 @@ public final class SpeedMeter implements Runnable, SecureNotifiable
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (InterruptedException ex)
|
||||
{
|
||||
} catch (InterruptedException ex) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private String calculateRemTime(long seconds)
|
||||
{
|
||||
private String calculateRemTime(long seconds) {
|
||||
int days = (int) TimeUnit.SECONDS.toDays(seconds);
|
||||
|
||||
long hours = TimeUnit.SECONDS.toHours(seconds) -
|
||||
TimeUnit.DAYS.toHours(days);
|
||||
long hours = TimeUnit.SECONDS.toHours(seconds)
|
||||
- TimeUnit.DAYS.toHours(days);
|
||||
|
||||
long minutes = TimeUnit.SECONDS.toMinutes(seconds) -
|
||||
TimeUnit.DAYS.toMinutes(days) -
|
||||
TimeUnit.HOURS.toMinutes(hours);
|
||||
long minutes = TimeUnit.SECONDS.toMinutes(seconds)
|
||||
- TimeUnit.DAYS.toMinutes(days)
|
||||
- TimeUnit.HOURS.toMinutes(hours);
|
||||
|
||||
long secs = TimeUnit.SECONDS.toSeconds(seconds) -
|
||||
TimeUnit.DAYS.toSeconds(days) -
|
||||
TimeUnit.HOURS.toSeconds(hours) -
|
||||
TimeUnit.MINUTES.toSeconds(minutes);
|
||||
long secs = TimeUnit.SECONDS.toSeconds(seconds)
|
||||
- TimeUnit.DAYS.toSeconds(days)
|
||||
- TimeUnit.HOURS.toSeconds(hours)
|
||||
- TimeUnit.MINUTES.toSeconds(minutes);
|
||||
|
||||
return String.format("%dd %d:%02d:%02d", days, hours, minutes, secs);
|
||||
}
|
||||
|
@ -12,24 +12,27 @@ import static java.util.logging.Logger.getLogger;
|
||||
*/
|
||||
public final class SqliteSingleton {
|
||||
|
||||
public static final String SQLITE_FILE="megabasterd.db";
|
||||
public static final String SQLITE_FILE = "megabasterd.db";
|
||||
|
||||
public static SqliteSingleton getInstance() {
|
||||
|
||||
return LazyHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private SqliteSingleton() {}
|
||||
private SqliteSingleton() {
|
||||
}
|
||||
|
||||
public Connection getConn() {
|
||||
|
||||
Connection conn=null;
|
||||
Connection conn = null;
|
||||
|
||||
try {
|
||||
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
|
||||
conn = DriverManager.getConnection("jdbc:sqlite:"+SQLITE_FILE);
|
||||
conn = DriverManager.getConnection("jdbc:sqlite:" + SQLITE_FILE);
|
||||
|
||||
}catch(ClassNotFoundException | SQLException ex) {
|
||||
} catch (ClassNotFoundException | SQLException ex) {
|
||||
getLogger(SqliteSingleton.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
|
||||
|
@ -64,11 +64,9 @@ public final class StreamThrottlerSupervisor implements Runnable, SecureNotifiab
|
||||
return _output_slice_queue;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void secureNotify()
|
||||
{
|
||||
synchronized(_secure_notify_lock) {
|
||||
public void secureNotify() {
|
||||
synchronized (_secure_notify_lock) {
|
||||
|
||||
_notified = true;
|
||||
|
||||
@ -79,9 +77,8 @@ public final class StreamThrottlerSupervisor implements Runnable, SecureNotifiab
|
||||
@Override
|
||||
public void secureWait() {
|
||||
|
||||
synchronized(_secure_notify_lock)
|
||||
{
|
||||
while(!_notified) {
|
||||
synchronized (_secure_notify_lock) {
|
||||
while (!_notified) {
|
||||
|
||||
try {
|
||||
_secure_notify_lock.wait();
|
||||
@ -97,7 +94,7 @@ public final class StreamThrottlerSupervisor implements Runnable, SecureNotifiab
|
||||
@Override
|
||||
public void secureNotifyAll() {
|
||||
|
||||
synchronized(_secure_notify_lock) {
|
||||
synchronized (_secure_notify_lock) {
|
||||
|
||||
_notified = true;
|
||||
|
||||
@ -108,37 +105,35 @@ public final class StreamThrottlerSupervisor implements Runnable, SecureNotifiab
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
while(true) {
|
||||
while (true) {
|
||||
|
||||
if(_maxBytesPerSecInput > 0) {
|
||||
if (_maxBytesPerSecInput > 0) {
|
||||
|
||||
_input_slice_queue.clear();
|
||||
|
||||
int slice_num = (int)Math.floor((double)_maxBytesPerSecInput / _slice_size);
|
||||
int slice_num = (int) Math.floor((double) _maxBytesPerSecInput / _slice_size);
|
||||
|
||||
for(int i=0; i<slice_num; i++)
|
||||
{
|
||||
for (int i = 0; i < slice_num; i++) {
|
||||
_input_slice_queue.add(_slice_size);
|
||||
}
|
||||
|
||||
if(_maxBytesPerSecInput % _slice_size != 0) {
|
||||
if (_maxBytesPerSecInput % _slice_size != 0) {
|
||||
|
||||
_input_slice_queue.add(_maxBytesPerSecInput % _slice_size);
|
||||
}
|
||||
}
|
||||
|
||||
if(_maxBytesPerSecOutput > 0) {
|
||||
if (_maxBytesPerSecOutput > 0) {
|
||||
|
||||
_output_slice_queue.clear();
|
||||
|
||||
int slice_num = (int)Math.floor((double)_maxBytesPerSecOutput / _slice_size);
|
||||
int slice_num = (int) Math.floor((double) _maxBytesPerSecOutput / _slice_size);
|
||||
|
||||
for(int i=0; i<slice_num; i++)
|
||||
{
|
||||
for (int i = 0; i < slice_num; i++) {
|
||||
_output_slice_queue.add(_slice_size);
|
||||
}
|
||||
|
||||
if(_maxBytesPerSecOutput % _slice_size != 0) {
|
||||
if (_maxBytesPerSecOutput % _slice_size != 0) {
|
||||
|
||||
_output_slice_queue.add(_maxBytesPerSecOutput % _slice_size);
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ import static java.util.logging.Logger.getLogger;
|
||||
import javax.swing.JOptionPane;
|
||||
import static megabasterd.MainPanel.FONT_DEFAULT;
|
||||
import static megabasterd.MainPanel.THREAD_POOL;
|
||||
import static megabasterd.MiscTools.copyTextToClipboard;
|
||||
import static megabasterd.MiscTools.deflateURL;
|
||||
import static megabasterd.MiscTools.extractFirstMegaLinkFromString;
|
||||
import static megabasterd.MiscTools.extractStringFromClipboardContents;
|
||||
@ -30,6 +29,7 @@ public final class StreamerDialog extends javax.swing.JDialog implements Clipboa
|
||||
|
||||
/**
|
||||
* Creates new form Streamer
|
||||
*
|
||||
* @param clipboardspy
|
||||
*/
|
||||
public StreamerDialog(java.awt.Frame parent, boolean modal, ClipboardSpy clipboardspy) {
|
||||
@ -38,14 +38,15 @@ public final class StreamerDialog extends javax.swing.JDialog implements Clipboa
|
||||
|
||||
_clipboardspy = clipboardspy;
|
||||
|
||||
MiscTools.swingInvokeIt(new Runnable(){
|
||||
MiscTools.swingInvokeIt(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {updateFont(put_label, FONT_DEFAULT, Font.PLAIN);
|
||||
|
||||
updateFont(dance_button, FONT_DEFAULT, Font.PLAIN);}}, true);
|
||||
|
||||
public void run() {
|
||||
updateFont(put_label, FONT_DEFAULT, Font.PLAIN);
|
||||
|
||||
updateFont(dance_button, FONT_DEFAULT, Font.PLAIN);
|
||||
}
|
||||
}, true);
|
||||
|
||||
notifyClipboardChange();
|
||||
}
|
||||
@ -126,17 +127,17 @@ public final class StreamerDialog extends javax.swing.JDialog implements Clipboa
|
||||
|
||||
final Dialog tthis = this;
|
||||
|
||||
THREAD_POOL.execute(new Runnable(){
|
||||
THREAD_POOL.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
boolean error=false;
|
||||
boolean error = false;
|
||||
|
||||
String stream_link=null;
|
||||
String stream_link = null;
|
||||
|
||||
String link=((String)swingReflectionInvokeAndWaitForReturn("getText", original_link_textfield)).trim();
|
||||
String link = ((String) swingReflectionInvokeAndWaitForReturn("getText", original_link_textfield)).trim();
|
||||
|
||||
if(link.length() > 0) {
|
||||
if (link.length() > 0) {
|
||||
|
||||
try {
|
||||
|
||||
@ -148,17 +149,16 @@ public final class StreamerDialog extends javax.swing.JDialog implements Clipboa
|
||||
|
||||
String data;
|
||||
|
||||
link=link.replace("/#!N?", "/#N!");
|
||||
link = link.replace("/#!N?", "/#N!");
|
||||
|
||||
if( findFirstRegex("://mega(\\.co)?\\.nz/#[^fF]", link, 0) != null)
|
||||
{
|
||||
data=findFirstRegex("/#(N?!.+)", link, 1);
|
||||
if (findFirstRegex("://mega(\\.co)?\\.nz/#[^fF]", link, 0) != null) {
|
||||
data = findFirstRegex("/#(N?!.+)", link, 1);
|
||||
|
||||
stream_link = "http://localhost:1337/video/mega/"+data;
|
||||
stream_link = "http://localhost:1337/video/mega/" + data;
|
||||
|
||||
} else if( (data=findFirstRegex("https?://([^/]+/![^!]+![0-9a-fA-F]+)", link, 1)) != null) {
|
||||
} else if ((data = findFirstRegex("https?://([^/]+/![^!]+![0-9a-fA-F]+)", link, 1)) != null) {
|
||||
|
||||
stream_link = "http://localhost:1337/video/"+data;
|
||||
stream_link = "http://localhost:1337/video/" + data;
|
||||
|
||||
} else {
|
||||
|
||||
@ -170,7 +170,7 @@ public final class StreamerDialog extends javax.swing.JDialog implements Clipboa
|
||||
error = true;
|
||||
}
|
||||
|
||||
if(error) {
|
||||
if (error) {
|
||||
|
||||
JOptionPane.showMessageDialog(tthis, "Please, paste a mega/megacrypter link!", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
|
||||
@ -184,7 +184,7 @@ public final class StreamerDialog extends javax.swing.JDialog implements Clipboa
|
||||
|
||||
try {
|
||||
|
||||
copyTextToClipboard(deflateURL(stream_link));
|
||||
MiscTools.copyTextToClipboard(deflateURL(stream_link));
|
||||
|
||||
JOptionPane.showMessageDialog(tthis, "Streaming link was copied to clipboard!\n(Remember to keep MegaBasterd running in background while playing)");
|
||||
|
||||
@ -197,7 +197,8 @@ public final class StreamerDialog extends javax.swing.JDialog implements Clipboa
|
||||
}
|
||||
}
|
||||
|
||||
}});
|
||||
}
|
||||
});
|
||||
}//GEN-LAST:event_dance_buttonActionPerformed
|
||||
|
||||
@Override
|
||||
@ -205,17 +206,16 @@ public final class StreamerDialog extends javax.swing.JDialog implements Clipboa
|
||||
|
||||
String link = extractFirstMegaLinkFromString(extractStringFromClipboardContents(_clipboardspy.getContents()));
|
||||
|
||||
if(!link.contains("/#F!")) {
|
||||
if (!link.contains("/#F!")) {
|
||||
|
||||
swingReflectionInvoke("setText", original_link_textfield, link);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JButton dance_button;
|
||||
private javax.swing.JTextField original_link_textfield;
|
||||
private javax.swing.JLabel put_label;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,6 @@ public final class ThrottledInputStream extends InputStream {
|
||||
|
||||
private boolean _stream_finish;
|
||||
|
||||
|
||||
public ThrottledInputStream(InputStream rawStream, StreamThrottlerSupervisor stream_supervisor) {
|
||||
|
||||
_rawStream = rawStream;
|
||||
@ -29,23 +28,22 @@ public final class ThrottledInputStream extends InputStream {
|
||||
_slice_size = null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
|
||||
if(_stream_supervisor.getMaxBytesPerSecInput() > 0) {
|
||||
if (_stream_supervisor.getMaxBytesPerSecInput() > 0) {
|
||||
|
||||
if(!_stream_finish) {
|
||||
if (!_stream_finish) {
|
||||
|
||||
int r;
|
||||
|
||||
throttle(1);
|
||||
|
||||
if(_slice_size != null) {
|
||||
if (_slice_size != null) {
|
||||
|
||||
r = _rawStream.read();
|
||||
|
||||
if(r == -1) {
|
||||
if (r == -1) {
|
||||
|
||||
_stream_finish = true;
|
||||
}
|
||||
@ -69,46 +67,45 @@ public final class ThrottledInputStream extends InputStream {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int read(byte[] b) throws IOException {
|
||||
|
||||
if(_stream_supervisor.getMaxBytesPerSecInput() > 0) {
|
||||
if (_stream_supervisor.getMaxBytesPerSecInput() > 0) {
|
||||
|
||||
if(!_stream_finish) {
|
||||
if (!_stream_finish) {
|
||||
|
||||
int readLen = 0, readSlice, len=b.length, r=0;
|
||||
int readLen = 0, readSlice, len = b.length, r = 0;
|
||||
|
||||
do {
|
||||
|
||||
throttle(len - readLen);
|
||||
|
||||
if(_slice_size != null) {
|
||||
if (_slice_size != null) {
|
||||
|
||||
readSlice=0;
|
||||
readSlice = 0;
|
||||
|
||||
do{
|
||||
r = _rawStream.read(b, readLen+readSlice, _slice_size-readSlice );
|
||||
do {
|
||||
r = _rawStream.read(b, readLen + readSlice, _slice_size - readSlice);
|
||||
|
||||
if(r!=-1){
|
||||
if (r != -1) {
|
||||
|
||||
readSlice+=r;
|
||||
readSlice += r;
|
||||
|
||||
} else {
|
||||
|
||||
_stream_finish = true;
|
||||
}
|
||||
|
||||
}while(r != -1 && readSlice < _slice_size);
|
||||
} while (r != -1 && readSlice < _slice_size);
|
||||
|
||||
readLen+=readSlice;
|
||||
readLen += readSlice;
|
||||
|
||||
} else {
|
||||
|
||||
return _rawStream.read(b);
|
||||
}
|
||||
|
||||
}while( r != -1 && readLen < len );
|
||||
} while (r != -1 && readLen < len);
|
||||
|
||||
return readLen;
|
||||
|
||||
@ -123,47 +120,46 @@ public final class ThrottledInputStream extends InputStream {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int read(byte[] b, int off, int len) throws IOException {
|
||||
|
||||
if(_stream_supervisor.getMaxBytesPerSecInput() > 0) {
|
||||
if (_stream_supervisor.getMaxBytesPerSecInput() > 0) {
|
||||
|
||||
if(!_stream_finish) {
|
||||
if (!_stream_finish) {
|
||||
|
||||
int readLen = 0, r=0;
|
||||
int readLen = 0, r = 0;
|
||||
|
||||
do {
|
||||
|
||||
throttle(len-readLen);
|
||||
throttle(len - readLen);
|
||||
|
||||
if(_slice_size != null) {
|
||||
if (_slice_size != null) {
|
||||
|
||||
int readSlice=0;
|
||||
int readSlice = 0;
|
||||
|
||||
do{
|
||||
r = _rawStream.read(b, off+readSlice+readLen, _slice_size - readSlice);
|
||||
do {
|
||||
r = _rawStream.read(b, off + readSlice + readLen, _slice_size - readSlice);
|
||||
|
||||
if(r!=-1){
|
||||
if (r != -1) {
|
||||
|
||||
readSlice+=r;
|
||||
readSlice += r;
|
||||
|
||||
} else {
|
||||
|
||||
_stream_finish = true;
|
||||
}
|
||||
|
||||
}while(r!=-1 && readSlice<_slice_size);
|
||||
} while (r != -1 && readSlice < _slice_size);
|
||||
|
||||
readLen+=readSlice;
|
||||
readLen += readSlice;
|
||||
|
||||
} else {
|
||||
|
||||
r = _rawStream.read(b, off+readLen, len-readLen);
|
||||
r = _rawStream.read(b, off + readLen, len - readLen);
|
||||
|
||||
if(r!=-1){
|
||||
if (r != -1) {
|
||||
|
||||
readLen+=r;
|
||||
readLen += r;
|
||||
|
||||
} else {
|
||||
|
||||
@ -171,7 +167,7 @@ public final class ThrottledInputStream extends InputStream {
|
||||
}
|
||||
}
|
||||
|
||||
}while( r!=-1 && readLen < len );
|
||||
} while (r != -1 && readLen < len);
|
||||
|
||||
return readLen;
|
||||
|
||||
@ -187,7 +183,6 @@ public final class ThrottledInputStream extends InputStream {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void reset() throws IOException {
|
||||
|
||||
@ -197,17 +192,16 @@ public final class ThrottledInputStream extends InputStream {
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void throttle(int size) throws IOException {
|
||||
|
||||
_slice_size = null;
|
||||
|
||||
while(_stream_supervisor.getMaxBytesPerSecInput() > 0 && (_slice_size=_stream_supervisor.getInput_slice_queue().poll()) == null) {
|
||||
while (_stream_supervisor.getMaxBytesPerSecInput() > 0 && (_slice_size = _stream_supervisor.getInput_slice_queue().poll()) == null) {
|
||||
|
||||
_stream_supervisor.secureWait();
|
||||
}
|
||||
|
||||
if(_slice_size != null && size < _slice_size) {
|
||||
if (_slice_size != null && size < _slice_size) {
|
||||
|
||||
_stream_supervisor.getInput_slice_queue().add(_slice_size - size);
|
||||
|
||||
|
@ -15,7 +15,6 @@ public final class ThrottledOutputStream extends OutputStream {
|
||||
|
||||
private Integer slice_size;
|
||||
|
||||
|
||||
public ThrottledOutputStream(OutputStream rawStream, StreamThrottlerSupervisor stream_supervisor) {
|
||||
|
||||
_rawStream = rawStream;
|
||||
@ -26,32 +25,31 @@ public final class ThrottledOutputStream extends OutputStream {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void write(byte[] b, int off, int len) throws IOException {
|
||||
|
||||
if(_stream_supervisor.getMaxBytesPerSecOutput() > 0) {
|
||||
if (_stream_supervisor.getMaxBytesPerSecOutput() > 0) {
|
||||
|
||||
int writeLen=0;
|
||||
int writeLen = 0;
|
||||
|
||||
do {
|
||||
|
||||
throttle(len-writeLen);
|
||||
throttle(len - writeLen);
|
||||
|
||||
if(slice_size != null) {
|
||||
if (slice_size != null) {
|
||||
|
||||
_rawStream.write(b, off+writeLen, slice_size);
|
||||
_rawStream.write(b, off + writeLen, slice_size);
|
||||
|
||||
writeLen+=slice_size;
|
||||
writeLen += slice_size;
|
||||
|
||||
} else {
|
||||
|
||||
_rawStream.write(b, off+writeLen, len-writeLen);
|
||||
_rawStream.write(b, off + writeLen, len - writeLen);
|
||||
|
||||
writeLen = len;
|
||||
}
|
||||
|
||||
}while( writeLen < len );
|
||||
} while (writeLen < len);
|
||||
|
||||
} else {
|
||||
|
||||
@ -62,7 +60,7 @@ public final class ThrottledOutputStream extends OutputStream {
|
||||
@Override
|
||||
public void write(int i) throws IOException {
|
||||
|
||||
if(_stream_supervisor.getMaxBytesPerSecOutput() > 0) {
|
||||
if (_stream_supervisor.getMaxBytesPerSecOutput() > 0) {
|
||||
|
||||
throttle(1);
|
||||
|
||||
@ -74,17 +72,16 @@ public final class ThrottledOutputStream extends OutputStream {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void throttle(int size) throws IOException {
|
||||
|
||||
slice_size = null;
|
||||
|
||||
while(_stream_supervisor.getMaxBytesPerSecOutput() > 0 && (slice_size=_stream_supervisor.getOutput_slice_queue().poll()) == null) {
|
||||
while (_stream_supervisor.getMaxBytesPerSecOutput() > 0 && (slice_size = _stream_supervisor.getOutput_slice_queue().poll()) == null) {
|
||||
|
||||
_stream_supervisor.secureWait();
|
||||
}
|
||||
|
||||
if(slice_size != null && size < slice_size) {
|
||||
if (slice_size != null && size < slice_size) {
|
||||
|
||||
_stream_supervisor.getOutput_slice_queue().add(slice_size - size);
|
||||
|
||||
|
@ -10,12 +10,13 @@ public interface Transference {
|
||||
|
||||
int MIN_WORKERS = 2;
|
||||
int MAX_WORKERS = 20;
|
||||
int MAX_SIM_TRANSFERENCES=20;
|
||||
int MAX_SIM_TRANSFERENCES = 20;
|
||||
boolean USE_SLOTS_DEFAULT = false;
|
||||
int WORKERS_DEFAULT = 4;
|
||||
int SIM_TRANSFERENCES_DEFAULT=2;
|
||||
boolean LIMIT_TRANSFERENCE_SPEED_DEFAULT=false;
|
||||
int MAX_TRANSFERENCE_SPEED_DEFAULT=5;
|
||||
int SIM_TRANSFERENCES_DEFAULT = 2;
|
||||
boolean LIMIT_TRANSFERENCE_SPEED_DEFAULT = false;
|
||||
int MAX_TRANSFERENCE_SPEED_DEFAULT = 5;
|
||||
int MAX_WAIT_WORKERS_SHUTDOWN = 10;
|
||||
|
||||
void start();
|
||||
|
||||
|
@ -38,13 +38,14 @@ abstract public class TransferenceManager implements Runnable, SecureNotifiable
|
||||
private volatile boolean _starting_transferences;
|
||||
private volatile boolean _preprocessing_transferences;
|
||||
private volatile int _pre_count;
|
||||
|
||||
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;
|
||||
_pre_count=0;
|
||||
_starting_transferences = false;
|
||||
_preprocessing_transferences = false;
|
||||
_pre_count = 0;
|
||||
_main_panel = main_panel;
|
||||
_max_running_trans = max_running_trans;
|
||||
_scroll_panel = scroll_panel;
|
||||
@ -98,9 +99,9 @@ abstract public class TransferenceManager implements Runnable, SecureNotifiable
|
||||
}
|
||||
|
||||
public synchronized void addPre_count(int pre_count) {
|
||||
_pre_count+=pre_count;
|
||||
_pre_count += pre_count;
|
||||
|
||||
if(_pre_count <0) {
|
||||
if (_pre_count < 0) {
|
||||
|
||||
_pre_count = 0;
|
||||
}
|
||||
@ -110,12 +111,9 @@ abstract public class TransferenceManager implements Runnable, SecureNotifiable
|
||||
this._max_running_trans = _max_running_trans;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void secureNotify()
|
||||
{
|
||||
synchronized(_secure_notify_lock) {
|
||||
public void secureNotify() {
|
||||
synchronized (_secure_notify_lock) {
|
||||
|
||||
_notified = true;
|
||||
|
||||
@ -126,9 +124,8 @@ abstract public class TransferenceManager implements Runnable, SecureNotifiable
|
||||
@Override
|
||||
public void secureWait() {
|
||||
|
||||
synchronized(_secure_notify_lock)
|
||||
{
|
||||
while(!_notified) {
|
||||
synchronized (_secure_notify_lock) {
|
||||
while (!_notified) {
|
||||
|
||||
try {
|
||||
_secure_notify_lock.wait();
|
||||
@ -144,7 +141,7 @@ abstract public class TransferenceManager implements Runnable, SecureNotifiable
|
||||
@Override
|
||||
public void secureNotifyAll() {
|
||||
|
||||
synchronized(_secure_notify_lock) {
|
||||
synchronized (_secure_notify_lock) {
|
||||
|
||||
_notified = true;
|
||||
|
||||
@ -188,8 +185,7 @@ abstract public class TransferenceManager implements Runnable, SecureNotifiable
|
||||
return _scroll_panel;
|
||||
}
|
||||
|
||||
public void closeAllFinished()
|
||||
{
|
||||
public void closeAllFinished() {
|
||||
_transference_remove_queue.addAll(new ArrayList(_transference_finished_queue));
|
||||
|
||||
_transference_finished_queue.clear();
|
||||
@ -197,8 +193,7 @@ abstract public class TransferenceManager implements Runnable, SecureNotifiable
|
||||
secureNotify();
|
||||
}
|
||||
|
||||
public void closeAllPreProWaiting()
|
||||
{
|
||||
public void closeAllPreProWaiting() {
|
||||
_transference_preprocess_queue.clear();
|
||||
|
||||
_pre_count = 0;
|
||||
@ -216,18 +211,17 @@ abstract public class TransferenceManager implements Runnable, SecureNotifiable
|
||||
|
||||
_transference_running_list.add(transference);
|
||||
|
||||
_scroll_panel.add((Component)transference.getView(), 0);
|
||||
_scroll_panel.add((Component) transference.getView(), 0);
|
||||
|
||||
transference.start();
|
||||
|
||||
secureNotify();
|
||||
}
|
||||
|
||||
public void pauseAll()
|
||||
{
|
||||
for(Transference transference:_transference_running_list) {
|
||||
public void pauseAll() {
|
||||
for (Transference transference : _transference_running_list) {
|
||||
|
||||
if(!transference.isPaused()) {
|
||||
if (!transference.isPaused()) {
|
||||
|
||||
transference.pause();
|
||||
}
|
||||
@ -236,11 +230,10 @@ abstract public class TransferenceManager implements Runnable, SecureNotifiable
|
||||
secureNotify();
|
||||
}
|
||||
|
||||
public void sortTransferenceStartQueue()
|
||||
{
|
||||
public void sortTransferenceStartQueue() {
|
||||
ArrayList<Transference> trans_list = new ArrayList(_transference_waitstart_queue);
|
||||
|
||||
trans_list.sort(new Comparator<Transference> () {
|
||||
trans_list.sort(new Comparator<Transference>() {
|
||||
|
||||
@Override
|
||||
public int compare(Transference o1, Transference o2) {
|
||||
@ -256,13 +249,13 @@ abstract public class TransferenceManager implements Runnable, SecureNotifiable
|
||||
|
||||
private void updateView() {
|
||||
|
||||
if(!_transference_running_list.isEmpty()) {
|
||||
if (!_transference_running_list.isEmpty()) {
|
||||
|
||||
boolean show_pause_all = false;
|
||||
|
||||
for(Transference trans:_transference_running_list) {
|
||||
for (Transference trans : _transference_running_list) {
|
||||
|
||||
if((show_pause_all = !trans.isPaused())) {
|
||||
if ((show_pause_all = !trans.isPaused())) {
|
||||
|
||||
break;
|
||||
}
|
||||
@ -277,9 +270,9 @@ abstract public class TransferenceManager implements Runnable, SecureNotifiable
|
||||
|
||||
swingReflectionInvoke("setEnabled", _clean_all_menu, !_transference_preprocess_queue.isEmpty() || !_transference_provision_queue.isEmpty() || !_transference_waitstart_queue.isEmpty());
|
||||
|
||||
if(!_transference_finished_queue.isEmpty()) {
|
||||
if (!_transference_finished_queue.isEmpty()) {
|
||||
|
||||
swingReflectionInvoke("setText", _close_all_button, "Close all finished ("+_transference_finished_queue.size()+")" );
|
||||
swingReflectionInvoke("setText", _close_all_button, "Close all finished (" + _transference_finished_queue.size() + ")");
|
||||
|
||||
swingReflectionInvoke("setVisible", _close_all_button, true);
|
||||
|
||||
@ -303,33 +296,31 @@ abstract public class TransferenceManager implements Runnable, SecureNotifiable
|
||||
|
||||
int finish = _transference_finished_queue.size();
|
||||
|
||||
if(finish > 0 && _pre_count+prov+wait+run == 0 && !(boolean)swingReflectionInvokeAndWaitForReturn("isVisible", _main_panel.getView())) {
|
||||
if (finish > 0 && _pre_count + prov + wait + run == 0 && !(boolean) swingReflectionInvokeAndWaitForReturn("isVisible", _main_panel.getView())) {
|
||||
|
||||
swingReflectionInvoke("displayMessage", _main_panel.getTrayicon(), "MegaBasterd says:", "All your transferences have finished", TrayIcon.MessageType.INFO);
|
||||
|
||||
}
|
||||
|
||||
return (_pre_count+prov+rem+wait+run+finish > 0)?"Pre: "+_pre_count+" / Pro: "+prov+" / Wait: "+wait+" / Run: "+run+" / Finish: "+finish+" / Rem: "+rem:"";
|
||||
return (_pre_count + prov + rem + wait + run + finish > 0) ? "Pre: " + _pre_count + " / Pro: " + prov + " / Wait: " + wait + " / Run: " + run + " / Finish: " + finish + " / Rem: " + rem : "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
while(true)
|
||||
{
|
||||
if(!isPreprocessing_transferences() && !getTransference_preprocess_queue().isEmpty()) {
|
||||
while (true) {
|
||||
if (!isPreprocessing_transferences() && !getTransference_preprocess_queue().isEmpty()) {
|
||||
|
||||
setPreprocessing_transferences(true);
|
||||
|
||||
THREAD_POOL.execute(new Runnable(){
|
||||
THREAD_POOL.execute(new Runnable() {
|
||||
@Override
|
||||
public void run(){
|
||||
public void run() {
|
||||
|
||||
while(!getTransference_preprocess_queue().isEmpty())
|
||||
{
|
||||
while (!getTransference_preprocess_queue().isEmpty()) {
|
||||
Runnable run = getTransference_preprocess_queue().poll();
|
||||
|
||||
if(run != null) {
|
||||
if (run != null) {
|
||||
|
||||
run.run();
|
||||
}
|
||||
@ -339,22 +330,22 @@ abstract public class TransferenceManager implements Runnable, SecureNotifiable
|
||||
|
||||
secureNotify();
|
||||
|
||||
}});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if(!isProvisioning_transferences() && !getTransference_provision_queue().isEmpty()) {
|
||||
if (!isProvisioning_transferences() && !getTransference_provision_queue().isEmpty()) {
|
||||
|
||||
setProvisioning_transferences(true);
|
||||
|
||||
THREAD_POOL.execute(new Runnable(){
|
||||
THREAD_POOL.execute(new Runnable() {
|
||||
@Override
|
||||
public void run(){
|
||||
public void run() {
|
||||
|
||||
while(!getTransference_provision_queue().isEmpty())
|
||||
{
|
||||
while (!getTransference_provision_queue().isEmpty()) {
|
||||
Transference transference = getTransference_provision_queue().poll();
|
||||
|
||||
if(transference != null) {
|
||||
if (transference != null) {
|
||||
|
||||
provision(transference);
|
||||
|
||||
@ -365,23 +356,24 @@ abstract public class TransferenceManager implements Runnable, SecureNotifiable
|
||||
|
||||
secureNotify();
|
||||
|
||||
}});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
if(!isRemoving_transferences() && !getTransference_remove_queue().isEmpty()) {
|
||||
if (!isRemoving_transferences() && !getTransference_remove_queue().isEmpty()) {
|
||||
|
||||
setRemoving_transferences(true);
|
||||
|
||||
THREAD_POOL.execute(new Runnable(){
|
||||
THREAD_POOL.execute(new Runnable() {
|
||||
@Override
|
||||
public void run(){
|
||||
public void run() {
|
||||
|
||||
while(!getTransference_remove_queue().isEmpty()) {
|
||||
while (!getTransference_remove_queue().isEmpty()) {
|
||||
|
||||
Transference transference = getTransference_remove_queue().poll();
|
||||
|
||||
if(transference != null) {
|
||||
if (transference != null) {
|
||||
remove(transference);
|
||||
}
|
||||
}
|
||||
@ -390,21 +382,22 @@ abstract public class TransferenceManager implements Runnable, SecureNotifiable
|
||||
|
||||
secureNotify();
|
||||
|
||||
}});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if(!isStarting_transferences() && !getTransference_waitstart_queue().isEmpty() && getTransference_running_list().size() < _max_running_trans) {
|
||||
if (!isStarting_transferences() && !getTransference_waitstart_queue().isEmpty() && getTransference_running_list().size() < _max_running_trans) {
|
||||
setStarting_transferences(true);
|
||||
|
||||
THREAD_POOL.execute(new Runnable(){
|
||||
THREAD_POOL.execute(new Runnable() {
|
||||
@Override
|
||||
public void run(){
|
||||
public void run() {
|
||||
|
||||
while(!getTransference_waitstart_queue().isEmpty() && getTransference_running_list().size() < _max_running_trans) {
|
||||
while (!getTransference_waitstart_queue().isEmpty() && getTransference_running_list().size() < _max_running_trans) {
|
||||
|
||||
Transference transference = getTransference_waitstart_queue().poll();
|
||||
|
||||
if(transference != null) {
|
||||
if (transference != null) {
|
||||
|
||||
start(transference);
|
||||
}
|
||||
@ -414,7 +407,8 @@ abstract public class TransferenceManager implements Runnable, SecureNotifiable
|
||||
|
||||
secureNotify();
|
||||
|
||||
}});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
updateView();
|
||||
|
@ -7,14 +7,23 @@ package megabasterd;
|
||||
public interface TransferenceView {
|
||||
|
||||
void pause();
|
||||
|
||||
void stop();
|
||||
|
||||
void resume();
|
||||
|
||||
void updateSpeed(String speed, Boolean visible);
|
||||
|
||||
void updateRemainingTime(String rem_time, Boolean visible);
|
||||
|
||||
void updateProgressBar(long progress, double bar_rate);
|
||||
|
||||
void updateSlotsStatus();
|
||||
|
||||
void printStatusNormal(String msg);
|
||||
|
||||
void printStatusOK(String msg);
|
||||
|
||||
void printStatusError(String msg);
|
||||
|
||||
}
|
||||
|
@ -35,9 +35,9 @@ import static megabasterd.MiscTools.truncateText;
|
||||
public final class Upload implements Transference, Runnable, SecureNotifiable {
|
||||
|
||||
private final MainPanel _main_panel;
|
||||
private volatile UploadView _view=null; //lazy init
|
||||
private volatile SpeedMeter _speed_meter=null; //lazy init
|
||||
private volatile ProgressMeter _progress_meter=null; //lazy init
|
||||
private volatile UploadView _view = null; //lazy init
|
||||
private volatile SpeedMeter _speed_meter = null; //lazy init
|
||||
private volatile ProgressMeter _progress_meter = null; //lazy init
|
||||
private String _exit_message;
|
||||
private String _dir_name;
|
||||
private volatile boolean _exit;
|
||||
@ -269,7 +269,7 @@ public final class Upload implements Transference, Runnable, SecureNotifiable {
|
||||
|
||||
if (result == null) {
|
||||
|
||||
synchronized(this) {
|
||||
synchronized (this) {
|
||||
|
||||
result = _speed_meter;
|
||||
|
||||
@ -291,7 +291,7 @@ public final class Upload implements Transference, Runnable, SecureNotifiable {
|
||||
|
||||
if (result == null) {
|
||||
|
||||
synchronized(this) {
|
||||
synchronized (this) {
|
||||
|
||||
result = _progress_meter;
|
||||
|
||||
@ -313,7 +313,7 @@ public final class Upload implements Transference, Runnable, SecureNotifiable {
|
||||
|
||||
if (result == null) {
|
||||
|
||||
synchronized(this) {
|
||||
synchronized (this) {
|
||||
|
||||
result = _view;
|
||||
|
||||
@ -329,9 +329,8 @@ public final class Upload implements Transference, Runnable, SecureNotifiable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void secureNotify()
|
||||
{
|
||||
synchronized(_secure_notify_lock) {
|
||||
public void secureNotify() {
|
||||
synchronized (_secure_notify_lock) {
|
||||
|
||||
_notified = true;
|
||||
|
||||
@ -342,9 +341,8 @@ public final class Upload implements Transference, Runnable, SecureNotifiable {
|
||||
@Override
|
||||
public void secureWait() {
|
||||
|
||||
synchronized(_secure_notify_lock)
|
||||
{
|
||||
while(!_notified) {
|
||||
synchronized (_secure_notify_lock) {
|
||||
while (!_notified) {
|
||||
|
||||
try {
|
||||
_secure_notify_lock.wait();
|
||||
@ -360,7 +358,7 @@ public final class Upload implements Transference, Runnable, SecureNotifiable {
|
||||
@Override
|
||||
public void secureNotifyAll() {
|
||||
|
||||
synchronized(_secure_notify_lock) {
|
||||
synchronized (_secure_notify_lock) {
|
||||
|
||||
_notified = true;
|
||||
|
||||
@ -368,20 +366,19 @@ public final class Upload implements Transference, Runnable, SecureNotifiable {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void provisionIt() {
|
||||
|
||||
printStatus("Provisioning upload, please wait...");
|
||||
|
||||
String exit_msg=null;
|
||||
String exit_msg = null;
|
||||
|
||||
File the_file = new File(_file_name);
|
||||
|
||||
if(!the_file.exists()) {
|
||||
if (!the_file.exists()) {
|
||||
|
||||
_provision_ok=false;
|
||||
_provision_ok = false;
|
||||
|
||||
exit_msg = "ERROR: FILE NOT FOUND -> "+_file_name;
|
||||
exit_msg = "ERROR: FILE NOT FOUND -> " + _file_name;
|
||||
|
||||
} else {
|
||||
|
||||
@ -390,13 +387,13 @@ public final class Upload implements Transference, Runnable, SecureNotifiable {
|
||||
|
||||
File temp_file;
|
||||
|
||||
temp_file = new File("."+HashString("SHA-1", _file_name));
|
||||
temp_file = new File("." + HashString("SHA-1", _file_name));
|
||||
|
||||
if(_ul_key!=null && temp_file.exists() && temp_file.length()>0) {
|
||||
if (_ul_key != null && temp_file.exists() && temp_file.length() > 0) {
|
||||
|
||||
FileInputStream fis = new FileInputStream(temp_file);
|
||||
|
||||
byte[] data = new byte[(int)temp_file.length()];
|
||||
byte[] data = new byte[(int) temp_file.length()];
|
||||
|
||||
fis.read(data);
|
||||
|
||||
@ -408,12 +405,12 @@ public final class Upload implements Transference, Runnable, SecureNotifiable {
|
||||
|
||||
_saved_file_mac = bin2i32a(BASE642Bin(fdata[2]));
|
||||
|
||||
} else if(temp_file.exists()) {
|
||||
} else if (temp_file.exists()) {
|
||||
|
||||
temp_file.delete();
|
||||
}
|
||||
|
||||
if(_ul_key == null || _restart) {
|
||||
if (_ul_key == null || _restart) {
|
||||
|
||||
try {
|
||||
|
||||
@ -423,7 +420,7 @@ public final class Upload implements Transference, Runnable, SecureNotifiable {
|
||||
|
||||
} catch (IOException | SQLException ex) {
|
||||
|
||||
_provision_ok=false;
|
||||
_provision_ok = false;
|
||||
|
||||
exit_msg = ex.getMessage();
|
||||
}
|
||||
@ -434,15 +431,15 @@ public final class Upload implements Transference, Runnable, SecureNotifiable {
|
||||
}
|
||||
}
|
||||
|
||||
if(!_provision_ok) {
|
||||
if (!_provision_ok) {
|
||||
|
||||
getView().hideAllExceptStatus();
|
||||
|
||||
if(_fatal_error != null) {
|
||||
if (_fatal_error != null) {
|
||||
|
||||
printStatusError(_fatal_error);
|
||||
|
||||
}else if(exit_msg!=null) {
|
||||
} else if (exit_msg != null) {
|
||||
|
||||
printStatusError(exit_msg);
|
||||
}
|
||||
@ -469,7 +466,6 @@ public final class Upload implements Transference, Runnable, SecureNotifiable {
|
||||
swingReflectionInvoke("setVisible", getView().getClose_button(), true);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
|
||||
@ -478,7 +474,7 @@ public final class Upload implements Transference, Runnable, SecureNotifiable {
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
if(!isExit()) {
|
||||
if (!isExit()) {
|
||||
stopUploader();
|
||||
}
|
||||
}
|
||||
@ -486,13 +482,13 @@ public final class Upload implements Transference, Runnable, SecureNotifiable {
|
||||
@Override
|
||||
public void pause() {
|
||||
|
||||
if(isPaused()) {
|
||||
if (isPaused()) {
|
||||
|
||||
setPause(false);
|
||||
|
||||
getSpeed_meter().secureNotify();
|
||||
|
||||
for(ChunkUploader uploader:getChunkworkers()) {
|
||||
for (ChunkUploader uploader : getChunkworkers()) {
|
||||
|
||||
uploader.secureNotify();
|
||||
}
|
||||
@ -544,15 +540,15 @@ public final class Upload implements Transference, Runnable, SecureNotifiable {
|
||||
@Override
|
||||
public synchronized void checkSlotsAndWorkers() {
|
||||
|
||||
if(!isExit()) {
|
||||
if (!isExit()) {
|
||||
|
||||
int sl = (int)swingReflectionInvokeAndWaitForReturn("getValue", getView().getSlots_spinner());
|
||||
int sl = (int) swingReflectionInvokeAndWaitForReturn("getValue", getView().getSlots_spinner());
|
||||
|
||||
int cworkers = getChunkworkers().size();
|
||||
|
||||
if(sl != cworkers) {
|
||||
if (sl != cworkers) {
|
||||
|
||||
if(sl > cworkers) {
|
||||
if (sl > cworkers) {
|
||||
|
||||
startSlot();
|
||||
|
||||
@ -570,15 +566,13 @@ public final class Upload implements Transference, Runnable, SecureNotifiable {
|
||||
return getPartialProgressQueue();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public MainPanel getMain_panel() {
|
||||
return _main_panel;
|
||||
}
|
||||
|
||||
public synchronized void startSlot()
|
||||
{
|
||||
int chunkthiser_id = _chunkworkers.size()+1;
|
||||
public synchronized void startSlot() {
|
||||
int chunkthiser_id = _chunkworkers.size() + 1;
|
||||
|
||||
ChunkUploader c = new ChunkUploader(chunkthiser_id, this);
|
||||
|
||||
@ -588,26 +582,27 @@ public final class Upload implements Transference, Runnable, SecureNotifiable {
|
||||
|
||||
_thread_pool.execute(c);
|
||||
|
||||
}catch(java.util.concurrent.RejectedExecutionException e){System.out.println(e.getMessage());}
|
||||
} catch (java.util.concurrent.RejectedExecutionException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void setPause(boolean pause) {
|
||||
_pause = pause;
|
||||
}
|
||||
|
||||
public synchronized void stopLastStartedSlot()
|
||||
{
|
||||
if(!_chunkworkers.isEmpty()) {
|
||||
public synchronized void stopLastStartedSlot() {
|
||||
if (!_chunkworkers.isEmpty()) {
|
||||
|
||||
swingReflectionInvoke("setEnabled", getView().getSlots_spinner(), false);
|
||||
|
||||
int i = _chunkworkers.size()-1;
|
||||
int i = _chunkworkers.size() - 1;
|
||||
|
||||
while(i>=0) {
|
||||
while (i >= 0) {
|
||||
|
||||
ChunkUploader chunkuploader = _chunkworkers.get(i);
|
||||
|
||||
if(!chunkuploader.isExit()) {
|
||||
if (!chunkuploader.isExit()) {
|
||||
|
||||
chunkuploader.setExit(true);
|
||||
|
||||
@ -625,8 +620,7 @@ public final class Upload implements Transference, Runnable, SecureNotifiable {
|
||||
}
|
||||
}
|
||||
|
||||
public void rejectChunkId(long chunk_id)
|
||||
{
|
||||
public void rejectChunkId(long chunk_id) {
|
||||
_rejectedChunkIds.add(chunk_id);
|
||||
}
|
||||
|
||||
@ -639,17 +633,15 @@ public final class Upload implements Transference, Runnable, SecureNotifiable {
|
||||
|
||||
printStatus("Starting upload, please wait...");
|
||||
|
||||
if(!_exit)
|
||||
{
|
||||
if(_ul_url == null) {
|
||||
if (!_exit) {
|
||||
if (_ul_url == null) {
|
||||
|
||||
_ul_url = _ma.initUploadFile(_file_name);
|
||||
|
||||
try {
|
||||
|
||||
DBTools.updateUploadUrl(_file_name, _ma.getEmail(), _ul_url);
|
||||
}
|
||||
catch (SQLException ex) {
|
||||
} catch (SQLException ex) {
|
||||
getLogger(Upload.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
@ -660,16 +652,15 @@ public final class Upload implements Transference, Runnable, SecureNotifiable {
|
||||
|
||||
_byte_file_iv = i32a2bin(file_iv);
|
||||
|
||||
if(!_exit)
|
||||
{
|
||||
if (!_exit) {
|
||||
|
||||
swingReflectionInvoke("setMinimum", getView().getProgress_pbar(), 0);
|
||||
swingReflectionInvoke("setMaximum", getView().getProgress_pbar(), Integer.MAX_VALUE);
|
||||
swingReflectionInvoke("setStringPainted", getView().getProgress_pbar(), true);
|
||||
|
||||
if(_file_size > 0) {
|
||||
if (_file_size > 0) {
|
||||
|
||||
_progress_bar_rate = Integer.MAX_VALUE/(double)_file_size;
|
||||
_progress_bar_rate = Integer.MAX_VALUE / (double) _file_size;
|
||||
|
||||
swingReflectionInvoke("setValue", getView().getProgress_pbar(), 0);
|
||||
|
||||
@ -690,10 +681,9 @@ public final class Upload implements Transference, Runnable, SecureNotifiable {
|
||||
|
||||
_thread_pool.execute(_mac_generator);
|
||||
|
||||
if(_use_slots) {
|
||||
if (_use_slots) {
|
||||
|
||||
for(int t=1; t <= _slots; t++)
|
||||
{
|
||||
for (int t = 1; t <= _slots; t++) {
|
||||
ChunkUploader c = new ChunkUploader(t, this);
|
||||
|
||||
_chunkworkers.add(c);
|
||||
@ -707,7 +697,6 @@ public final class Upload implements Transference, Runnable, SecureNotifiable {
|
||||
|
||||
swingReflectionInvoke("setVisible", getView().getSlot_status_label(), true);
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
ChunkUploaderMono c = new ChunkUploaderMono(this);
|
||||
@ -723,7 +712,7 @@ public final class Upload implements Transference, Runnable, SecureNotifiable {
|
||||
swingReflectionInvoke("setVisible", getView().getSlot_status_label(), false);
|
||||
}
|
||||
|
||||
printStatus("Uploading file to mega ("+_ma.getEmail()+") ...");
|
||||
printStatus("Uploading file to mega (" + _ma.getEmail() + ") ...");
|
||||
|
||||
getMain_panel().getUpload_manager().secureNotify();
|
||||
|
||||
@ -745,38 +734,42 @@ public final class Upload implements Transference, Runnable, SecureNotifiable {
|
||||
|
||||
_thread_pool.shutdown();
|
||||
|
||||
while(!_thread_pool.isTerminated())
|
||||
{
|
||||
while (!_thread_pool.isTerminated()) {
|
||||
try {
|
||||
|
||||
_thread_pool.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
|
||||
_thread_pool.awaitTermination(MAX_WAIT_WORKERS_SHUTDOWN, TimeUnit.SECONDS);
|
||||
|
||||
} catch (InterruptedException ex) {
|
||||
getLogger(Upload.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
if (!_thread_pool.isTerminated()) {
|
||||
|
||||
System.out.println("Cerrando thread pool a lo mecagüen...");
|
||||
|
||||
_thread_pool.shutdownNow();
|
||||
}
|
||||
|
||||
System.out.println("Uploader thread pool finished!");
|
||||
|
||||
getMain_panel().getGlobal_up_speed().detachSpeedMeter(getSpeed_meter());
|
||||
|
||||
getMain_panel().getGlobal_up_speed().secureNotify();
|
||||
|
||||
|
||||
swingReflectionInvoke("setVisible", new Object[]{getView().getSpeed_label(),getView().getRemtime_label(),getView().getPause_button(),getView().getStop_button(),getView().getSlots_label(),getView().getSlots_spinner()}, false);
|
||||
|
||||
swingReflectionInvoke("setVisible", new Object[]{getView().getSpeed_label(), getView().getRemtime_label(), getView().getPause_button(), getView().getStop_button(), getView().getSlots_label(), getView().getSlots_spinner()}, false);
|
||||
|
||||
getMain_panel().getUpload_manager().secureNotify();
|
||||
|
||||
if(!_exit) {
|
||||
if (!_exit) {
|
||||
|
||||
if(_completion_handle != null) {
|
||||
if (_completion_handle != null) {
|
||||
|
||||
printStatus("Uploading (finishing) file to mega ("+_ma.getEmail()+") ...");
|
||||
printStatus("Uploading (finishing) file to mega (" + _ma.getEmail() + ") ...");
|
||||
|
||||
File f = new File(_file_name);
|
||||
|
||||
HashMap<String, Object> upload_res=null;
|
||||
HashMap<String, Object> upload_res = null;
|
||||
|
||||
int[] ul_key = _ul_key;
|
||||
|
||||
@ -786,11 +779,11 @@ public final class Upload implements Transference, Runnable, SecureNotifiable {
|
||||
|
||||
System.out.println(upload_res);
|
||||
|
||||
List files = (List)upload_res.get("f");
|
||||
List files = (List) upload_res.get("f");
|
||||
|
||||
_fid = (String)((Map<String,Object>)files.get(0)).get("h");
|
||||
_fid = (String) ((Map<String, Object>) files.get(0)).get("h");
|
||||
|
||||
_exit_message = "File successfully uploaded! ("+_ma.getEmail()+")";
|
||||
_exit_message = "File successfully uploaded! (" + _ma.getEmail() + ")";
|
||||
|
||||
try {
|
||||
|
||||
@ -815,7 +808,7 @@ public final class Upload implements Transference, Runnable, SecureNotifiable {
|
||||
_status_error = true;
|
||||
}
|
||||
|
||||
} else if(_fatal_error != null) {
|
||||
} else if (_fatal_error != null) {
|
||||
|
||||
getView().hideAllExceptStatus();
|
||||
|
||||
@ -834,17 +827,13 @@ public final class Upload implements Transference, Runnable, SecureNotifiable {
|
||||
_status_error = true;
|
||||
}
|
||||
|
||||
}
|
||||
else if(_fatal_error != null)
|
||||
{
|
||||
} else if (_fatal_error != null) {
|
||||
getView().hideAllExceptStatus();
|
||||
|
||||
printStatusError(_fatal_error);
|
||||
|
||||
_status_error = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
getView().hideAllExceptStatus();
|
||||
|
||||
_exit_message = "Upload CANCELED!";
|
||||
@ -854,9 +843,7 @@ public final class Upload implements Transference, Runnable, SecureNotifiable {
|
||||
_status_error = true;
|
||||
}
|
||||
|
||||
}
|
||||
else if(_fatal_error != null)
|
||||
{
|
||||
} else if (_fatal_error != null) {
|
||||
getView().hideAllExceptStatus();
|
||||
|
||||
_exit_message = _fatal_error;
|
||||
@ -864,9 +851,7 @@ public final class Upload implements Transference, Runnable, SecureNotifiable {
|
||||
printStatusError(_fatal_error);
|
||||
|
||||
_status_error = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
getView().hideAllExceptStatus();
|
||||
|
||||
_exit_message = "Upload CANCELED!";
|
||||
@ -877,7 +862,7 @@ public final class Upload implements Transference, Runnable, SecureNotifiable {
|
||||
|
||||
}
|
||||
|
||||
if(!_exit) {
|
||||
if (!_exit) {
|
||||
|
||||
try {
|
||||
DBTools.deleteUpload(_file_name, _ma.getEmail());
|
||||
@ -898,17 +883,16 @@ public final class Upload implements Transference, Runnable, SecureNotifiable {
|
||||
|
||||
swingReflectionInvoke("setVisible", getView().getClose_button(), true);
|
||||
|
||||
if(_status_error) {
|
||||
if (_status_error) {
|
||||
swingReflectionInvoke("setVisible", getView().getRestart_button(), true);
|
||||
}
|
||||
|
||||
System.out.println("Uploader BYE BYE");
|
||||
}
|
||||
|
||||
|
||||
public synchronized void pause_worker() {
|
||||
|
||||
if(++_paused_workers >= _chunkworkers.size() && !_exit) {
|
||||
if (++_paused_workers >= _chunkworkers.size() && !_exit) {
|
||||
|
||||
printStatus("Upload paused!");
|
||||
swingReflectionInvoke("setText", getView().getPause_button(), "RESUME UPLOAD");
|
||||
@ -916,24 +900,22 @@ public final class Upload implements Transference, Runnable, SecureNotifiable {
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void stopThisSlot(ChunkUploader chunkuploader)
|
||||
{
|
||||
if(_chunkworkers.remove(chunkuploader))
|
||||
{
|
||||
if(!chunkuploader.isExit()) {
|
||||
public synchronized void stopThisSlot(ChunkUploader chunkuploader) {
|
||||
if (_chunkworkers.remove(chunkuploader)) {
|
||||
if (!chunkuploader.isExit()) {
|
||||
|
||||
_finishing_upload = true;
|
||||
|
||||
swingReflectionInvoke("setEnabled", getView().getSlots_spinner(), false);
|
||||
|
||||
swingReflectionInvokeAndWait("setValue", getView().getSlots_spinner(), (int)swingReflectionInvokeAndWaitForReturn("getValue", getView().getSlots_spinner())-1);
|
||||
swingReflectionInvokeAndWait("setValue", getView().getSlots_spinner(), (int) swingReflectionInvokeAndWaitForReturn("getValue", getView().getSlots_spinner()) - 1);
|
||||
|
||||
} else if(!_finishing_upload) {
|
||||
} else if (!_finishing_upload) {
|
||||
|
||||
swingReflectionInvoke("setEnabled", getView().getSlots_spinner(), true);
|
||||
}
|
||||
|
||||
if(!_exit && _pause && _paused_workers == _chunkworkers.size()) {
|
||||
if (!_exit && _pause && _paused_workers == _chunkworkers.size()) {
|
||||
|
||||
printStatus("Upload paused!");
|
||||
swingReflectionInvoke("setText", getView().getPause_button(), "RESUME UPLOAD");
|
||||
@ -944,24 +926,20 @@ public final class Upload implements Transference, Runnable, SecureNotifiable {
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void emergencyStopUploader(String reason)
|
||||
{
|
||||
if(_fatal_error == null)
|
||||
{
|
||||
_fatal_error = reason!=null?reason:"FATAL ERROR!";
|
||||
public synchronized void emergencyStopUploader(String reason) {
|
||||
if (_fatal_error == null) {
|
||||
_fatal_error = reason != null ? reason : "FATAL ERROR!";
|
||||
|
||||
stopUploader();
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized long nextChunkId()
|
||||
{
|
||||
public synchronized long nextChunkId() {
|
||||
Long next_id;
|
||||
|
||||
if((next_id=_rejectedChunkIds.poll()) != null) {
|
||||
if ((next_id = _rejectedChunkIds.poll()) != null) {
|
||||
return next_id;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return ++_last_chunk_id_dispatched;
|
||||
}
|
||||
}
|
||||
@ -970,10 +948,8 @@ public final class Upload implements Transference, Runnable, SecureNotifiable {
|
||||
_exit = exit;
|
||||
}
|
||||
|
||||
public synchronized void stopUploader()
|
||||
{
|
||||
if(!_exit)
|
||||
{
|
||||
public synchronized void stopUploader() {
|
||||
if (!_exit) {
|
||||
setExit(true);
|
||||
|
||||
try {
|
||||
@ -994,28 +970,24 @@ public final class Upload implements Transference, Runnable, SecureNotifiable {
|
||||
|
||||
getView().stop();
|
||||
|
||||
for(ChunkUploader uploader:_chunkworkers) {
|
||||
for (ChunkUploader uploader : _chunkworkers) {
|
||||
|
||||
uploader.secureNotify();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void printStatusError(String message)
|
||||
{
|
||||
private void printStatusError(String message) {
|
||||
swingReflectionInvoke("setForeground", getView().getStatus_label(), Color.red);
|
||||
swingReflectionInvoke("setText", getView().getStatus_label(), message);
|
||||
}
|
||||
|
||||
private void printStatusOK(String message)
|
||||
{
|
||||
swingReflectionInvoke("setForeground", getView().getStatus_label(), new Color(0,128,0));
|
||||
private void printStatusOK(String message) {
|
||||
swingReflectionInvoke("setForeground", getView().getStatus_label(), new Color(0, 128, 0));
|
||||
swingReflectionInvoke("setText", getView().getStatus_label(), message);
|
||||
}
|
||||
|
||||
private void printStatus(String message)
|
||||
{
|
||||
private void printStatus(String message) {
|
||||
swingReflectionInvoke("setForeground", getView().getStatus_label(), Color.BLACK);
|
||||
swingReflectionInvoke("setText", getView().getStatus_label(), message);
|
||||
}
|
||||
@ -1026,5 +998,4 @@ public final class Upload implements Transference, Runnable, SecureNotifiable {
|
||||
getView().updateProgressBar(_progress, _progress_bar_rate);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -25,12 +25,13 @@ import static megabasterd.MiscTools.i32a2bin;
|
||||
public final class UploadMACGenerator implements Runnable, SecureNotifiable {
|
||||
|
||||
private long _last_chunk_id_read;
|
||||
private final ConcurrentHashMap<Long,Chunk> _chunk_queue;
|
||||
private final ConcurrentHashMap<Long, Chunk> _chunk_queue;
|
||||
private final Upload _upload;
|
||||
private final Object _secure_notify_lock;
|
||||
private boolean _notified;
|
||||
private volatile boolean _exit;
|
||||
private long _bytes_read;
|
||||
|
||||
public UploadMACGenerator(Upload upload) {
|
||||
_secure_notify_lock = new Object();
|
||||
_notified = false;
|
||||
@ -38,14 +39,12 @@ public final class UploadMACGenerator implements Runnable, SecureNotifiable {
|
||||
_chunk_queue = new ConcurrentHashMap();
|
||||
_bytes_read = _upload.getProgress();
|
||||
_last_chunk_id_read = _upload.getLast_chunk_id_dispatched();
|
||||
_exit=false;
|
||||
_exit = false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void secureNotify()
|
||||
{
|
||||
synchronized(_secure_notify_lock) {
|
||||
public void secureNotify() {
|
||||
synchronized (_secure_notify_lock) {
|
||||
|
||||
_notified = true;
|
||||
|
||||
@ -56,9 +55,8 @@ public final class UploadMACGenerator implements Runnable, SecureNotifiable {
|
||||
@Override
|
||||
public void secureWait() {
|
||||
|
||||
synchronized(_secure_notify_lock)
|
||||
{
|
||||
while(!_notified) {
|
||||
synchronized (_secure_notify_lock) {
|
||||
while (!_notified) {
|
||||
|
||||
try {
|
||||
_secure_notify_lock.wait();
|
||||
@ -74,7 +72,7 @@ public final class UploadMACGenerator implements Runnable, SecureNotifiable {
|
||||
@Override
|
||||
public void secureNotifyAll() {
|
||||
|
||||
synchronized(_secure_notify_lock) {
|
||||
synchronized (_secure_notify_lock) {
|
||||
|
||||
_notified = true;
|
||||
|
||||
@ -106,13 +104,12 @@ public final class UploadMACGenerator implements Runnable, SecureNotifiable {
|
||||
_exit = exit;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
try{
|
||||
try {
|
||||
|
||||
File temp_file = new File("."+HashString("SHA-1", _upload.getFile_name()));
|
||||
File temp_file = new File("." + HashString("SHA-1", _upload.getFile_name()));
|
||||
|
||||
FileOutputStream temp_file_out;
|
||||
|
||||
@ -121,46 +118,40 @@ public final class UploadMACGenerator implements Runnable, SecureNotifiable {
|
||||
int reads;
|
||||
byte[] byte_block = new byte[16];
|
||||
String temp_file_data = "";
|
||||
boolean new_chunk=false;
|
||||
boolean new_chunk = false;
|
||||
|
||||
while(!_exit && (!_upload.isStopped() || !_upload.getChunkworkers().isEmpty()) && (_bytes_read < _upload.getFile_size() || (_upload.getFile_size() == 0 && _last_chunk_id_read < 1)))
|
||||
{
|
||||
while(_chunk_queue.containsKey(_last_chunk_id_read+1))
|
||||
{
|
||||
chunk = _chunk_queue.get(_last_chunk_id_read+1);
|
||||
while (!_exit && (!_upload.isStopped() || !_upload.getChunkworkers().isEmpty()) && (_bytes_read < _upload.getFile_size() || (_upload.getFile_size() == 0 && _last_chunk_id_read < 1))) {
|
||||
while (_chunk_queue.containsKey(_last_chunk_id_read + 1)) {
|
||||
chunk = _chunk_queue.get(_last_chunk_id_read + 1);
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
int[] chunk_mac = {file_iv[0], file_iv[1], file_iv[0], file_iv[1]};
|
||||
|
||||
InputStream chunk_is = chunk.getInputStream();
|
||||
|
||||
while( (reads=chunk_is.read(byte_block)) != -1 )
|
||||
{
|
||||
if(reads<byte_block.length)
|
||||
{
|
||||
for(int i=reads; i<byte_block.length; i++)
|
||||
byte_block[i]=0;
|
||||
while ((reads = chunk_is.read(byte_block)) != -1) {
|
||||
if (reads < byte_block.length) {
|
||||
for (int i = reads; i < byte_block.length; i++) {
|
||||
byte_block[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int_block = bin2i32a(byte_block);
|
||||
|
||||
for(int i=0; i<chunk_mac.length; i++)
|
||||
{
|
||||
chunk_mac[i]^=int_block[i];
|
||||
for (int i = 0; i < chunk_mac.length; i++) {
|
||||
chunk_mac[i] ^= int_block[i];
|
||||
}
|
||||
|
||||
chunk_mac = CryptTools.aes_cbc_encrypt_ia32(chunk_mac, bin2i32a(_upload.getByte_file_key()), mac_iv);
|
||||
}
|
||||
|
||||
for(int i=0; i<file_mac.length; i++)
|
||||
{
|
||||
file_mac[i]^=chunk_mac[i];
|
||||
for (int i = 0; i < file_mac.length; i++) {
|
||||
file_mac[i] ^= chunk_mac[i];
|
||||
}
|
||||
|
||||
file_mac = CryptTools.aes_cbc_encrypt_ia32(file_mac, bin2i32a(_upload.getByte_file_key()), mac_iv);
|
||||
|
||||
_bytes_read+=chunk.getSize();
|
||||
_bytes_read += chunk.getSize();
|
||||
|
||||
} catch (IOException | NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException ex) {
|
||||
getLogger(UploadMACGenerator.class.getName()).log(Level.SEVERE, null, ex);
|
||||
@ -174,11 +165,11 @@ public final class UploadMACGenerator implements Runnable, SecureNotifiable {
|
||||
|
||||
}
|
||||
|
||||
if(new_chunk) {
|
||||
if (new_chunk) {
|
||||
|
||||
temp_file_data = (String.valueOf(_last_chunk_id_read)+"|"+String.valueOf(_bytes_read)+"|"+Bin2BASE64(i32a2bin(file_mac)));
|
||||
temp_file_data = (String.valueOf(_last_chunk_id_read) + "|" + String.valueOf(_bytes_read) + "|" + Bin2BASE64(i32a2bin(file_mac)));
|
||||
|
||||
System.out.println("Macgenerator -> "+temp_file_data);
|
||||
System.out.println("Macgenerator -> " + temp_file_data);
|
||||
|
||||
temp_file_out = new FileOutputStream(temp_file);
|
||||
|
||||
@ -189,16 +180,15 @@ public final class UploadMACGenerator implements Runnable, SecureNotifiable {
|
||||
new_chunk = false;
|
||||
}
|
||||
|
||||
if(!_exit && (!_upload.isStopped() || !_upload.getChunkworkers().isEmpty()) && (_bytes_read < _upload.getFile_size() || (_upload.getFile_size() == 0 && _last_chunk_id_read < 1)))
|
||||
{
|
||||
if (!_exit && (!_upload.isStopped() || !_upload.getChunkworkers().isEmpty()) && (_bytes_read < _upload.getFile_size() || (_upload.getFile_size() == 0 && _last_chunk_id_read < 1))) {
|
||||
System.out.println("METAMAC wait...");
|
||||
secureWait();
|
||||
}
|
||||
}
|
||||
|
||||
if(_bytes_read == _upload.getFile_size()) {
|
||||
if (_bytes_read == _upload.getFile_size()) {
|
||||
|
||||
int[] meta_mac={file_mac[0]^file_mac[1], file_mac[2]^file_mac[3]};
|
||||
int[] meta_mac = {file_mac[0] ^ file_mac[1], file_mac[2] ^ file_mac[3]};
|
||||
|
||||
_upload.setFile_meta_mac(meta_mac);
|
||||
}
|
||||
|
@ -8,8 +8,6 @@ import static java.util.logging.Logger.getLogger;
|
||||
import static megabasterd.DBTools.deleteUpload;
|
||||
import static megabasterd.MiscTools.HashString;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tonikelope
|
||||
@ -23,30 +21,29 @@ public final class UploadManager extends TransferenceManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void provision(Transference upload)
|
||||
{
|
||||
getScroll_panel().add(((Upload)upload).getView());
|
||||
public void provision(Transference upload) {
|
||||
getScroll_panel().add(((Upload) upload).getView());
|
||||
|
||||
((Upload)upload).provisionIt();
|
||||
((Upload) upload).provisionIt();
|
||||
|
||||
if(((Upload)upload).isProvision_ok()) {
|
||||
if (((Upload) upload).isProvision_ok()) {
|
||||
|
||||
getTransference_waitstart_queue().add(upload);
|
||||
|
||||
if(getTransference_provision_queue().isEmpty()) {
|
||||
if (getTransference_provision_queue().isEmpty()) {
|
||||
|
||||
sortTransferenceStartQueue();
|
||||
|
||||
for(Transference up:getTransference_waitstart_queue()) {
|
||||
for (Transference up : getTransference_waitstart_queue()) {
|
||||
|
||||
getScroll_panel().remove((Component)up.getView());
|
||||
getScroll_panel().add((Component)up.getView());
|
||||
getScroll_panel().remove((Component) up.getView());
|
||||
getScroll_panel().add((Component) up.getView());
|
||||
}
|
||||
|
||||
for(Transference up:getTransference_finished_queue()) {
|
||||
for (Transference up : getTransference_finished_queue()) {
|
||||
|
||||
getScroll_panel().remove((Component)up.getView());
|
||||
getScroll_panel().add((Component)up.getView());
|
||||
getScroll_panel().remove((Component) up.getView());
|
||||
getScroll_panel().add((Component) up.getView());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -57,11 +54,10 @@ public final class UploadManager extends TransferenceManager {
|
||||
secureNotify();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void remove(Transference upload) {
|
||||
|
||||
getScroll_panel().remove(((Upload)upload).getView());
|
||||
getScroll_panel().remove(((Upload) upload).getView());
|
||||
|
||||
getTransference_waitstart_queue().remove(upload);
|
||||
|
||||
@ -69,19 +65,19 @@ public final class UploadManager extends TransferenceManager {
|
||||
|
||||
getTransference_finished_queue().remove(upload);
|
||||
|
||||
if(((Upload)upload).isProvision_ok()) {
|
||||
if (((Upload) upload).isProvision_ok()) {
|
||||
|
||||
try {
|
||||
deleteUpload(upload.getFile_name(), ((Upload)upload).getMa().getEmail());
|
||||
deleteUpload(upload.getFile_name(), ((Upload) upload).getMa().getEmail());
|
||||
} catch (SQLException ex) {
|
||||
getLogger(UploadManager.class.getName()).log(SEVERE, null, ex);
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
File temp_file = new File("."+HashString("SHA-1", upload.getFile_name()));
|
||||
File temp_file = new File("." + HashString("SHA-1", upload.getFile_name()));
|
||||
|
||||
if(temp_file.exists()) {
|
||||
if (temp_file.exists()) {
|
||||
|
||||
temp_file.delete();
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ import javax.swing.JSpinner;
|
||||
import javax.swing.SpinnerNumberModel;
|
||||
import static megabasterd.MainPanel.FONT_DEFAULT;
|
||||
import static megabasterd.MainPanel.THREAD_POOL;
|
||||
import static megabasterd.MiscTools.copyTextToClipboard;
|
||||
import static megabasterd.MiscTools.swingReflectionInvoke;
|
||||
import static megabasterd.MiscTools.swingReflectionInvokeAndWait;
|
||||
import static megabasterd.MiscTools.updateFont;
|
||||
@ -82,14 +81,13 @@ public final class UploadView extends javax.swing.JPanel implements Transference
|
||||
return status_label;
|
||||
}
|
||||
|
||||
|
||||
public UploadView(Upload upload){
|
||||
public UploadView(Upload upload) {
|
||||
|
||||
initComponents();
|
||||
|
||||
_upload = upload;
|
||||
|
||||
MiscTools.swingInvokeIt(new Runnable(){
|
||||
MiscTools.swingInvokeIt(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
@ -110,16 +108,16 @@ public final class UploadView extends javax.swing.JPanel implements Transference
|
||||
updateFont(restart_button, FONT_DEFAULT, PLAIN);
|
||||
updateFont(slot_status_label, FONT_DEFAULT, BOLD);
|
||||
|
||||
|
||||
}}, true);
|
||||
}
|
||||
}, true);
|
||||
|
||||
swingReflectionInvokeAndWait("setModel", slots_spinner, new SpinnerNumberModel(_upload.getMain_panel().getDefault_slots_up(), MIN_WORKERS, MAX_WORKERS, 1));
|
||||
|
||||
swingReflectionInvoke("setEditable", ((JSpinner.DefaultEditor)slots_spinner.getEditor()).getTextField(), false);
|
||||
swingReflectionInvoke("setEditable", ((JSpinner.DefaultEditor) slots_spinner.getEditor()).getTextField(), false);
|
||||
|
||||
swingReflectionInvoke("setVisible", new Object[]{slots_spinner, slots_label,pause_button,stop_button,speed_label,remtime_label,progress_pbar,file_name_label,close_button,restart_button,file_size_label}, false);
|
||||
swingReflectionInvoke("setVisible", new Object[]{slots_spinner, slots_label, pause_button, stop_button, speed_label, remtime_label, progress_pbar, file_name_label, close_button, restart_button, file_size_label}, false);
|
||||
|
||||
swingReflectionInvoke("setForeground", speed_label, new Color(0,128,255));
|
||||
swingReflectionInvoke("setForeground", speed_label, new Color(0, 128, 255));
|
||||
|
||||
}
|
||||
|
||||
@ -326,7 +324,7 @@ public final class UploadView extends javax.swing.JPanel implements Transference
|
||||
|
||||
private void slots_spinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_slots_spinnerStateChanged
|
||||
|
||||
THREAD_POOL.execute(new Runnable(){
|
||||
THREAD_POOL.execute(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
@ -356,9 +354,8 @@ public final class UploadView extends javax.swing.JPanel implements Transference
|
||||
|
||||
}//GEN-LAST:event_pause_buttonActionPerformed
|
||||
|
||||
public void hideAllExceptStatus()
|
||||
{
|
||||
swingReflectionInvoke("setVisible", new Object[]{speed_label, remtime_label, slots_spinner, slots_label,slot_status_label,pause_button,stop_button,progress_pbar}, false);
|
||||
public void hideAllExceptStatus() {
|
||||
swingReflectionInvoke("setVisible", new Object[]{speed_label, remtime_label, slots_spinner, slots_label, slot_status_label, pause_button, stop_button, progress_pbar}, false);
|
||||
}
|
||||
|
||||
private void folder_link_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_folder_link_buttonActionPerformed
|
||||
@ -367,7 +364,7 @@ public final class UploadView extends javax.swing.JPanel implements Transference
|
||||
|
||||
folder_link_button.setText("Please wait...");
|
||||
|
||||
copyTextToClipboard(_upload.getFolder_link());
|
||||
MiscTools.copyTextToClipboard(_upload.getFolder_link());
|
||||
|
||||
folder_link_button.setText("Copy folder link");
|
||||
|
||||
@ -382,7 +379,7 @@ public final class UploadView extends javax.swing.JPanel implements Transference
|
||||
|
||||
file_link_button.setText("Please wait...");
|
||||
|
||||
copyTextToClipboard(_upload.getFile_link());
|
||||
MiscTools.copyTextToClipboard(_upload.getFile_link());
|
||||
|
||||
file_link_button.setText("Copy file link");
|
||||
|
||||
@ -392,13 +389,12 @@ public final class UploadView extends javax.swing.JPanel implements Transference
|
||||
|
||||
}//GEN-LAST:event_file_link_buttonActionPerformed
|
||||
|
||||
|
||||
@Override
|
||||
public void pause() {
|
||||
|
||||
printStatusNormal("Pausing upload ...");
|
||||
|
||||
swingReflectionInvoke("setEnabled", new Object[]{pause_button,speed_label,slots_label,slots_spinner}, false);
|
||||
swingReflectionInvoke("setEnabled", new Object[]{pause_button, speed_label, slots_label, slots_spinner}, false);
|
||||
swingReflectionInvoke("setVisible", stop_button, true);
|
||||
|
||||
}
|
||||
@ -408,7 +404,7 @@ public final class UploadView extends javax.swing.JPanel implements Transference
|
||||
|
||||
printStatusNormal("Stopping upload safely, please wait...");
|
||||
|
||||
swingReflectionInvoke("setEnabled", new Object[]{pause_button,stop_button,speed_label,slots_label,slots_spinner}, false);
|
||||
swingReflectionInvoke("setEnabled", new Object[]{pause_button, stop_button, speed_label, slots_label, slots_spinner}, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -416,7 +412,7 @@ public final class UploadView extends javax.swing.JPanel implements Transference
|
||||
|
||||
printStatusNormal("Uploading file to mega ...");
|
||||
|
||||
swingReflectionInvoke("setEnabled", new Object[]{pause_button,speed_label,slots_label,slots_spinner}, true);
|
||||
swingReflectionInvoke("setEnabled", new Object[]{pause_button, speed_label, slots_label, slots_spinner}, true);
|
||||
swingReflectionInvoke("setVisible", stop_button, false);
|
||||
swingReflectionInvoke("setText", pause_button, "PAUSE UPLOAD");
|
||||
swingReflectionInvoke("setVisible", _upload.getMain_panel().getView().getPause_all_up_button(), true);
|
||||
@ -425,12 +421,12 @@ public final class UploadView extends javax.swing.JPanel implements Transference
|
||||
@Override
|
||||
public void updateSpeed(String sp, Boolean visible) {
|
||||
|
||||
if(sp != null) {
|
||||
if (sp != null) {
|
||||
|
||||
swingReflectionInvoke("setText", speed_label, sp);
|
||||
}
|
||||
|
||||
if(visible != null) {
|
||||
if (visible != null) {
|
||||
|
||||
swingReflectionInvoke("setVisible", speed_label, visible);
|
||||
}
|
||||
@ -439,12 +435,12 @@ public final class UploadView extends javax.swing.JPanel implements Transference
|
||||
@Override
|
||||
public void updateRemainingTime(String remtime, Boolean visible) {
|
||||
|
||||
if(remtime != null) {
|
||||
if (remtime != null) {
|
||||
|
||||
swingReflectionInvoke("setText", remtime_label, remtime);
|
||||
}
|
||||
|
||||
if(visible != null) {
|
||||
if (visible != null) {
|
||||
|
||||
swingReflectionInvoke("setVisible", remtime_label, visible);
|
||||
}
|
||||
@ -453,7 +449,7 @@ public final class UploadView extends javax.swing.JPanel implements Transference
|
||||
@Override
|
||||
public void updateProgressBar(long progress, double bar_rate) {
|
||||
|
||||
swingReflectionInvoke("setValue", progress_pbar, (int)Math.ceil(bar_rate*progress));
|
||||
swingReflectionInvoke("setValue", progress_pbar, (int) Math.ceil(bar_rate * progress));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -464,7 +460,7 @@ public final class UploadView extends javax.swing.JPanel implements Transference
|
||||
|
||||
@Override
|
||||
public void printStatusOK(String msg) {
|
||||
swingReflectionInvoke("setForeground", status_label, new Color(0,128,0));
|
||||
swingReflectionInvoke("setForeground", status_label, new Color(0, 128, 0));
|
||||
swingReflectionInvoke("setText", status_label, msg);
|
||||
}
|
||||
|
||||
@ -480,9 +476,9 @@ public final class UploadView extends javax.swing.JPanel implements Transference
|
||||
|
||||
int conta_exit = 0;
|
||||
|
||||
for(ChunkUploader c:_upload.getChunkworkers()) {
|
||||
for (ChunkUploader c : _upload.getChunkworkers()) {
|
||||
|
||||
if(c.isExit()) {
|
||||
if (c.isExit()) {
|
||||
|
||||
conta_exit++;
|
||||
}
|
||||
@ -490,15 +486,15 @@ public final class UploadView extends javax.swing.JPanel implements Transference
|
||||
|
||||
int conta_error = 0;
|
||||
|
||||
for(ChunkUploader c:_upload.getChunkworkers()) {
|
||||
for (ChunkUploader c : _upload.getChunkworkers()) {
|
||||
|
||||
if(c.isError_wait()) {
|
||||
if (c.isError_wait()) {
|
||||
|
||||
conta_error++;
|
||||
}
|
||||
}
|
||||
|
||||
if(conta_error > 0) {
|
||||
if (conta_error > 0) {
|
||||
|
||||
swingReflectionInvoke("setForeground", slot_status_label, Color.red);
|
||||
|
||||
@ -507,10 +503,9 @@ public final class UploadView extends javax.swing.JPanel implements Transference
|
||||
swingReflectionInvoke("setForeground", slot_status_label, Color.black);
|
||||
}
|
||||
|
||||
swingReflectionInvoke("setText", slot_status_label, (conta_exit>0?"Removing: "+conta_exit:"") + (conta_error>0?((conta_exit>0?" / ":"")+"Error: " + conta_error):""));
|
||||
swingReflectionInvoke("setText", slot_status_label, (conta_exit > 0 ? "Removing: " + conta_exit : "") + (conta_error > 0 ? ((conta_exit > 0 ? " / " : "") + "Error: " + conta_error) : ""));
|
||||
}
|
||||
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JButton close_button;
|
||||
private javax.swing.JButton file_link_button;
|
||||
|
Loading…
x
Reference in New Issue
Block a user