diff --git a/Assemble/install/Install.exe b/Assemble/install/Install.exe
index 1b1fdaf..8e6b825 100644
Binary files a/Assemble/install/Install.exe and b/Assemble/install/Install.exe differ
diff --git a/Assemble/install/Uninstall.exe b/Assemble/install/Uninstall.exe
index c8920a5..e574afc 100644
Binary files a/Assemble/install/Uninstall.exe and b/Assemble/install/Uninstall.exe differ
diff --git a/GPUPrefSwitcher.sln b/GPUPrefSwitcher.sln
index 5dac333..b3a4540 100644
--- a/GPUPrefSwitcher.sln
+++ b/GPUPrefSwitcher.sln
@@ -104,8 +104,8 @@ Global
{6C338214-045F-4BBD-8F10-6001B666215E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6C338214-045F-4BBD-8F10-6001B666215E}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{6C338214-045F-4BBD-8F10-6001B666215E}.Debug|ARM64.Build.0 = Debug|Any CPU
- {6C338214-045F-4BBD-8F10-6001B666215E}.Debug|x64.ActiveCfg = Debug|Any CPU
- {6C338214-045F-4BBD-8F10-6001B666215E}.Debug|x64.Build.0 = Debug|Any CPU
+ {6C338214-045F-4BBD-8F10-6001B666215E}.Debug|x64.ActiveCfg = Debug|x64
+ {6C338214-045F-4BBD-8F10-6001B666215E}.Debug|x64.Build.0 = Debug|x64
{6C338214-045F-4BBD-8F10-6001B666215E}.Debug|x86.ActiveCfg = Debug|x86
{6C338214-045F-4BBD-8F10-6001B666215E}.Debug|x86.Build.0 = Debug|x86
{6C338214-045F-4BBD-8F10-6001B666215E}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -151,6 +151,7 @@ Global
{76BFD458-C88C-4484-9578-DC1B75BB945C}.Debug|Any CPU.ActiveCfg = Debug
{76BFD458-C88C-4484-9578-DC1B75BB945C}.Debug|ARM64.ActiveCfg = Debug
{76BFD458-C88C-4484-9578-DC1B75BB945C}.Debug|x64.ActiveCfg = Debug
+ {76BFD458-C88C-4484-9578-DC1B75BB945C}.Debug|x64.Build.0 = Debug
{76BFD458-C88C-4484-9578-DC1B75BB945C}.Debug|x86.ActiveCfg = Debug
{76BFD458-C88C-4484-9578-DC1B75BB945C}.Release|Any CPU.ActiveCfg = Release
{76BFD458-C88C-4484-9578-DC1B75BB945C}.Release|ARM64.ActiveCfg = Release
diff --git a/GPUPrefSwitcher/AppLogger.cs b/GPUPrefSwitcher/AppLogger.cs
index 5ef17b5..5ee2086 100644
--- a/GPUPrefSwitcher/AppLogger.cs
+++ b/GPUPrefSwitcher/AppLogger.cs
@@ -110,7 +110,7 @@ public static AppLogger Initialize (string logFolderPath_Error, string logFileNa
};
//useful for capturing fire-and-forget tasks that error out
- /* //TODO this doesn't actually work
+ ///TODO this doesn't work?
System.Threading.Tasks.TaskScheduler.UnobservedTaskException += (sender, e) =>
{
logger.DumpStandardLogBufferToStandardLog().Wait();
@@ -119,7 +119,6 @@ public static AppLogger Initialize (string logFolderPath_Error, string logFileNa
logger.ErrorLog(e.ToString()).Wait();
};
- */
return logger;
}
diff --git a/GPUPrefSwitcher/FileSwapper.cs b/GPUPrefSwitcher/FileSwapper.cs
index 945fbfb..a48577d 100644
--- a/GPUPrefSwitcher/FileSwapper.cs
+++ b/GPUPrefSwitcher/FileSwapper.cs
@@ -68,7 +68,7 @@ public FileSwapper(AppEntry appEntry, PreferencesXML preferencesXML)
}
- public void InitiateFileSwaps(PowerLineStatus forPowerLineStatus, PreferencesXML preferencesXML)
+ public async Task InitiateFileSwaps(PowerLineStatus forPowerLineStatus, PreferencesXML preferencesXML)
{
Logger.inst.Log($"Initiating FileSwap for AppEntry with target path {AppEntry.AppPath}");
@@ -96,12 +96,19 @@ public void InitiateFileSwaps(PowerLineStatus forPowerLineStatus, PreferencesXML
ForPowerLineStatus = forPowerLineStatus,
};
- //fire and forget
- _ = InitiateSingleFileSwap(current, i);
+
+ try
+ {
+ await InitiateSingleFileSwap(current, i);
+ }
+ catch (AggregateException)
+ {
+ throw;
+ }
} //...repeat for every SwapPath
- Logger.inst.Log($"Finished FileSwap for AppEntry with target path {AppEntry.AppPath}");
+ Logger.inst.Log($"Finished firing FileSwap logic for AppEntry with target path {AppEntry.AppPath}");
}
@@ -191,15 +198,13 @@ private async Task InitiateSingleFileSwap(FileSwapPathTask fileSwapPathTask, int
//no need to cancel the save if the substitution fails
FileCopyConsiderAccessRules(swapPath, pluggedInStoredFilePath, true, false); //save current config to PluggedIn store
string s1 = $"Saved SwapPath {swapPath} for app {AppEntry.AppPath} as PluggedIn";
- Debug.WriteLine(s1);
- _ = Logger.inst.Log(s1);
+ Logger.inst.Log(s1);
errorFlag = 1;
FileCopyConsiderAccessRules(onBatteryStoredFilePath, swapPath, true, true); //then substitute with OnBattery config
string s2 = $"Substituted OnBattery config into SwapPath {swapPath} for app {AppEntry.AppPath}";
- _ = Logger.inst.Log(s2);
- Debug.WriteLine(s2);
+ Logger.inst.Log(s2);
}
catch (IOException)
@@ -237,25 +242,23 @@ private async Task InitiateSingleFileSwap(FileSwapPathTask fileSwapPathTask, int
//no need to cancel the save if the substitution fails
FileCopyConsiderAccessRules(swapPath, onBatteryStoredFilePath, true, false); //save current config to OnBattery store
string s1 = $"Saved SwapPath {swapPath} for app {AppEntry.AppPath} as OnBattery";
- Debug.WriteLine(s1);
- _ = Logger.inst.Log(s1);
+ Logger.inst.Log(s1);
errorFlag = 1;
FileCopyConsiderAccessRules(pluggedInStoredFilePath, swapPath, true, true); //then substitute with PluggedIn config
string s2 = $"Substituted PluggedIn config into SwapPath {swapPath} for app {AppEntry.AppPath}";
- _ = Logger.inst.Log(s2);
- Debug.WriteLine(s2);
+ Logger.inst.Log(s2);
}
catch (IOException)
{
if (errorFlag == 0)
{
- _ = Logger.inst.Log($"Could not copy to destination {onBatteryStoredFilePath}, retrying in some time.");
+ Logger.inst.Log($"Could not copy to destination {onBatteryStoredFilePath}, retrying in some time.");
}
else if (errorFlag == 1)
{
- _ = Logger.inst.Log($"Could not copy to destination {swapPath}, retrying in some time.");
+ Logger.inst.Log($"Could not copy to destination {swapPath}, retrying in some time.");
}
await Task.Delay(5000);
goto TryAgain;
@@ -266,7 +269,7 @@ private async Task InitiateSingleFileSwap(FileSwapPathTask fileSwapPathTask, int
preferencesXML.ModifyAppEntryAndSave(AppEntry.AppPath, modified);
string s3 = $"Saved SwapPath state for SwapPath {swapPath} for app {AppEntry.AppPath}";
- _ = Logger.inst.Log(s3);
+ Logger.inst.Log(s3);
}
}
else
@@ -274,6 +277,8 @@ private async Task InitiateSingleFileSwap(FileSwapPathTask fileSwapPathTask, int
Debug.WriteLine($"Unknown power state: " + forPowerLineStatus.ToString());
}
+ Logger.inst.Log($"FileSwaps Task finished for {AppEntry.AppPath}");
+
OngoingFileSwapTasks.Remove(fileSwapPathTask);
}
diff --git a/GPUPrefSwitcher/GPUPrefSwitcher.csproj b/GPUPrefSwitcher/GPUPrefSwitcher.csproj
index fde2f90..62af8a4 100644
--- a/GPUPrefSwitcher/GPUPrefSwitcher.csproj
+++ b/GPUPrefSwitcher/GPUPrefSwitcher.csproj
@@ -12,7 +12,7 @@
..\Assemble
- ..\GPUPrefSwitcherGUI\bin\x64\Debug\
+ bin\x64\Debug\
bin\x64\Release\
diff --git a/GPUPrefSwitcher/PreferencesXML.cs b/GPUPrefSwitcher/PreferencesXML.cs
index cd23bbb..73140f3 100644
--- a/GPUPrefSwitcher/PreferencesXML.cs
+++ b/GPUPrefSwitcher/PreferencesXML.cs
@@ -241,69 +241,67 @@ XmlNode AppEntryNodeByAppPath(string path)
/// If an AppEntry with the same AppPath already exists in the data store
internal void AddAppEntryAndSave(AppEntry appEntry)
{
- lock(WriteLock)
- {
- ReloadXML();
- //check for duplicates
- if (GetAppEntries().Any(entry => entry.AppPath == appEntry.AppPath))
- {
- throw new InvalidOperationException($"Tried to add an AppEntry with an AppPath that already exists in the data store: {appEntry.AppPath} — this is undefined behavior.");
- }
+ ReloadXML();
+
+ //check for duplicates
+ if (GetAppEntries().Any(entry => entry.AppPath == appEntry.AppPath))
+ {
+ throw new InvalidOperationException($"Tried to add an AppEntry with an AppPath that already exists in the data store: {appEntry.AppPath} — this is undefined behavior.");
+ }
- XmlNode root = xmlDocument.DocumentElement;
+ XmlNode root = xmlDocument.DocumentElement;
+ {
+ XmlElement xmlAppEntry = xmlDocument.CreateElement(XML_APP_ENTRY);
+ XmlElement xmlPath = xmlDocument.CreateElement(XML_APP_PATH);
{
- XmlElement xmlAppEntry = xmlDocument.CreateElement(XML_APP_ENTRY);
- XmlElement xmlPath = xmlDocument.CreateElement(XML_APP_PATH);
+ xmlPath.InnerText = appEntry.AppPath;
{
- xmlPath.InnerText = appEntry.AppPath;
+ XmlElement xmlGpuPref = xmlDocument.CreateElement(XML_GPU_PREFERENCE);
+ {
+ xmlGpuPref.SetAttribute(XML_ATTR_ENABLESWITCHER, appEntry.EnableSwitcher.ToString());
+ xmlGpuPref.SetAttribute(XML_ATTR_ENABLEFILESWAPPER, appEntry.EnableFileSwapper.ToString());
+
+ XmlElement runOnBattery = xmlDocument.CreateElement(XML_RUN_ON_BATTERY_PATH);
+ XmlElement runPluggedIn = xmlDocument.CreateElement(XML_RUN_PLUGGED_IN_PATH);
+ xmlGpuPref.AppendChild(runOnBattery);
+ xmlGpuPref.AppendChild(runPluggedIn);
+ }
+ XmlElement xmlPluggedIn = xmlDocument.CreateElement(XML_PLUGGED_IN);
{
- XmlElement xmlGpuPref = xmlDocument.CreateElement(XML_GPU_PREFERENCE);
- {
- xmlGpuPref.SetAttribute(XML_ATTR_ENABLESWITCHER, appEntry.EnableSwitcher.ToString());
- xmlGpuPref.SetAttribute(XML_ATTR_ENABLEFILESWAPPER, appEntry.EnableFileSwapper.ToString());
-
- XmlElement runOnBattery = xmlDocument.CreateElement(XML_RUN_ON_BATTERY_PATH);
- XmlElement runPluggedIn = xmlDocument.CreateElement(XML_RUN_PLUGGED_IN_PATH);
- xmlGpuPref.AppendChild(runOnBattery);
- xmlGpuPref.AppendChild(runPluggedIn);
- }
- XmlElement xmlPluggedIn = xmlDocument.CreateElement(XML_PLUGGED_IN);
- {
- xmlPluggedIn.InnerText = appEntry.GPUPrefPluggedIn.ToString();
- }
- //xmlPluggedIn.InnerText = defaultPluggedin;
- XmlElement xmlOnBattery = xmlDocument.CreateElement(XML_ON_BATTERY);
- {
- xmlOnBattery.InnerText = appEntry.GPUPrefOnBattery.ToString();
- }
- XmlElement xmlFileSwapper = xmlDocument.CreateElement(XML_FILE_SWAPPER);
-
-
- //xmlOnBattery.InnerText = defaultOnBattery;
- root.AppendChild(xmlAppEntry);
- {
- xmlAppEntry.AppendChild(xmlPath);
- xmlAppEntry.AppendChild(xmlGpuPref);
- xmlAppEntry.AppendChild(xmlFileSwapper);
- }
- xmlGpuPref.AppendChild(xmlPluggedIn);
- xmlGpuPref.AppendChild(xmlOnBattery);
-
- if (appEntry.PendingAddToRegistry)
- {
- XmlElement pendingAdd = xmlDocument.CreateElement(XML_PENDING_ADD);
- xmlAppEntry.AppendChild(pendingAdd);
- }
-
- XmlElement seenInRegistry = xmlDocument.CreateElement(XML_SEEN_IN_REGISTRY);
- seenInRegistry.InnerText = appEntry.SeenInRegistry.ToString();
- xmlAppEntry.AppendChild(seenInRegistry);
+ xmlPluggedIn.InnerText = appEntry.GPUPrefPluggedIn.ToString();
}
+ //xmlPluggedIn.InnerText = defaultPluggedin;
+ XmlElement xmlOnBattery = xmlDocument.CreateElement(XML_ON_BATTERY);
+ {
+ xmlOnBattery.InnerText = appEntry.GPUPrefOnBattery.ToString();
+ }
+ XmlElement xmlFileSwapper = xmlDocument.CreateElement(XML_FILE_SWAPPER);
+
+
+ //xmlOnBattery.InnerText = defaultOnBattery;
+ root.AppendChild(xmlAppEntry);
+ {
+ xmlAppEntry.AppendChild(xmlPath);
+ xmlAppEntry.AppendChild(xmlGpuPref);
+ xmlAppEntry.AppendChild(xmlFileSwapper);
+ }
+ xmlGpuPref.AppendChild(xmlPluggedIn);
+ xmlGpuPref.AppendChild(xmlOnBattery);
+
+ if (appEntry.PendingAddToRegistry)
+ {
+ XmlElement pendingAdd = xmlDocument.CreateElement(XML_PENDING_ADD);
+ xmlAppEntry.AppendChild(pendingAdd);
+ }
+
+ XmlElement seenInRegistry = xmlDocument.CreateElement(XML_SEEN_IN_REGISTRY);
+ seenInRegistry.InnerText = appEntry.SeenInRegistry.ToString();
+ xmlAppEntry.AppendChild(seenInRegistry);
}
}
- xmlDocument.Save(XML_PREFERENCES_PATH);
+ xmlDocument.Save(XML_PREFERENCES_PATH);
}
}
@@ -332,112 +330,110 @@ internal bool TryDeleteAppEntryAndSave(string path)
public void ModifyAppEntryAndSave(string path, AppEntry newAppEntry) //TODO file swapper functionality
{
- lock (WriteLock)
- {
- ReloadXML();
+
+ ReloadXML();
- XmlNode xmlAppEntry = AppEntryNodeByAppPath(path);
- if (xmlAppEntry == null) //I believe an exception is better than a Try function here because it results in less code assuming we get the logic right in the first place
- {
- throw new XMLHelperException($"ModifyAppEntry: AppEntry with the specified path not found in data store: {path}");
- }
+ XmlNode xmlAppEntry = AppEntryNodeByAppPath(path);
+ if (xmlAppEntry == null) //I believe an exception is better than a Try function here because it results in less code assuming we get the logic right in the first place
+ {
+ throw new XMLHelperException($"ModifyAppEntry: AppEntry with the specified path not found in data store: {path}");
+ }
- string newAppPath = newAppEntry.AppPath;
- string newEnableSwitcher = newAppEntry.EnableSwitcher.ToString().ToLower();
- string newGPUPrefPluggedIn = newAppEntry.GPUPrefPluggedIn.ToString();
- string newGPUPrefOnBattery = newAppEntry.GPUPrefOnBattery.ToString();
- string newEnableFileSwapper = newAppEntry.EnableFileSwapper.ToString().ToLower();
- string newRunOnBatteryPath = newAppEntry.RunOnBatteryPath;
- string newRunPluggedInPath = newAppEntry.RunPluggedInPath;
- string newSeenInRegistry = newAppEntry.SeenInRegistry.ToString().ToLower();
-
- string[] newFileSwapperPaths = newAppEntry.FileSwapperPaths;
-
- if (newAppPath == null)
- throw new InvalidOperationException("AppEntry passed in had a null AppPath value");
- if (newEnableSwitcher == null)
- throw new InvalidOperationException($"AppEntry passed in had a null EnableSwitcher value (by AppPath {path})");
- if (newGPUPrefPluggedIn == null)
- throw new InvalidOperationException($"AppEntry passed in had a null GPUPrefPluggedIn value (by AppPath {path})");
- if (newGPUPrefOnBattery == null)
- throw new InvalidOperationException($"AppEntry passed in had a null GPUPrefOnBattery value (by AppPath {path})");
- if (newEnableFileSwapper == null)
- throw new InvalidOperationException($"AppEntry passed in had a null EnableFileSwapper value (by AppPath{path}");
- if (newRunOnBatteryPath == null)
- throw new InvalidOperationException($"AppEntry passed in had a null RunOnBatteryPath value (by AppPath{path}");
- if (newRunPluggedInPath == null)
- throw new InvalidOperationException($"AppEntry passed in had a null RunPluggedInPath value (by AppPath{path}");
- if (newSeenInRegistry == null)
- throw new InvalidOperationException($"AppEntry passed in had a null SeenInRegistry value (by AppPath{path}");
-
- //try
- {
- xmlAppEntry.SelectSingleNode(XML_APP_PATH).InnerText = newAppPath;
+ string newAppPath = newAppEntry.AppPath;
+ string newEnableSwitcher = newAppEntry.EnableSwitcher.ToString().ToLower();
+ string newGPUPrefPluggedIn = newAppEntry.GPUPrefPluggedIn.ToString();
+ string newGPUPrefOnBattery = newAppEntry.GPUPrefOnBattery.ToString();
+ string newEnableFileSwapper = newAppEntry.EnableFileSwapper.ToString().ToLower();
+ string newRunOnBatteryPath = newAppEntry.RunOnBatteryPath;
+ string newRunPluggedInPath = newAppEntry.RunPluggedInPath;
+ string newSeenInRegistry = newAppEntry.SeenInRegistry.ToString().ToLower();
+
+ string[] newFileSwapperPaths = newAppEntry.FileSwapperPaths;
+
+ if (newAppPath == null)
+ throw new InvalidOperationException("AppEntry passed in had a null AppPath value");
+ if (newEnableSwitcher == null)
+ throw new InvalidOperationException($"AppEntry passed in had a null EnableSwitcher value (by AppPath {path})");
+ if (newGPUPrefPluggedIn == null)
+ throw new InvalidOperationException($"AppEntry passed in had a null GPUPrefPluggedIn value (by AppPath {path})");
+ if (newGPUPrefOnBattery == null)
+ throw new InvalidOperationException($"AppEntry passed in had a null GPUPrefOnBattery value (by AppPath {path})");
+ if (newEnableFileSwapper == null)
+ throw new InvalidOperationException($"AppEntry passed in had a null EnableFileSwapper value (by AppPath{path}");
+ if (newRunOnBatteryPath == null)
+ throw new InvalidOperationException($"AppEntry passed in had a null RunOnBatteryPath value (by AppPath{path}");
+ if (newRunPluggedInPath == null)
+ throw new InvalidOperationException($"AppEntry passed in had a null RunPluggedInPath value (by AppPath{path}");
+ if (newSeenInRegistry == null)
+ throw new InvalidOperationException($"AppEntry passed in had a null SeenInRegistry value (by AppPath{path}");
+
+ //try
+ {
+ xmlAppEntry.SelectSingleNode(XML_APP_PATH).InnerText = newAppPath;
- xmlAppEntry.SelectSingleNode(XML_SEEN_IN_REGISTRY).InnerText = newSeenInRegistry;
+ xmlAppEntry.SelectSingleNode(XML_SEEN_IN_REGISTRY).InnerText = newSeenInRegistry;
- XmlNode gpuPreference = xmlAppEntry.SelectSingleNode(XML_GPU_PREFERENCE);
- gpuPreference.Attributes[XML_ATTR_ENABLESWITCHER].Value = newEnableSwitcher;
- gpuPreference.Attributes[XML_ATTR_ENABLEFILESWAPPER].Value = newEnableFileSwapper;
- {
- gpuPreference.SelectSingleNode(XML_PLUGGED_IN).InnerText = newGPUPrefPluggedIn;
- gpuPreference.SelectSingleNode(XML_ON_BATTERY).InnerText = newGPUPrefOnBattery;
+ XmlNode gpuPreference = xmlAppEntry.SelectSingleNode(XML_GPU_PREFERENCE);
+ gpuPreference.Attributes[XML_ATTR_ENABLESWITCHER].Value = newEnableSwitcher;
+ gpuPreference.Attributes[XML_ATTR_ENABLEFILESWAPPER].Value = newEnableFileSwapper;
+ {
+ gpuPreference.SelectSingleNode(XML_PLUGGED_IN).InnerText = newGPUPrefPluggedIn;
+ gpuPreference.SelectSingleNode(XML_ON_BATTERY).InnerText = newGPUPrefOnBattery;
- gpuPreference.SelectSingleNode(XML_RUN_PLUGGED_IN_PATH).InnerText = newRunPluggedInPath;
- gpuPreference.SelectSingleNode(XML_RUN_ON_BATTERY_PATH).InnerText = newRunOnBatteryPath;
+ gpuPreference.SelectSingleNode(XML_RUN_PLUGGED_IN_PATH).InnerText = newRunPluggedInPath;
+ gpuPreference.SelectSingleNode(XML_RUN_ON_BATTERY_PATH).InnerText = newRunOnBatteryPath;
- }
+ }
- //TODO this is jank, I think Switcher.cs needs to not have access to this and only access to AppEntrySaveHandler instead
- if (newAppEntry.PendingAddToRegistry)
+ //TODO this is jank, I think Switcher.cs needs to not have access to this and only access to AppEntrySaveHandler instead
+ if (newAppEntry.PendingAddToRegistry)
+ {
+ XmlElement pendingAddToRegistry = xmlDocument.CreateElement(XML_PENDING_ADD);
+ if (xmlAppEntry.SelectSingleNode(XML_PENDING_ADD) == null)
{
- XmlElement pendingAddToRegistry = xmlDocument.CreateElement(XML_PENDING_ADD);
- if (xmlAppEntry.SelectSingleNode(XML_PENDING_ADD) == null)
- {
- xmlAppEntry.AppendChild(pendingAddToRegistry);
- }
+ xmlAppEntry.AppendChild(pendingAddToRegistry);
}
- else
+ }
+ else
+ {
+ var pendingAdd = xmlAppEntry.SelectSingleNode(XML_PENDING_ADD);
+ if (pendingAdd != null)
{
- var pendingAdd = xmlAppEntry.SelectSingleNode(XML_PENDING_ADD);
- if (pendingAdd != null)
- {
- xmlAppEntry.RemoveChild(pendingAdd);
- }
+ xmlAppEntry.RemoveChild(pendingAdd);
}
+ }
- //replace the SwapPath's
- XmlNode fileSwapper = xmlAppEntry.SelectSingleNode(XML_FILE_SWAPPER);
- fileSwapper.RemoveAll();
+ //replace the SwapPath's
+ XmlNode fileSwapper = xmlAppEntry.SelectSingleNode(XML_FILE_SWAPPER);
+ fileSwapper.RemoveAll();
+ {
+ /*
+ foreach(string p in newFileSwapperPaths)
{
- /*
- foreach(string p in newFileSwapperPaths)
- {
- XmlElement xmlElement = xmlDocument.CreateElement(XML_SWAP_PATH);
- xmlElement.InnerText = p;
- fileSwapper.AppendChild(xmlElement);
- }
- */
- for (int i = 0; i < newFileSwapperPaths.Count(); i++)
- {
- string newFileSwapperPath = newFileSwapperPaths[i];
+ XmlElement xmlElement = xmlDocument.CreateElement(XML_SWAP_PATH);
+ xmlElement.InnerText = p;
+ fileSwapper.AppendChild(xmlElement);
+ }
+ */
+ for (int i = 0; i < newFileSwapperPaths.Count(); i++)
+ {
+ string newFileSwapperPath = newFileSwapperPaths[i];
- XmlElement xmlElement = xmlDocument.CreateElement(XML_SWAP_PATH);
+ XmlElement xmlElement = xmlDocument.CreateElement(XML_SWAP_PATH);
- xmlElement.SetAttribute(XML_ATTR_SWAPPATHSTATUS, PowerLineStatusConversions.PowerLineStatusToOfflineOrOnline(newAppEntry.SwapperStates[i]));//TODO: does this gauruntee order?
+ xmlElement.SetAttribute(XML_ATTR_SWAPPATHSTATUS, PowerLineStatusConversions.PowerLineStatusToOfflineOrOnline(newAppEntry.SwapperStates[i]));//TODO: does this gauruntee order?
- xmlElement.InnerText = newFileSwapperPath;
+ xmlElement.InnerText = newFileSwapperPath;
- fileSwapper.AppendChild(xmlElement);//remember to append it!!!
- }
+ fileSwapper.AppendChild(xmlElement);//remember to append it!!!
}
+ }
- xmlDocument.Save(XML_PREFERENCES_PATH);
- }/* catch (NullReferenceException)
- {
- throw new XmlException($"An error occured while trying to modify AppEntry with AppPath {path}; check if the entry is malformed in Preferences.xml");
- }*/
- }
+ xmlDocument.Save(XML_PREFERENCES_PATH);
+ }/* catch (NullReferenceException)
+ {
+ throw new XmlException($"An error occured while trying to modify AppEntry with AppPath {path}; check if the entry is malformed in Preferences.xml");
+ }*/
}
//XML navigation reference https://learn.microsoft.com/en-us/dotnet/standard/data/xml/select-nodes-using-xpath-navigation
diff --git a/GPUPrefSwitcher/RegistryHelper.cs b/GPUPrefSwitcher/RegistryHelper.cs
index 6b66333..b331fab 100644
--- a/GPUPrefSwitcher/RegistryHelper.cs
+++ b/GPUPrefSwitcher/RegistryHelper.cs
@@ -172,11 +172,11 @@ private static void SetGpuPref_internal(string pathvalue, string data)
if (!GpuPrefPathvalueExistsAndIsValid(pathvalue)) throw new ArgumentException("pathvalue " + pathvalue + " does not exist in the registry or doesn't have a GpuPreference data entry");
- RegistryKey gpuPref = GetLoggedInGpuPrefKey();
+ RegistryKey gpuPrefKey = GetLoggedInGpuPrefKey();
- Logger.inst.Log($"Modifiying registry key: setting {gpuPref} to {data}");
+ Logger.inst.Log($"Modifiying registry key: setting {pathvalue} to {data}");
- gpuPref.SetValue(pathvalue, data);
+ gpuPrefKey.SetValue(pathvalue, data);
}
diff --git a/GPUPrefSwitcher/Switcher.cs b/GPUPrefSwitcher/Switcher.cs
index 8dc8278..c0245a7 100644
--- a/GPUPrefSwitcher/Switcher.cs
+++ b/GPUPrefSwitcher/Switcher.cs
@@ -143,6 +143,7 @@ private static Task RunUpdateLogic()
PowerLineStatus currentPowerLineStatus;
+ currentPowerLineStatus = SystemInformation.PowerStatus.PowerLineStatus;
if (spoofPowerStateEnabled)
{
Logger.inst.Log($"Power State spoofing enabled: {spoofPowerState}");
@@ -161,16 +162,8 @@ private static Task RunUpdateLogic()
throw new ArgumentException("Unknown SpoofPowerState");
}
}
- else
- {
- currentPowerLineStatus = SystemInformation.PowerStatus.PowerLineStatus;
- }
- if (!runOnce)
- {
- Logger.inst.Log("Updating preferences regardless since this is the first update.");
- goto CheckAndUpdate;
- }
+
if (!lastShutdownWasClean)
{
//doesn't actually serve a purpose for now
@@ -178,18 +171,22 @@ private static Task RunUpdateLogic()
}
//skip update if powerline status hasn't changed
- if (prevPowerLineStatus == currentPowerLineStatus)
+ if (prevPowerLineStatus == currentPowerLineStatus && runOnce)
{
Logger.inst.Log($"PowerLine status has NOT changed since last update. (Current state: {currentPowerLineStatus}; last state: {prevPowerLineStatus})", 2000);
return Task.CompletedTask;
}
else
{
- Logger.inst.Log($"PowerLine status has changed since last update. Previous: {prevPowerLineStatus}; Current: {currentPowerLineStatus}");
- goto CheckAndUpdate;
+ if (!runOnce)
+ {
+ Logger.inst.Log("Updating preferences regardless since this is the first update.");
+ } else
+ {
+ Logger.inst.Log($"PowerLine status has changed since last update. Previous: {prevPowerLineStatus}; Current: {currentPowerLineStatus}");
+ }
}
- CheckAndUpdate:
runOnce = true;
RegAndXMLMatchState regAndXMLMatchState = GetRegAndXmlMatchState();
@@ -412,6 +409,9 @@ internal static void WriteXMLToRegistry(PowerLineStatus powerLineStatus)
{
IEnumerable appEntries = preferencesXML.GetAppEntries();
+ bool systemIsOnbattery = powerLineStatus == PowerLineStatus.Offline;
+ Logger.inst.Log($"System is on battery: {systemIsOnbattery}");
+
foreach (AppEntry appEntry in appEntries)
{
@@ -449,8 +449,6 @@ internal static void WriteXMLToRegistry(PowerLineStatus powerLineStatus)
}
Logger.inst.Log("Updating registry for pathvalue: " + pathvalue, 2000);
- bool systemIsOnbattery = powerLineStatus == PowerLineStatus.Offline;
-
try
{
if (systemIsOnbattery)
diff --git a/GPUPrefSwitcherGUI/OptionsForm.Designer.cs b/GPUPrefSwitcherGUI/OptionsForm.Designer.cs
index 8e347f7..2838f72 100644
--- a/GPUPrefSwitcherGUI/OptionsForm.Designer.cs
+++ b/GPUPrefSwitcherGUI/OptionsForm.Designer.cs
@@ -52,6 +52,8 @@ private void InitializeComponent()
toolTip1 = new System.Windows.Forms.ToolTip(components);
OpenTaskSchedulerButton = new System.Windows.Forms.Button();
button1 = new System.Windows.Forms.Button();
+ label5 = new System.Windows.Forms.Label();
+ OpenAppDirButton = new System.Windows.Forms.Button();
SuspendLayout();
//
// UpdateIntervalTextbox
@@ -148,7 +150,7 @@ private void InitializeComponent()
// ResetAppPreferencesListButton
//
ResetAppPreferencesListButton.ImageAlign = System.Drawing.ContentAlignment.TopLeft;
- ResetAppPreferencesListButton.Location = new System.Drawing.Point(10, 437);
+ ResetAppPreferencesListButton.Location = new System.Drawing.Point(10, 478);
ResetAppPreferencesListButton.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
ResetAppPreferencesListButton.Name = "ResetAppPreferencesListButton";
ResetAppPreferencesListButton.Size = new System.Drawing.Size(289, 22);
@@ -162,7 +164,7 @@ private void InitializeComponent()
//
label2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
label2.ImageAlign = System.Drawing.ContentAlignment.TopLeft;
- label2.Location = new System.Drawing.Point(10, 330);
+ label2.Location = new System.Drawing.Point(10, 371);
label2.Name = "label2";
label2.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
label2.Size = new System.Drawing.Size(290, 2);
@@ -217,7 +219,7 @@ private void InitializeComponent()
// CleanSettingsBankButton
//
CleanSettingsBankButton.ImageAlign = System.Drawing.ContentAlignment.TopLeft;
- CleanSettingsBankButton.Location = new System.Drawing.Point(10, 343);
+ CleanSettingsBankButton.Location = new System.Drawing.Point(10, 384);
CleanSettingsBankButton.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
CleanSettingsBankButton.Name = "CleanSettingsBankButton";
CleanSettingsBankButton.Size = new System.Drawing.Size(289, 26);
@@ -231,7 +233,7 @@ private void InitializeComponent()
//
label4.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
label4.ImageAlign = System.Drawing.ContentAlignment.TopLeft;
- label4.Location = new System.Drawing.Point(10, 422);
+ label4.Location = new System.Drawing.Point(10, 463);
label4.Name = "label4";
label4.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
label4.Size = new System.Drawing.Size(290, 2);
@@ -252,7 +254,7 @@ private void InitializeComponent()
// FolderStatsLabel1
//
FolderStatsLabel1.AutoSize = true;
- FolderStatsLabel1.Location = new System.Drawing.Point(7, 397);
+ FolderStatsLabel1.Location = new System.Drawing.Point(7, 438);
FolderStatsLabel1.Name = "FolderStatsLabel1";
FolderStatsLabel1.Size = new System.Drawing.Size(38, 15);
FolderStatsLabel1.TabIndex = 19;
@@ -261,7 +263,7 @@ private void InitializeComponent()
// FolderStatsLabel2
//
FolderStatsLabel2.AutoSize = true;
- FolderStatsLabel2.Location = new System.Drawing.Point(7, 377);
+ FolderStatsLabel2.Location = new System.Drawing.Point(7, 418);
FolderStatsLabel2.Name = "FolderStatsLabel2";
FolderStatsLabel2.Size = new System.Drawing.Size(38, 15);
FolderStatsLabel2.TabIndex = 20;
@@ -288,11 +290,33 @@ private void InitializeComponent()
button1.Visible = false;
button1.Click += button1_Click;
//
+ // label5
+ //
+ label5.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
+ label5.ImageAlign = System.Drawing.ContentAlignment.TopLeft;
+ label5.Location = new System.Drawing.Point(10, 325);
+ label5.Name = "label5";
+ label5.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
+ label5.Size = new System.Drawing.Size(290, 2);
+ label5.TabIndex = 23;
+ //
+ // OpenAppDirButton
+ //
+ OpenAppDirButton.Location = new System.Drawing.Point(12, 337);
+ OpenAppDirButton.Name = "OpenAppDirButton";
+ OpenAppDirButton.Size = new System.Drawing.Size(287, 23);
+ OpenAppDirButton.TabIndex = 24;
+ OpenAppDirButton.Text = "Open App Data Directory (logs, settings, etc.)";
+ OpenAppDirButton.UseVisualStyleBackColor = true;
+ OpenAppDirButton.Click += OpenAppDirButton_Click;
+ //
// OptionsForm
//
AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- ClientSize = new System.Drawing.Size(311, 477);
+ ClientSize = new System.Drawing.Size(311, 513);
+ Controls.Add(OpenAppDirButton);
+ Controls.Add(label5);
Controls.Add(button1);
Controls.Add(OpenTaskSchedulerButton);
Controls.Add(FolderStatsLabel2);
@@ -348,5 +372,7 @@ private void InitializeComponent()
private System.Windows.Forms.ToolTip toolTip1;
private System.Windows.Forms.Button OpenTaskSchedulerButton;
private System.Windows.Forms.Button button1;
+ private System.Windows.Forms.Label label5;
+ private System.Windows.Forms.Button OpenAppDirButton;
}
}
\ No newline at end of file
diff --git a/GPUPrefSwitcherGUI/OptionsForm.cs b/GPUPrefSwitcherGUI/OptionsForm.cs
index ac09e26..b3d7c7e 100644
--- a/GPUPrefSwitcherGUI/OptionsForm.cs
+++ b/GPUPrefSwitcherGUI/OptionsForm.cs
@@ -5,6 +5,7 @@
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;
+using System.Windows.Shapes;
namespace GPUPrefSwitcherGUI
{
@@ -333,5 +334,15 @@ private void button1_Click(object sender, EventArgs e)
var f = new GPUPrefSwitcherRepairer.RepairForm();
f.Show();
}
+
+ private void OpenAppDirButton_Click(object sender, EventArgs e)
+ {
+ using Process fileopener = new Process();
+
+ fileopener.StartInfo.FileName = "explorer";
+ fileopener.StartInfo.Arguments = "\"" + System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"AppData") + "\"";
+ fileopener.Start();
+
+ }
}
}
diff --git a/Install/Install.csproj b/Install/Install.csproj
index a9646ba..615fe02 100644
--- a/Install/Install.csproj
+++ b/Install/Install.csproj
@@ -35,7 +35,7 @@
true
full
false
- bin\Debug\
+ ..\Assemble\install\
DEBUG;TRACE
prompt
4
diff --git a/Uninstall/Uninstall.csproj b/Uninstall/Uninstall.csproj
index e193b24..0b69711 100644
--- a/Uninstall/Uninstall.csproj
+++ b/Uninstall/Uninstall.csproj
@@ -35,7 +35,7 @@
true
full
false
- bin\Debug\
+ ..\Assemble\install\
DEBUG;TRACE
prompt
4