private static async Task <ObservableCollection <ConsoleMachine> > RefreshConsolesAsync() { ObservableCollection <ConsoleMachine> consoleMachines = new ObservableCollection <ConsoleMachine>(); if (!Directory.Exists(GamePath)) { Directory.CreateDirectory(GamePath); } var gameDirectoryInfo = new DirectoryInfo(GamePath); await StopRunningScanAsync(); GameListProperties.SyncTask = Task.Run(async() => { foreach (var consoleDirectoryInfo in gameDirectoryInfo.EnumerateDirectories()) { if (GameListProperties.SyncCts.IsCancellationRequested) //break thread here { break; } string consoleDirectoryPath = consoleDirectoryInfo.FullName; var console = new ConsoleMachine(consoleDirectoryPath); var iconPath = Path.Combine(Config.IconCacheDirectory, "Folder.png"); if (!File.Exists(iconPath)) { W32FileInfo.GetLargeIcon(console.Path).ToBitmap().Save(iconPath, ImageFormat.Png); } consoleMachines.Add(console); await console.RefreshWithoutCache(); } }); bool notify = true; var notifyTask = new Task(() => { Thread.Sleep(NotifyDelay); if (notify) { GameListProperties.NotifySyncChanged(); } }); notifyTask.Start(); await GameListProperties.SyncTask.ConfigureAwait(false); notify = false; GameListProperties.NotifySyncChanged(); return(consoleMachines); }
static void Main(string[] args) { ConsoleSelect main = new ConsoleSelect("Main", "Main Menu"); ConsoleSelect first = new ConsoleSelect("First", "First menu"); first.AddOption(new ConsoleCommand("Command One", () => { Console.WriteLine("Command One"); Console.ReadKey(); })); first.AddOption(new ConsoleCommand("Command Two", () => { Console.WriteLine("Command Two"); Console.ReadKey(); })); first.AddOption(new ConsoleCommand("Command Three", () => { Console.WriteLine("Command Three"); Console.ReadKey(); })); first.AddOption(new ConsoleCommand("Command Four", () => { Console.WriteLine("Command Four"); Console.ReadKey(); })); first.AddOption(new ConsoleCommand("Write Tree", () => { ConsoleMachine.CurrentMachine.WriteTree(); })); ConsoleSelect second = new ConsoleSelect("Second", "Second menu"); ConsoleSelect secondOne = new ConsoleSelect("One", "Second menu - [1]"); secondOne.AddOption(new ConsoleCommand("My method", MyMethod)); secondOne.AddOption(new ConsoleCommand("Paint", Paint.StartPaint)); secondOne.AddOption(new ConsoleCommand("Force exit", () => ConsoleMachine.CurrentMachine.Exit())); second.AddOption(secondOne); second.AddOption(new ConsoleSelect("Two", "Second menu - [2]")); second.AddOption(new ConsoleSelect("Three", "Second menu - [3]")); ConsoleSelect third = new ConsoleSelect("Third", "Third menu"); third.AddOption(CreateSubMachine()); ConsoleSelect fourth = new ConsoleSelect("Fourth", "Fourth menu"); main.AddOption(first); main.AddOption(second); main.AddOption(third); main.AddOption(fourth); ConsoleMachine.Start(main); }
private async void BtnCreate_Click(object sender, RoutedEventArgs e) { string trueName; try { trueName = FileExtension.ValidateFileName(ViewModel.Name); } catch (Exception ex) { MessageBox.Show(ex.Message, Title, MessageBoxButton.OK, MessageBoxImage.Error); return; } var path = Path.Combine(App.Config.GameDirectory, trueName); Directory.CreateDirectory(path); var console = new ConsoleMachine(path); App.GameListLoader.AddConsoleMachine(console); await console.Refresh(); _baseWindow.Close(); }
public void AddConsoleMachine(ConsoleMachine consoleMachine) { _consoleMachines.Add(consoleMachine); }
public static async Task RefreshWithoutCache(this ConsoleMachine console) { await StopRunningRefreshAsync(); GameListExtensionProperties.RefreshTask = Task.Run(() => { if (!File.Exists(console.DescriptionPath)) { console.InitDescription(); } if (!Directory.Exists(console.RomDirectoryPath)) { Directory.CreateDirectory(console.RomDirectoryPath); } else { Execute.OnUiThread(() => { console.Games.Clear(); }, MainWindow.SynchronizationContext); var romDirectoryInfo = new DirectoryInfo(console.RomDirectoryPath); var config = App.Config.GameConsoleConfigs.FirstOrDefault(k => k.Identity == console.Identity); string[] filter = null; bool filterUseWhiteList = false; if (config != null) { filter = config.ExtensionFilter?.Split('|').Select(k => "." + k.Trim().TrimStart('.')).ToArray() ?? new string[0]; filterUseWhiteList = config.UseWhiteList; } foreach (var romFileInfo in romDirectoryInfo.EnumerateFiles()) { if (GameListExtensionProperties.RefreshCts.IsCancellationRequested) //break thread here { break; } if (config != null) { if (filterUseWhiteList) { if (!filter.Contains(romFileInfo.Extension)) { continue; } } else { if (filter.Contains(romFileInfo.Extension)) { continue; } } } var romPath = romFileInfo.FullName; var game = new Game(romPath); if (!Directory.Exists(game.MetaDirectory)) { Directory.CreateDirectory(game.MetaDirectory); var metaDir = new DirectoryInfo(game.MetaDirectory); metaDir.Attributes = metaDir.Attributes | FileAttributes.Hidden; } if (!Directory.Exists(game.ScreenShotDirectory)) { Directory.CreateDirectory(game.ScreenShotDirectory); } if (!File.Exists(game.DescriptionPath)) { game.InitDescription(); } string iconPath; if (Game.SpecialExtensions.Contains(game.Extension)) { var iconName = $"{game.Identity.Replace("/", "").Replace("\\", "").Replace(" ", "")}.png"; iconPath = Path.Combine(Config.IconCacheDirectory, iconName); } else { iconPath = Path.Combine(Config.IconCacheDirectory, game.Extension + ".png"); } if (!File.Exists(iconPath)) { Icon.ExtractAssociatedIcon(game.Path)?.ToBitmap().Save(iconPath, ImageFormat.Png); } game.Length = romFileInfo.Length; Execute.OnUiThread(() => { console.Games.Add(game); }, MainWindow.SynchronizationContext); } } if (!Directory.Exists(console.EmulatorDirectoryPath)) { Directory.CreateDirectory(console.EmulatorDirectoryPath); } }); bool notify = true; var notifyTask = new Task(() => { Thread.Sleep(GameListLoader.NotifyDelay); if (notify) { GameListExtensionProperties.NotifyRefreshChanged(); } }); notifyTask.Start(); await GameListExtensionProperties.RefreshTask.ConfigureAwait(false); notify = false; GameListExtensionProperties.NotifyRefreshChanged(); }
public static async Task Refresh(this ConsoleMachine console) { await RefreshWithoutCache(console); App.GameListLoader.SaveCache(); }
public AddGamePage(AddGameConsoleWindow baseWindow, ConsoleMachine baseConsole) { _baseWindow = baseWindow; _baseConsole = baseConsole; InitializeComponent(); }
public AddGameConsoleWindow(ConsoleMachine console) { _console = console; InitializeComponent(); }