|
17 | 17 | import java.util.stream.Stream; |
18 | 18 |
|
19 | 19 | 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; |
22 | 22 |
|
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 | + } |
44 | 44 |
|
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 | + } |
54 | 54 |
|
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 | + } |
69 | 73 | } |
0 commit comments