Files
VisualSapfor/src/_VisualDVM/Repository/Component/Visualiser.java

89 lines
3.3 KiB
Java
Raw Normal View History

2024-10-09 22:21:57 +03:00
package _VisualDVM.Repository.Component;
2024-10-11 00:00:30 +03:00
import Common.Utils.Utils_;
2024-10-09 22:21:57 +03:00
import _VisualDVM.GlobalData.GlobalDatabase;
import _VisualDVM.Global;
2024-10-09 22:21:57 +03:00
import _VisualDVM.GlobalData.Settings.SettingName;
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.Pass;
2023-09-17 22:13:42 +03:00
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;
public class Visualiser extends Component {
//-----------------------------------------
private static Date getClassBuildTime() {
Date d = null;
Class<?> currentClass = new Object() {
}.getClass().getEnclosingClass();
URL resource = currentClass.getResource(currentClass.getSimpleName() + ".class");
if (resource != null) {
if (resource.getProtocol().equals("file")) {
try {
d = new Date(new File(resource.toURI()).lastModified());
} catch (URISyntaxException ignored) {
}
} else if (resource.getProtocol().equals("jar")) {
String path = resource.getPath();
d = new Date(new File(path.substring(5, path.indexOf("!"))).lastModified());
} else if (resource.getProtocol().equals("zip")) {
String path = resource.getPath();
File jarFileOnDisk = new File(path.substring(0, path.indexOf("!")));
try (JarFile jf = new JarFile(jarFileOnDisk)) {
ZipEntry ze = jf.getEntry(path.substring(path.indexOf("!") + 2));
long zeTimeLong = ze.getTime();
Date zeTimeDate = new Date(zeTimeLong);
d = zeTimeDate;
} catch (IOException | RuntimeException ignored) {
}
}
}
return d;
}
@Override
public String getFileName() {
return "VisualSapfor.jar";
}
@Override
public String getNewFileName() {
return "VisualSapfor_new.jar";
}
@Override
public ComponentType getComponentType() {
return ComponentType.Visualiser;
}
//</editor-fold>
//<editor-fold desc="Методы">
//</editor-// fold>
//http://www.seostella.com/ru/article/2012/02/05/formatirovanie-daty-v-java.html
@Override
public void GetVersionInfo() {
version = 1115;
2023-09-17 22:13:42 +03:00
String pattern = "MMM dd yyyy HH:mm:ss";
DateFormat df = new SimpleDateFormat(pattern, Locale.ENGLISH);
date_text = df.format(getClassBuildTime());
}
@Override
public void Update() throws Exception {
super.Update();
Global.visualizer_2.SendRequest("update: ");
System.exit(0);
}
public File getWorkspace() {
2024-10-11 00:00:30 +03:00
if (!((GlobalDatabase) Utils_.db).settings.get(SettingName.Workspace).toString().isEmpty()) {
File workspace = new File(((GlobalDatabase) Utils_.db).settings.get(SettingName.Workspace).toString());
2023-09-17 22:13:42 +03:00
if (workspace.exists())
return workspace;
else
2024-10-09 23:37:58 +03:00
Pass.passes.get(PassCode.UpdateSetting).Do(
2023-09-17 22:13:42 +03:00
SettingName.Workspace, "");
}
return Global.ProjectsDirectory;
}
}