Skip to content

Commit

Permalink
Merge branch 'dev/exp' into streamdownload
Browse files Browse the repository at this point in the history
Signed-off-by: OsakaRuma <[email protected]>

# Conflicts:
#	src/Starward/Services/Download/InstallGameService.cs
  • Loading branch information
iamscottxu committed Oct 17, 2024
2 parents 0674c97 + 655df9a commit 533129e
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/Starward/Services/Cache/CacheBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public async Task RemoveExpiredAsync(TimeSpan? duration = null)
continue;
}

if (await IsFileOutOfDateAsync(file, expiryDuration, false).ConfigureAwait(false))
if (IsFileOutOfDateAsync(file, expiryDuration, false))
{
filesToDelete.Add(file);
}
Expand Down Expand Up @@ -315,16 +315,17 @@ public Task PreCacheAsync(Uri uri, bool throwOnError = false, bool storeToMemory
/// <param name="duration">cache duration</param>
/// <param name="treatNullFileAsOutOfDate">option to mark uninitialized file as expired</param>
/// <returns>bool indicate whether file has expired or not</returns>
protected virtual async Task<bool> IsFileOutOfDateAsync(StorageFile file, TimeSpan duration, bool treatNullFileAsOutOfDate = true)
protected virtual bool IsFileOutOfDateAsync(StorageFile file, TimeSpan duration, bool treatNullFileAsOutOfDate = true)
{
if (file == null)
{
return treatNullFileAsOutOfDate;
}

var properties = await file.GetBasicPropertiesAsync().AsTask().ConfigureAwait(false);
// Fix #1097: StorageFile.GetBasicPropertiesAsync() causes inexplicable occasional crashes
var fileInfo = new FileInfo(file.Path);

return properties.Size == 0 || DateTime.Now.Subtract(properties.DateModified.DateTime) > duration;
return fileInfo.Length == 0 || DateTime.Now.Subtract(fileInfo.LastWriteTime) > duration;
}

/// <summary>
Expand Down Expand Up @@ -409,7 +410,7 @@ protected virtual string GetCacheFileName(Uri uri)
var folder = await GetCacheFolderAsync().ConfigureAwait(false);
var baseFile = await folder.TryGetItemAsync(fileName) as StorageFile;

bool downloadDataFile = baseFile == null || await IsFileOutOfDateAsync(baseFile, CacheDuration).ConfigureAwait(false);
bool downloadDataFile = baseFile == null || IsFileOutOfDateAsync(baseFile, CacheDuration);

if (baseFile == null)
{
Expand Down Expand Up @@ -457,9 +458,9 @@ protected virtual string GetCacheFileName(Uri uri)

if (_inMemoryFileStorage.MaxItemCount > 0)
{
var properties = await baseFile.GetBasicPropertiesAsync().AsTask().ConfigureAwait(false);
var fileInfo = new FileInfo(baseFile.Path);

var msi = new InMemoryStorageItem<T>(fileName, properties.DateModified.DateTime, instance);
var msi = new InMemoryStorageItem<T>(fileName, fileInfo.LastWriteTime, instance);
_inMemoryFileStorage.SetItem(msi);
}
}
Expand Down

0 comments on commit 533129e

Please sign in to comment.