Skip to content

Commit dcbd7e8

Browse files
authored
Merge pull request #3 from sharpjd/development
improve file swapper functionality
2 parents 7ccac4c + 5a5a98d commit dcbd7e8

File tree

13 files changed

+224
-188
lines changed

13 files changed

+224
-188
lines changed

Assemble/install/Install.exe

512 Bytes
Binary file not shown.

Assemble/install/Uninstall.exe

512 Bytes
Binary file not shown.

GPUPrefSwitcher.sln

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ Global
104104
{6C338214-045F-4BBD-8F10-6001B666215E}.Debug|Any CPU.Build.0 = Debug|Any CPU
105105
{6C338214-045F-4BBD-8F10-6001B666215E}.Debug|ARM64.ActiveCfg = Debug|Any CPU
106106
{6C338214-045F-4BBD-8F10-6001B666215E}.Debug|ARM64.Build.0 = Debug|Any CPU
107-
{6C338214-045F-4BBD-8F10-6001B666215E}.Debug|x64.ActiveCfg = Debug|Any CPU
108-
{6C338214-045F-4BBD-8F10-6001B666215E}.Debug|x64.Build.0 = Debug|Any CPU
107+
{6C338214-045F-4BBD-8F10-6001B666215E}.Debug|x64.ActiveCfg = Debug|x64
108+
{6C338214-045F-4BBD-8F10-6001B666215E}.Debug|x64.Build.0 = Debug|x64
109109
{6C338214-045F-4BBD-8F10-6001B666215E}.Debug|x86.ActiveCfg = Debug|x86
110110
{6C338214-045F-4BBD-8F10-6001B666215E}.Debug|x86.Build.0 = Debug|x86
111111
{6C338214-045F-4BBD-8F10-6001B666215E}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -151,6 +151,7 @@ Global
151151
{76BFD458-C88C-4484-9578-DC1B75BB945C}.Debug|Any CPU.ActiveCfg = Debug
152152
{76BFD458-C88C-4484-9578-DC1B75BB945C}.Debug|ARM64.ActiveCfg = Debug
153153
{76BFD458-C88C-4484-9578-DC1B75BB945C}.Debug|x64.ActiveCfg = Debug
154+
{76BFD458-C88C-4484-9578-DC1B75BB945C}.Debug|x64.Build.0 = Debug
154155
{76BFD458-C88C-4484-9578-DC1B75BB945C}.Debug|x86.ActiveCfg = Debug
155156
{76BFD458-C88C-4484-9578-DC1B75BB945C}.Release|Any CPU.ActiveCfg = Release
156157
{76BFD458-C88C-4484-9578-DC1B75BB945C}.Release|ARM64.ActiveCfg = Release

GPUPrefSwitcher/AppLogger.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public static AppLogger Initialize (string logFolderPath_Error, string logFileNa
110110
};
111111

112112
//useful for capturing fire-and-forget tasks that error out
113-
/* //TODO this doesn't actually work
113+
///TODO this doesn't work?
114114
System.Threading.Tasks.TaskScheduler.UnobservedTaskException += (sender, e) =>
115115
{
116116
logger.DumpStandardLogBufferToStandardLog().Wait();
@@ -119,7 +119,6 @@ public static AppLogger Initialize (string logFolderPath_Error, string logFileNa
119119
logger.ErrorLog(e.ToString()).Wait();
120120

121121
};
122-
*/
123122

124123
return logger;
125124
}

GPUPrefSwitcher/FileSwapper.cs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public FileSwapper(AppEntry appEntry, PreferencesXML preferencesXML)
6868
}
6969

7070

71-
public void InitiateFileSwaps(PowerLineStatus forPowerLineStatus, PreferencesXML preferencesXML)
71+
public async Task InitiateFileSwaps(PowerLineStatus forPowerLineStatus, PreferencesXML preferencesXML)
7272
{
7373
Logger.inst.Log($"Initiating FileSwap for AppEntry with target path {AppEntry.AppPath}");
7474

@@ -96,12 +96,19 @@ public void InitiateFileSwaps(PowerLineStatus forPowerLineStatus, PreferencesXML
9696
ForPowerLineStatus = forPowerLineStatus,
9797
};
9898

99-
//fire and forget
100-
_ = InitiateSingleFileSwap(current, i);
99+
100+
try
101+
{
102+
await InitiateSingleFileSwap(current, i);
103+
}
104+
catch (AggregateException)
105+
{
106+
throw;
107+
}
101108

102109
} //...repeat for every SwapPath
103110

