package Visual_DVM_2021.Passes.All;
import Common.Constants;
import Common.Current;
import Common.Global;
import TestingSystem.Common.TasksPackageState;
import TestingSystem.DVM.DVMPackage.DVMPackage;

import java.io.File;
import java.util.Vector;
public class DownloadDVMPackage extends DownloadDVMPackages {
    DVMPackage dvmPackage;
    protected boolean canStart(Object... args) throws Exception {
        if (Current.Check(Log, Current.DVMPackage)) {
            //--
            dvmPackage = Current.getDVMPackage();
            //--
            if (!dvmPackage.state.equals(TasksPackageState.Done)) {
                Log.Writeln_("Возможно скачать и отобразить задачи только завершённого пакета!");
                return false;
            }
            if (new File(dvmPackage.getLocalWorkspace(), Constants.LOADED).exists()) {
                Global.testingServer.db.dvmRunTasks.ShowDVMPackage(dvmPackage);
                return false;
            }
            Vector<Integer> packages = new Vector<>();
            packages.add(dvmPackage.id);
            return super.canStart(packages);
        }
        return false;
    }
    @Override
    protected void showDone() throws Exception {
        Global.testingServer.db.dvmRunTasks.ShowDVMPackage(dvmPackage);
    }
}
