mirror of
https://github.com/OMGeeky/ATCS.git
synced 2026-01-01 17:14:36 +01:00
Enhanced Tiled integration. Now in "File->Edit workspace settings" menu,
you have tools to help selecting external tools to bview/edit images and tmx maps. Still rough.
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
package com.gpl.rpg.atcontentstudio.utils;
|
||||
|
||||
import java.awt.Desktop;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
|
||||
import com.gpl.rpg.atcontentstudio.model.Workspace;
|
||||
|
||||
public class DesktopIntegration {
|
||||
|
||||
public static void openTmxMap(File f) {
|
||||
if (Workspace.activeWorkspace.settings.useSystemDefaultMapEditor.getCurrentValue()) {
|
||||
try {
|
||||
Desktop.getDesktop().open(f);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
Runtime.getRuntime().exec(Workspace.activeWorkspace.settings.mapEditorCommand.getCurrentValue()+" "+f.getAbsolutePath());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void openImage(File f) {
|
||||
if (Workspace.activeWorkspace.settings.useSystemDefaultImageViewer.getCurrentValue()) {
|
||||
try {
|
||||
Desktop.getDesktop().open(f);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else if (Workspace.activeWorkspace.settings.useSystemDefaultImageEditor.getCurrentValue()) {
|
||||
try {
|
||||
Desktop.getDesktop().edit(f);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
Runtime.getRuntime().exec(Workspace.activeWorkspace.settings.imageEditorCommand.getCurrentValue()+" "+f.getAbsolutePath());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static enum OSType {
|
||||
Windows, MacOS, NIX, Other
|
||||
}
|
||||
|
||||
public static OSType detectedOS = detectOS();
|
||||
|
||||
private static OSType detectOS() {
|
||||
String os = System.getProperty("os.name", "generic").toLowerCase(Locale.ENGLISH);
|
||||
if ((os.indexOf("mac") >= 0) || (os.indexOf("darwin") >= 0)) return OSType.MacOS;
|
||||
if (os.indexOf("win") >= 0) return OSType.Windows;
|
||||
if ((os.indexOf("nux") >= 0) || (os.indexOf("nix") >= 0) || (os.indexOf("aix") >= 0) || (os.indexOf("sunos") >= 0) || (os.indexOf("solaris") >= 0)) return OSType.NIX;
|
||||
return OSType.Other;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -9,6 +9,9 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
@@ -108,8 +111,48 @@ public class FileUtils {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static boolean makeSymlink(File targetFile, File linkFile) {
|
||||
Path target = Paths.get(targetFile.getAbsolutePath());
|
||||
Path link = Paths.get(linkFile.getAbsolutePath());
|
||||
if (!Files.exists(link)) {
|
||||
try {
|
||||
Files.createSymbolicLink(link, target);
|
||||
} catch (Exception e) {
|
||||
System.err.println("Failed to create symbolic link to target \""+targetFile.getAbsolutePath()+"\" as \""+linkFile.getAbsolutePath()+"\" the java.nio way:");
|
||||
e.printStackTrace();
|
||||
switch (DesktopIntegration.detectedOS) {
|
||||
case Windows:
|
||||
System.err.println("Trying the Windows way with mklink");
|
||||
try {
|
||||
Runtime.getRuntime().exec("mklink "+(targetFile.isDirectory() ? "/J " : "")+linkFile.getAbsolutePath()+" "+targetFile.getAbsolutePath());
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
break;
|
||||
case MacOS:
|
||||
case NIX:
|
||||
case Other:
|
||||
System.err.println("Trying the unix way with ln -s");
|
||||
try {
|
||||
Runtime.getRuntime().exec("ln -s "+targetFile.getAbsolutePath()+" "+linkFile.getAbsolutePath());
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
System.out.println("Unrecognized OS. Please contact ATCS dev.");
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!Files.exists(link)) {
|
||||
System.err.println("Failed to create link \""+linkFile.getAbsolutePath()+"\" targetting \""+targetFile.getAbsolutePath()+"\"");
|
||||
System.err.println("You can try running ATCS with administrative privileges once, or create the symbolic link manually.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user