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

54 lines
2.0 KiB
Java
Raw Normal View History

2024-10-14 12:14:01 +03:00
package _VisualDVM.Passes.All;
2024-10-14 15:19:13 +03:00
import Common.Visual.Windows.Dialog.VFileChooser;
import _VisualDVM.Global;
2024-10-09 22:01:19 +03:00
import _VisualDVM.GlobalProperties;
2024-10-14 12:14:01 +03:00
import _VisualDVM.Passes.CurrentComponentPass;
2023-09-17 22:13:42 +03:00
import java.io.File;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
public class InstallComponentFromFolder extends CurrentComponentPass {
File file;
@Override
public String getIconPath() {
return "/Common/icons/Search.png";
2023-09-17 22:13:42 +03:00
}
@Override
public String getButtonText() {
return "";
}
@Override
protected boolean canStart(Object... args) throws Exception {
2024-10-14 15:19:13 +03:00
if (super.canStart(args)) {
2023-09-17 22:13:42 +03:00
VFileChooser fileChooser = target.getFileChooser();
2024-10-14 15:19:13 +03:00
String propertyName = target.getComponentType() + "Path";
2023-09-17 22:13:42 +03:00
String lastDirectory = (String) GlobalProperties.class.getField(propertyName).get(Global.properties);
2024-10-14 15:19:13 +03:00
if (!lastDirectory.isEmpty()) {
2023-09-17 22:13:42 +03:00
//настройка выставлена не впервые, устанавливаем ее как папку
fileChooser.SetCurrentDirectory(lastDirectory);
}
boolean res = (file = fileChooser.ShowDialog()) != null;
File newDirectory = fileChooser.getCurrentDirectory();
GlobalProperties.class.getField(propertyName).set(Global.properties, newDirectory.getAbsolutePath());
Global.properties.Update();
return res;
}
return false;
}
@Override
protected void body() throws Exception {
Files.copy(file.toPath(), target.getNewFile().toPath(), StandardCopyOption.REPLACE_EXISTING);
target.Update();
}
@Override
protected void performDone() throws Exception {
target.InitialVersionCheck();
if (target.CanBeUpdated())
target.CheckIfNeedsUpdateOrPublish();
}
@Override
protected void showDone() throws Exception {
2024-10-22 20:18:50 +03:00
Global.components.refreshUpdatesStatus();
2023-09-17 22:13:42 +03:00
}
}