summaryrefslogtreecommitdiff
path: root/src/main/java/com/keuin/kbackupfabric/ui/PrimitiveBackupInfo.java
blob: e3a00607e5c4b1bb00f88e38735d512a5ccc59a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package com.keuin.kbackupfabric.ui;

import com.keuin.kbackupfabric.backup.name.BackupFileNameEncoder;
import com.keuin.kbackupfabric.backup.name.PrimitiveBackupFileNameEncoder;
import com.keuin.kbackupfabric.operation.backup.method.ConfiguredBackupMethod;
import com.keuin.kbackupfabric.util.FilesystemUtil;
import net.minecraft.server.MinecraftServer;

import java.io.File;
import java.time.LocalDateTime;

/**
 * Used in UI part.
 */
public class PrimitiveBackupInfo implements BackupInfo {
    private final String name;
    private final LocalDateTime creationTime;
    private final long sizeBytes;
    private final String fileName;

    @Deprecated
    private PrimitiveBackupInfo(String name, LocalDateTime creationTime, long sizeBytes) {
        this.name = name;
        this.creationTime = creationTime;
        this.sizeBytes = sizeBytes;
        this.fileName = PrimitiveBackupFileNameEncoder.INSTANCE.encode(name, creationTime);
    }

    private PrimitiveBackupInfo(String fileName, long sizeBytes) {
        this.fileName = fileName;
        BackupFileNameEncoder.BackupBasicInformation info = PrimitiveBackupFileNameEncoder.INSTANCE.decode(fileName);
        if (info == null)
            throw new IllegalArgumentException("Invalid file name.");
        this.name = info.customName;
        this.creationTime = info.time;
        this.sizeBytes = sizeBytes;
    }

    public static PrimitiveBackupInfo fromFile(File zipFile) {
        // TODO: fix this, use metadata file instead
        return new PrimitiveBackupInfo(zipFile.getName(), FilesystemUtil.getFileSizeBytes(zipFile));
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public LocalDateTime getCreationTime() {
        return creationTime;
    }

    @Override
    public long getSizeBytes() {
        return sizeBytes;
    }

    @Override
    public String getType() {
        return "ZIP";
    }

    @Override
    public ConfiguredBackupMethod createConfiguredBackupMethod(MinecraftServer server) {
        throw new RuntimeException("not implemented");
    }

    @Override
    public String getBackupFileName() {
        return fileName;
    }
}