Skip to content

Commit fe9f823

Browse files
authored
Remove system commands in File Helper (#57)
* remove system commands in FileHandler * clear changelog and bump version
1 parent 2405eb6 commit fe9f823

3 files changed

Lines changed: 22 additions & 95 deletions

File tree

doc/changelog.html

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,5 @@ <h1>JourneyMap ${version} for Minecraft ${mcversion}</h1>
2323

2424
<p>New in ${version}</p>
2525
<ul>
26-
<li>Fix: biome label under minimap compass now updates instantly instead of with up to ~1400ms delay. (Eldrinn-Elantey)</li>
27-
<li>Fix: replace internal sun.awt.image.IntegerComponentRaster with standard Java API in PixelPaint. (Eldrinn-Elantey)</li>
28-
<li>Fix: arrow keys in settings now control the slider under the cursor instead of always the first enabled slider. (Eldrinn-Elantey)</li>
29-
<li>Fix: double sliders no longer lose precision when dragged. (Eldrinn-Elantey)</li>
30-
<li>Fix: resolve some WorldClient memory leaks (Alexdoru)</li>
31-
<li>Fix: reduce memory allocations during mapping. (Alexdoru)</li>
26+
<li>Fix: remove direct system commands in FileHandler. (Alexdoru)</li>
3227
</ul>

project.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ group_id=teamjm
44
mod_id=journeymap
55
jm_major=5
66
jm_minor=2
7-
jm_micro=13
7+
jm_micro=14
88
jm_patch=
99
fairPlay=FairPlay
1010
unlimited=Unlimited

src/main/java/journeymap/client/io/FileHandler.java

Lines changed: 20 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,27 @@
2020
import journeymap.client.log.LogFormatter;
2121
import journeymap.common.Journeymap;
2222
import net.minecraft.client.Minecraft;
23-
import net.minecraft.util.Util;
23+
import org.apache.commons.io.FileUtils;
2424
import org.apache.logging.log4j.Level;
25-
import org.lwjgl.Sys;
2625

2726
import javax.imageio.ImageIO;
2827
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;
3135
import java.net.URL;
3236
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;
3444
import java.util.zip.ZipEntry;
3545
import java.util.zip.ZipFile;
3646

@@ -507,55 +517,6 @@ public OutputStream openStream() throws IOException
507517
}
508518
}
509519

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-
559520
public static boolean copyResources(File targetDirectory, String assetsPath, String setName, boolean overwrite)
560521
{
561522
return copyResources(targetDirectory, assetsPath, Collections.singletonList(setName), overwrite);
@@ -675,43 +636,14 @@ public static boolean delete(File file)
675636
{
676637
return file.delete();
677638
}
678-
679-
String[] cmd = null;
680-
String path = file.getAbsolutePath();
681-
Util.EnumOS os = Util.getOSType();
682-
683-
switch (os)
639+
else
684640
{
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
696642
{
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();
713646
}
714-
return file.exists();
715647
}
716648

717649
public static BufferedImage getIconFromFile(File parentdir, String assetsPath, String setName, String iconPath, BufferedImage defaultImg)

0 commit comments

Comments
 (0)