private void Window_Loaded(object sender, RoutedEventArgs e) { BUTTON_LARGE = (MainWin.ColumnDefinitions[1].ActualWidth / 100) * BUTTON_LARGE_PCT; BUTTON_SMALL = BUTTON_LARGE * (BUTTON_SMALL_PCT / 100); BUTTON_SPACE = BUTTON_LARGE * (BUTTON_SPACE_PCT / 100); int tilesWide = (int)(MainWin.ColumnDefinitions[1].ActualWidth / (BUTTON_LARGE + BUTTON_SPACE)); int tilesHigh = (int)(launchers.Count / tilesWide) + (launchers.Count % tilesWide); int x, y; for (x = 0; x < tilesWide && x < launchers.Count; x++) { ColumnDefinition col = new ColumnDefinition(); col.Width = new GridLength(BUTTON_LARGE + BUTTON_SPACE); LauncherGrid.ColumnDefinitions.Add(col); } for (y = 0; y < tilesHigh && launchers.Count > tilesWide; y++) { RowDefinition row = new RowDefinition(); row.Height = new GridLength(BUTTON_LARGE + BUTTON_SPACE); LauncherGrid.RowDefinitions.Add(row); } x = y = 0; foreach (Launcher launcher in launchers) { Button btn = new Button(); btn.Content = launcher.Name; launcher.Width = btn.Width = launcher.Height = btn.Height = BUTTON_SMALL; btn.SetResourceReference(Button.StyleProperty, "LaunchButton"); btn.Tag = launcher; if (launcher.ImagePath != null && FileSystem.FileExists(launcher.ImagePath)) { btn.Background = new ImageBrush { ImageSource = new BitmapImage(new Uri(launcher.ImagePath, UriKind.RelativeOrAbsolute)) }; } else { try { System.Drawing.Icon icon = System.Drawing.Icon.ExtractAssociatedIcon(launcher.LaunchPath); btn.Background = new ImageBrush { ImageSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon( icon.Handle, new Int32Rect(0, 0, icon.Width, icon.Height), BitmapSizeOptions.FromEmptyOptions() ) }; } catch { string err = string.Format(localized.ERROR_LAUNCHER_ICON, launcher.LaunchPath); logError(err, EventLogEntryType.Error); showError(err); } } if (x == tilesWide) { x = 0; y++; } btn.SetValue(Grid.RowProperty, y); btn.SetValue(Grid.ColumnProperty, x); LauncherGrid.Children.Add(btn); x++; btn.MouseEnter += new MouseEventHandler(buttons_MouseEnter); btn.GotFocus += new RoutedEventHandler(buttons_GotFocus); btn.LostFocus += new RoutedEventHandler(buttons_LostFocus); btn.Click += new RoutedEventHandler(buttons_Click); } if (LauncherGrid.Children.Count > 0) { LauncherGrid.Children[0].Focus(); } Launcher pbL = new Launcher(localized.POWER_OFF, "shutdown", "/s /t 0"); pbL.Width = PowerButton.Width; pbL.Height = PowerButton.Height; PowerButton.Tag = pbL; PowerButton.Width = PowerButton.Height = BUTTON_SMALL / 4; PowerButton.MouseEnter += new MouseEventHandler(buttons_MouseEnter); PowerButton.GotFocus += new RoutedEventHandler(buttons_GotFocus); PowerButton.LostFocus += new RoutedEventHandler(buttons_LostFocus); PowerButton.Click += new RoutedEventHandler(buttons_Click); gpTimer.AutoReset = true; gpTimer.Interval = 10; gpTimer.Elapsed += PollGamepad; gpTimer.Start(); }
private void LaunchProcess(Launcher launcher) { ProcessStartInfo pInfo = new ProcessStartInfo(launcher.LaunchPath); if (!String.IsNullOrEmpty(launcher.Args)) pInfo.Arguments = launcher.Args; try { Process process = new Process(); process.StartInfo = pInfo; process.EnableRaisingEvents = true; process.Exited += (s, e) => { gpTimer.Start(); ChangeWindowState(System.Windows.WindowState.Maximized); process.Dispose(); }; process.Start(); gpTimer.Stop(); ChangeWindowState(System.Windows.WindowState.Minimized); } catch { showError(string.Format(localized.ERROR_LAUNCHER_START, launcher.LaunchPath, LAUNCHER_CFG)); } }