/// <summary> /// Loads all platforms or their descriptors if a cache file exists /// </summary> private async Task LoadPlatformsAsync() { Stopwatch sw = Stopwatch.StartNew(); CancellationToken cancellationToken = _cancellationTokenSource.Token; if (File.Exists(_cacheFilePath)) { foreach (CustomPlatform platform in EnumeratePlatformDescriptorsFromFile()) { AllPlatforms.AddSorted(1, AllPlatforms.Count - 1, platform); } } // Load all remaining platforms, or all if no cache file is found foreach (string path in Directory.EnumerateFiles(DirectoryPath, "*.plat")) { cancellationToken.ThrowIfCancellationRequested(); if (AllPlatforms.Any(x => x.fullPath == path)) { continue; } CustomPlatform?platform = await CreatePlatformAsync(path); if (platform is null) { continue; } AllPlatforms.AddSorted(1, AllPlatforms.Count - 1, platform); } sw.Stop(); _siraLog.Info($"Loaded {AllPlatforms.Count.ToString(NumberFormatInfo.InvariantInfo)} platforms in {sw.ElapsedMilliseconds.ToString(NumberFormatInfo.InvariantInfo)}ms"); }
/// <summary> /// Loads all platforms or their descriptors if a cache file exists /// </summary> private async Task LoadPlatformsAsync(CancellationToken cancellationToken) { Stopwatch sw = Stopwatch.StartNew(); try { foreach (CustomPlatform platform in EnumeratePlatformDescriptorsFromFile()) { AllPlatforms.AddSorted(BuildInPlatformsCount, AllPlatforms.Count - BuildInPlatformsCount, platform); } } catch (Exception e) { _siraLog.Debug($"Failed to read cache file:\n{e}"); try { File.Delete(_cacheFilePath); } catch { /* Ignored */ } } // Load all remaining platforms, or all if no cache file is found foreach (string path in Directory.EnumerateFiles(DirectoryPath, "*.plat").Where(x => AllPlatforms.All(y => y.fullPath != x))) { if (cancellationToken.IsCancellationRequested) { return; } CustomPlatform?platform = await CreatePlatformAsync(path); if (platform is null) { continue; } AllPlatforms.AddSorted(BuildInPlatformsCount, AllPlatforms.Count - BuildInPlatformsCount, platform); } sw.Stop(); _siraLog.Debug($"Loaded {AllPlatforms.Count.ToString(NumberFormatInfo.InvariantInfo)} platforms in {sw.ElapsedMilliseconds.ToString(NumberFormatInfo.InvariantInfo)}ms"); }