Exemple #1
0
        /// <summary>
        /// Provides alternatives when the game fails to download, either through an update or through an installation.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">Contains the type of failure that occurred.</param>
        private void OnGameDownloadFailed(object sender, EventArgs e)
        {
            Application.Invoke((o, args) =>
            {
                switch (this.Mode)
                {
                case ELauncherMode.Install:
                case ELauncherMode.Update:
                case ELauncherMode.Repair:
                    {
                        // Set the mode to the same as it was, but no longer in progress.
                        // The modes which fall to this case are all capable of repairing an incomplete or
                        // broken install on their own.
                        SetLauncherMode(this.Mode, false);
                        break;
                    }

                default:
                    {
                        // Other cases (such as Launch) will go to the default mode of Repair.
                        SetLauncherMode(ELauncherMode.Repair, false);
                        break;
                    }
                }
            });
        }
Exemple #2
0
 /// <summary>
 /// Handles the package enumerated event from the explorer builder.
 /// </summary>
 /// <param name="sender">Sender.</param>
 /// <param name="e">E.</param>
 private void OnPackageEnumerated(object sender, ReferenceEnumeratedEventArgs e)
 {
     Application.Invoke(delegate
     {
         this.FiletreeBuilder.NodeStorage.AddPackageNode(e.Reference);
     });
 }
Exemple #3
0
 /// <summary>
 /// Updates the progress bar and progress label during installations, repairs and updates.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">Contains the progress values and current filename.</param>
 private void OnModuleInstallationProgressChanged(object sender, ModuleProgressChangedArgs e)
 {
     Application.Invoke((o, args) =>
     {
         this.MainProgressBar.Text     = e.ProgressBarMessage;
         this.StatusLabel.Text         = e.IndicatorLabelMessage;
         this.MainProgressBar.Fraction = e.ProgressFraction;
     });
 }
Exemple #4
0
        /// <summary>
        /// Warns the user when the game fails to launch, and offers to attempt a repair.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">Empty event args.</param>
        private void OnGameLaunchFailed(object sender, EventArgs e)
        {
            Application.Invoke((o, args) =>
            {
                this.StatusLabel.Text     = LocalizationCatalog.GetString("The game failed to launch. Try repairing the installation.");
                this.MainProgressBar.Text = string.Empty;

                SetLauncherMode(ELauncherMode.Repair, false);
            });
        }
Exemple #5
0
        /// <summary>
        /// Starts the launcher update process when its files have finished downloading.
        /// </summary>
        private static void OnLauncherDownloadFinished(object sender, EventArgs e)
        {
            Application.Invoke((o, args) =>
            {
                ProcessStartInfo script = LauncherHandler.CreateUpdateScript();
                Process.Start(script);

                Application.Quit();
            });
        }
Exemple #6
0
 public void LinkReceived()
 {
     Application.Invoke((_, _) =>
     {
         try
         {
             GtkHelper.ShowMessageBox(this, TextResource.GetText("MSG_REF_LINK_MSG"));
             CloseAndDispose();
         }
         catch { }
     });
 }
Exemple #7
0
        /// <summary>
        /// Load a simulation from a given .dll file and a classname, create
        /// a new simulation run, initialize it and update the start configuration.
        /// </summary>
        /// <param name="path"></param>
        /// <param name="className"></param>
        private bool Load(string path, string className)
        {
            try
            {
                _model.Sim?.Unload();
                _model.Sim = new Simulation(path, className);

                // -- Create run from simulation

                var run = new SimRun(_model.Sim.Spawn())
                {
                    RenderHeight     = _model.RenderHeight,
                    RenderWidth      = _model.RenderWidth,
                    IsWriteLogToFile = _model.WriteLogToFile,
                    SimDelay         = _model.SimDelay
                };
                run.OnUpdate += (sender, args) =>
                {
                    Application.Invoke((s, a) => AfterUpdate());
                };
                run.OnLog += (sender, args) =>
                {
                    Application.Invoke((s, a) => _logOutput.Log(args.Message));
                };
                run.Init(run.Instance.GetConfig());

                _model.ActiveRun.Set(run);

                return(true);
            }
            catch (ArgumentException e)
            {
                ShowMessageDialog(e.Message);
                _model.Sim = null;
                LoadDefault();

                return(false);
            }
        }
Exemple #8
0
        private async void InitStart()
        {
            InitData initData = new InitData();
            await Task.Run(() =>
            {
                Progres.Visible = false;

                Application.Invoke(delegate
                                   { textView.Buffer.Text = LoadingHistory.Loading(); });



                initData = Settings.SettingsFileRead().Result;
            });



            if (initData != null)
            {
                Application.Invoke(delegate
                                   { Entry.Text = initData.Currency + initData.Address; });
            }
        }