104-
Logger.inst.Log($"Finished FileSwap for AppEntry with target path {AppEntry.AppPath}");
111+
Logger.inst.Log($"Finished firing FileSwap logic for AppEntry with target path {AppEntry.AppPath}");
105112

106113
}
107114

@@ -191,15 +198,13 @@ private async Task InitiateSingleFileSwap(FileSwapPathTask fileSwapPathTask, int
191198
//no need to cancel the save if the substitution fails
192199
FileCopyConsiderAccessRules(swapPath, pluggedInStoredFilePath, true, false); //save current config to PluggedIn store
193200
string s1 = $"Saved SwapPath {swapPath} for app {AppEntry.AppPath} as PluggedIn";
194-
Debug.WriteLine(s1);
195-
_ = Logger.inst.Log(s1);
201+
Logger.inst.Log(s1);
196202

197203
errorFlag = 1;
198204

199205
FileCopyConsiderAccessRules(onBatteryStoredFilePath, swapPath, true, true); //then substitute with OnBattery config
200206
string s2 = $"Substituted OnBattery config into SwapPath {swapPath} for app {AppEntry.AppPath}";
201-
_ = Logger.inst.Log(s2);
202-
Debug.WriteLine(s2);
207+
Logger.inst.Log(s2);
203208

204209
}
205210
catch (IOException)
@@ -237,25 +242,23 @@ private async Task InitiateSingleFileSwap(FileSwapPathTask fileSwapPathTask, int
237242
//no need to cancel the save if the substitution fails
238243
FileCopyConsiderAccessRules(swapPath, onBatteryStoredFilePath, true, false); //save current config to OnBattery store
239244
string s1 = $"Saved SwapPath {swapPath} for app {AppEntry.AppPath} as OnBattery";
240-
Debug.WriteLine(s1);
241-
_ = Logger.inst.Log(s1);
245+
Logger.inst.Log(s1);
242246

243247
errorFlag = 1;
244248

245249
FileCopyConsiderAccessRules(pluggedInStoredFilePath, swapPath, true, true); //then substitute with PluggedIn config
246250
string s2 = $"Substituted PluggedIn config into SwapPath {swapPath} for app {AppEntry.AppPath}";
247-
_ = Logger.inst.Log(s2);
248-
Debug.WriteLine(s2);
251+
Logger.inst.Log(s2);
249252
}
250253
catch (IOException)
251254
{
252255
if (errorFlag == 0)
253256
{
254-
_ = Logger.inst.Log($"Could not copy to destination {onBatteryStoredFilePath}, retrying in some time.");
257+
Logger.inst.Log($"Could not copy to destination {onBatteryStoredFilePath}, retrying in some time.");
255258
}
256259
else if (errorFlag == 1)
257260
{
258-
_ = Logger.inst.Log($"Could not copy to destination {swapPath}, retrying in some time.");
261+
Logger.inst.Log($"Could not copy to destination {swapPath}, retrying in some time.");
259262
}
260263
await Task.Delay(5000);
261264
goto TryAgain;
@@ -266,14 +269,16 @@ private async Task InitiateSingleFileSwap(FileSwapPathTask fileSwapPathTask, int
266269

267270
preferencesXML.ModifyAppEntryAndSave(AppEntry.AppPath, modified);
268271
string s3 = $"Saved SwapPath state for SwapPath {swapPath} for app {AppEntry.AppPath}";
269-
_ = Logger.inst.Log(s3);
272+
Logger.inst.Log(s3);
270273
}
271274
}
272275
else
273276
{
274277
Debug.WriteLine($"Unknown power state: " + forPowerLineStatus.ToString());
275278
}
276279

280+
Logger.inst.Log($"FileSwaps Task finished for {AppEntry.AppPath}");
281+
277282
OngoingFileSwapTasks.Remove(fileSwapPathTask);
278283

279284
}

GPUPrefSwitcher/GPUPrefSwitcher.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<BaseOutputPath>..\Assemble</BaseOutputPath>
1313
</PropertyGroup>
1414
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
15-
<OutputPath>..\GPUPrefSwitcherGUI\bin\x64\Debug\</OutputPath>
15+
<OutputPath>bin\x64\Debug\</OutputPath>
1616
</PropertyGroup>
1717
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
1818
<OutputPath>bin\x64\Release\</OutputPath>

0 commit comments

Comments
 (0)