void SaveInfo(object sender, System.EventArgs ev) { var enOrig = Controller.Enabled; Controller.Enabled = false; // TODO: VALIDATE FOR GRIMMY'S SAKE! // TODO: Foreground/Powermode need to be informed of any relevant changes. // ----------------------------------------------- // VALIDATE var fnlen = (friendlyName.Text.Length > 0); var exnam = (execName.Text.Length > 0); var path = (pathName.Text.Length > 0); if (!fnlen || friendlyName.Text.Contains("]") || friendlyName.Text.Contains("[")) { Controller.Valid = false; MessageBox.Show("Friendly name is missing or includes illegal characters (such as square brackets).", "Malconfigured friendly name", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } if (!path && !exnam) { Controller.Valid = false; MessageBox.Show("No path nor executable defined.", "Configuration error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } if ((rescanFreq.Value > 0) && !exnam) { Controller.Valid = false; MessageBox.Show("Rescan requires executable to be defined.", "Configuration error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } var dprc = Taskmaster.processmanager.getWatchedController(friendlyName.Text); if (dprc != null && dprc != Controller) { Controller.Valid = false; MessageBox.Show("Friendly Name conflict.", "Configuration error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } if (!Controller.Valid) { Log.Warning("[{FriendlyName}] Can't save, configuration invalid.", friendlyName.Text); return; } // ----------------------------------------------- // TODO: Warn about conflicting section name string newfriendlyname = friendlyName.Text.Trim(); if (!newPrc && !newfriendlyname.Equals(Controller.FriendlyName)) { Controller.DeleteConfig(); // SharpConfig doesn't seem to support renaming sections, so we delete the old one instead } Controller.FriendlyName = newfriendlyname; Controller.Executable = execName.Text.Length > 0 ? execName.Text.Trim() : null; Controller.Path = pathName.Text.Length > 0 ? pathName.Text.Trim() : null; if (priorityClass.SelectedIndex == 5) { Controller.Priority = null; Controller.PriorityStrategy = ProcessPriorityStrategy.None; } else { Controller.Priority = ProcessHelpers.IntToPriority(priorityClass.SelectedIndex); // is this right? Controller.PriorityStrategy = ProcessPriorityStrategy.None; if (increasePrio.Checked && decreasePrio.Checked) { Controller.PriorityStrategy = ProcessPriorityStrategy.Force; } else if (increasePrio.Checked && !decreasePrio.Checked) { Controller.PriorityStrategy = ProcessPriorityStrategy.Increase; } else if (decreasePrio.Checked && !increasePrio.Checked) { Controller.PriorityStrategy = ProcessPriorityStrategy.Decrease; } } if (affstrategy.SelectedIndex != 0) { if (cpumask == -1) { Controller.Affinity = null; } else { Controller.Affinity = new IntPtr(cpumask); Controller.AffinityStrategy = affstrategy.SelectedIndex == 1 ? ProcessAffinityStrategy.Limit : ProcessAffinityStrategy.Force; } } else { // strategy = ignore Controller.Affinity = null; Controller.AffinityStrategy = ProcessAffinityStrategy.None; } Controller.ModifyDelay = (int)(modifyDelay.Value * 1000); Controller.PowerPlan = PowerManager.GetModeByName(powerPlan.Text); if (Controller.PowerPlan == PowerInfo.PowerMode.Custom) { Controller.PowerPlan = PowerInfo.PowerMode.Undefined; } Controller.Rescan = Convert.ToInt32(rescanFreq.Value); Controller.AllowPaging = allowPaging.Checked; Controller.ForegroundOnly = foregroundOnly.Checked; if (ignorelist.Items.Count > 0) { List <string> ignlist = new List <string>(); foreach (ListViewItem item in ignorelist.Items) { ignlist.Add(item.Text); } Controller.IgnoreList = ignlist.ToArray(); } else { Controller.IgnoreList = null; } Controller.Enabled = enOrig; Controller.SaveConfig(); DialogResult = DialogResult.OK; Close(); }