mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 23:12:56 +08:00
Move init method to bottom of file
This commit is contained in:
parent
01501f3b82
commit
7dba21fdac
@ -49,57 +49,6 @@ namespace osu.Game.Beatmaps
|
|||||||
prepareLocalCache();
|
prepareLocalCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void prepareLocalCache()
|
|
||||||
{
|
|
||||||
string cacheFilePath = storage.GetFullPath(cache_database_name);
|
|
||||||
string compressedCacheFilePath = $@"{cacheFilePath}.bz2";
|
|
||||||
|
|
||||||
cacheDownloadRequest = new FileWebRequest(compressedCacheFilePath, $@"https://assets.ppy.sh/client-resources/{cache_database_name}.bz2?{DateTimeOffset.UtcNow:yyyyMMdd}");
|
|
||||||
|
|
||||||
cacheDownloadRequest.Failed += ex =>
|
|
||||||
{
|
|
||||||
File.Delete(compressedCacheFilePath);
|
|
||||||
File.Delete(cacheFilePath);
|
|
||||||
|
|
||||||
Logger.Log($@"{nameof(BeatmapUpdaterMetadataLookup)}'s online cache download failed: {ex}", LoggingTarget.Database);
|
|
||||||
};
|
|
||||||
|
|
||||||
cacheDownloadRequest.Finished += () =>
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using (var stream = File.OpenRead(cacheDownloadRequest.Filename))
|
|
||||||
using (var outStream = File.OpenWrite(cacheFilePath))
|
|
||||||
using (var bz2 = new BZip2Stream(stream, CompressionMode.Decompress, false))
|
|
||||||
bz2.CopyTo(outStream);
|
|
||||||
|
|
||||||
// set to null on completion to allow lookups to begin using the new source
|
|
||||||
cacheDownloadRequest = null;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Logger.Log($@"{nameof(LocalCachedBeatmapMetadataSource)}'s online cache extraction failed: {ex}", LoggingTarget.Database);
|
|
||||||
File.Delete(cacheFilePath);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
File.Delete(compressedCacheFilePath);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Task.Run(async () =>
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await cacheDownloadRequest.PerformAsync().ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
// Prevent throwing unobserved exceptions, as they will be logged from the network request to the log file anyway.
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool Available =>
|
public bool Available =>
|
||||||
// no download in progress.
|
// no download in progress.
|
||||||
cacheDownloadRequest == null
|
cacheDownloadRequest == null
|
||||||
@ -173,6 +122,57 @@ namespace osu.Game.Beatmaps
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void prepareLocalCache()
|
||||||
|
{
|
||||||
|
string cacheFilePath = storage.GetFullPath(cache_database_name);
|
||||||
|
string compressedCacheFilePath = $@"{cacheFilePath}.bz2";
|
||||||
|
|
||||||
|
cacheDownloadRequest = new FileWebRequest(compressedCacheFilePath, $@"https://assets.ppy.sh/client-resources/{cache_database_name}.bz2?{DateTimeOffset.UtcNow:yyyyMMdd}");
|
||||||
|
|
||||||
|
cacheDownloadRequest.Failed += ex =>
|
||||||
|
{
|
||||||
|
File.Delete(compressedCacheFilePath);
|
||||||
|
File.Delete(cacheFilePath);
|
||||||
|
|
||||||
|
Logger.Log($@"{nameof(BeatmapUpdaterMetadataLookup)}'s online cache download failed: {ex}", LoggingTarget.Database);
|
||||||
|
};
|
||||||
|
|
||||||
|
cacheDownloadRequest.Finished += () =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var stream = File.OpenRead(cacheDownloadRequest.Filename))
|
||||||
|
using (var outStream = File.OpenWrite(cacheFilePath))
|
||||||
|
using (var bz2 = new BZip2Stream(stream, CompressionMode.Decompress, false))
|
||||||
|
bz2.CopyTo(outStream);
|
||||||
|
|
||||||
|
// set to null on completion to allow lookups to begin using the new source
|
||||||
|
cacheDownloadRequest = null;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logger.Log($@"{nameof(LocalCachedBeatmapMetadataSource)}'s online cache extraction failed: {ex}", LoggingTarget.Database);
|
||||||
|
File.Delete(cacheFilePath);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
File.Delete(compressedCacheFilePath);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Task.Run(async () =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await cacheDownloadRequest.PerformAsync().ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// Prevent throwing unobserved exceptions, as they will be logged from the network request to the log file anyway.
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void logForModel(BeatmapSetInfo set, string message) =>
|
private void logForModel(BeatmapSetInfo set, string message) =>
|
||||||
RealmArchiveModelImporter<BeatmapSetInfo>.LogForModel(set, $@"[{nameof(LocalCachedBeatmapMetadataSource)}] {message}");
|
RealmArchiveModelImporter<BeatmapSetInfo>.LogForModel(set, $@"[{nameof(LocalCachedBeatmapMetadataSource)}] {message}");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user