Files
VisualSapfor/src/_VisualDVM/Passes/All/DownloadSapforPackage.java

59 lines
2.2 KiB
Java
Raw Normal View History

2024-10-14 12:14:01 +03:00
package _VisualDVM.Passes.All;
import Common.CommonConstants;
2024-10-14 15:19:13 +03:00
import Common.Passes.Pass;
2024-10-11 00:00:30 +03:00
import Common.Utils.Utils_;
import _VisualDVM.Global;
2024-10-14 15:19:13 +03:00
import _VisualDVM.Passes.PassCode;
2025-02-04 16:24:32 +03:00
import _VisualDVM.Passes.Server.TestingSystemPass_OLD;
2024-10-09 22:21:57 +03:00
import _VisualDVM.Repository.Server.ServerCode;
import _VisualDVM.Repository.Server.ServerExchangeUnit_2021;
import _VisualDVM.TestingSystem.SAPFOR.SapforPackage.SapforPackage;
2024-10-14 15:19:13 +03:00
import _VisualDVM.Utils;
2023-12-18 00:04:44 +03:00
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.util.Date;
2024-10-09 23:37:58 +03:00
public class DownloadSapforPackage extends Pass<SapforPackage> {
2024-10-14 15:19:13 +03:00
File loaded;
byte[] packed;
2023-12-18 00:04:44 +03:00
@Override
protected boolean needsAnimation() {
return true;
}
@Override
protected boolean canStart(Object... args) throws Exception {
target = (SapforPackage) args[0];
2024-10-14 15:19:13 +03:00
if (!target.state.isDone()) {
2023-12-18 00:04:44 +03:00
Log.Writeln_("Возможно загрузить только завершенный пакет.");
return false;
}
int id = target.id;
loaded = new File(target.getLocalWorkspace(), CommonConstants.LOADED);
2024-10-14 15:19:13 +03:00
if (!loaded.exists()) {
2025-02-04 16:24:32 +03:00
Pass pass = new TestingSystemPass_OLD() {
2023-12-18 00:04:44 +03:00
@Override
public String getDescription() {
2024-10-14 15:19:13 +03:00
return "Скачивание";
2023-12-18 00:04:44 +03:00
}
@Override
protected void ServerAction() throws Exception {
2024-10-14 15:19:13 +03:00
Command(new ServerExchangeUnit_2021(ServerCode.DownloadSapforPackage, "", id));
packed = (byte[]) server_response.object;
2023-12-18 00:04:44 +03:00
}
};
return pass.Do();
2024-10-14 15:19:13 +03:00
}
;
2023-12-18 00:04:44 +03:00
return false;
}
@Override
protected void body() throws Exception {
File workspace = target.getLocalWorkspace();
2024-10-14 12:54:52 +03:00
Utils_.forceDeleteWithCheck(workspace);
2023-12-18 00:04:44 +03:00
File archive = Utils.getTempFileName(String.valueOf(target.id));
2024-10-14 15:19:13 +03:00
Utils_.bytesToFile(packed, archive);
Global.mainModule.getPass(PassCode.UnzipFolderPass).Do(archive.getAbsolutePath(), Global.SapforPackagesDirectory.getAbsolutePath());
2023-12-18 00:04:44 +03:00
FileUtils.writeStringToFile(loaded, new Date().toString());
}
}