Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ dotnet test --project Symlinker.Tests
- Upload the `.msixbundle` in Partner Center > Symlinker > the submission > Packages. Store ID `9P8H93Z0TGK4`.
- Manifest template and tile assets live in `packaging/msix/`. Identity values there must match Partner Center.
- `Properties/DisplayName` must be a name reserved in Partner Center (Manage app names). "Symlinker" alone is taken, so it is "Symlinker - Symlink Creator". The Start menu name (`VisualElements DisplayName`) stays "Symlinker".
- The Store build behaves like the others: the window starts unelevated and only the link helper elevates. The `allowElevation` capability lets it show the UAC prompt. The script fails if the built exe asks for admin at launch.
- The manifest disables file/registry write virtualization so links created under AppData land in the real location.
- The Store build behaves like the others: the window starts unelevated and only the link helper elevates, with a UAC prompt. The script fails if the built exe asks for admin at launch.
- The only capability is `runFullTrust`. The Store denied `allowElevation` and `unvirtualizedResources`, and neither is needed (tested with Developer Mode off): the helper's `runas` launch works without `allowElevation`, and mklink runs in `cmd.exe`, a child process that writes to the real `AppData`. Only new files and folders that Symlinker's own process creates under `AppData` go to the package's private copy (renames and deletes of existing items are fine). So in the Store package, `LinkCreator` refuses to move files into `AppData` (`MoveIntoAppDataUnsupported`); moving out of it works. The script fails if the package declares any other capability.

## Architecture

Expand Down Expand Up @@ -171,6 +171,7 @@ Releases are automated via GitHub Actions:
## Known Limitations

- **Drag and drop**: Works because the window always runs unelevated. It does not work if the user starts Symlinker as administrator themselves, because Windows blocks drops from a lower-privilege Explorer.
- **Store version, moving into AppData**: the Microsoft Store version can't move existing files into a target under `AppData` (see "Publishing (Microsoft Store / MSIX)"). Linking there without moving works.
- **Platform**: Windows 10/11 only.

## Localization
Expand Down
6 changes: 6 additions & 0 deletions Symlinker.Tests/ElevationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,11 @@ public void CanCreateSymbolicLinks_ProbesForReal()
{
Assert.Equal(SymlinkSupport.Available, Elevation.CanCreateSymbolicLinks());
}

[Fact]
public void IsPackaged_IsFalse_OutsideAnMsixPackage()
{
Assert.False(Elevation.IsPackaged());
}
}
}
45 changes: 45 additions & 0 deletions Symlinker.Tests/LinkCreatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,51 @@ public async Task Move_IntoAnEmptyFolder_ReplacesIt()
Assert.Equal(Res.MessageBoxSuccessTitle, dialogs.Last.Title);
}

[Fact]
public async Task Move_IntoAppData_IsRefused_InTheStorePackage()
{
temp.File(@"links\name\data.txt");
creator.IsPackaged = () => true;
creator.AppDataFolder = temp.Dir("AppData");

await Create("name", temp.PathOf("AppData", "Local", "moved"));

Assert.Equal((Res.MessageBoxErrorTitle, Res.MoveIntoAppDataUnsupported), dialogs.Last);
Assert.Empty(dialogs.Questions);
Assert.Empty(runner.Prepared);
Assert.True(File.Exists(temp.PathOf("links", "name", "data.txt")));
Assert.False(Directory.Exists(temp.PathOf("AppData", "Local", "moved")));
}

[Fact]
public async Task Move_OutOfAppData_Works_InTheStorePackage()
{
temp.File(@"AppData\Local\name\data.txt");
var target = temp.PathOf("elsewhere");
creator.IsPackaged = () => true;
creator.AppDataFolder = temp.PathOf("AppData");

await Create("name", target, linkLocation: temp.PathOf("AppData", "Local"));

Assert.True(File.Exists(Path.Combine(target, "data.txt")));
Assert.Equal(Res.MessageBoxSuccessTitle, dialogs.Last.Title);
}

[Fact]
public async Task Move_IntoAppData_Works_OutsideTheStorePackage()
{
temp.File(@"links\name\data.txt");
creator.IsPackaged = () => false;
creator.AppDataFolder = temp.PathOf("AppData");
temp.Dir("AppData", "Local");
var target = temp.PathOf("AppData", "Local", "moved");

await Create("name", target);

Assert.True(File.Exists(Path.Combine(target, "data.txt")));
Assert.Equal(Res.MessageBoxSuccessTitle, dialogs.Last.Title);
}

