mirror of
https://github.com/FalloutCollaborationProject/FCP-Mod-Updater.git
synced 2026-07-27 17:04:05 -07:00
Change Refresh Status to also clear repository cache
This commit is contained in:
@@ -110,6 +110,30 @@ public class GitHubApiServiceTests : IDisposable
|
||||
Assert.Equal(1, _handler.RequestCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ClearCache_NextRequestFetchesFreshRepositories()
|
||||
{
|
||||
CancellationToken token = TestContext.Current.CancellationToken;
|
||||
|
||||
_handler.ResponseQueue.Enqueue(new HttpResponseMessage(HttpStatusCode.OK)
|
||||
{
|
||||
Content = new StringContent(JsonSerializer.Serialize(new[] { MakeRepo("FCP-Weapons") }))
|
||||
});
|
||||
_handler.ResponseQueue.Enqueue(new HttpResponseMessage(HttpStatusCode.OK)
|
||||
{
|
||||
Content = new StringContent(JsonSerializer.Serialize(new[] { MakeRepo("FCP-Armor") }))
|
||||
});
|
||||
|
||||
IReadOnlyList<RemoteRepo> cached = await _service.GetOrganizationReposAsync(token);
|
||||
|
||||
_service.ClearCache();
|
||||
IReadOnlyList<RemoteRepo> refreshed = await _service.GetOrganizationReposAsync(token);
|
||||
|
||||
Assert.Equal("FCP-Weapons", Assert.Single(cached).Name);
|
||||
Assert.Equal("FCP-Armor", Assert.Single(refreshed).Name);
|
||||
Assert.Equal(2, _handler.RequestCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RateLimitHeaders_Parsed()
|
||||
{
|
||||
|
||||
@@ -141,6 +141,12 @@ The tool opens an interactive menu — use the **arrow keys** to navigate, **Ent
|
||||
2. Choose the mod you want to manage
|
||||
3. Select **Switch Branch** to pick a branch, or **Checkout Specific Commit** to pin to a specific version
|
||||
|
||||
### To clear cached data and refresh mod status:
|
||||
1. Select **Clear Cache & Refresh** from the main menu
|
||||
2. The manager retrieves the FCP repository list again, rescans the Mods directory, and fetches the latest Git status for every installed Git mod
|
||||
|
||||
This does not pull updates, switch versions, or overwrite local changes.
|
||||
|
||||
### To Batch Update Mods
|
||||
|
||||
```bash
|
||||
|
||||
@@ -17,6 +17,12 @@ public class GitHubApiService(HttpClient httpClient) : IGitHubApiService
|
||||
public int? RemainingRateLimit { get; private set; }
|
||||
public DateTimeOffset? RateLimitReset { get; private set; }
|
||||
|
||||
public void ClearCache()
|
||||
{
|
||||
_cachedRepos = null;
|
||||
_cacheTime = DateTimeOffset.MinValue;
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyList<RemoteRepo>> GetOrganizationReposAsync(CancellationToken ct = default)
|
||||
{
|
||||
if (_cachedRepos != null && DateTimeOffset.UtcNow - _cacheTime < _cacheExpiry)
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace FCPModUpdater.Services;
|
||||
|
||||
public interface IGitHubApiService
|
||||
{
|
||||
void ClearCache();
|
||||
Task<IReadOnlyList<RemoteRepo>> GetOrganizationReposAsync(CancellationToken ct = default);
|
||||
Task<RemoteRepo?> GetRepoByNameAsync(string repoName, CancellationToken ct = default);
|
||||
int? RemainingRateLimit { get; }
|
||||
|
||||
@@ -66,7 +66,7 @@ public class InteractiveMenu
|
||||
"Uninstall Mods",
|
||||
"Convert Local to Git",
|
||||
"Mod Version Selector",
|
||||
"Refresh Status",
|
||||
"Clear Cache & Refresh",
|
||||
"Exit"
|
||||
), ct);
|
||||
|
||||
@@ -79,7 +79,7 @@ public class InteractiveMenu
|
||||
"Uninstall Mods" => await HandleUninstallAsync(ct),
|
||||
"Convert Local to Git" => await HandleConvertAsync(ct),
|
||||
"Mod Version Selector" => await HandleVersionSelectorAsync(ct),
|
||||
"Refresh Status" => await HandleRefreshAsync(ct),
|
||||
"Clear Cache & Refresh" => await HandleClearCacheAndRefreshAsync(ct),
|
||||
"Exit" => true,
|
||||
_ => false
|
||||
};
|
||||
@@ -549,8 +549,9 @@ public class InteractiveMenu
|
||||
WaitForKey();
|
||||
}
|
||||
|
||||
private async Task<bool> HandleRefreshAsync(CancellationToken ct)
|
||||
private async Task<bool> HandleClearCacheAndRefreshAsync(CancellationToken ct)
|
||||
{
|
||||
_gitHubApiService.ClearCache();
|
||||
await RefreshModsAsync(ct);
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user