Skip to content

Commit

Permalink
Merge pull request #3 from sharpjd/development
Browse files Browse the repository at this point in the history
improve file swapper functionality
  • Loading branch information
sharpjd authored Mar 10, 2024
2 parents 7ccac4c + 5a5a98d commit dcbd7e8
Show file tree
Hide file tree
Showing 13 changed files with 224 additions and 188 deletions.
Binary file modified Assemble/install/Install.exe
Binary file not shown.
Binary file modified Assemble/install/Uninstall.exe
Binary file not shown.
5 changes: 3 additions & 2 deletions GPUPrefSwitcher.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions GPUPrefSwitcher/AppLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -119,7 +119,6 @@ public static AppLogger Initialize (string logFolderPath_Error, string logFileNa
logger.ErrorLog(e.ToString()).Wait();

};
*/

return logger;
}
Expand Down
35 changes: 20 additions & 15 deletions GPUPrefSwitcher/FileSwapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}");

Expand Down Expand Up @@ -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}");

}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand All @@ -266,14 +269,16 @@ 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
{
Debug.WriteLine($"Unknown power state: " + forPowerLineStatus.ToString());
}

Logger.inst.Log($"FileSwaps Task finished for {AppEntry.AppPath}");

OngoingFileSwapTasks.Remove(fileSwapPathTask);

}
Expand Down
2 changes: 1 addition & 1 deletion GPUPrefSwitcher/GPUPrefSwitcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<BaseOutputPath>..\Assemble</BaseOutputPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<OutputPath>..\GPUPrefSwitcherGUI\bin\x64\Debug\</OutputPath>
<OutputPath>bin\x64\Debug\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
Expand Down
Loading

0 comments on commit dcbd7e8

Please sign in to comment.