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

84 lines
3.0 KiB
Java
Raw Normal View History

2024-10-09 22:21:57 +03:00
package _VisualDVM.Repository.Component;
import _VisualDVM.Global;
2024-10-14 12:14:01 +03:00
import _VisualDVM.Passes.PassCode;
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() {
2025-01-18 01:36:02 +03:00
version = 1137;
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();
2024-10-22 20:25:26 +03:00
ComponentsSet.visualizer_2.SendRequest("update: ");
2023-09-17 22:13:42 +03:00
System.exit(0);
}
public File getWorkspace() {
2025-01-18 01:36:02 +03:00
if (!Global.normalProperties.Workspace.isEmpty()) {
File workspace = new File(Global.normalProperties.Workspace);
2023-09-17 22:13:42 +03:00
if (workspace.exists())
return workspace;
else
2025-01-11 14:26:24 +03:00
Global.mainModule.getPass(PassCode.UpdateProperty).Do("Workspace", "");
2023-09-17 22:13:42 +03:00
}
return Global.ProjectsDirectory;
}
}