Exemplo n.º 1
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            if (Environment.OSVersion.Version < new Version(10, 0, 18362))
            {
                MessageBox.Show(this, "This program only works on Windows 10 19H1 or later. Please upgrade to the latest OS version.",
                                Text, MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1);
                Close();
                return;
            }

            DistroListView.Columns.Clear();
            foreach (var eachProperty in typeof(DistroProperties).GetProperties())
            {
                var browsableAttr = eachProperty.GetCustomAttribute <BrowsableAttribute>();
                if (browsableAttr != null && !browsableAttr.Browsable)
                {
                    continue;
                }

                var colItem = new ColumnHeader();

                var displayNameAttr = eachProperty.GetCustomAttribute <DisplayNameAttribute>();
                if (displayNameAttr != null)
                {
                    colItem.Text = displayNameAttr.DisplayName;
                }
                else
                {
                    colItem.Text = eachProperty.Name;
                }

                DistroListView.Columns.Add(colItem);
            }

            if (!SharedRoutines.IsWsl2SupportedOS())
            {
                shutdownAllDistrosToolStripMenuItem.Visible = false;
            }

            if (!File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "wsl.exe")))
            {
                MessageBox.Show(this, "This program is only available when Windows Subsystem for Linux is enabled. Check the system settings.",
                                Text, MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1);
                Close();
                return;
            }

            this.emptyLabel = new Label()
            {
                Parent      = this,
                Text        = "No WSL distro installed.",
                TextAlign   = ContentAlignment.MiddleCenter,
                Font        = new Font(this.Font.FontFamily, 18f, FontStyle.Bold),
                Dock        = DockStyle.Fill,
                UseMnemonic = false,
                Visible     = false,
            };

            refreshToolStripMenuItem.PerformClick();

            if (!IconGenerator.IsBusy)
            {
                IconGenerator.RunWorkerAsync();
            }
        }