From a49e8fc0ad4335268095001acff693eb65c8e221 Mon Sep 17 00:00:00 2001
From: project-sbc <78889381+project-sbc@users.noreply.github.com>
Date: Fri, 5 Aug 2022 21:35:27 -0400
Subject: [PATCH] added settings, made profiles to the point where they will
work (not yet finished), added date/time to the QAM, adjustable QAM size in
settings
---
MainWindow.xaml.cs | 12 ++++
.../Classes/ChangeTDP/ChangeTDP.cs | 10 +++-
.../Classes/ManageXML/ManageXML.cs | 57 +++++++++++++++++-
PowerControlPanel/Classes/StartUp/StartUp.cs | 2 +-
.../Classes/WriteLog/StreamWriterLog.cs | 19 +++---
PowerControlPanel/Pages/ProfilesPage.xaml | 1 +
PowerControlPanel/Pages/ProfilesPage.xaml.cs | 58 ++++++++++++++-----
PowerControlPanel/Pages/SettingsPage.xaml | 46 ++++++++++++++-
PowerControlPanel/Pages/SettingsPage.xaml.cs | 15 +++++
PowerControlPanel/ProfileData/Profiles.xml | 27 +--------
QuickAccessMenu.xaml | 2 +
QuickAccessMenu.xaml.cs | 1 +
12 files changed, 196 insertions(+), 54 deletions(-)
diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs
index ad7648e..7376eac 100644
--- a/MainWindow.xaml.cs
+++ b/MainWindow.xaml.cs
@@ -57,6 +57,7 @@ public static class GlobalVariables
public static string ActiveProfile = "None";
public static string DefaultProfile = "None";
public static string ActiveApp = "None";
+ public static string powerStatus = "";
//display settings
public static string resolution = "";
@@ -194,6 +195,17 @@ private void timerTick(object sender, EventArgs e)
setTheme();
theme = Properties.Settings.Default.systemTheme;
}
+
+
+
+ //Profile or power status change updater
+ string Power = SystemParameters.PowerLineStatus.ToString();
+ if (Power != GlobalVariables.powerStatus & GlobalVariables.powerStatus != "" & GlobalVariables.ActiveProfile != "None")
+ {
+ MessageBox.Show("run change profile here");
+
+ }
+
}
private void OSKEvent(object sender, EventArgs e)
{
diff --git a/PowerControlPanel/Classes/ChangeTDP/ChangeTDP.cs b/PowerControlPanel/Classes/ChangeTDP/ChangeTDP.cs
index daed2d0..f7017ae 100644
--- a/PowerControlPanel/Classes/ChangeTDP/ChangeTDP.cs
+++ b/PowerControlPanel/Classes/ChangeTDP/ChangeTDP.cs
@@ -22,7 +22,7 @@ public class ChangeTDP
string RWDelay = "800"; //legacy value, RW.exe is not used anymore
private Object objLock = new Object();
private string processorName = "";
- //public string BaseDir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
+
public string BaseDir = AppDomain.CurrentDomain.BaseDirectory;
//Read TDP routines
@@ -88,6 +88,14 @@ public void changeTDP(int pl1TDP, int pl2TDP)
//StreamWriterLog.startStreamWriter("Start TDP change");
determineCPU();
//StreamWriterLog.startStreamWriter("CPU type is " + cpuType);
+
+ //check to make sure input TDP is not above maximum set and minimum 5
+ if (pl1TDP < 5) { pl1TDP = 5; }
+ if (pl2TDP < 5) { pl2TDP = 5; }
+ if (pl1TDP > Properties.Settings.Default.maxTDP) { pl1TDP = Properties.Settings.Default.maxTDP; }
+ if (pl2TDP > Properties.Settings.Default.maxTDP) { pl2TDP = Properties.Settings.Default.maxTDP; }
+
+
if (cpuType == "Intel")
{
if (Properties.Settings.Default.IntelMMIOMSR.Contains("MMIO"))
diff --git a/PowerControlPanel/Classes/ManageXML/ManageXML.cs b/PowerControlPanel/Classes/ManageXML/ManageXML.cs
index b8613f7..f97bc86 100644
--- a/PowerControlPanel/Classes/ManageXML/ManageXML.cs
+++ b/PowerControlPanel/Classes/ManageXML/ManageXML.cs
@@ -188,11 +188,36 @@ public void changeProfileParameter(string powerStatus, string parameter, string
}
- public void updateProfile(string address)
+ public void changeProfileName(string oldName, string newName)
{
+
+ System.Xml.XmlDocument xmlDocument = new System.Xml.XmlDocument();
+ xmlDocument.Load(GlobalVariables.xmlFile);
+ XmlNode xmlNode = xmlDocument.SelectSingleNode("//Configuration/Profiles");
+ XmlNodeList xmlSelectedNodes = xmlNode.SelectNodes("Profile/ProfileName[text()='" + oldName + "']");
+ if (xmlSelectedNodes != null)
+ {
+ foreach (XmlNode xmlNode1 in xmlSelectedNodes)
+ {
+ XmlNode nameNode = xmlNode1.SelectSingleNode("ProfileName");
+ if (nameNode != null)
+ {
+ if (nameNode.InnerText == oldName) { nameNode.InnerText = newName; }
+
+ }
+
+ }
+ }
+
+ xmlDocument.Save(GlobalVariables.xmlFile);
+
+ xmlDocument = null;
+
}
+
+
public void applyProfile()
{
@@ -219,6 +244,36 @@ public DataTable appList()
}
+
+ public void changeProfileNameInApps(string oldName, string newName)
+ {
+
+ System.Xml.XmlDocument xmlDocument = new System.Xml.XmlDocument();
+ xmlDocument.Load(GlobalVariables.xmlFile);
+ XmlNode xmlNode = xmlDocument.SelectSingleNode("//Configuration/Applications");
+ XmlNodeList xmlSelectedNodes = xmlNode.SelectNodes("App/Profile[text()='" + oldName + "']");
+ if (xmlSelectedNodes != null)
+ {
+ foreach (XmlNode xmlNode1 in xmlSelectedNodes)
+ {
+ XmlNode nameNode = xmlNode1.SelectSingleNode("Profile");
+ if (nameNode != null)
+ {
+ if (nameNode.InnerText == oldName) { nameNode.InnerText = newName; }
+
+ }
+
+ }
+
+
+ }
+
+ xmlDocument.Save(GlobalVariables.xmlFile);
+
+ xmlDocument = null;
+
+ }
+
public void createApp()
{
System.Xml.XmlDocument xmlDocument = new System.Xml.XmlDocument();
diff --git a/PowerControlPanel/Classes/StartUp/StartUp.cs b/PowerControlPanel/Classes/StartUp/StartUp.cs
index 100f1f8..586c106 100644
--- a/PowerControlPanel/Classes/StartUp/StartUp.cs
+++ b/PowerControlPanel/Classes/StartUp/StartUp.cs
@@ -16,7 +16,7 @@ public static void runStartUp()
{
TaskScheduler.TaskScheduler.startScheduler();
GlobalVariables.tdp.readTDP();
- if (GlobalVariables.readPL1 > 4000) { Properties.Settings.Default.IntelMMIOMSR = "MSR"; Properties.Settings.Default.Save(); GlobalVariables.tdp.readTDP(); }
+
ChangeDisplaySettings.ChangeDisplaySettings.generateDisplayResolutionAndRateList();
ChangeDisplaySettings.ChangeDisplaySettings.getCurrentDisplaySettings();
diff --git a/PowerControlPanel/Classes/WriteLog/StreamWriterLog.cs b/PowerControlPanel/Classes/WriteLog/StreamWriterLog.cs
index 12c08ac..28c7f8e 100644
--- a/PowerControlPanel/Classes/WriteLog/StreamWriterLog.cs
+++ b/PowerControlPanel/Classes/WriteLog/StreamWriterLog.cs
@@ -8,33 +8,30 @@
namespace Power_Control_Panel.PowerControlPanel.Classes
{
- public class StreamWriterLog
+ public static class StreamWriterLog
{
- //public static string BaseDir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
+
public static string BaseDir = AppDomain.CurrentDomain.BaseDirectory;
public static Object objLock = new Object();
public static void startStreamWriter(string newLog)
{
try
{
- if (!File.Exists(BaseDir + "\\PowerControlPanel\\Logs\\application_log.txt")) { createLogFile(); }
- using (StreamWriter w = File.AppendText("PowerControlPanel/Logs/application_log.txt"))
+ lock (objLock)
{
- lock(objLock)
+ if (!File.Exists(BaseDir + "\\PowerControlPanel\\Logs\\application_log.txt")) { createLogFile(); }
+ using (StreamWriter w = File.AppendText(BaseDir + "\\PowerControlPanel\\Logs\\application_log.txt"))
{
Log(newLog, w);
+
}
-
+
}
-
-
-
-
}
catch (Exception ex)
{
- MessageBox.Show(ex.Message);
+
}
diff --git a/PowerControlPanel/Pages/ProfilesPage.xaml b/PowerControlPanel/Pages/ProfilesPage.xaml
index 1bd898e..ff1a886 100644
--- a/PowerControlPanel/Pages/ProfilesPage.xaml
+++ b/PowerControlPanel/Pages/ProfilesPage.xaml
@@ -68,6 +68,7 @@
+
diff --git a/PowerControlPanel/Pages/ProfilesPage.xaml.cs b/PowerControlPanel/Pages/ProfilesPage.xaml.cs
index 453adf7..2d6987c 100644
--- a/PowerControlPanel/Pages/ProfilesPage.xaml.cs
+++ b/PowerControlPanel/Pages/ProfilesPage.xaml.cs
@@ -21,22 +21,33 @@ namespace Power_Control_Panel.PowerControlPanel.Pages
public partial class ProfilesPage : Page
{
private Classes.ManageXML.ManageXML_Profiles xmlP;
+ private Classes.ManageXML.ManageXML_Apps xmlA;
private string ProfileName = "";
public ProfilesPage()
{
InitializeComponent();
+ //initialize xml management class
xmlP = new Classes.ManageXML.ManageXML_Profiles();
+ xmlA = new Classes.ManageXML.ManageXML_Apps();
+ //populate profile list
loadListView();
-
+ //change theme to match general theme
ThemeManager.Current.ChangeTheme(this, Properties.Settings.Default.systemTheme);
-
+ //hide AMD specific stuff if cpu is intel
if (GlobalVariables.cpuType =="Intel")
{
online_GPUCLK_DP.Visibility = Visibility.Collapsed;
offline_GPUCLK_DP.Visibility = Visibility.Collapsed;
}
+
+
+ //set max tdp on sliders
+ offline_sliderTDP1.Maximum = Properties.Settings.Default.maxTDP;
+ offline_sliderTDP2.Maximum = Properties.Settings.Default.maxTDP;
+ online_sliderTDP1.Maximum = Properties.Settings.Default.maxTDP;
+ online_sliderTDP2.Maximum = Properties.Settings.Default.maxTDP;
}
private void loadListView()
@@ -55,19 +66,32 @@ private void btnAddProfile_Click(object sender, System.Windows.RoutedEventArgs e
private void btnDeleteProfile_Click(object sender, System.Windows.RoutedEventArgs e)
{
-
+ bool deleteProfile = true;
+
- xmlP.deleteProfile(ProfileName);
- loadListView();
- clearProfile();
- if (GlobalVariables.ActiveProfile == ProfileName)
- {
- GlobalVariables.ActiveProfile = "None";
-
+ if (ProfileName == "Default")
+ {
+ if (System.Windows.Forms.MessageBox.Show("Deleting the Default profile will disable having a default. Do you still want to delete it?", "Confirm", MessageBoxButtons.YesNo) == DialogResult.No)
+ {
+ deleteProfile = false;
+ }
}
+
+ if (deleteProfile == true)
+ {
+ xmlP.deleteProfile(ProfileName);
+ loadListView();
+ clearProfile();
+ if (GlobalVariables.ActiveProfile == ProfileName)
+ {
+ GlobalVariables.ActiveProfile = "None";
+
+ }
+ }
+
}
private void saveProfile()
{
@@ -130,10 +154,18 @@ private void saveProfile()
//check if profile name has changed! if yes, update any applications or active profiles with new name
if (ProfileName != txtbxProfileName.Text)
{
- //if not match, then name was changed
- System.Windows.MessageBox.Show("ADD PROFILE NAME CHANGE CODE HERE");
+ //if not match, then name was changed. Update profile name in profiles section of XML. Update all apps with profilename
+ xmlP.changeProfileName(ProfileName, txtbxProfileName.Text);
+ xmlA.changeProfileNameInApps(ProfileName, txtbxProfileName.Text);
- if (GlobalVariables.ActiveProfile == ProfileName) { GlobalVariables.ActiveProfile = txtbxProfileName.Text; }
+ loadListView();
+
+ //if active profile name is the one changed, then update profile
+ if (GlobalVariables.ActiveProfile == ProfileName)
+ {
+ GlobalVariables.ActiveProfile = txtbxProfileName.Text;
+ System.Windows.MessageBox.Show("MAKE CODE TO RUN PROFILE AFTER PROFILE UPDATE");
+ }
}
System.Windows.MessageBox.Show("Profile Saved");
diff --git a/PowerControlPanel/Pages/SettingsPage.xaml b/PowerControlPanel/Pages/SettingsPage.xaml
index 612c305..6b1ad89 100644
--- a/PowerControlPanel/Pages/SettingsPage.xaml
+++ b/PowerControlPanel/Pages/SettingsPage.xaml
@@ -42,7 +42,7 @@
-
+
@@ -105,13 +105,14 @@
-