Skip to content
Snippets Groups Projects
Commit 2b3cc1a0 authored by Dmitry Shamrikov's avatar Dmitry Shamrikov
Browse files

env. variable replacement fixed

parent 89f335c5
No related branches found
No related tags found
No related merge requests found
package mslinks;
import java.io.IOException;
import mslinks.extra.ConsoleData.Font;
public class Main {
public static void main(String[] args) throws IOException, ShellLinkException {
public static void main(String[] args) throws IOException {
ShellLink sl = ShellLink.createLink("pause.bat")
.setWorkingDir("..");
.setWorkingDir("..");
sl.getConsoleData()
.setFont(Font.LucindaConsole)
.setFont(mslinks.extra.ConsoleData.Font.Consolas)
.setFontSize(24)
.setTextColor(5);
sl.saveTo("testlink.lnk");
System.out.println(sl.getWorkingDir());
System.out.println(sl.resolveTarget());
}
}
......@@ -8,11 +8,12 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import java.net.InetAddress;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;
import mslinks.data.CNRLink;
import mslinks.data.ItemID;
......@@ -25,6 +26,8 @@ import mslinks.extra.Tracker;
import mslinks.extra.VistaIDList;
public class ShellLink {
private static Map<String, String> env = System.getenv();
private static HashMap<Integer, Class> extraTypes = new HashMap<Integer, Class>() {{
put(ConsoleData.signature, ConsoleData.class);
put(ConsoleFEData.signature, ConsoleFEData.class);
......@@ -292,6 +295,10 @@ public class ShellLink {
public static ShellLink createLink(String target) {
ShellLink sl = new ShellLink();
for (String i : env.keySet())
target = Pattern.compile("%"+i+"%", Pattern.CASE_INSENSITIVE).matcher(target).replaceAll(env.get(i));
Path tar = Paths.get(target).toAbsolutePath();
target = tar.toString();
......
......@@ -128,11 +128,6 @@ public class ItemID implements Serializable {
public ItemID setName(String s) throws ShellLinkException {
if (s == null)
return this;
if (s.startsWith("%") && s.endsWith("%")) {
String value = System.getenv(s.substring(1, s.length() - 2));
if (value != null)
s = value;
}
if (type == TYPE_FILE || type == TYPE_DIRECTORY) {
if (s.contains("\\"))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment