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
21 changes: 20 additions & 1 deletion Knossos.NET/Classes/KnUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,21 @@ static KnUtils()
public static bool IsAppImage => isAppImage;
public static string AppImagePath => appImagePath;

/// <summary>
/// Keeps a list of remote resources loaded to cache (or checked) during this session
/// So we don't constantly query these remote URLs for changes
/// </summary>
private static List<string> remoteResourceLoadedToCache = new List<string>();

/// <summary>
/// Clear list of remote url resources downloaded to cache (or checked) during this session
/// So they can be checked and redownloaded again without restarting if they are outdated.
/// </summary>
public static void ClearDownloadedRemoteResourceList()
{
remoteResourceLoadedToCache.Clear();
}

/// <summary>
/// Full path to AppImage file
/// </summary>
Expand Down Expand Up @@ -673,6 +688,7 @@ public static string GetCachePath()
var fileInCacheEtagPath = fileInCachePath + ".etag";
string? remoteEtag = null;
bool cacheFileExists = File.Exists(fileInCachePath);
bool cachedOrCheckedDuringThisSession = remoteResourceLoadedToCache.Contains(resourceURL);
Uri uri = new Uri(resourceURL);
bool isNebulaFile = Nebula.nebulaMirrors.Contains(uri.Host.ToLower());
cacheFileIsValid = cacheFileExists && new FileInfo(fileInCachePath).Length > 0 ? true : false;
Expand All @@ -681,9 +697,10 @@ public static string GetCachePath()
if (cacheFileIsValid && cacheFileExists)
{
bool cacheFileEtagExists = File.Exists(fileInCacheEtagPath);
if (isNebulaFile)
if (isNebulaFile || cachedOrCheckedDuringThisSession)
{
//This is a nebula file, nebula files are stored by their checksum so they never update
//Or we already downloaded or checked this file during this session, lets not do it again
return fileInCachePath;
}
else if (cacheFileEtagExists)
Expand All @@ -694,6 +711,7 @@ public static string GetCachePath()
if (cachedEtag != null && cachedEtag == remoteEtag)
{
//cache is up to date
remoteResourceLoadedToCache.Add(resourceURL);
return fileInCachePath;
}
else
Expand Down Expand Up @@ -736,6 +754,7 @@ public static string GetCachePath()
Log.Add(Log.LogSeverity.Error, "KnUtils.GetRemoteResource()", ex);
}
}
remoteResourceLoadedToCache.Add(resourceURL);
return fileInCachePath;
}
catch (Exception ex)
Expand Down
1 change: 1 addition & 0 deletions Knossos.NET/Classes/Knossos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,7 @@ public static void ResetBasePath()
TaskViewModel.Instance?.CancelAllRunningTasks();
Nebula.CancelOperations();
await Task.Delay(2000).ConfigureAwait(false);
KnUtils.ClearDownloadedRemoteResourceList();
LoadBasePath();
});
}
Expand Down