BattletechModders / BattleTechModLoader

A simple mod loader and injector for HBS's PC game BattleTech.
The Unlicense
48 stars 10 forks source link

Prevent File Locks #16

Closed mpstark closed 5 years ago

mpstark commented 6 years ago

Can use Assembly.Load(byte[]) I believe to prevent file locks.

YoungCP commented 6 years ago

Shadow copying (in theory) should already prevent this... https://docs.microsoft.com/en-us/dotnet/framework/app-domains/shadow-copy-assemblies

Something like this...

var appDom = AppDomain.CurrentDomain;
appDom.SetShadowCopyFiles();
appDom.SetCachePath(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Cache"));

I think Mono implements this correctly, although the methods are marked as [Obsolete] with a recommendation to go the AppDomainSetup route, I think that only works for new domains and not for the current domain.

It's worth a shot to see if this works in this version of Unity.