UAC dirty script for better windows integration to create symlinks. More

data using a thread-safe collection. Some NPEs fixed. 
More data protection in tiled integration functions (better state
checking, backup tiled-made file before saving ATCS-made data).
jardesc file added for convenience.
This commit is contained in:
Zukero
2017-03-02 18:10:03 +01:00
parent 97ae63693a
commit dfe3cc8480
11 changed files with 73 additions and 13 deletions

View File

@@ -6,6 +6,7 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -128,10 +129,14 @@ public class FileUtils {
case Windows:
System.err.println("Trying the Windows way with mklink");
try {
Runtime.getRuntime().exec("mklink "+(targetFile.isDirectory() ? "/J " : "")+linkFile.getAbsolutePath()+" "+targetFile.getAbsolutePath());
Runtime.getRuntime().exec("cmd.exe /C mklink "+(targetFile.isDirectory() ? "/J " : "")+linkFile.getAbsolutePath()+" "+targetFile.getAbsolutePath());
} catch (IOException e1) {
e1.printStackTrace();
}
System.err.println("Attempting UAC elevation through VBS script.");
if (!linkFile.exists()) {
runWithUac("cmd.exe /C mklink "+(targetFile.isDirectory() ? "/J " : "")+linkFile.getAbsolutePath()+" "+targetFile.getAbsolutePath(), 3, linkFile);
}
break;
case MacOS:
case NIX:
@@ -167,4 +172,28 @@ public class FileUtils {
return null;
}
static final String uacBatName = "ATCS_elevateWithUac.bat";
public static void runWithUac(String command, int tries, File checkExists) {
File tmpFolder = new File(System.getProperty("java.io.tmpdir"));
File batFile = new File(tmpFolder, uacBatName);
batFile.deleteOnExit();
FileWriter writer;
try {
writer = new FileWriter(batFile, false);
writer.write(
"@echo Set objShell = CreateObject(\"Shell.Application\") > %temp%\\sudo.tmp.vbs\r\n"
+ "@echo args = Right(\"%*\", (Len(\"%*\") - Len(\"%1\"))) >> %temp%\\sudo.tmp.vbs\r\n"
+ "@echo objShell.ShellExecute \"%1\", args, \"\", \"runas\" >> %temp%\\sudo.tmp.vbs\r\n"
+ "@cscript %temp%\\sudo.tmp.vbs\r\n"
+ "del /f %temp%\\sudo.tmp.vbs\r\n");
writer.close();
while (!checkExists.exists() && tries-- > 0) {
Runtime.getRuntime().exec(new String[]{"cmd.exe","/C", batFile.getAbsolutePath()+" "+command});
}
} catch (IOException e) {
e.printStackTrace();
}
}
}