Skip to content

Commit c817d3f

Browse files
Use Java multi-line syntax for PowerShell script definition
1 parent eef259a commit c817d3f

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

src/main/java/dev/dirs/impl/WindowsPowerShell.java

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,27 @@ public WindowsPowerShell() {}
1919
// This string needs to end up being a multiple of 3 bytes after conversion to UTF-16. (It is currently 1200 bytes.)
2020
// This is because Base64 converts 3 bytes to 4 letters; other numbers of bytes would introduce padding, which
2121
// would make it harder to simply concatenate this precomputed string with whatever directories the user requests.
22-
static final String SCRIPT_START_BASE64 = Constants.operatingSystem == 'w' ? toUTF16LEBase64("& {\n" +
23-
"[Console]::OutputEncoding = [System.Text.Encoding]::UTF8\n" +
24-
"Add-Type @\"\n" +
25-
"using System;\n" +
26-
"using System.Runtime.InteropServices;\n" +
27-
"public class Dir {\n" +
28-
" [DllImport(\"shell32.dll\")]\n" +
29-
" private static extern int SHGetKnownFolderPath([MarshalAs(UnmanagedType.LPStruct)] Guid rfid, uint dwFlags, IntPtr hToken, out IntPtr pszPath);\n" +
30-
" public static string GetKnownFolderPath(string rfid) {\n" +
31-
" IntPtr pszPath;\n" +
32-
" if (SHGetKnownFolderPath(new Guid(rfid), 0, IntPtr.Zero, out pszPath) != 0) return \"\";\n" +
33-
" string path = Marshal.PtrToStringUni(pszPath);\n" +
34-
" Marshal.FreeCoTaskMem(pszPath);\n" +
35-
" return path;\n" +
36-
" }\n" +
37-
"}\n" +
38-
"\"@\n") : null;
22+
static final String SCRIPT_START_BASE64 = Constants.operatingSystem == 'w' ? toUTF16LEBase64(
23+
"""
24+
& {
25+
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
26+
Add-Type @"
27+
using System;
28+
using System.Runtime.InteropServices;
29+
public class Dir {
30+
[DllImport("shell32.dll")]
31+
private static extern int SHGetKnownFolderPath([MarshalAs(UnmanagedType.LPStruct)] Guid rfid, uint dwFlags, IntPtr hToken, out IntPtr pszPath);
32+
public static string GetKnownFolderPath(string rfid) {
33+
IntPtr pszPath;
34+
if (SHGetKnownFolderPath(new Guid(rfid), 0, IntPtr.Zero, out pszPath) != 0) return "";
35+
string path = Marshal.PtrToStringUni(pszPath);
36+
Marshal.FreeCoTaskMem(pszPath);
37+
return path;
38+
}
39+
}
40+
"@
41+
"""
42+
) : null;
3943

4044
public String[] winDirs(String... guids) {
4145
int guidsLength = guids.length;

0 commit comments

Comments
 (0)