Skip to content

Commit 29b985f

Browse files
committed
Use InputBox with browse button to add app, add yes/no prompt to reset profile
1 parent f62aa86 commit 29b985f

File tree

3 files changed

+32
-46
lines changed

3 files changed

+32
-46
lines changed

nspector/Common/Helper/InputBox.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ internal static DialogResult Show(string title, string promptText, ref string va
8888
buttonBrowse.Click += buttonBrowse_Click;
8989
}
9090

91-
imageBox.SetBounds(Dpi(368), Dpi(40), Dpi(16), Dpi(16));
91+
imageBox.SetBounds(Dpi(368), Dpi(44), Dpi(16), Dpi(16));
9292

9393
label.AutoSize = true;
9494
label.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;

nspector/frmDrvSettings.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nspector/frmDrvSettings.cs

Lines changed: 30 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,15 @@ private async void tsbRestoreProfile_Click(object sender, EventArgs e)
816816
}
817817
}
818818
else
819-
ResetCurrentProfile();
819+
{
820+
if (MessageBox.Show(this,
821+
"Restore profile to NVIDIA driver defaults?",
822+
"Restore profile",
823+
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
824+
{
825+
ResetCurrentProfile();
826+
}
827+
}
820828
}
821829

822830
private void tsbRefreshProfile_Click(object sender, EventArgs e)
@@ -927,15 +935,24 @@ private void tsbDeleteProfile_Click(object sender, EventArgs e)
927935

928936
private void tsbAddApplication_Click(object sender, EventArgs e)
929937
{
930-
var openDialog = new OpenFileDialog();
931-
openDialog.DefaultExt = "*.exe";
932-
openDialog.Filter = "Application EXE Name|*.exe|Application Absolute Path|*.exe";
938+
if (_CurrentProfile == GetBaseProfileName() || _CurrentProfile == _baseProfileName)
939+
return;
933940

934-
if (openDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
941+
var applications = new Dictionary<string, string>();
942+
_currentProfileSettingItems = _drs.GetSettingsForProfile(_CurrentProfile, GetSettingViewMode(), ref applications);
943+
944+
var existingPaths = new HashSet<string>(applications.Values, StringComparer.OrdinalIgnoreCase);
945+
var applicationName = "";
946+
947+
if (InputBox.Show("Add Application", "Enter an application path/filename/UWP ID to add to the profile:", ref applicationName, new List<string>(), "", 2048, true) == DialogResult.OK)
935948
{
936-
string applicationName = new FileInfo(openDialog.FileName).Name;
937-
if (openDialog.FilterIndex == 2)
938-
applicationName = openDialog.FileName;
949+
// Add new application path
950+
if (existingPaths.Contains(applicationName))
951+
{
952+
MessageBox.Show("This application is already assigned to this profile!",
953+
"Error adding Application", MessageBoxButtons.OK, MessageBoxIcon.Error);
954+
return;
955+
}
939956

940957
try
941958
{
@@ -946,25 +963,26 @@ private void tsbAddApplication_Click(object sender, EventArgs e)
946963
if (ex.Status == Native.NVAPI2.NvAPI_Status.NVAPI_EXECUTABLE_ALREADY_IN_USE || ex.Status == Native.NVAPI2.NvAPI_Status.NVAPI_ERROR)
947964
{
948965
if (lblApplications.Text.ToUpper().IndexOf(" " + applicationName.ToUpper() + ",") != -1)
949-
MessageBox.Show("This application executable is already assigned to this profile!",
966+
MessageBox.Show("This application is already assigned to this profile!",
950967
"Error adding Application", MessageBoxButtons.OK, MessageBoxIcon.Error);
951968
else
952969
{
953970
string profileNames = _scanner.FindProfilesUsingApplication(applicationName);
954971
if (profileNames == "")
955-
MessageBox.Show("This application executable might already be assigned to another profile!",
972+
MessageBox.Show("This application might already be assigned to another profile!",
956973
"Error adding Application", MessageBoxButtons.OK, MessageBoxIcon.Error);
957974
else
958975
MessageBox.Show(
959-
"This application executable is already assigned to the following profiles: " +
976+
"This application is already assigned to the following profiles: " +
960977
profileNames, "Error adding Application", MessageBoxButtons.OK, MessageBoxIcon.Error);
961978
}
962979
}
963980
else
964981
throw;
965982
}
983+
984+
RefreshCurrentProfile();
966985
}
967-
RefreshCurrentProfile();
968986
}
969987

970988
private void tssbRemoveApplication_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e)
@@ -1411,38 +1429,6 @@ private void CopyModifiedSettingsToClipBoard()
14111429
Clipboard.SetText(sbSettings.ToString());
14121430

14131431
}
1414-
1415-
private void lblApplications_DoubleClick(object sender, EventArgs e)
1416-
{
1417-
if (_CurrentProfile == GetBaseProfileName() || _CurrentProfile == _baseProfileName)
1418-
return;
1419-
if (_CurrentProfile.StartsWith("0x"))
1420-
return; // monitor/device profile
1421-
1422-
var applications = new Dictionary<string, string>();
1423-
_currentProfileSettingItems = _drs.GetSettingsForProfile(_CurrentProfile, GetSettingViewMode(), ref applications);
1424-
1425-
var existingPaths = new HashSet<string>(applications.Values, StringComparer.OrdinalIgnoreCase);
1426-
var appPath = "";
1427-
1428-
if (InputBox.Show("Add App Path", "Enter application path/filename/UWP ID to add to the profile", ref appPath, new List<string>(), "", 2048) == DialogResult.OK)
1429-
{
1430-
// Add new application path
1431-
if (!existingPaths.Contains(appPath))
1432-
{
1433-
try
1434-
{
1435-
_drs.AddApplication(_CurrentProfile, appPath);
1436-
}
1437-
catch (NvapiException ex) // NVAPI_EXECUTABLE_ALREADY_IN_USE etc
1438-
{
1439-
MessageBox.Show(ex.Message, "NvAPI Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
1440-
}
1441-
1442-
RefreshCurrentProfile();
1443-
}
1444-
}
1445-
}
14461432
}
14471433
}
14481434

0 commit comments

Comments
 (0)