Skip to content

Commit

Permalink
Fix relative "shortcuts" in Windows
Browse files Browse the repository at this point in the history
Apparently there is no support for relative shortcuts in Windows. Use symlinks instead thus fixing the relative paths.
  • Loading branch information
Maczuga authored Sep 29, 2023
1 parent 1c17c70 commit ea9b579
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/moving.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,25 @@ File findNotExistingName(File initialFile) {
///
/// WARN: Crashes with non-ascii names :(
Future<File> 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
final targetRelativePath = p.relative(target.path, from: link.parent.path);
if (Platform.isWindows) {
final res = await Process.run(
'powershell.exe',
workingDirectory: link.parent.path,
[
'-ExecutionPolicy',
'Bypass',
'-NoLogo',
'-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) {
Expand Down

0 comments on commit ea9b579

Please sign in to comment.