Files
VisualSapfor/src/_VisualDVM/Passes/All/InstallComponentFromFolder.java
2025-01-18 01:36:02 +03:00

54 lines
2.0 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package _VisualDVM.Passes.All;
import Common.Visual.Windows.Dialog.VFileChooser;
import _VisualDVM.Global;
import _VisualDVM.NormalProperties;
import _VisualDVM.Passes.CurrentComponentPass;
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";
}
@Override
public String getButtonText() {
return "";
}
@Override
protected boolean canStart(Object... args) throws Exception {
if (super.canStart(args)) {
VFileChooser fileChooser = target.getFileChooser();
String propertyName = target.getComponentType() + "Path";
String lastDirectory = (String) NormalProperties.class.getField(propertyName).get(Global.normalProperties);
if (!lastDirectory.isEmpty()) {
//настройка выставлена не впервые, устанавливаем ее как папку
fileChooser.SetCurrentDirectory(lastDirectory);
}
boolean res = (file = fileChooser.ShowDialog()) != null;
File newDirectory = fileChooser.getCurrentDirectory();
NormalProperties.class.getField(propertyName).set(Global.normalProperties, newDirectory.getAbsolutePath());
Global.normalProperties.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 {
Global.components.refreshUpdatesStatus();
}
}