[Fact]
public async Task Move_IsRefused_WhenTheTargetIsInsideTheSource()
{
Expand Down
12 changes: 12 additions & 0 deletions Symlinker/Elevation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ public static bool IsElevated
/// </summary>
public static bool CanCreateSymbolicLinks() => CanCreateSymbolicLinks(IsElevated, File.CreateSymbolicLink);

/// <summary>Whether this process runs from an MSIX package (the Microsoft Store version).</summary>
public static bool IsPackaged()
{
var length = 0;
return GetCurrentPackageFullName(ref length, null) != AppModelErrorNoPackage;
}

private const int AppModelErrorNoPackage = 15700;

[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
private static extern int GetCurrentPackageFullName(ref int packageFullNameLength, char[] packageFullName);

/// <summary>The check behind <see cref="CanCreateSymbolicLinks()"/>, with the link creation replaceable in tests.</summary>
internal static bool CanCreateSymbolicLinks(bool isElevated, Func<string, string, FileSystemInfo> createSymbolicLink)
{
Expand Down
16 changes: 16 additions & 0 deletions Symlinker/LinkCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ public LinkCreator(IDialogService dialogs, ILinkRunner runner)
/// <summary>Minimum time between progress updates while copying.</summary>
internal TimeSpan ProgressInterval { get; set; } = TimeSpan.FromMilliseconds(100);

/// <summary>Whether this copy runs from the Microsoft Store package.</summary>
internal Func<bool> IsPackaged { get; set; } = Elevation.IsPackaged;

/// <summary>The user's AppData folder (the parent of Local and Roaming).</summary>
internal string AppDataFolder { get; set; } =
Path.GetDirectoryName(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData));

public async Task CreateAsync(LinkInput request)
{
try
Expand Down Expand Up @@ -159,6 +166,15 @@ private async Task ReplaceOrCreateAsync(LinkInput request, string linkPath, stri

private async Task OfferMoveAsync(LinkInput request, FileSystemInfo existing, string linkPath, string target)
{
// In the Store package, Windows keeps files this process creates under AppData in a
// private per-package copy: other apps can't see them and uninstalling deletes them.
// Links are fine (mklink runs in cmd.exe), but moved files would end up hidden there.
if (IsPackaged() && LinkMover.IsSameOrInside(target, AppDataFolder))
{
await dialogs.ShowMessageAsync(Res.MessageBoxErrorTitle, Res.MoveIntoAppDataUnsupported);
return;
}

var message = string.Format(
CultureInfo.CurrentUICulture,
request.IsFolder ? Res.DialogMoveFolder : Res.DialogMoveFile,
Expand Down
9 changes: 9 additions & 0 deletions Symlinker/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Symlinker/Properties/Resources.de.resx
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,7 @@ Ins Ziel verschieben und an ihrer Stelle einen Link anlegen? Alles, was den alte
<data name="MoveTargetInsideSource" xml:space="preserve">
<value>Das Ziel darf nicht innerhalb des zu verschiebenden Elements liegen und umgekehrt.</value>
</data>
<data name="MoveIntoAppDataUnsupported" xml:space="preserve">
<value>Die Microsoft Store-Version kann keine Dateien in den AppData-Ordner verschieben: Windows würde sie in einer privaten Kopie ablegen, die nur Symlinker sieht. Wählen Sie ein Ziel außerhalb von AppData, oder verschieben Sie die Dateien selbst dorthin und erstellen Sie den Link erneut.</value>
</data>
</root>
3 changes: 3 additions & 0 deletions Symlinker/Properties/Resources.es.resx
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,7 @@ o modo carpeta (enlazar una carpeta a otra carpeta).</value>
<data name="MoveTargetInsideSource" xml:space="preserve">
<value>El destino no puede estar dentro del elemento que se mueve, ni al revés.</value>
</data>
<data name="MoveIntoAppDataUnsupported" xml:space="preserve">
<value>La versión de Microsoft Store no puede mover archivos a la carpeta AppData: Windows los guardaría en una copia privada que solo ve Symlinker. Elige un destino fuera de AppData, o mueve tú los archivos allí y vuelve a crear el enlace.</value>
</data>
</root>
3 changes: 3 additions & 0 deletions Symlinker/Properties/Resources.fr.resx
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,7 @@ Le déplacer vers la cible et laisser un lien à sa place ? Tout ce qui utilise
<data name="MoveTargetInsideSource" xml:space="preserve">
<value>La cible ne peut pas se trouver dans l'élément déplacé, ni l'inverse.</value>
</data>
<data name="MoveIntoAppDataUnsupported" xml:space="preserve">
<value>La version Microsoft Store ne peut pas déplacer de fichiers dans le dossier AppData : Windows les garderait dans une copie privée que seul Symlinker voit. Choisissez une cible en dehors d'AppData, ou déplacez vous-même les fichiers puis recréez le lien.</value>
</data>
</root>
3 changes: 3 additions & 0 deletions Symlinker/Properties/Resources.hi.resx
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,7 @@
<data name="MoveTargetInsideSource" xml:space="preserve">
<value>लक्ष्य, ले जाए जा रहे आइटम के अंदर नहीं हो सकता, और न ही इसका उल्टा।</value>
</data>
<data name="MoveIntoAppDataUnsupported" xml:space="preserve">
<value>Microsoft Store संस्करण फ़ाइलों को AppData फ़ोल्डर में नहीं ले जा सकता: Windows उन्हें एक निजी कॉपी में रखेगा जिसे सिर्फ़ Symlinker देख सकता है। AppData के बाहर कोई लक्ष्य चुनें, या फ़ाइलों को खुद वहाँ ले जाएं और फिर से लिंक बनाएं।</value>
</data>
</root>
3 changes: 3 additions & 0 deletions Symlinker/Properties/Resources.it.resx
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,7 @@ Spostarlo nella destinazione e lasciare un link al suo posto? Tutto ciò che usa
<data name="MoveTargetInsideSource" xml:space="preserve">
<value>La destinazione non può trovarsi all'interno dell'elemento da spostare, né viceversa.</value>
</data>
<data name="MoveIntoAppDataUnsupported" xml:space="preserve">
<value>La versione di Microsoft Store non può spostare file nella cartella AppData: Windows li terrebbe in una copia privata visibile solo a Symlinker. Scegli una destinazione fuori da AppData, oppure sposta tu i file e crea di nuovo il collegamento.</value>
</data>
</root>
3 changes: 3 additions & 0 deletions Symlinker/Properties/Resources.ja.resx
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,7 @@
<data name="MoveTargetInsideSource" xml:space="preserve">
<value>ターゲットを移動対象の中に置くことはできません。その逆もできません。</value>
</data>
<data name="MoveIntoAppDataUnsupported" xml:space="preserve">
<value>Microsoft Store 版では、AppData フォルダーにファイルを移動できません。Windows がファイルを Symlinker だけが見えるプライベートなコピーに保存してしまうためです。AppData の外にあるターゲットを選ぶか、ファイルを自分で移動してからもう一度リンクを作成してください。</value>
</data>
</root>
3 changes: 3 additions & 0 deletions Symlinker/Properties/Resources.pt.resx
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,7 @@ Movê-lo para o destino e deixar um link no lugar dele? Tudo que usa o caminho a
<data name="MoveTargetInsideSource" xml:space="preserve">
<value>O destino não pode estar dentro do item que está sendo movido, nem o contrário.</value>
</data>
<data name="MoveIntoAppDataUnsupported" xml:space="preserve">
<value>A versão da Microsoft Store não pode mover arquivos para a pasta AppData: o Windows os guardaria em uma cópia privada que só o Symlinker vê. Escolha um destino fora da AppData ou mova você mesmo os arquivos e crie o link novamente.</value>
</data>
</root>
3 changes: 3 additions & 0 deletions Symlinker/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -335,4 +335,7 @@ Move it to the target and leave a link in its place? Anything using the old path
<data name="MoveTargetInsideSource" xml:space="preserve">
<value>The target can't be inside the item being moved, or the other way around.</value>
</data>
<data name="MoveIntoAppDataUnsupported" xml:space="preserve">
<value>The Microsoft Store version can't move files into the AppData folder: Windows would keep them in a private copy that only Symlinker sees. Pick a target outside AppData, or move the files there yourself and create the link again.</value>
</data>
</root>
3 changes: 3 additions & 0 deletions Symlinker/Properties/Resources.zh.resx
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,7 @@
<data name="MoveTargetInsideSource" xml:space="preserve">
<value>目标位置不能位于要移动的项目内部,反之亦然。</value>
</data>
<data name="MoveIntoAppDataUnsupported" xml:space="preserve">
<value>Microsoft Store 版本无法将文件移动到 AppData 文件夹:Windows 会把它们保存在只有 Symlinker 能看到的私有副本中。请选择 AppData 以外的目标,或者自己移动文件后再重新创建链接。</value>
</data>
</root>
13 changes: 8 additions & 5 deletions build-msix.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ foreach ($arch in $Architectures) {
Set-Content -Path (Join-Path $layout "AppxManifest.xml") -Encoding utf8

# The window must start unelevated so drag and drop works. Only the link helper
# (Symlinker.exe --link-helper) elevates, through allowElevation.
# (Symlinker.exe --link-helper) elevates, with a UAC prompt.
$exeManifest = Join-Path $outDir "$arch/Symlinker.exe.manifest"
& $mt -nologo -inputresource:"$(Join-Path $layout 'Symlinker.exe');#1" -out:$exeManifest | Out-Null
if ($LASTEXITCODE -ne 0 -or -not (Select-String -Path $exeManifest -Pattern 'level="asInvoker"' -Quiet)) {
Expand All @@ -164,10 +164,13 @@ foreach ($arch in $Architectures) {
}
$capabilities = @($built.Package.Capabilities.ChildNodes |
Where-Object { $_.NodeType -eq 'Element' } | ForEach-Object { $_.GetAttribute('Name') })
foreach ($needed in 'runFullTrust', 'allowElevation', 'unvirtualizedResources') {
if ($capabilities -notcontains $needed) {
Write-Error "The package doesn't declare the $needed capability."
}
if ($capabilities -notcontains 'runFullTrust') {
Write-Error "The package doesn't declare the runFullTrust capability."
}
# The Store denied allowElevation and unvirtualizedResources, and the app works without them.
$extra = @($capabilities | Where-Object { $_ -ne 'runFullTrust' })
if ($extra) {
Write-Error "The package declares $($extra -join ', '). The Store only approved runFullTrust."
}
Write-Output "Packed $msix"
}
Expand Down
15 changes: 6 additions & 9 deletions packaging/msix/AppxManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
xmlns:desktop6="http://schemas.microsoft.com/appx/manifest/desktop/windows10/6"
IgnorableNamespaces="uap rescap desktop6">
IgnorableNamespaces="uap rescap">

<Identity
Name="AlejandroMoraDaz.Symlinker-SymlinkCreator"
Expand All @@ -25,9 +24,6 @@
<DisplayName>Symlinker - Symlink Creator</DisplayName>
<PublisherDisplayName>Alejandro MD</PublisherDisplayName>
<Logo>Assets\StoreLogo.png</Logo>
<!-- Links must land where the user points, not in the package's private AppData copy. -->
<desktop6:FileSystemWriteVirtualization>disabled</desktop6:FileSystemWriteVirtualization>
<desktop6:RegistryWriteVirtualization>disabled</desktop6:RegistryWriteVirtualization>
</Properties>

<Dependencies>
Expand Down Expand Up @@ -60,10 +56,11 @@
</Applications>

<Capabilities>
<!--
runFullTrust only. The Store denied allowElevation and unvirtualizedResources, and neither
is needed: the link helper elevates with UAC without allowElevation, and mklink runs in
cmd.exe, outside the package's AppData redirection.
-->
<rescap:Capability Name="runFullTrust" />
<!-- Symbolic links need admin: the hidden link helper elevates with UAC. -->
<rescap:Capability Name="allowElevation" />
<!-- Required by the desktop6 virtualization opt-outs above. -->
<rescap:Capability Name="unvirtualizedResources" />
</Capabilities>
</Package>
6 changes: 2 additions & 4 deletions packaging/msix/store/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ Upload folder with `listingData.csv` would do both at once, but it failed with a

```
runFullTrust: Symlinker is a WPF desktop app packaged as a full-trust desktop app. It runs the Windows mklink command (cmd.exe) to create symbolic links, hard links and directory junctions at paths the user chooses, which is not possible from an AppContainer.

allowElevation: Windows requires administrator rights to create symbolic links unless Developer Mode is on. The app itself runs unelevated. Only when the user creates a symbolic link that needs admin, it starts a hidden helper with the standard UAC prompt, and the helper only runs mklink on the paths the user entered. It makes no other system changes.

unvirtualizedResources: Users create links in any folder they choose, including under AppData. With write virtualization on, links created there would silently land in the package's private folder instead of the real location the user picked, so the app turns off file and registry write virtualization.
```

That is the only one. The first submission also asked for `allowElevation` and `unvirtualizedResources`, and both were denied. Neither is needed: the elevated link helper still gets its UAC prompt without `allowElevation`, and links made through `cmd.exe` land in the real `AppData` without `unvirtualizedResources`. `build-msix.ps1` fails if either comes back.

## Notes for certification (Additional Testing Information)

```
Expand Down
Loading