2023-11-19 02:12:44 +03:00
|
|
|
|
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;
|
2024-10-07 00:58:29 +03:00
|
|
|
|
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;
|
2023-11-19 02:12:44 +03:00
|
|
|
|
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) {
|
2024-10-13 22:08:13 +03:00
|
|
|
|
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);
|
2024-01-08 20:37:16 +03:00
|
|
|
|
if ((user.connection.getFileKBSize(src.full_name)) <= maxSize) {
|
2023-09-17 22:13:42 +03:00
|
|
|
|
ShowMessage2("Запаковка папки проекта..");
|
2024-01-08 20:37:16 +03:00
|
|
|
|
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("Загрузка проекта..");
|
2024-01-08 20:37:16 +03:00
|
|
|
|
user.connection.getSingleFile(remote_archive.full_name, local_archive.getAbsolutePath());
|
2023-09-17 22:13:42 +03:00
|
|
|
|
// } catch (Exception ex) {
|
|
|
|
|
|
// throw new PassException("Ошибка загрузки");
|
|
|
|
|
|
// }
|
2024-01-08 20:37:16 +03:00
|
|
|
|
user.connection.sftpChannel.rm(remote_archive.full_name);
|
2023-09-17 22:13:42 +03:00
|
|
|
|
} else throw new PassException("Размер проекта превышает " + maxSize + " KB.\n");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
//диалога не вышло, сбрасываем файл.
|
2024-10-13 22:08:13 +03:00
|
|
|
|
Global.mainModule.set(Current.RemoteFile, null);
|
2023-09-17 22:13:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected boolean validate() {
|
2024-10-13 22:08:13 +03:00
|
|
|
|
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-13 23:55:03 +03:00
|
|
|
|
if ( Global.mainModule.getPass(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-13 23:55:03 +03:00
|
|
|
|
Global.mainModule.getPass(PassCode.OpenCurrentProject).Do(project);
|
2023-09-17 22:13:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|