Files
VisualSapfor/src/Visual_DVM_2021/Passes/All/DownloadProject.java

63 lines
2.8 KiB
Java
Raw Normal View History

package Visual_DVM_2021.Passes.All;
2024-10-09 23:37:58 +03:00
import Common.Current_;
2024-10-11 00:00:30 +03:00
import Common.Utils.Utils_;
import Common.Visual.UI_;
2024-10-09 22:01:19 +03:00
import _VisualDVM.Current;
import _VisualDVM.Global;
2024-10-09 22:01:19 +03:00
import _VisualDVM.Visual.UI;
import _VisualDVM.Utils;
2024-10-09 22:21:57 +03:00
import _VisualDVM.GlobalData.RemoteFile.RemoteFile;
2024-10-09 23:37:58 +03:00
import Visual_DVM_2021.Passes.PassCode;
2024-10-10 23:57:36 +03:00
import Common.Passes.PassException;
import Visual_DVM_2021.Passes.SSH.CurrentConnectionPass;
2023-09-17 22:13:42 +03:00
import java.io.File;
import java.nio.file.Paths;
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 = (UI.getRemoteFileChooser().ShowDialog(getDescription(), this, true));
if (dialogOK) {
src = Global.mainModule.getRemoteFile();
2023-09-17 22:13:42 +03:00
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) {
2023-09-17 22:13:42 +03:00
ShowMessage2("Запаковка папки проекта..");
user.connection.Command(
2024-10-11 00:00:30 +03:00
"cd " + Utils_.DQuotes(src.full_name),
"zip -r " + Utils_.DQuotes(remote_archive.full_name) + " ./"
2023-09-17 22:13:42 +03:00
);
// try {
ShowMessage2("Загрузка проекта..");
user.connection.getSingleFile(remote_archive.full_name, local_archive.getAbsolutePath());
2023-09-17 22:13:42 +03:00
// } catch (Exception ex) {
// throw new PassException("Ошибка загрузки");
// }
user.connection.sftpChannel.rm(remote_archive.full_name);
2023-09-17 22:13:42 +03:00
} else throw new PassException("Размер проекта превышает " + maxSize + " KB.\n");
} else {
//диалога не вышло, сбрасываем файл.
Global.mainModule.set(Current.RemoteFile, null);
2023-09-17 22:13:42 +03:00
}
}
@Override
protected boolean validate() {
Global.mainModule.Check(Log, Current.RemoteFile);
2023-09-17 22:13:42 +03:00
return (Log.isEmpty());
}
@Override
protected void performDone() throws Exception {
File project = Paths.get(Global.visualiser.getWorkspace().getAbsolutePath(),
2024-10-11 00:00:30 +03:00
Utils_.getDateName(src.name)).toFile();
2024-10-09 23:37:58 +03:00
if (passes.get(PassCode.UnzipFolderPass).Do(local_archive.getAbsolutePath(), project.getAbsolutePath())) {
2024-10-11 00:00:30 +03:00
if (UI_.Question("Проект " + Utils_.Brackets(src.name) + " успешно загружен. Открыть его"))
2024-10-09 23:37:58 +03:00
passes.get(PassCode.OpenCurrentProject).Do(project);
2023-09-17 22:13:42 +03:00
}
}
}