public async Task LoadRomsAndEmulatorsAsync() { // Use a Task.Run() here to get these methods off the UI thread as they're slow and it will lock up responsiveness. await Task.Run(() => { IsLoading = true; LoadingText = "Loading emulator information from disk..."; EmulatorModels = IOHelper.GetEmulatorInformationFromDisk(EmuManagerModel.EmulatorDirectory); LoadingText = "Loading rom information from disk..."; RomModels = IOHelper.GetRomInformationFromDisk(EmuManagerModel.RomDirectory); LoadingText = string.Empty; IsLoading = false; }); if (EmulatorModels == null || RomModels == null) { // If either model is null, we probably have already shown an error to the user, // since something screwed up. But we may want to explain that nothing has happened in terms // of loading the emulators and roms. // TODO: Show error alert. return; } EmuManagerModel.RomsLoadedCount = RomModels.Length.ToString(); EmuManagerModel.EmulatorsLoadedCount = EmulatorModels.Length.ToString(); EmuManagerModel.ConsolesWithRomsCount = RomModels.GroupBy(x => x.Console).ToList().Count.ToString(); }
public async Task LoadRomsAndEmulatorsAsync(bool showError = true) { if (CheckRomAndEmulatorDirectories() && CheckCanDoWork()) { // Use a Task.Run() here to get these methods off the UI thread as they're slow and it will lock up responsiveness. await Task.Run(() => { IsLoading = true; LoadingText = "Loading emulator information from disk..."; EmulatorModels = IOHelper.GetEmulatorInformationFromDisk(EmuManagerModel.EmulatorDirectory); LoadingText = "Loading rom information from disk..."; RomModels = IOHelper.GetRomInformationFromDisk(EmuManagerModel.RomDirectory); LoadingText = string.Empty; IsLoading = false; }); if (EmulatorModels == null || RomModels == null) { DebugManager.ShowErrorDialog("No roms, or no emulators were able to be loaded. Please check your directories layout.", null); return; } EmuManagerModel.RomsLoadedCount = RomModels.Length.ToString(); EmuManagerModel.EmulatorsLoadedCount = EmulatorModels.Length.ToString(); EmuManagerModel.ConsolesWithRomsCount = RomModels.GroupBy(x => x.Console).ToList().Count.ToString(); } else { // Since this could conceivably be autoloaded we don't want to show an error unless it's a distinct user interaction that calls this method if (showError) { DebugManager.ShowErrorDialog("You must load your ROMs and emulators first.", null); } } }