From 854cc3d0ee24e86bf7825062b282bf451fef9ecd Mon Sep 17 00:00:00 2001 From: Orbmu2k Date: Sat, 23 Mar 2019 16:13:08 +0100 Subject: [PATCH] fix #13 remember window size, fix crash on closing app while scanning --- nspector/Common/DrsScannerService.cs | 8 +- nspector/Common/Helper/UserSettings.cs | 40 +++++++++ nspector/app.config | 3 - nspector/frmBitEditor.cs | 7 -- nspector/frmDrvSettings.Designer.cs | 120 ++++++++++++------------- nspector/frmDrvSettings.cs | 61 ++++++++++++- nspector/frmDrvSettings.resx | 12 +-- nspector/nvidiaProfileInspector.csproj | 4 +- 8 files changed, 170 insertions(+), 85 deletions(-) create mode 100644 nspector/Common/Helper/UserSettings.cs delete mode 100644 nspector/app.config diff --git a/nspector/Common/DrsScannerService.cs b/nspector/Common/DrsScannerService.cs index 89aa5235..9e35ef34 100644 --- a/nspector/Common/DrsScannerService.cs +++ b/nspector/Common/DrsScannerService.cs @@ -79,7 +79,7 @@ private int CalcPercent(int current, int max) return (current > 0) ? (int)Math.Round((current * 100f) / max) : 0; ; } - public async Task ScanForModifiedProfilesAsync(IProgress progress) + public async Task ScanForModifiedProfilesAsync(IProgress progress, CancellationToken token = default(CancellationToken)) { await Task.Run(() => { @@ -98,6 +98,8 @@ await Task.Run(() => foreach (IntPtr hProfile in profileHandles) { + if (token.IsCancellationRequested) break; + progress?.Report(CalcPercent(curProfilePos++, maxProfileCount)); var profile = GetProfileInfo(hSession, hProfile); @@ -165,7 +167,7 @@ await Task.Run(() => }); } - public async Task ScanForPredefinedProfileSettingsAsync(IProgress progress) + public async Task ScanForPredefinedProfileSettingsAsync(IProgress progress, CancellationToken token = default(CancellationToken)) { await Task.Run(() => { @@ -181,6 +183,8 @@ await Task.Run(() => foreach (IntPtr hProfile in profileHandles) { + if (token.IsCancellationRequested) break; + progress?.Report(CalcPercent(curProfilePos++, maxProfileCount)); var profile = GetProfileInfo(hSession, hProfile); diff --git a/nspector/Common/Helper/UserSettings.cs b/nspector/Common/Helper/UserSettings.cs new file mode 100644 index 00000000..261b2e96 --- /dev/null +++ b/nspector/Common/Helper/UserSettings.cs @@ -0,0 +1,40 @@ +using System; +using System.IO; +using System.Text; +using System.Windows.Forms; + +namespace nspector.Common.Helper +{ + public class UserSettings + { + public int WindowTop { get; set; } + + public int WindowLeft { get; set; } + + public int WindowWidth { get; set; } + + public int WindowHeight { get; set; } + + public FormWindowState WindowState { get; set; } + + private static string GetSettingsFilename() + { + var path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), Application.ProductName); + if (!Directory.Exists(path)) Directory.CreateDirectory(path); + return Path.Combine(path, "settings.xml"); ; + } + + public void SaveSettings() + { + XMLHelper.SerializeToXmlFile(this, GetSettingsFilename(), Encoding.Unicode, true); + } + + public static UserSettings LoadSettings() + { + var filename = GetSettingsFilename(); + if (!File.Exists(filename)) return new UserSettings(); + + return XMLHelper.DeserializeFromXMLFile(GetSettingsFilename()); + } + } +} diff --git a/nspector/app.config b/nspector/app.config deleted file mode 100644 index 801c8731..00000000 --- a/nspector/app.config +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/nspector/frmBitEditor.cs b/nspector/frmBitEditor.cs index 3763ffa8..53ff630e 100644 --- a/nspector/frmBitEditor.cs +++ b/nspector/frmBitEditor.cs @@ -211,13 +211,6 @@ private void ApplyValueToProfile(uint val) .SetDwordValueToProfile(_SettingsOwner._CurrentProfile, _Settingid, val); } - private uint GetStoredValue() - { - return DrsServiceLocator - .SettingService - .GetDwordValueFromProfile(_SettingsOwner._CurrentProfile, _Settingid); - } - private async void btnDirectApply_Click(object sender, EventArgs e) { ApplyValueToProfile(_CurrentValue); diff --git a/nspector/frmDrvSettings.Designer.cs b/nspector/frmDrvSettings.Designer.cs index 85fad9c1..26e8c108 100644 --- a/nspector/frmDrvSettings.Designer.cs +++ b/nspector/frmDrvSettings.Designer.cs @@ -91,10 +91,10 @@ private void InitializeComponent() // this.pbMain.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.pbMain.Location = new System.Drawing.Point(12, 475); - this.pbMain.Margin = new System.Windows.Forms.Padding(4); + this.pbMain.Location = new System.Drawing.Point(16, 585); + this.pbMain.Margin = new System.Windows.Forms.Padding(5); this.pbMain.Name = "pbMain"; - this.pbMain.Size = new System.Drawing.Size(840, 9); + this.pbMain.Size = new System.Drawing.Size(1120, 11); this.pbMain.TabIndex = 19; // // tsMain @@ -132,10 +132,10 @@ private void InitializeComponent() this.tsSep6, this.tsbApplyProfile}); this.tsMain.LayoutStyle = System.Windows.Forms.ToolStripLayoutStyle.HorizontalStackWithOverflow; - this.tsMain.Location = new System.Drawing.Point(12, 4); + this.tsMain.Location = new System.Drawing.Point(16, 5); this.tsMain.Name = "tsMain"; this.tsMain.RenderMode = System.Windows.Forms.ToolStripRenderMode.Professional; - this.tsMain.Size = new System.Drawing.Size(840, 25); + this.tsMain.Size = new System.Drawing.Size(1120, 31); this.tsMain.TabIndex = 24; this.tsMain.Text = "toolStrip1"; // @@ -144,7 +144,7 @@ private void InitializeComponent() this.tslProfiles.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None; this.tslProfiles.Margin = new System.Windows.Forms.Padding(0, 5, 10, 2); this.tslProfiles.Name = "tslProfiles"; - this.tslProfiles.Size = new System.Drawing.Size(49, 18); + this.tslProfiles.Size = new System.Drawing.Size(61, 24); this.tslProfiles.Text = "Profiles:"; // // cbProfiles @@ -156,7 +156,7 @@ private void InitializeComponent() this.cbProfiles.Margin = new System.Windows.Forms.Padding(1); this.cbProfiles.MaxDropDownItems = 50; this.cbProfiles.Name = "cbProfiles"; - this.cbProfiles.Size = new System.Drawing.Size(290, 23); + this.cbProfiles.Size = new System.Drawing.Size(385, 28); this.cbProfiles.SelectedIndexChanged += new System.EventHandler(this.cbProfiles_SelectedIndexChanged); this.cbProfiles.TextChanged += new System.EventHandler(this.cbProfiles_TextChanged); // @@ -167,7 +167,7 @@ private void InitializeComponent() this.tsbModifiedProfiles.Image = global::nspector.Properties.Resources.home_sm; this.tsbModifiedProfiles.ImageTransparentColor = System.Drawing.Color.Magenta; this.tsbModifiedProfiles.Name = "tsbModifiedProfiles"; - this.tsbModifiedProfiles.Size = new System.Drawing.Size(36, 22); + this.tsbModifiedProfiles.Size = new System.Drawing.Size(39, 28); this.tsbModifiedProfiles.TextImageRelation = System.Windows.Forms.TextImageRelation.Overlay; this.tsbModifiedProfiles.ToolTipText = "Back to global profile (Home) / User modified profiles"; this.tsbModifiedProfiles.ButtonClick += new System.EventHandler(this.tsbModifiedProfiles_ButtonClick); @@ -176,7 +176,7 @@ private void InitializeComponent() // toolStripSeparator1 // this.toolStripSeparator1.Name = "toolStripSeparator1"; - this.toolStripSeparator1.Size = new System.Drawing.Size(6, 25); + this.toolStripSeparator1.Size = new System.Drawing.Size(6, 31); // // tsbRefreshProfile // @@ -184,7 +184,7 @@ private void InitializeComponent() this.tsbRefreshProfile.Image = ((System.Drawing.Image)(resources.GetObject("tsbRefreshProfile.Image"))); this.tsbRefreshProfile.ImageTransparentColor = System.Drawing.Color.Magenta; this.tsbRefreshProfile.Name = "tsbRefreshProfile"; - this.tsbRefreshProfile.Size = new System.Drawing.Size(24, 22); + this.tsbRefreshProfile.Size = new System.Drawing.Size(24, 28); this.tsbRefreshProfile.Text = "Refresh current profile."; this.tsbRefreshProfile.Click += new System.EventHandler(this.tsbRefreshProfile_Click); // @@ -194,7 +194,7 @@ private void InitializeComponent() this.tsbRestoreProfile.Image = ((System.Drawing.Image)(resources.GetObject("tsbRestoreProfile.Image"))); this.tsbRestoreProfile.ImageTransparentColor = System.Drawing.Color.Magenta; this.tsbRestoreProfile.Name = "tsbRestoreProfile"; - this.tsbRestoreProfile.Size = new System.Drawing.Size(24, 22); + this.tsbRestoreProfile.Size = new System.Drawing.Size(24, 28); this.tsbRestoreProfile.Text = "Restore current profile to NVIDIA defaults."; this.tsbRestoreProfile.Click += new System.EventHandler(this.tsbRestoreProfile_Click); // @@ -204,7 +204,7 @@ private void InitializeComponent() this.tsbCreateProfile.Image = ((System.Drawing.Image)(resources.GetObject("tsbCreateProfile.Image"))); this.tsbCreateProfile.ImageTransparentColor = System.Drawing.Color.Magenta; this.tsbCreateProfile.Name = "tsbCreateProfile"; - this.tsbCreateProfile.Size = new System.Drawing.Size(24, 22); + this.tsbCreateProfile.Size = new System.Drawing.Size(24, 28); this.tsbCreateProfile.Text = "Create new profile"; this.tsbCreateProfile.Click += new System.EventHandler(this.tsbCreateProfile_Click); // @@ -214,14 +214,14 @@ private void InitializeComponent() this.tsbDeleteProfile.Image = global::nspector.Properties.Resources.ieframe_1_18212; this.tsbDeleteProfile.ImageTransparentColor = System.Drawing.Color.Magenta; this.tsbDeleteProfile.Name = "tsbDeleteProfile"; - this.tsbDeleteProfile.Size = new System.Drawing.Size(24, 22); + this.tsbDeleteProfile.Size = new System.Drawing.Size(24, 28); this.tsbDeleteProfile.Text = "Delete current Profile"; this.tsbDeleteProfile.Click += new System.EventHandler(this.tsbDeleteProfile_Click); // // tsSep2 // this.tsSep2.Name = "tsSep2"; - this.tsSep2.Size = new System.Drawing.Size(6, 25); + this.tsSep2.Size = new System.Drawing.Size(6, 31); // // tsbAddApplication // @@ -229,7 +229,7 @@ private void InitializeComponent() this.tsbAddApplication.Image = global::nspector.Properties.Resources.window_application_add; this.tsbAddApplication.ImageTransparentColor = System.Drawing.Color.Magenta; this.tsbAddApplication.Name = "tsbAddApplication"; - this.tsbAddApplication.Size = new System.Drawing.Size(24, 22); + this.tsbAddApplication.Size = new System.Drawing.Size(24, 28); this.tsbAddApplication.Text = "Add application to current profile."; this.tsbAddApplication.Click += new System.EventHandler(this.tsbAddApplication_Click); // @@ -239,7 +239,7 @@ private void InitializeComponent() this.tssbRemoveApplication.Image = global::nspector.Properties.Resources.window_application_delete; this.tssbRemoveApplication.ImageTransparentColor = System.Drawing.Color.Magenta; this.tssbRemoveApplication.Name = "tssbRemoveApplication"; - this.tssbRemoveApplication.Size = new System.Drawing.Size(36, 22); + this.tssbRemoveApplication.Size = new System.Drawing.Size(39, 28); this.tssbRemoveApplication.Text = "Remove application from current profile"; this.tssbRemoveApplication.DropDownItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.tssbRemoveApplication_DropDownItemClicked); this.tssbRemoveApplication.Click += new System.EventHandler(this.tssbRemoveApplication_Click); @@ -247,7 +247,7 @@ private void InitializeComponent() // tsSep3 // this.tsSep3.Name = "tsSep3"; - this.tsSep3.Size = new System.Drawing.Size(6, 25); + this.tsSep3.Size = new System.Drawing.Size(6, 31); // // tsbExportProfiles // @@ -260,35 +260,35 @@ private void InitializeComponent() this.tsbExportProfiles.Image = global::nspector.Properties.Resources.export1; this.tsbExportProfiles.ImageTransparentColor = System.Drawing.Color.Magenta; this.tsbExportProfiles.Name = "tsbExportProfiles"; - this.tsbExportProfiles.Size = new System.Drawing.Size(36, 22); + this.tsbExportProfiles.Size = new System.Drawing.Size(39, 28); this.tsbExportProfiles.Text = "Export user defined profiles"; this.tsbExportProfiles.Click += new System.EventHandler(this.tsbExportProfiles_Click); // // exportCurrentProfileOnlyToolStripMenuItem // this.exportCurrentProfileOnlyToolStripMenuItem.Name = "exportCurrentProfileOnlyToolStripMenuItem"; - this.exportCurrentProfileOnlyToolStripMenuItem.Size = new System.Drawing.Size(342, 22); + this.exportCurrentProfileOnlyToolStripMenuItem.Size = new System.Drawing.Size(422, 26); this.exportCurrentProfileOnlyToolStripMenuItem.Text = "Export current profile only"; this.exportCurrentProfileOnlyToolStripMenuItem.Click += new System.EventHandler(this.exportCurrentProfileOnlyToolStripMenuItem_Click); // // exportCurrentProfileIncludingPredefinedSettingsToolStripMenuItem // this.exportCurrentProfileIncludingPredefinedSettingsToolStripMenuItem.Name = "exportCurrentProfileIncludingPredefinedSettingsToolStripMenuItem"; - this.exportCurrentProfileIncludingPredefinedSettingsToolStripMenuItem.Size = new System.Drawing.Size(342, 22); + this.exportCurrentProfileIncludingPredefinedSettingsToolStripMenuItem.Size = new System.Drawing.Size(422, 26); this.exportCurrentProfileIncludingPredefinedSettingsToolStripMenuItem.Text = "Export current profile including predefined settings"; this.exportCurrentProfileIncludingPredefinedSettingsToolStripMenuItem.Click += new System.EventHandler(this.exportCurrentProfileIncludingPredefinedSettingsToolStripMenuItem_Click); // // exportUserdefinedProfilesToolStripMenuItem // this.exportUserdefinedProfilesToolStripMenuItem.Name = "exportUserdefinedProfilesToolStripMenuItem"; - this.exportUserdefinedProfilesToolStripMenuItem.Size = new System.Drawing.Size(342, 22); + this.exportUserdefinedProfilesToolStripMenuItem.Size = new System.Drawing.Size(422, 26); this.exportUserdefinedProfilesToolStripMenuItem.Text = "Export all customized profiles"; this.exportUserdefinedProfilesToolStripMenuItem.Click += new System.EventHandler(this.exportUserdefinedProfilesToolStripMenuItem_Click); // // exportAllProfilesNVIDIATextFormatToolStripMenuItem // this.exportAllProfilesNVIDIATextFormatToolStripMenuItem.Name = "exportAllProfilesNVIDIATextFormatToolStripMenuItem"; - this.exportAllProfilesNVIDIATextFormatToolStripMenuItem.Size = new System.Drawing.Size(342, 22); + this.exportAllProfilesNVIDIATextFormatToolStripMenuItem.Size = new System.Drawing.Size(422, 26); this.exportAllProfilesNVIDIATextFormatToolStripMenuItem.Text = "Export all driver profiles (NVIDIA Text Format)"; this.exportAllProfilesNVIDIATextFormatToolStripMenuItem.Click += new System.EventHandler(this.exportAllProfilesNVIDIATextFormatToolStripMenuItem_Click); // @@ -301,28 +301,28 @@ private void InitializeComponent() this.tsbImportProfiles.Image = global::nspector.Properties.Resources.import1; this.tsbImportProfiles.ImageTransparentColor = System.Drawing.Color.Magenta; this.tsbImportProfiles.Name = "tsbImportProfiles"; - this.tsbImportProfiles.Size = new System.Drawing.Size(36, 22); + this.tsbImportProfiles.Size = new System.Drawing.Size(39, 28); this.tsbImportProfiles.Text = "Import user defined profiles"; this.tsbImportProfiles.Click += new System.EventHandler(this.tsbImportProfiles_Click); // // importProfilesToolStripMenuItem // this.importProfilesToolStripMenuItem.Name = "importProfilesToolStripMenuItem"; - this.importProfilesToolStripMenuItem.Size = new System.Drawing.Size(364, 22); + this.importProfilesToolStripMenuItem.Size = new System.Drawing.Size(453, 26); this.importProfilesToolStripMenuItem.Text = "Import profile(s)"; this.importProfilesToolStripMenuItem.Click += new System.EventHandler(this.importProfilesToolStripMenuItem_Click); // // importAllProfilesNVIDIATextFormatToolStripMenuItem // this.importAllProfilesNVIDIATextFormatToolStripMenuItem.Name = "importAllProfilesNVIDIATextFormatToolStripMenuItem"; - this.importAllProfilesNVIDIATextFormatToolStripMenuItem.Size = new System.Drawing.Size(364, 22); + this.importAllProfilesNVIDIATextFormatToolStripMenuItem.Size = new System.Drawing.Size(453, 26); this.importAllProfilesNVIDIATextFormatToolStripMenuItem.Text = "Import (replace) all driver profiles (NVIDIA Text Format)"; this.importAllProfilesNVIDIATextFormatToolStripMenuItem.Click += new System.EventHandler(this.importAllProfilesNVIDIATextFormatToolStripMenuItem_Click); // // tsSep4 // this.tsSep4.Name = "tsSep4"; - this.tsSep4.Size = new System.Drawing.Size(6, 25); + this.tsSep4.Size = new System.Drawing.Size(6, 31); // // tscbShowCustomSettingNamesOnly // @@ -331,14 +331,14 @@ private void InitializeComponent() this.tscbShowCustomSettingNamesOnly.Image = global::nspector.Properties.Resources.filter_user; this.tscbShowCustomSettingNamesOnly.ImageTransparentColor = System.Drawing.Color.Magenta; this.tscbShowCustomSettingNamesOnly.Name = "tscbShowCustomSettingNamesOnly"; - this.tscbShowCustomSettingNamesOnly.Size = new System.Drawing.Size(24, 22); + this.tscbShowCustomSettingNamesOnly.Size = new System.Drawing.Size(24, 28); this.tscbShowCustomSettingNamesOnly.Text = "Show the settings and values from CustomSettingNames file only."; this.tscbShowCustomSettingNamesOnly.CheckedChanged += new System.EventHandler(this.cbCustomSettingsOnly_CheckedChanged); // // tsSep5 // this.tsSep5.Name = "tsSep5"; - this.tsSep5.Size = new System.Drawing.Size(6, 25); + this.tsSep5.Size = new System.Drawing.Size(6, 31); // // tscbShowScannedUnknownSettings // @@ -348,7 +348,7 @@ private void InitializeComponent() this.tscbShowScannedUnknownSettings.Image = global::nspector.Properties.Resources.find_set2; this.tscbShowScannedUnknownSettings.ImageTransparentColor = System.Drawing.Color.Magenta; this.tscbShowScannedUnknownSettings.Name = "tscbShowScannedUnknownSettings"; - this.tscbShowScannedUnknownSettings.Size = new System.Drawing.Size(24, 22); + this.tscbShowScannedUnknownSettings.Size = new System.Drawing.Size(24, 28); this.tscbShowScannedUnknownSettings.Text = "Show unknown settings from NVIDIA predefined profiles"; this.tscbShowScannedUnknownSettings.Click += new System.EventHandler(this.tscbShowScannedUnknownSettings_Click); // @@ -358,14 +358,14 @@ private void InitializeComponent() this.tsbBitValueEditor.Image = global::nspector.Properties.Resources.text_binary; this.tsbBitValueEditor.ImageTransparentColor = System.Drawing.Color.Magenta; this.tsbBitValueEditor.Name = "tsbBitValueEditor"; - this.tsbBitValueEditor.Size = new System.Drawing.Size(24, 22); + this.tsbBitValueEditor.Size = new System.Drawing.Size(24, 28); this.tsbBitValueEditor.Text = "Show bit value editor."; this.tsbBitValueEditor.Click += new System.EventHandler(this.tsbBitValueEditor_Click); // // tsSep6 // this.tsSep6.Name = "tsSep6"; - this.tsSep6.Size = new System.Drawing.Size(6, 25); + this.tsSep6.Size = new System.Drawing.Size(6, 31); // // tsbApplyProfile // @@ -374,7 +374,7 @@ private void InitializeComponent() this.tsbApplyProfile.ImageTransparentColor = System.Drawing.Color.Magenta; this.tsbApplyProfile.Name = "tsbApplyProfile"; this.tsbApplyProfile.Overflow = System.Windows.Forms.ToolStripItemOverflow.Never; - this.tsbApplyProfile.Size = new System.Drawing.Size(109, 22); + this.tsbApplyProfile.Size = new System.Drawing.Size(130, 28); this.tsbApplyProfile.Text = "Apply changes"; this.tsbApplyProfile.TextAlign = System.Drawing.ContentAlignment.MiddleRight; this.tsbApplyProfile.Click += new System.EventHandler(this.tsbApplyProfile_Click); @@ -384,10 +384,10 @@ private void InitializeComponent() this.btnResetValue.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.btnResetValue.Enabled = false; this.btnResetValue.Image = global::nspector.Properties.Resources.nv_btn; - this.btnResetValue.Location = new System.Drawing.Point(732, 175); + this.btnResetValue.Location = new System.Drawing.Point(976, 215); this.btnResetValue.Margin = new System.Windows.Forms.Padding(0, 1, 0, 0); this.btnResetValue.Name = "btnResetValue"; - this.btnResetValue.Size = new System.Drawing.Size(25, 19); + this.btnResetValue.Size = new System.Drawing.Size(33, 23); this.btnResetValue.TabIndex = 7; this.btnResetValue.UseVisualStyleBackColor = true; this.btnResetValue.Click += new System.EventHandler(this.btnResetValue_Click); @@ -399,10 +399,10 @@ private void InitializeComponent() this.lblApplications.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(118)))), ((int)(((byte)(185)))), ((int)(((byte)(0))))); this.lblApplications.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; this.lblApplications.ForeColor = System.Drawing.Color.White; - this.lblApplications.Location = new System.Drawing.Point(12, 32); - this.lblApplications.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.lblApplications.Location = new System.Drawing.Point(16, 39); + this.lblApplications.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); this.lblApplications.Name = "lblApplications"; - this.lblApplications.Size = new System.Drawing.Size(840, 17); + this.lblApplications.Size = new System.Drawing.Size(1120, 21); this.lblApplications.TabIndex = 25; this.lblApplications.Text = "fsagame.exe, bond.exe, herozero.exe"; // @@ -440,10 +440,10 @@ private void InitializeComponent() // this.cbValues.BackColor = System.Drawing.SystemColors.Window; this.cbValues.FormattingEnabled = true; - this.cbValues.Location = new System.Drawing.Point(524, 175); - this.cbValues.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.cbValues.Location = new System.Drawing.Point(699, 215); + this.cbValues.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); this.cbValues.Name = "cbValues"; - this.cbValues.Size = new System.Drawing.Size(72, 21); + this.cbValues.Size = new System.Drawing.Size(95, 24); this.cbValues.TabIndex = 5; this.cbValues.Visible = false; this.cbValues.SelectedValueChanged += new System.EventHandler(this.cbValues_SelectedValueChanged); @@ -451,40 +451,40 @@ private void InitializeComponent() // // lblWidth96 // - this.lblWidth96.Location = new System.Drawing.Point(77, 233); - this.lblWidth96.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.lblWidth96.Location = new System.Drawing.Point(103, 287); + this.lblWidth96.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); this.lblWidth96.Name = "lblWidth96"; - this.lblWidth96.Size = new System.Drawing.Size(96, 18); + this.lblWidth96.Size = new System.Drawing.Size(128, 22); this.lblWidth96.TabIndex = 77; this.lblWidth96.Text = "96"; this.lblWidth96.Visible = false; // // lblWidth330 // - this.lblWidth330.Location = new System.Drawing.Point(77, 210); - this.lblWidth330.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.lblWidth330.Location = new System.Drawing.Point(103, 258); + this.lblWidth330.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); this.lblWidth330.Name = "lblWidth330"; - this.lblWidth330.Size = new System.Drawing.Size(330, 22); + this.lblWidth330.Size = new System.Drawing.Size(440, 27); this.lblWidth330.TabIndex = 78; this.lblWidth330.Text = "330 (Helper Labels for DPI Scaling)"; this.lblWidth330.Visible = false; // // lblWidth16 // - this.lblWidth16.Location = new System.Drawing.Point(77, 269); - this.lblWidth16.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.lblWidth16.Location = new System.Drawing.Point(103, 331); + this.lblWidth16.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); this.lblWidth16.Name = "lblWidth16"; - this.lblWidth16.Size = new System.Drawing.Size(16, 18); + this.lblWidth16.Size = new System.Drawing.Size(21, 22); this.lblWidth16.TabIndex = 79; this.lblWidth16.Text = "16"; this.lblWidth16.Visible = false; // // lblWidth30 // - this.lblWidth30.Location = new System.Drawing.Point(77, 251); - this.lblWidth30.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.lblWidth30.Location = new System.Drawing.Point(103, 309); + this.lblWidth30.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); this.lblWidth30.Name = "lblWidth30"; - this.lblWidth30.Size = new System.Drawing.Size(30, 18); + this.lblWidth30.Size = new System.Drawing.Size(40, 22); this.lblWidth30.TabIndex = 80; this.lblWidth30.Text = "30"; this.lblWidth30.Visible = false; @@ -501,12 +501,12 @@ private void InitializeComponent() this.lvSettings.FullRowSelect = true; this.lvSettings.GridLines = true; this.lvSettings.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None; - this.lvSettings.Location = new System.Drawing.Point(12, 51); - this.lvSettings.Margin = new System.Windows.Forms.Padding(4); + this.lvSettings.Location = new System.Drawing.Point(16, 63); + this.lvSettings.Margin = new System.Windows.Forms.Padding(5); this.lvSettings.MultiSelect = false; this.lvSettings.Name = "lvSettings"; this.lvSettings.ShowItemToolTips = true; - this.lvSettings.Size = new System.Drawing.Size(840, 418); + this.lvSettings.Size = new System.Drawing.Size(1119, 514); this.lvSettings.SmallImageList = this.ilListView; this.lvSettings.TabIndex = 2; this.lvSettings.UseCompatibleStateImageBehavior = false; @@ -514,7 +514,6 @@ private void InitializeComponent() this.lvSettings.ColumnWidthChanging += new System.Windows.Forms.ColumnWidthChangingEventHandler(this.lvSettings_ColumnWidthChanging); this.lvSettings.SelectedIndexChanged += new System.EventHandler(this.lvSettings_SelectedIndexChanged); this.lvSettings.DoubleClick += new System.EventHandler(this.lvSettings_DoubleClick); - this.lvSettings.KeyDown += new System.Windows.Forms.KeyEventHandler(this.lvSettings_KeyDown); this.lvSettings.Resize += new System.EventHandler(this.lvSettings_Resize); // // chSettingID @@ -534,9 +533,9 @@ private void InitializeComponent() // // frmDrvSettings // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(864, 492); + this.ClientSize = new System.Drawing.Size(1152, 606); this.Controls.Add(this.lblWidth30); this.Controls.Add(this.lblWidth16); this.Controls.Add(this.lblWidth330); @@ -547,12 +546,13 @@ private void InitializeComponent() this.Controls.Add(this.pbMain); this.Controls.Add(this.btnResetValue); this.Controls.Add(this.cbValues); - this.Margin = new System.Windows.Forms.Padding(4); - this.MinimumSize = new System.Drawing.Size(880, 348); + this.Margin = new System.Windows.Forms.Padding(5); + this.MinimumSize = new System.Drawing.Size(1167, 417); this.Name = "frmDrvSettings"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "nSpector - Driver Profile Settings"; this.Activated += new System.EventHandler(this.frmDrvSettings_Activated); + this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.frmDrvSettings_FormClosed); this.Load += new System.EventHandler(this.frmDrvSettings_Load); this.Shown += new System.EventHandler(this.frmDrvSettings_Shown); this.tsMain.ResumeLayout(false); diff --git a/nspector/frmDrvSettings.cs b/nspector/frmDrvSettings.cs index 463435ea..dd969399 100644 --- a/nspector/frmDrvSettings.cs +++ b/nspector/frmDrvSettings.cs @@ -536,6 +536,7 @@ private void frmDrvSettings_Load(object sender, EventArgs e) { SetupLayout(); SetTitleVersion(); + LoadSettings(); RefreshProfilesCombo(); cbProfiles.Text = GetBaseProfileName(); @@ -661,6 +662,8 @@ private void ShowExportProfiles() MessageBox.Show("No user modified profiles found! Nothing to export.", "Userprofile Search", MessageBoxButtons.OK, MessageBoxIcon.Information); } + private CancellationTokenSource _scannerCancelationTokenSource; + private async Task ScanProfilesSilentAsync(bool scanPredefined, bool showProfileDialog) { if (_skipScan) @@ -671,6 +674,8 @@ private async Task ScanProfilesSilentAsync(bool scanPredefined, bool showProfile pbMain.Minimum = 0; pbMain.Maximum = 100; + _scannerCancelationTokenSource = new CancellationTokenSource(); + var progressHandler = new Progress(value => { pbMain.Value = value; @@ -680,12 +685,12 @@ private async Task ScanProfilesSilentAsync(bool scanPredefined, bool showProfile if (scanPredefined && !_alreadyScannedForPredefinedSettings) { _alreadyScannedForPredefinedSettings = true; - await _scanner.ScanForPredefinedProfileSettingsAsync(progressHandler); + await _scanner.ScanForPredefinedProfileSettingsAsync(progressHandler, _scannerCancelationTokenSource.Token); _meta.ResetMetaCache(); tscbShowScannedUnknownSettings.Enabled = true; } - await _scanner.ScanForModifiedProfilesAsync(progressHandler); + await _scanner.ScanForModifiedProfilesAsync(progressHandler, _scannerCancelationTokenSource.Token); RefreshModifiesProfilesDropDown(); tsbModifiedProfiles.Enabled = true; @@ -808,7 +813,7 @@ private async void frmDrvSettings_Shown(object sender, EventArgs e) new Thread(SetTaskbarIcon).Start(); await ScanProfilesSilentAsync(true, false); - if (WindowState != FormWindowState.Maximized) + if (!_scannerCancelationTokenSource.Token.IsCancellationRequested && WindowState != FormWindowState.Maximized) { new MessageHelper().bringAppToFront((int)this.Handle); } @@ -1127,9 +1132,57 @@ private void lvSettings_DoubleClick(object sender, EventArgs e) } } - private void lvSettings_KeyDown(object sender, KeyEventArgs e) + private void HandleScreenConstraints() + { + var workingArea = Screen.GetWorkingArea(this); + + if (Left < workingArea.X) + Left = workingArea.X; + + if (Top < workingArea.Y) + Top = workingArea.Y; + + if ((Left + Width) > workingArea.X + workingArea.Width) + Left = (workingArea.X + workingArea.Width) - Width; + + if ((Top + Height) > workingArea.Y + workingArea.Height) + Top = (workingArea.Y + workingArea.Height) - Height; + } + + private void SaveSettings() + { + var settings = UserSettings.LoadSettings(); + + if (WindowState == FormWindowState.Normal) + { + settings.WindowTop = Top; + settings.WindowLeft = Left; + settings.WindowHeight = Height; + settings.WindowWidth = Width; + } + else + { + settings.WindowTop = RestoreBounds.Top; + settings.WindowLeft = RestoreBounds.Left; + settings.WindowHeight = RestoreBounds.Height; + settings.WindowWidth = RestoreBounds.Width; + } + settings.WindowState = WindowState; + settings.SaveSettings(); + } + + private void LoadSettings() { + var settings = UserSettings.LoadSettings(); + SetBounds(settings.WindowLeft, settings.WindowTop, settings.WindowWidth, settings.WindowHeight); + WindowState = settings.WindowState != FormWindowState.Minimized ? settings.WindowState : FormWindowState.Normal; + HandleScreenConstraints(); + } + private void frmDrvSettings_FormClosed(object sender, FormClosedEventArgs e) + { + _scannerCancelationTokenSource?.Cancel(); + SaveSettings(); } } } diff --git a/nspector/frmDrvSettings.resx b/nspector/frmDrvSettings.resx index 199b0d15..f209c000 100644 --- a/nspector/frmDrvSettings.resx +++ b/nspector/frmDrvSettings.resx @@ -125,7 +125,7 @@ AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0 ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAADI - DAAAAk1TRnQBSQFMAgEBBAEAAZABBwGQAQcBEAEAARABAAT/ARkBAAj/AUIBTQE2BwABNgMAASgDAAFA + DAAAAk1TRnQBSQFMAgEBBAEAAagBBwGoAQcBEAEAARABAAT/ARkBAAj/AUIBTQE2BwABNgMAASgDAAFA AwABIAMAAQEBAAEYBgABGP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/ADMAAcgBvQGvAacBkQF5BgAD/iEA A+QD2gYAA/4hAAGXAcMBqwFMAZwBcAYAA/4hAAOmA2gGAAP+FQAB8gHxAfABqQGPAXQBzwHHAbwD/wG6 AaUBjAGuAZQBeAHxAe8B7QHvAe0B6wGhAYgBbQHkAeAB2xIAA/UD3QPmA/8D4APeA/QD8wPaA+4SAAHt @@ -195,7 +195,7 @@ iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 - YQUAAA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DhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9 0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc diff --git a/nspector/nvidiaProfileInspector.csproj b/nspector/nvidiaProfileInspector.csproj index e2891782..8bd9b5c8 100644 --- a/nspector/nvidiaProfileInspector.csproj +++ b/nspector/nvidiaProfileInspector.csproj @@ -139,6 +139,7 @@ + @@ -225,9 +226,6 @@ Resources.resx True - - Designer - Designer