Skip to content

Commit

Permalink
Add: Explicit Mod Refresh on Dependency Check & Revert Accidentally D…
Browse files Browse the repository at this point in the history
…eployed OneDrive Hack
  • Loading branch information
Sewer56 committed Mar 8, 2024
1 parent 4925da0 commit d0ecf9e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 21 deletions.
22 changes: 1 addition & 21 deletions source/Reloaded.Mod.Launcher.Lib/Update.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ public static async Task ResolveMissingPackagesAsync(CancellationToken token = d
ModDependencyResolveResult? lastResolveResult = default;
ModDependencyResolveResult resolveResult;

var isOneDrive = IsOneDrive();
do
{
resolveResult = await GetMissingDependenciesToDownload(token);
Expand All @@ -180,9 +179,6 @@ public static async Task ResolveMissingPackagesAsync(CancellationToken token = d

lastResolveResult = resolveResult;
DownloadPackages(resolveResult, token);

// Very terrible hack, caused by a FileSystem bug on MSFT's end somewhere.
if (isOneDrive) await Task.Delay(1000, token);
}
while (true);

Expand All @@ -200,7 +196,6 @@ public static void ResolveMissingPackages()

ModDependencyResolveResult? lastResolveResult = default;
ModDependencyResolveResult resolveResult;
var isOneDrive = IsOneDrive();

do
{
Expand All @@ -215,10 +210,7 @@ public static void ResolveMissingPackages()
}

DownloadPackages(resolveResult);
lastResolveResult = resolveResult;

// Very terrible hack, caused by a FileSystem bug on MSFT's end somewhere.
if (isOneDrive) Thread.Sleep(1000);
lastResolveResult = resolveResult;
}
while (true);

Expand Down Expand Up @@ -335,18 +327,6 @@ public static bool CheckForInternetConnection()

return false;
}

/// <summary>
/// On Windows 11, Microsoft defaults some accounts to sync via OneDrive.
/// Unfortunately their implementation has issues, files that were downloaded can't immediately be seen by FileSystem.
///
/// We 'hack' around this (poorly), but our solution is far from ideal.
/// </summary>
private static bool IsOneDrive()
{
var conf = IoC.Get<LoaderConfig>();
return conf.GetModConfigDirectory().Contains("OneDrive", StringComparison.OrdinalIgnoreCase);
}

// TODO: This is a temporary hack to get people unstuck.
private static bool IsSameAsLast(ModDependencyResolveResult thisItem, ModDependencyResolveResult? lastItem)
Expand Down
9 changes: 9 additions & 0 deletions source/Reloaded.Mod.Loader.IO/Services/ConfigServiceBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ public void MoveFolder(string newDirectory)
{
throw new NotImplementedException("This feature will be implemented in the future.");
}

/// <summary>
/// Populates the mod list governed by <see cref="Items"/>.
/// </summary>
protected void ForceRefresh()
{
bool executeImmediately = _context == null;
GetItems(executeImmediately);
}

/// <summary>
/// Populates the mod list governed by <see cref="Items"/>.
Expand Down
5 changes: 5 additions & 0 deletions source/Reloaded.Mod.Loader.IO/Services/ModConfigService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public ModConfigService(LoaderConfig config, SynchronizationContext context = nu
/// </summary>
public DependencyResolutionResult GetMissingDependencies(IEnumerable<ModConfig> modsToResolve)
{
// Force a refresh of all mods.
// On some FileSystems, you can't get reliable notifications on FS changes.
// This includes OneDrive, which is now enabled by default on Windows 11 installs (unfortunately).
ForceRefresh();

// Get list of all mods.
var allMods = Items.ToArray();
var allModIds = new HashSet<string>(allMods.Length);
Expand Down

0 comments on commit d0ecf9e

Please sign in to comment.