|
20 | 20 | import journeymap.client.log.LogFormatter; |
21 | 21 | import journeymap.common.Journeymap; |
22 | 22 | import net.minecraft.client.Minecraft; |
23 | | -import net.minecraft.util.Util; |
| 23 | +import org.apache.commons.io.FileUtils; |
24 | 24 | import org.apache.logging.log4j.Level; |
25 | | -import org.lwjgl.Sys; |
26 | 25 |
|
27 | 26 | import javax.imageio.ImageIO; |
28 | 27 | import java.awt.image.BufferedImage; |
29 | | -import java.io.*; |
30 | | -import java.net.URI; |
| 28 | +import java.io.File; |
| 29 | +import java.io.FileOutputStream; |
| 30 | +import java.io.FilenameFilter; |
| 31 | +import java.io.IOException; |
| 32 | +import java.io.InputStream; |
| 33 | +import java.io.InputStreamReader; |
| 34 | +import java.io.OutputStream; |
31 | 35 | import java.net.URL; |
32 | 36 | import java.nio.file.Paths; |
33 | | -import java.util.*; |
| 37 | +import java.util.Arrays; |
| 38 | +import java.util.Collection; |
| 39 | +import java.util.Collections; |
| 40 | +import java.util.Comparator; |
| 41 | +import java.util.Enumeration; |
| 42 | +import java.util.List; |
| 43 | +import java.util.Properties; |
34 | 44 | import java.util.zip.ZipEntry; |
35 | 45 | import java.util.zip.ZipFile; |
36 | 46 |
|
@@ -507,55 +517,6 @@ public OutputStream openStream() throws IOException |
507 | 517 | } |
508 | 518 | } |
509 | 519 |
|
510 | | - public static void open(File file) |
511 | | - { |
512 | | - |
513 | | - String path = file.getAbsolutePath(); |
514 | | - |
515 | | - if (Util.getOSType() == Util.EnumOS.OSX) |
516 | | - { |
517 | | - try |
518 | | - { |
519 | | - Runtime.getRuntime().exec(new String[]{"/usr/bin/open", path}); |
520 | | - return; |
521 | | - } |
522 | | - catch (IOException e) |
523 | | - { |
524 | | - Journeymap.getLogger().error("Could not open path with /usr/bin/open: {} : {}", path, LogFormatter.toString(e)); |
525 | | - } |
526 | | - } |
527 | | - else |
528 | | - { |
529 | | - if (Util.getOSType() == Util.EnumOS.WINDOWS) |
530 | | - { |
531 | | - |
532 | | - String cmd = String.format("cmd.exe /C start \"Open file\" \"%s\"", new Object[]{path}); |
533 | | - |
534 | | - try |
535 | | - { |
536 | | - Runtime.getRuntime().exec(cmd); |
537 | | - return; |
538 | | - } |
539 | | - catch (IOException e) |
540 | | - { |
541 | | - Journeymap.getLogger().error("Could not open path with cmd.exe: {} : {}", path, LogFormatter.toString(e)); |
542 | | - } |
543 | | - } |
544 | | - } |
545 | | - |
546 | | - try |
547 | | - { |
548 | | - Class desktopClass = Class.forName("java.awt.Desktop"); |
549 | | - Object method = desktopClass.getMethod("getDesktop", new Class[0]).invoke((Object) null, new Object[0]); |
550 | | - desktopClass.getMethod("browse", new Class[]{URI.class}).invoke(method, new Object[]{file.toURI()}); |
551 | | - } |
552 | | - catch (Throwable e) |
553 | | - { |
554 | | - Journeymap.getLogger().error("Could not open path with Desktop: {} : {}", path, LogFormatter.toString(e)); |
555 | | - Sys.openURL("file://" + path); |
556 | | - } |
557 | | - } |
558 | | - |
559 | 520 | public static boolean copyResources(File targetDirectory, String assetsPath, String setName, boolean overwrite) |
560 | 521 | { |
561 | 522 | return copyResources(targetDirectory, assetsPath, Collections.singletonList(setName), overwrite); |
@@ -675,43 +636,14 @@ public static boolean delete(File file) |
675 | 636 | { |
676 | 637 | return file.delete(); |
677 | 638 | } |
678 | | - |
679 | | - String[] cmd = null; |
680 | | - String path = file.getAbsolutePath(); |
681 | | - Util.EnumOS os = Util.getOSType(); |
682 | | - |
683 | | - switch (os) |
| 639 | + else |
684 | 640 | { |
685 | | - case WINDOWS: |
686 | | - { |
687 | | - cmd = new String[]{String.format("cmd.exe /C RD /S /Q \"%s\"", path)}; |
688 | | - break; |
689 | | - } |
690 | | - case OSX: |
691 | | - { |
692 | | - cmd = new String[]{"rm", "-rf", path}; |
693 | | - break; |
694 | | - } |
695 | | - default: |
| 641 | + try |
696 | 642 | { |
697 | | - cmd = new String[]{"rm", "-rf", path}; |
698 | | - break; |
699 | | - } |
700 | | - } |
701 | | - |
702 | | - try |
703 | | - { |
704 | | - ProcessBuilder pb = new ProcessBuilder(cmd); |
705 | | - pb.redirectOutput(ProcessBuilder.Redirect.INHERIT); |
706 | | - pb.redirectError(ProcessBuilder.Redirect.INHERIT); |
707 | | - Process p = pb.start(); |
708 | | - p.waitFor(); |
709 | | - } |
710 | | - catch (Throwable e) |
711 | | - { |
712 | | - Journeymap.getLogger().error("Could not delete using: {} : {}", Joiner.on(" ").join(cmd), LogFormatter.toString(e)); |
| 643 | + FileUtils.deleteDirectory(file); |
| 644 | + } catch (IOException e) {} |
| 645 | + return !file.exists(); |
713 | 646 | } |
714 | | - return file.exists(); |
715 | 647 | } |
716 | 648 |
|
717 | 649 | public static BufferedImage getIconFromFile(File parentdir, String assetsPath, String setName, String iconPath, BufferedImage defaultImg) |
|
0 commit comments