Commit 13052025

Old Photo Deleter .
This commit is contained in:
2025-05-13 14:52:26 +07:00
parent d2e7d1155d
commit bc6821a33e
9 changed files with 302 additions and 14 deletions

View File

@@ -12,6 +12,7 @@ import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.PixelFormat;
import javafx.scene.image.WritableImage;
import lombok.NonNull;
import org.bytedeco.javacv.Frame;
import org.bytedeco.javacv.Java2DFrameConverter;
import org.bytedeco.javacv.OpenCVFrameConverter;
@@ -34,9 +35,12 @@ import java.net.InetAddress;
import java.nio.ByteBuffer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.FileTime;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.bytedeco.opencv.global.opencv_core.CV_64F;
@@ -182,6 +186,74 @@ public class SomeCodes {
return x.format(dtf);
}
public static LocalDateTime StringToLocalDateTime(String x){
if (ValidString(x)){
try{
return LocalDateTime.parse(x, dtf);
} catch (Exception e){
Logger.error("Error parsing date: "+x+", Msg : "+e.getMessage());
}
}
return null;
}
public static LocalDateTime GetCreationTime(Path p){
try{
BasicFileAttributes attr = Files.readAttributes(p, BasicFileAttributes.class);
FileTime ft = attr.creationTime();
return LocalDateTime.ofInstant(ft.toInstant(), java.time.ZoneId.systemDefault());
} catch (Exception e){
Logger.error("Error getting creation time: "+p+", Msg : "+e.getMessage());
}
return null;
}
public static @NonNull Path[] GetFilesInDirectory(String path) {
if (ValidDirectory(path)) {
try{
return Files.list(Path.of(path))
.filter(Files::isRegularFile)
.toArray(Path[]::new);
} catch (Exception ignored){}
}
return new Path[0];
}
public static boolean Delete(String... path){
if (path!=null && path.length>0){
Boolean[] result = new Boolean[path.length];
for(int i=0; i<path.length; i++){
try{
result[i] = Files.deleteIfExists(Path.of(path[i]));
if (result[i]) System.out.println("Delete: "+path[i]);
} catch (Exception e){
result[i] = false;
System.out.println("Error deleting file: "+path[i]+", Msg : "+e.getMessage());
}
}
return Arrays.stream(result).allMatch(x->x);
}
return false;
}
public static boolean Delete(Path... path){
if (path!=null && path.length>0){
Boolean[] result = new Boolean[path.length];
for(int i=0; i<path.length; i++){
try{
result[i] = Files.deleteIfExists(path[i]);
if (result[i]) System.out.println("Delete: "+path[i]);
} catch (Exception e){
result[i] = false;
System.out.println("Error deleting file: "+path[i]+", Msg : "+e.getMessage());
}
}
return Arrays.stream(result).allMatch(x->x);
}
return false;
}
/**
* Extract resource file to current directory
* @param filename resource file name