Files
VisualSapfor/src/_VisualDVM/Passes/All/DownloadProject.java
2025-01-29 15:20:24 +03:00

59 lines
2.7 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package _VisualDVM.Passes.All;
import Common.Passes.PassException;
import Common.Utils.Utils_;
import Common.Visual.UI;
import _VisualDVM.Current;
import _VisualDVM.Global;
import _VisualDVM.GlobalData.RemoteFile.RemoteFile;
import _VisualDVM.Passes.PassCode;
import _VisualDVM.Passes.SSH.CurrentConnectionPass;
import _VisualDVM.Utils;
import java.io.File;
public class DownloadProject extends CurrentConnectionPass {
private static final int maxSize = 10240;
boolean dialogOK = false;
RemoteFile src;
RemoteFile remote_archive;
File local_archive;
@Override
protected void ServerAction() throws Exception {
dialogOK = (Global.mainModule.getUI().getRemoteFileChooser().ShowDialog(getDescription(), this, true));
if (dialogOK) {
src = Global.mainModule.getRemoteFile();
remote_archive = new RemoteFile(src.full_name, src.name + ".zip", false);
local_archive = Utils.getTempFileName(remote_archive.name);
if ((user.connection.getFileKBSize(src.full_name)) <= maxSize) {
ShowMessage2("Запаковка папки проекта..");
user.connection.Command(
"cd " + Utils_.DQuotes(src.full_name),
"zip -r " + Utils_.DQuotes(remote_archive.full_name) + " ./"
);
// try {
ShowMessage2("Загрузка проекта..");
user.connection.getSingleFile(remote_archive.full_name, local_archive.getAbsolutePath());
// } catch (Exception ex) {
// throw new PassException("Ошибка загрузки");
// }
user.connection.sftpChannel.rm(remote_archive.full_name);
} else throw new PassException("Размер проекта превышает " + maxSize + " KB.\n");
} else {
//диалога не вышло, сбрасываем файл.
Global.mainModule.set(Current.RemoteFile, null);
}
}
@Override
protected boolean validate() {
Global.mainModule.Check(Log, Current.RemoteFile);
return (Log.isEmpty());
}
@Override
protected void performDone() throws Exception {
File project = new File(Global.visualiser.getDownloadsDirectory(), Utils_.getDateName(src.name));
if (Global.mainModule.getPass(PassCode.UnzipFolderPass).Do(local_archive.getAbsolutePath(), project.getAbsolutePath())) {
if (UI.Question("Проект " + Utils_.Brackets(src.name) + " успешно загружен. Открыть его"))
Global.mainModule.getPass(PassCode.OpenCurrentProject).Do(project);
}
}
}