// Path: src/main/java/de/idrinth/waraddonclient/Utils.java
// public class Utils {
// 
//     private Utils() {
//     }
// 
//     public static void emptyFolder(File folder) throws IOException {
//         if (folder == null || !folder.exists()) {
//             return;
//         }
//         for (File file : Objects.requireNonNull(folder.listFiles())) {
//             if (file.isDirectory()) {
//                 emptyFolder(file);
//             }
//             Files.deleteIfExists(file.toPath());
//         }
//     }
// 
//     public static void deleteFolder(File folder) throws IOException {
//         if (folder == null || !folder.exists()) {
//             return;
//         }
//         emptyFolder(folder);
//         Files.deleteIfExists(folder.toPath());
//     }
//     public static void sleep(int duration, BaseLogger logger) {
//         try {
//             Thread.sleep(duration);
//         } catch (InterruptedException exception) {
//             logger.info(exception);
//         }
//     }
// }


import de.idrinth.waraddonclient.Utils;
import java.io.File;
import java.io.IOException;
import java.time.format.DateTimeFormatter;
import net.lingala.zip4j.exception.ZipException;

package de.idrinth.waraddonclient.service;


public class Backup {
    private final Config config;
    public Backup(Config config) {
        this.config = config;
    }

    public void create(ProgressReporter reporter) throws IOException {
        reporter.incrementMax(3);
        String warDir = config.getWARPath();
        java.io.File folder = new java.io.File(warDir+"/backups");
        if (!folder.isDirectory()) {
            folder.mkdir();
        }
        reporter.incrementCurrent();
        java.time.LocalDateTime now = java.time.LocalDateTime.now();
        File file = new java.io.File(warDir+"/backups/"+ now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm")) +".zip");
        try (net.lingala.zip4j.ZipFile zip = new net.lingala.zip4j.ZipFile(file)) {
            zip.addFolder(new File(warDir + "/user"));
            reporter.incrementCurrent();
            zip.addFolder(new File(warDir + "/Interface"));
        }
        reporter.incrementCurrent();
    }

    public void restore(java.io.File backup, ProgressReporter reporter) throws IOException {
        reporter.incrementMax(3);
        create(reporter);
        String warDir = config.getWARPath();
        try (net.lingala.zip4j.ZipFile zip = new net.lingala.zip4j.ZipFile(backup)) {
            reporter.incrementCurrent();

// Path: src/main/java/de/idrinth/waraddonclient/Utils.java
// public class Utils {
// 
//     private Utils() {
//     }
// 
//     public static void emptyFolder(File folder) throws IOException {
//         if (folder == null || !folder.exists()) {
//             return;
//         }
//         for (File file : Objects.requireNonNull(folder.listFiles())) {
//             if (file.isDirectory()) {
//                 emptyFolder(file);
//             }
//             Files.deleteIfExists(file.toPath());
//         }
//     }
// 
//     public static void deleteFolder(File folder) throws IOException {
//         if (folder == null || !folder.exists()) {
//             return;
//         }
//         emptyFolder(folder);
//         Files.deleteIfExists(folder.toPath());
//     }
//     public static void sleep(int duration, BaseLogger logger) {
//         try {
//             Thread.sleep(duration);
//         } catch (InterruptedException exception) {
//             logger.info(exception);
//         }
//     }
// }


// Path: src/main/java/de/idrinth/waraddonclient/service/Backup.java
import de.idrinth.waraddonclient.Utils;
import java.io.File;
import java.io.IOException;
import java.time.format.DateTimeFormatter;
import net.lingala.zip4j.exception.ZipException;

package de.idrinth.waraddonclient.service;


public class Backup {
    private final Config config;
    public Backup(Config config) {
        this.config = config;
    }

    public void create(ProgressReporter reporter) throws IOException {
        reporter.incrementMax(3);
        String warDir = config.getWARPath();
        java.io.File folder = new java.io.File(warDir+"/backups");
        if (!folder.isDirectory()) {
            folder.mkdir();
        }
        reporter.incrementCurrent();
        java.time.LocalDateTime now = java.time.LocalDateTime.now();
        File file = new java.io.File(warDir+"/backups/"+ now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm")) +".zip");
        try (net.lingala.zip4j.ZipFile zip = new net.lingala.zip4j.ZipFile(file)) {
            zip.addFolder(new File(warDir + "/user"));
            reporter.incrementCurrent();
            zip.addFolder(new File(warDir + "/Interface"));
        }
        reporter.incrementCurrent();
    }

    public void restore(java.io.File backup, ProgressReporter reporter) throws IOException {
        reporter.incrementMax(3);
        create(reporter);
        String warDir = config.getWARPath();
        try (net.lingala.zip4j.ZipFile zip = new net.lingala.zip4j.ZipFile(backup)) {
            reporter.incrementCurrent();

            Utils.emptyFolder(new File(warDir + "/Interface"));
