From ea9b5791c4186f0bf18bb57d8b8f0ed49958cd75 Mon Sep 17 00:00:00 2001 From: Maczuga <544349+Maczuga@users.noreply.github.com> Date: Fri, 29 Sep 2023 04:39:36 -0700 Subject: [PATCH] Fix relative "shortcuts" in Windows Apparently there is no support for relative shortcuts in Windows. Use symlinks instead thus fixing the relative paths. --- lib/moving.dart | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/moving.dart b/lib/moving.dart index 92255a8f..a44749d5 100644 --- a/lib/moving.dart +++ b/lib/moving.dart @@ -26,7 +26,7 @@ File findNotExistingName(File initialFile) { /// /// WARN: Crashes with non-ascii names :( Future createShortcut(Directory location, File target) async { - final name = '${p.basename(target.path)}${Platform.isWindows ? '.lnk' : ''}'; + final name = p.basename(target.path); final link = findNotExistingName(File(p.join(location.path, name))); // this must be relative to not break when user moves whole folder around: // https://github.com/TheLastGimbus/GooglePhotosTakeoutHelper/issues/232 @@ -34,6 +34,7 @@ Future createShortcut(Directory location, File target) async { if (Platform.isWindows) { final res = await Process.run( 'powershell.exe', + workingDirectory: link.parent.path, [ '-ExecutionPolicy', 'Bypass', @@ -41,10 +42,9 @@ Future createShortcut(Directory location, File target) async { '-NonInteractive', '-NoProfile', '-Command', - '\$ws = New-Object -ComObject WScript.Shell; ' - '\$s = \$ws.CreateShortcut(\'${link.path}\'); ' - '\$s.TargetPath = \'$targetRelativePath\'; ' - '\$s.Save()', + 'New-Item -ItemType SymbolicLink ' + '-Path \'${link.path}\' ' + '-Target \'$targetRelativePath\'', ], ); if (res.exitCode != 0) {