-Chunks temp dir added fix
-Auto close
This commit is contained in:
tonikelope 2019-03-26 21:17:03 +01:00
parent 525df3d43f
commit 6bfeb1dade
9 changed files with 88 additions and 11 deletions

View File

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

View File

@ -232,11 +232,11 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
} else {
chunk_file = new File(_download.getChunkmanager().getChunks_dir() + "/" + _download.getFile_name() + ".chunk" + chunk_id);
chunk_file = new File(_download.getChunkmanager().getChunks_dir() + "/" + new File(_download.getFile_name()).getName() + ".chunk" + chunk_id);
if (!chunk_file.exists() || chunk_file.length() != chunk_size) {
tmp_chunk_file = new File(_download.getChunkmanager().getChunks_dir() + "/" + _download.getFile_name() + ".chunk" + chunk_id + ".tmp");
tmp_chunk_file = new File(_download.getChunkmanager().getChunks_dir() + "/" + new File(_download.getFile_name()).getName() + ".chunk" + chunk_id + ".tmp");
try (InputStream is = new ThrottledInputStream(con.getInputStream(), _download.getMain_panel().getStream_supervisor()); FileOutputStream tmp_chunk_file_os = new FileOutputStream(tmp_chunk_file)) {

View File

@ -75,7 +75,7 @@ public final class ChunkManager implements Runnable, SecureSingleThreadNotifiabl
_notified = false;
_exit = false;
_download = downloader;
_chunks_dir = _download.getDownload_path() + "/.mb_chunks_" + _download.getFile_name();
_chunks_dir = _create_chunks_temp_dir();
_secure_notify_lock = new Object();
_file_size = _download.getFile_size();
_byte_file_key = initMEGALinkKey(_download.getFile_key());
@ -93,8 +93,6 @@ public final class ChunkManager implements Runnable, SecureSingleThreadNotifiabl
_bytes_written = _download.getProgress();
}
_create_chunks_temp_dir();
Logger.getLogger(getClass().getName()).log(Level.INFO, "{0} Chunkmanager hello LAST CHUNK WRITTEN -> [{1}] {2}...", new Object[]{Thread.currentThread().getName(), _last_chunk_id_written, _bytes_written});
}
@ -135,10 +133,15 @@ public final class ChunkManager implements Runnable, SecureSingleThreadNotifiabl
return _last_chunk_id_written;
}
private void _create_chunks_temp_dir() {
private String _create_chunks_temp_dir() {
File chunks_temp_dir = new File(_download.getDownload_path() + "/.mb_chunks_" + new File(_download.getFile_name()).getName());
File chunks_temp_dir = new File(getChunks_dir());
chunks_temp_dir.mkdirs();
System.out.println(chunks_temp_dir.getAbsolutePath());
return chunks_temp_dir.getAbsolutePath();
}
public void delete_chunks_temp_dir() {
@ -162,7 +165,7 @@ public final class ChunkManager implements Runnable, SecureSingleThreadNotifiabl
if (_file_size > 0) {
while (!_exit && (!_download.isStopped() || !_download.getChunkworkers().isEmpty()) && _bytes_written < _file_size) {
File chunk_file = new File(getChunks_dir() + "/" + _download.getFile_name() + ".chunk" + String.valueOf(_last_chunk_id_written + 1));
File chunk_file = new File(getChunks_dir() + "/" + new File(_download.getFile_name()).getName() + ".chunk" + String.valueOf(_last_chunk_id_written + 1));
while (chunk_file.exists() && chunk_file.canRead()) {
@ -197,7 +200,7 @@ public final class ChunkManager implements Runnable, SecureSingleThreadNotifiabl
chunk_file.delete();
chunk_file = new File(getChunks_dir() + "/" + _download.getFile_name() + ".chunk" + String.valueOf(_last_chunk_id_written + 1));
chunk_file = new File(getChunks_dir() + "/" + new File(_download.getFile_name()).getName() + ".chunk" + String.valueOf(_last_chunk_id_written + 1));
}
if (!_exit && (!_download.isStopped() || !_download.getChunkworkers().isEmpty()) && _bytes_written < _file_size) {

View File

@ -262,6 +262,7 @@ public final class LabelTranslatorSingleton {
_addTranslation("Streaming server: ON (port ", "Servidor de streaming: ON (puerto ");
_addTranslation("MC reverse mode: ON (port ", "MC reverse mode: ON (puerto ");
_addTranslation("Joining file chunks, please wait...", "Juntando chunks, por favor espera...");
_addTranslation("Close MegaBasterd when all transfers finish", "Cerrar MegaBasterd cuando todas las transferencias terminen");
}

View File

@ -28,6 +28,8 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Timer;
import java.util.TimerTask;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import static java.util.concurrent.Executors.newCachedThreadPool;
@ -48,7 +50,7 @@ import javax.swing.UIManager;
*/
public final class MainPanel {
public static final String VERSION = "6.3";
public static final String VERSION = "6.4";
public static final int THROTTLE_SLICE_SIZE = 16 * 1024;
public static final int DEFAULT_BYTE_BUFFER_SIZE = 16 * 1024;
public static final int STREAMER_PORT = 1337;
@ -253,6 +255,48 @@ public final class MainPanel {
THREAD_POOL.execute((_clipboardspy = new ClipboardSpy()));
THREAD_POOL.execute(new Runnable() {
@Override
public void run() {
Object timer_lock = new Object();
Timer timer = new Timer();
TimerTask task = new TimerTask() {
@Override
public void run() {
synchronized (timer_lock) {
timer_lock.notify();
}
}
};
timer.schedule(task, 0, 5000);
while (true) {
synchronized (timer_lock) {
try {
if (_download_manager.no_transferences() && _upload_manager.no_transferences() && (!_download_manager.getTransference_finished_queue().isEmpty() || !_upload_manager.getTransference_finished_queue().isEmpty()) && getView().getAuto_close_menu().isSelected()) {
System.exit(0);
}
timer_lock.wait();
} catch (InterruptedException ex) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
}
}
}
}
});
try {
_streamserver = new KissVideoStreamServer(this);
_streamserver.start(STREAMER_PORT, "/video");

View File

@ -131,6 +131,18 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="hide_tray_menuActionPerformed"/>
</Events>
</MenuItem>
<MenuItem class="javax.swing.JCheckBoxMenuItem" name="auto_close_menu">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Dialog" size="18" style="0"/>
</Property>
<Property name="text" type="java.lang.String" value="Close MegaBasterd when all transfers finish"/>
<Property name="doubleBuffered" type="boolean" value="true"/>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/images/icons8-cancel-30.png"/>
</Property>
</Properties>
</MenuItem>
<MenuItem class="javax.swing.JMenuItem" name="exit_menu">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">

View File

@ -25,6 +25,7 @@ import static java.util.logging.Level.SEVERE;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
@ -128,6 +129,10 @@ public final class MainPanelView extends javax.swing.JFrame {
return mc_reverse_status;
}
public JCheckBoxMenuItem getAuto_close_menu() {
return auto_close_menu;
}
public void updateKissStreamServerStatus(final String status) {
String old_status = getKiss_server_status().getText();
@ -294,6 +299,7 @@ public final class MainPanelView extends javax.swing.JFrame {
clean_all_up_menu = new javax.swing.JMenuItem();
jSeparator2 = new javax.swing.JPopupMenu.Separator();
hide_tray_menu = new javax.swing.JMenuItem();
auto_close_menu = new javax.swing.JCheckBoxMenuItem();
exit_menu = new javax.swing.JMenuItem();
edit_menu = new javax.swing.JMenu();
settings_menu = new javax.swing.JMenuItem();
@ -548,6 +554,12 @@ public final class MainPanelView extends javax.swing.JFrame {
});
file_menu.add(hide_tray_menu);
auto_close_menu.setFont(new java.awt.Font("Dialog", 0, 18)); // NOI18N
auto_close_menu.setText("Close MegaBasterd when all transfers finish");
auto_close_menu.setDoubleBuffered(true);
auto_close_menu.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icons8-cancel-30.png"))); // NOI18N
file_menu.add(auto_close_menu);
exit_menu.setFont(new java.awt.Font("Dialog", 0, 18)); // NOI18N
exit_menu.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icons8-shutdown-30.png"))); // NOI18N
exit_menu.setText("Exit");
@ -1215,6 +1227,7 @@ public final class MainPanelView extends javax.swing.JFrame {
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JMenuItem about_menu;
private javax.swing.JCheckBoxMenuItem auto_close_menu;
private javax.swing.JMenuItem clean_all_down_menu;
private javax.swing.JMenuItem clean_all_up_menu;
private javax.swing.JButton close_all_finished_down_button;

View File

@ -83,6 +83,10 @@ abstract public class TransferenceManager implements Runnable, SecureSingleThrea
_transference_preprocess_queue = new ConcurrentLinkedQueue<>();
}
public boolean no_transferences() {
return getTransference_preprocess_queue().isEmpty() && getTransference_provision_queue().isEmpty() && getTransference_waitstart_queue().isEmpty() && getTransference_running_list().isEmpty();
}
public boolean isPaused_all() {
return _paused_all;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 178 KiB

After

Width:  |  Height:  |  Size: 182 KiB