-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Impl minimal install select feature #28
This is huge for the project
- Loading branch information
Showing
8 changed files
with
725 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
TinyNvidiaUpdateChecker/Forms/ComponentChooserForm.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Windows.Forms; | ||
using TinyNvidiaUpdateChecker.Handlers; | ||
|
||
namespace TinyNvidiaUpdateChecker.Forms | ||
{ | ||
public partial class ComponentChooserForm : Form | ||
{ | ||
List<Component> componentList; | ||
List<string> choosenComponents = []; | ||
int driverIdx = 0; | ||
|
||
public ComponentChooserForm() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
public List<string> OpenForm(List<Component> _componentList) | ||
{ | ||
componentList = _componentList; | ||
ShowDialog(); | ||
|
||
return choosenComponents; | ||
} | ||
|
||
private void ComponentChooserForm_Load(object sender, System.EventArgs e) | ||
{ | ||
foreach (Component component in componentList) | ||
{ | ||
string label = component.label; | ||
int idx = checkedListBox.Items.Add(label); | ||
component.index = idx; | ||
|
||
if (component.name == "Display.Driver") { driverIdx = idx; } | ||
} | ||
} | ||
|
||
private void checkedListBox_SelectedValueChanged(object sender, System.EventArgs e) | ||
{ | ||
Component comp = componentList.Where(x => x.index == checkedListBox.SelectedIndex).First(); | ||
string description = ComponentHandler.GetComponentDescription(comp.name); | ||
|
||
if (comp.dependencies.Count > 0) | ||
{ | ||
bool first = true; | ||
|
||
foreach (KeyValuePair<string, string> dependency in comp.dependencies) | ||
{ | ||
if (first) | ||
{ | ||
first = false; | ||
description += "\n\nRequires:\n"; | ||
} | ||
|
||
description += $"{dependency.Value}\n"; | ||
} | ||
} | ||
|
||
richTextBox.Text = description; | ||
} | ||
|
||
private void okButton_Click(object sender, System.EventArgs e) | ||
{ | ||
Enabled = false; | ||
choosenComponents.Clear(); | ||
|
||
Dictionary<string, bool> dependencyList = new() { | ||
{"Display.Driver", checkedListBox.CheckedIndices.Contains(driverIdx)} | ||
}; | ||
|
||
foreach (int idx in checkedListBox.CheckedIndices) | ||
{ | ||
Component comp = componentList.Where(x => x.index >= idx).First(); | ||
choosenComponents.Add(comp.name); | ||
|
||
foreach (KeyValuePair<string, string> dependency in comp.dependencies) | ||
{ | ||
dependencyList.TryAdd(dependency.Key, false); | ||
} | ||
} | ||
|
||
foreach (int idx in checkedListBox.CheckedIndices) | ||
{ | ||
Component comp = componentList.Where(x => x.index >= idx).First(); | ||
|
||
if (dependencyList.ContainsKey(comp.name)) | ||
{ | ||
dependencyList[comp.name] = true; | ||
} | ||
} | ||
|
||
bool canProceed = dependencyList.Where(x => x.Value == true).Count() == dependencyList.Count; | ||
|
||
if (canProceed) | ||
{ | ||
Close(); | ||
} | ||
else | ||
{ | ||
string missingComponents = string.Join("\n", dependencyList.Where(x => !x.Value).Select(x => ComponentHandler.GetComponentLabelFromName(x.Key))); | ||
string message = $"You are missing components, please review your selection.\n\nMissing required components:\n{missingComponents}"; | ||
MessageBox.Show(message, "TinyNvidiaUpdateChecker", MessageBoxButtons.OK, MessageBoxIcon.Warning); | ||
} | ||
|
||
Enabled = true; | ||
} | ||
|
||
private void noneLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) | ||
{ | ||
for (int i = 0; i < checkedListBox.Items.Count; i++) | ||
{ | ||
checkedListBox.SetItemChecked(i, false); | ||
} | ||
|
||
richTextBox.Text = ""; | ||
} | ||
|
||
private void allLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) | ||
{ | ||
for (int i = 0; i < checkedListBox.Items.Count; i++) | ||
{ | ||
checkedListBox.SetItemChecked(i, true); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.