Exemple #9
0
 /// <summary>
 /// Handles offering of repairing the game to the user should the game exit
 /// with a bad exit code.
 /// </summary>
 private void OnGameExited(object sender, int exitCode)
 {
     Application.Invoke((o, args) =>
     {
         if (exitCode != 0 &&
             exitCode != -1073741510)
         {
             using (var crashDialog = new MessageDialog
                                      (
                        this,
                        DialogFlags.Modal,
                        MessageType.Question,
                        ButtonsType.YesNo,
                        LocalizationCatalog.GetString
                        (
                            "Whoops! The game appears to have crashed.\n" +
                            "Would you like the launcher to verify the installation?"
                        )
                                      ))
             {
                 if (crashDialog.Run() == (int)ResponseType.Yes)
                 {
                     SetLauncherMode(ELauncherMode.Repair, false);
                     this.MainButton.Click();
                 }
                 else
                 {
                     SetLauncherMode(ELauncherMode.Launch, false);
                 }
             }
         }
         else
         {
             SetLauncherMode(ELauncherMode.Launch, false);
         }
     });
 }
Exemple #10
0
        /// <summary>
        /// Allows the user to launch or repair the game once installation finishes.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">Contains the result of the download.</param>
        private void OnGameDownloadFinished(object sender, EventArgs e)
        {
            Application.Invoke((o, args) =>
            {
                this.StatusLabel.Text = LocalizationCatalog.GetString("Idle");

                switch (this.Mode)
                {
                case ELauncherMode.Install:
                    {
                        this.MainProgressBar.Text = LocalizationCatalog.GetString("Installation finished");
                        break;
                    }

                case ELauncherMode.Update:
                    {
                        this.MainProgressBar.Text = LocalizationCatalog.GetString("Update finished");
                        break;
                    }

                case ELauncherMode.Repair:
                    {
                        this.MainProgressBar.Text = LocalizationCatalog.GetString("Repair finished");
                        break;
                    }

                default:
                    {
                        this.MainProgressBar.Text = string.Empty;
                        break;
                    }
                }

                SetLauncherMode(ELauncherMode.Launch, false);
            });
        }
Exemple #11
0
 public void DownloadCancelled(object?sender, EventArgs e)
 {
     active = false;
     Application.Invoke((_, _) => CloseWindow());
 }
Exemple #12
0
 /// <summary>
 ///    Invokes the given EventHandler on the GUI thread.
 /// </summary>
 /// <param name="sender">The sender parameter to pass to the handler</param>
 /// <param name="args">Arguments to pass to the handler</param>
 /// <param name="handler">The handler to invoke on the main thread</param>
 /// <remarks>
 ///    This routine should be used when your application needs
 ///    to invoke methods or access properties and events from Moonlight
 ///    or Gtk# from a thread that is not the main thread.
 /// </remarks>
 public static void Invoke(object sender, EventArgs args, EventHandler handler)
 {
     Application.Invoke(sender, args, handler);
 }
