Skip to content

Commit 931c313

Browse files
fix: fix #48 with MAGIC
1 parent bf0b6d7 commit 931c313

1 file changed

Lines changed: 50 additions & 46 deletions

File tree

src/client/java/dev/spiritstudios/snapper/util/ScreenshotActions.java

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -17,53 +17,57 @@
1717
import java.util.stream.Stream;
1818

1919
public class ScreenshotActions {
20-
public static void deleteScreenshot(Path path, Screen screen) {
21-
if (!Files.exists(path)) return;
20+
public static void deleteScreenshot(Path path, Screen screen) {
21+
if (!Files.exists(path)) return;
2222

23-
MinecraftClient client = MinecraftClient.getInstance();
24-
client.setScreen(
25-
new ConfirmScreen(
26-
confirmed -> {
27-
if (confirmed) {
28-
client.setScreen(new ProgressScreen(true));
29-
try {
30-
Files.deleteIfExists(path);
31-
} catch (IOException e) {
32-
Snapper.LOGGER.error("Failed to delete file", e);
33-
}
34-
}
35-
client.setScreen(screen);
36-
},
37-
Text.translatable("text.snapper.delete_question"),
38-
Text.translatable("text.snapper.delete_warning", path.getFileName()),
39-
Text.translatable("button.snapper.delete"),
40-
ScreenTexts.CANCEL
41-
)
42-
);
43-
}
23+
MinecraftClient client = MinecraftClient.getInstance();
24+
client.setScreen(
25+
new ConfirmScreen(
26+
confirmed -> {
27+
if (confirmed) {
28+
client.setScreen(new ProgressScreen(true));
29+
try {
30+
Files.deleteIfExists(path);
31+
} catch (IOException e) {
32+
Snapper.LOGGER.error("Failed to delete file", e);
33+
}
34+
}
35+
client.setScreen(screen);
36+
},
37+
Text.translatable("text.snapper.delete_question"),
38+
Text.translatable("text.snapper.delete_warning", path.getFileName()),
39+
Text.translatable("button.snapper.delete"),
40+
ScreenTexts.CANCEL
41+
)
42+
);
43+
}
4444

45-
public static void renameScreenshot(Path screenshot, String newName) {
46-
if (Files.exists(screenshot)) {
47-
try {
48-
Files.move(screenshot, screenshot.getParent().resolve(newName));
49-
} catch (IOException e) {
50-
Snapper.LOGGER.error("Failed to rename file", e);
51-
}
52-
}
53-
}
45+
public static void renameScreenshot(Path screenshot, String newName) {
46+
if (Files.exists(screenshot)) {
47+
try {
48+
Files.move(screenshot, screenshot.getParent().resolve(newName));
49+
} catch (IOException e) {
50+
Snapper.LOGGER.error("Failed to rename file", e);
51+
}
52+
}
53+
}
5454

55-
public static List<Path> getScreenshots() {
56-
try (Stream<Path> stream = Files.list(SnapperUtil.getConfiguredScreenshotDirectory())) {
57-
return stream.filter(path ->
58-
!Files.isDirectory(path) && SafeFiles.isContentType(path, "image/png", ".png"))
59-
.sorted(Comparator.<Path>comparingLong(path ->
60-
SafeFiles.getLastModifiedTime(path)
61-
.map(FileTime::toMillis)
62-
.orElse(0L))
63-
.reversed())
64-
.toList();
65-
} catch (IOException e) {
66-
throw new RuntimeException(e);
67-
}
68-
}
55+
public static List<Path> getScreenshots() {
56+
Path screenshotDirectory = SnapperUtil.getConfiguredScreenshotDirectory();
57+
if (!Files.exists(screenshotDirectory)) {
58+
return List.of();
59+
}
60+
try (Stream<Path> stream = Files.list(screenshotDirectory)) {
61+
return stream.filter(path ->
62+
!Files.isDirectory(path) && SafeFiles.isContentType(path, "image/png", ".png"))
63+
.sorted(Comparator.<Path>comparingLong(path ->
64+
SafeFiles.getLastModifiedTime(path)
65+
.map(FileTime::toMillis)
66+
.orElse(0L))
67+
.reversed())
68+
.toList();
69+
} catch (IOException e) {
70+
throw new RuntimeException(e);
71+
}
72+
}
6973
}

0 commit comments

Comments
 (0)