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;
import Common.CurrentAnchestor;
2024-10-07 14:22:52 +03:00
import Common.Utils.CommonUtils;
2024-10-08 22:33:49 +03:00
import Common.Visual.CommonUI;
import Common_old.Current;
import _VisualDVM.Global;
import Common_old.UI.UI;
import Common_old.Utils.Utils;
2023-09-17 22:13:42 +03:00
import GlobalData.RemoteFile.RemoteFile;
import Visual_DVM_2021.Passes.PassCode_2021;
import Visual_DVM_2021.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 = Current.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) {
2023-09-17 22:13:42 +03:00
ShowMessage2("Запаковка папки проекта..");
user.connection.Command(
2024-10-07 14:22:52 +03:00
"cd " + CommonUtils.DQuotes(src.full_name),
"zip -r " + CommonUtils.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 {
//диалога не вышло, сбрасываем файл.
CurrentAnchestor.set(Current.RemoteFile, null);
2023-09-17 22:13:42 +03:00
}
}
@Override
protected boolean validate() {
CurrentAnchestor.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-07 22:22:51 +03:00
CommonUtils.getDateName(src.name)).toFile();
2023-09-17 22:13:42 +03:00
if (passes.get(PassCode_2021.UnzipFolderPass).Do(local_archive.getAbsolutePath(), project.getAbsolutePath())) {
2024-10-08 22:33:49 +03:00
if (CommonUI.Question("Проект " + CommonUtils.Brackets(src.name) + " успешно загружен. Открыть его"))
2023-09-17 22:13:42 +03:00
passes.get(PassCode_2021.OpenCurrentProject).Do(project);
}
}
}