Exemple #13
0
 /// <summary>
 ///    Invokes the given EventHandler on the GUI thread.
 /// </summary>
 /// <param name="handler">The handler to invoke on the main thread</param>
 /// <remarks>
 ///    This routine should be used when your application needs
 ///    to invoke methods or access properties and events from Moonlight
 ///    or Gtk# from a thread that is not the main thread.
 /// </remarks>
 public static void Invoke(EventHandler handler)
 {
     Application.Invoke(handler);
 }
        public WindowBuilder()
        {
            _columnFilter = 0;
            _textToFilter = "";

            _processIdToKill = new List <int>();
            _listStore       = new ListStore(typeof(string), typeof(string), typeof(string), typeof(string),
                                             typeof(string), typeof(string), typeof(string), typeof(string), typeof(string), typeof(string));

            Application.Init();

            _window = new Window("Label sample");
            _window.Resize(1300, 600);
            _window.Title = "Process Watch";
            _window.SetIconFromFile("icons/processIconSmall.png");
            _window.BorderWidth  = 5;
            _window.DeleteEvent += OnWindowClose;

            var aboutButton = new Button();
            var aboutIcon   = new Image();

            aboutIcon.Pixbuf        = new Pixbuf("icons/information.png");
            aboutButton.Image       = aboutIcon;
            aboutButton.TooltipText = "About Process Watch";
            aboutButton.Clicked    += (sender, args) =>
            {
                _aboutDialog.Show();
            };

            _aboutDialog = CreateAboutDialog();

            var filterButton = new Button();

            filterButton.Image       = new Image(Stock.Find, IconSize.Button);
            filterButton.TooltipText = "Filtration utilities";
            filterButton.Clicked    += (sender, args) =>
            {
                if (_filtrationHBox.IsVisible)
                {
                    _filtrationHBox.Hide();
                }
                else
                {
                    _filtrationHBox.ShowAll();
                }
            };

            var windowHBox = new HBox(false, 5);

            windowHBox.PackEnd(aboutButton, false, false, 0);
            windowHBox.PackEnd(filterButton, false, false, 0);

            _processNameEntry          = new Entry();
            _processNameEntry.Changed += OnChanged;

            _processIdEntry               = new Entry();
            _processIdEntry.Changed      += OnChanged;
            _processIdEntry.TextInserted += OnlyNumerical;

            // String values for the combobox - filtration direction
            _filtrationDirectionOptions = new[]
            {
                ">",
                "≥",
                "=",
                "≤",
                "<"
            };

            // String values for the combobox - memory usage units
            _memoryFiltrationDirectionUnits = new[]
            {
                "B",
                "KB",
                "MB",
                "GB"
            };


            _memoryFiltrationEntry = new Entry();
            _memoryFiltrationEntry.MaxWidthChars = 7;
            _memoryFiltrationEntry.WidthChars    = 7;
            _memoryFiltrationEntry.Changed      += OnChanged;
            _memoryFiltrationEntry.TextInserted += OnlyNumerical;

            _memoryFiltrationDirectionComboBox          = new ComboBox(_filtrationDirectionOptions);
            _memoryFiltrationDirectionComboBox.Changed += OnChanged;

            _memoryFiltrationUnitsComboBox          = new ComboBox(_memoryFiltrationDirectionUnits);
            _memoryFiltrationUnitsComboBox.Changed += OnChanged;

            _memoryFiltrationHbox = new HBox();
            _memoryFiltrationHbox.PackStart(_memoryFiltrationDirectionComboBox, false, false, 0);
            _memoryFiltrationHbox.PackStart(_memoryFiltrationEntry, false, false, 0);
            _memoryFiltrationHbox.PackStart(_memoryFiltrationUnitsComboBox, false, false, 0);


            _cpuFiltrationEntry = new Entry();
            _cpuFiltrationEntry.MaxWidthChars = 7;
            _cpuFiltrationEntry.WidthChars    = 7;
            _cpuFiltrationEntry.Changed      += OnChanged;
            _cpuFiltrationEntry.TextInserted += OnlyNumerical;

            _cpuFiltrationDirectionComboBox          = new ComboBox(_filtrationDirectionOptions);
            _cpuFiltrationDirectionComboBox.Changed += OnChanged;

            var cpuFiltrationLabel = new Label("%");

            _cpuFiltrationHbox = new HBox();
            _cpuFiltrationHbox.PackStart(_cpuFiltrationDirectionComboBox, false, false, 0);
            _cpuFiltrationHbox.PackStart(_cpuFiltrationEntry, false, false, 0);
            _cpuFiltrationHbox.PackStart(cpuFiltrationLabel, false, false, 0);


            _filtrationOptions = new[]
            {
                "All processes",
                "Filter by PID",
                "Filter by Process Name",
                "Filter by Memory Usage",
                "Filter by CPU usage",
            };

            var filtrationCombo = new ComboBox(_filtrationOptions);

            filtrationCombo.Changed += ComboOnChanged;

            _filtrationHBox = new HBox(false, 5);
            _filtrationHBox.PackStart(filtrationCombo, false, false, 0);


            string[] columnLabels =
            {
                "PID",
                "Process name",
                "Memory usage",
                "Priority",
                "User CPU Time",
                "Privileged CPU Time",
                "Total CPU Time",
                "CPU usage",
                "Threads",
                "Start Time"
            };


            _treeModelFilter             = new TreeModelFilter(_listStore, null);
            _treeModelFilter.VisibleFunc = Filter;

            var treeModelSort = new TreeModelSort(_treeModelFilter);

            treeModelSort.SetSortFunc(0, WindowBuilderHelper.IdSortFunc);
            treeModelSort.SetSortFunc(1, WindowBuilderHelper.ProcessNameSortFunc);
            treeModelSort.SetSortFunc(2, WindowBuilderHelper.MemoryUsageSortFunc);
            treeModelSort.SetSortFunc(3, WindowBuilderHelper.PrioritySortFunc);
            treeModelSort.SetSortFunc(4, WindowBuilderHelper.UserCpuTimeSortFunc);
            treeModelSort.SetSortFunc(5, WindowBuilderHelper.PrivilegedCpuTimeSortFunc);
            treeModelSort.SetSortFunc(6, WindowBuilderHelper.TotalCpuTimeSortFunc);
            treeModelSort.SetSortFunc(7, WindowBuilderHelper.CpuUsageSortFunc);
            treeModelSort.SetSortFunc(8, WindowBuilderHelper.ThreadCountSortFunc);
            treeModelSort.SetSortFunc(9, WindowBuilderHelper.StartTimeSortFunc);

            var treeView = new TreeView();

            treeView.Model              = treeModelSort;
            treeView.Selection.Mode     = SelectionMode.Multiple;
            treeView.Selection.Changed += OnSelectionChanged;
            treeView.TooltipColumn      = 1;

            // Create a scrollable window
            var scrolledWindow = new ScrolledWindow();

            scrolledWindow.Add(treeView);

            // Create a CellRendererText responsible for proper rendering cell data
            var cellRendererText = new CellRendererText();

            cellRendererText.Alignment = Pango.Alignment.Right;
            cellRendererText.Xalign    = 0.5f;

            // Load the _treeView with TreeViewColumns
            for (int i = 0; i < 10; i++)
            {
                var treeViewColumn = new TreeViewColumn();
                treeViewColumn.Clickable     = true;
                treeViewColumn.Resizable     = true;
                treeViewColumn.Title         = columnLabels[i];
                treeViewColumn.SortIndicator = true;
                treeViewColumn.Alignment     = 0.5f;
                treeViewColumn.Expand        = true;
                treeViewColumn.SortColumnId  = i;
                treeViewColumn.PackStart(cellRendererText, true);
                treeViewColumn.AddAttribute(cellRendererText, "text", i);

                switch (i)
                {
                case 0:
                    break;

                case 1:
                    _window.GetSize(out int width, out int height);
                    treeViewColumn.MaxWidth = Math.Abs(width / 2);
                    break;

                case 2:
                    treeViewColumn.SetCellDataFunc(cellRendererText, WindowBuilderHelper.MemoryUsageFormatter);
                    break;

                case 3:
                    break;

                case 4:
                    treeViewColumn.SetCellDataFunc(cellRendererText, WindowBuilderHelper.UserCpuTimeFormatter);
                    break;

                case 5:
                    treeViewColumn.SetCellDataFunc(cellRendererText, WindowBuilderHelper.PrivilegedCpuTimeFormatter);
                    break;

                case 6:
                    treeViewColumn.SetCellDataFunc(cellRendererText, WindowBuilderHelper.TotalCpuTimeFormatter);
                    break;

                case 7:
                    treeViewColumn.SetCellDataFunc(cellRendererText, WindowBuilderHelper.CpuUsageFormatter);
                    break;

                case 8:
                    break;

                case 9:
                    treeViewColumn.SetCellDataFunc(cellRendererText, WindowBuilderHelper.StartTimeFormatter);
                    break;
                }

                treeView.AppendColumn(treeViewColumn);
            }

            var killButton = new Button("Kill process");

            killButton.Clicked += KillProcess;

            var windowVBox = new VBox(false, 5);

            windowVBox.PackStart(windowHBox, false, false, 0);
            windowVBox.PackStart(_filtrationHBox, false, false, 0);
            windowVBox.PackStart(scrolledWindow, true, true, 0);
            windowVBox.PackStart(killButton, false, false, 0);

            _window.Add(windowVBox);

            // Create an instance of the object Updater
            _processGrabber = new ProcessGrabber();
            // Add a callback executed when _processGrabber takes process data.
            // The callback clears the _treeView content and loads new data
            // Before clearing the _treeView content the callback saves the current scroll position
            _processGrabber.OnResult += (sender, processList) =>
            {
                Application.Invoke(delegate
                {
                    _currentScrollPosition = treeView.Vadjustment.Value;
                    StoreClear();
                    LoadStore(processList);

                    treeView.ShowAll();
                });
            };

            // Add a callback executed after 'Changed' event raised after changing the position of the _treeView
            // When the _treeView content is reloaded the previous scroll position is updated
            treeView.Vadjustment.Changed += (sender, args) =>
            {
                treeView.Vadjustment.Value = _currentScrollPosition;
            };

            // Start the Timer process responsible for grabbing process data periodically
            _processGrabber.Run();

            treeView.ShowAll();
            _window.ShowAll();

            // Hide widgets related to process filtration
            _filtrationHBox.Hide();
        }