Floogen / Stardrop

Stardrop is an open-source, cross-platform mod manager for the game Stardew Valley.
https://floogen.gitbook.io/stardrop/
GNU General Public License v3.0
114 stars 31 forks source link

Swap from creating Symlinks with ProcessInfo for api #162

Closed WDoughty closed 5 months ago

WDoughty commented 6 months ago

This changes creating symbolic links from the outside process to creating them via the api. This should reduce the time it takes to create the symbolic links.

Testing loading in 80 mods

  1. Process Info took around 1.7 secs
  2. Using api takes < 100ms

Before:
image

After:
image

Adda0 commented 5 months ago

Hello. I will try to have a look at this PR in the foreseeable future. Thank you for the PR. It looks good from a quick glance.

Floogen commented 5 months ago

Unfortunately Directory.CreateSymbolicLink is not an exact replacement for the current process.

Currently, Stardrop creates a junction while this PR creates a symbolic link. There are a few differences between the two, but the primary benefit of using a junction is that it does not require administrative privileges when using Windows. If you are using Linux / MacOS, I do not believe that it requires such (I have not tested this).

An example of the error:

[Debug][MainWindow.UpdateEnabledModsFolder: Line 2266] Failed to link all mod folders: System.IO.IOException: A required privilege is not held by the client. : 'C:\Users\Floogen\AppData\Roaming\Stardrop\Data\Selected Mods\AlternativeTextures' at Interop.Kernel32.CreateSymbolicLink(String symlinkFileName, String targetFileName, Boolean isDirectory) at System.IO.Directory.CreateSymbolicLink(String path, String pathToTarget) at Stardrop.Views.MainWindow.<>c.b__98_0(ModToLinkPath modToLinkPath) in C:\Users\Floogen\Documents\GitHub Repos\Stardrop\Stardrop\Views\MainWindow.axaml.cs:line 2276 at System.Collections.Generic.List1.ForEach(Action1 action) at Stardrop.Views.MainWindow.CreateSymlinkDirectories(List`1 modToLinkPaths) in C:\Users\Floogen\Documents\GitHub Repos\Stardrop\Stardrop\Views\MainWindow.axaml.cs:line 2274 at Stardrop.Views.MainWindow.UpdateEnabledModsFolder(Profile profile, String enabledModsPath) in C:\Users\Floogen\Documents\GitHub Repos\Stardrop\Stardrop\Views\MainWindow.axaml.cs:line 2260

Chaoschaot232 commented 5 months ago

Is there no way arround admin rights for a faster linking? Also is there a specific reson for using appdata folder here? It forces me to give SD admin rights because rly no app/software is allowed on my machin to write in this trash can folder because it only does wasting space on my C: drive and this also increases r/w operations which could simply eliminated by compleatly eliminating this behavior and instead storing all mods in the main SD Folder, then copy them into the created profile folders and then do one symlink from the profil to the mods folder. This would allow per profile configs which are only changing when updating the mod, otherwise you could have a mod in "n" different profiles but also with "n" different edits. Sure there are some 300MB+ mods but hey, who has today not at last 1TB SSD/NVMe storage installed?

So I would suggest to a per profile-mod-copy rather then the usage of unnessecary appdata folder - which needs definitly to be eliminated and get rid of - like MultiMC is doing it with different profiling where you can choos the storage path for each MC instance.

WDoughty commented 5 months ago

Unfortunately Directory.CreateSymbolicLink is not an exact replacement for the current process.

Currently, Stardrop creates a junction while this PR creates a symbolic link. There are a few differences between the two, but the primary benefit of using a junction is that it does not require administrative privileges when using Windows. If you are using Linux / MacOS, I do not believe that it requires such (I have not tested this).

An example of the error:

[Debug][MainWindow.UpdateEnabledModsFolder: Line 2266] Failed to link all mod folders: System.IO.IOException: A required privilege is not held by the client. : 'C:\Users\Floogen\AppData\Roaming\Stardrop\Data\Selected Mods\AlternativeTextures' at Interop.Kernel32.CreateSymbolicLink(String symlinkFileName, String targetFileName, Boolean isDirectory) at System.IO.Directory.CreateSymbolicLink(String path, String pathToTarget) at Stardrop.Views.MainWindow.<>c.b__98_0(ModToLinkPath modToLinkPath) in C:\Users\Floogen\Documents\GitHub Repos\Stardrop\Stardrop\Views\MainWindow.axaml.cs:line 2276 at System.Collections.Generic.List1.ForEach(Action1 action) at Stardrop.Views.MainWindow.CreateSymlinkDirectories(List`1 modToLinkPaths) in C:\Users\Floogen\Documents\GitHub Repos\Stardrop\Stardrop\Views\MainWindow.axaml.cs:line 2274 at Stardrop.Views.MainWindow.UpdateEnabledModsFolder(Profile profile, String enabledModsPath) in C:\Users\Floogen\Documents\GitHub Repos\Stardrop\Stardrop\Views\MainWindow.axaml.cs:line 2260

That's odd because I don't get any errors when running on Windows 11, but that may be up to my environment. Also a little weird that Microsoft doesn't have a junction link in the default library where something like node does include junctions. I'll do some more investigation when I have some more time.