Skip to content

Commit 2fde6d2

Browse files
committed
Add performance enhancements, better error checking, IsLoading checks, and correct RomModel updating
1 parent 70bf77b commit 2fde6d2

File tree

5 files changed

+51
-23
lines changed

5 files changed

+51
-23
lines changed

EmulationManager/EmulationManager/Commands/FixRomStreamingCompatibilityCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ public bool CanExecute(object parameter)
2424

2525
public event EventHandler CanExecuteChanged { add { } remove { } }
2626

27-
public void Execute(object parameter)
27+
public async void Execute(object parameter)
2828
{
2929
if (CanExecute(parameter))
3030
{
31-
_viewModel.FixRomStreamingCompatibilityAsync();
31+
await _viewModel.FixRomStreamingCompatibilityAsync();
3232
}
3333
}
3434
#endregion

EmulationManager/EmulationManager/Helpers/IOHelper.cs

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -220,14 +220,23 @@ public static RomModel[] FixRomsForStreaming(RomModel[] roms)
220220
int i = 0;
221221
foreach (var rom in roms)
222222
{
223-
if (!string.IsNullOrEmpty(rom.Path) && !string.IsNullOrEmpty(rom.StreamingCompatiblePath))
223+
try
224224
{
225-
if (rom.Path != rom.StreamingCompatiblePath)
225+
if (rom != null
226+
&& !string.IsNullOrEmpty(rom.Path) && !string.IsNullOrEmpty(rom.StreamingCompatiblePath))
226227
{
227-
File.Move(rom.Path, rom.StreamingCompatiblePath);
228+
if (rom.Path != rom.StreamingCompatiblePath)
229+
{
230+
File.Move(rom.Path, rom.StreamingCompatiblePath);
231+
}
232+
rom.UseStreamingCompatiblePath = true;
233+
newRoms[i] = rom;
228234
}
229-
rom.UseStreamingCompatiblePath = true;
230-
roms[i] = rom;
235+
}
236+
catch (System.IO.IOException)
237+
{
238+
i++;
239+
continue; // This hits randomly but still works?
231240
}
232241
i++;
233242
}
@@ -244,16 +253,25 @@ public static RomModel[] RevertRomsFromStreaming(RomModel[] roms)
244253
int i = 0;
245254
foreach (var rom in roms)
246255
{
247-
if (!string.IsNullOrEmpty(rom.Path) && !string.IsNullOrEmpty(rom.StreamingCompatiblePath))
256+
try
248257
{
249-
rom.Path = rom.StreamingCompatiblePath.Replace(ConfigurationHelper.GetStreamingCompatiblityReplacementName(), " ");
250-
if (rom.Path != rom.StreamingCompatiblePath)
258+
if (rom != null
259+
&& !string.IsNullOrEmpty(rom.Path) && !string.IsNullOrEmpty(rom.StreamingCompatiblePath))
251260
{
252-
File.Move(rom.StreamingCompatiblePath, rom.Path);
261+
rom.Path = rom.StreamingCompatiblePath.Replace(ConfigurationHelper.GetStreamingCompatiblityReplacementName(), " ");
262+
if (rom.Path != rom.StreamingCompatiblePath)
263+
{
264+
File.Move(rom.StreamingCompatiblePath, rom.Path);
265+
}
266+
rom.UseStreamingCompatiblePath = false;
267+
268+
newRoms[i] = rom;
253269
}
254-
rom.UseStreamingCompatiblePath = false;
255-
256-
newRoms[i] = rom;
270+
}
271+
catch (System.IO.IOException)
272+
{
273+
i++;
274+
continue; // This hits randomly but still works?
257275
}
258276
i++;
259277
}

EmulationManager/EmulationManager/ViewModels/EmuManagerViewModel.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public EmuManagerViewModel()
124124

125125
public async Task LoadRomsAndEmulatorsAsync(bool showError = true)
126126
{
127-
if (CheckRomAndEmulatorDirectories())
127+
if (CheckRomAndEmulatorDirectories() && CheckCanDoWork())
128128
{
129129
// Use a Task.Run() here to get these methods off the UI thread as they're slow and it will lock up responsiveness.
130130
await Task.Run(() =>
@@ -166,12 +166,12 @@ public void CleanRomNames()
166166

167167
public async Task RevertRomStreamingCompatibilityAsync()
168168
{
169-
if (CheckModelValidity())
169+
if (CheckModelValidity() && CheckCanDoWork())
170170
{
171171
await Task.Run(() =>
172172
{
173173
IsLoading = true;
174-
LoadingText = "Fixing rom streaming compatibility...";
174+
LoadingText = "Reverting rom streaming compatibility...";
175175

176176
RomModels = IOHelper.RevertRomsFromStreaming(RomModels);
177177

@@ -187,12 +187,12 @@ await Task.Run(() =>
187187

188188
public async Task FixRomStreamingCompatibilityAsync()
189189
{
190-
if (CheckModelValidity())
190+
if (CheckModelValidity() && CheckCanDoWork())
191191
{
192192
await Task.Run(() =>
193193
{
194194
IsLoading = true;
195-
LoadingText = "Reverting rom streaming compatibility...";
195+
LoadingText = "Fixing rom streaming compatibility...";
196196

197197
RomModels = IOHelper.FixRomsForStreaming(RomModels);
198198

@@ -208,7 +208,7 @@ await Task.Run(() =>
208208

209209
public async Task CreateSteamShortcutsAsync()
210210
{
211-
if (CheckModelValidity())
211+
if (CheckModelValidity() && CheckCanDoWork())
212212
{
213213
await LoadRomsAndEmulatorsAsync();
214214
await Task.Run(() =>
@@ -242,5 +242,15 @@ public bool CheckModelValidity()
242242
{
243243
return EmulatorModels != null && EmulatorModels.Length > 0 && RomModels != null && RomModels.Length > 0;
244244
}
245+
246+
public bool CheckCanDoWork()
247+
{
248+
if (IsLoading)
249+
{
250+
DebugManager.ShowErrorDialog("Please wait for the current operation to finish before proceeding.", null);
251+
return false;
252+
}
253+
return true;
254+
}
245255
}
246256
}

EmulationManager/EmulationManager/Views/EmuManager.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@
6969
<StackPanel Name="ShieldFunctions" Margin="0,15,0,0" HorizontalAlignment="Left">
7070
<TextBlock FontSize="14" FontWeight="Medium">Steam Link/Shield/Moonlight Big Picture Streaming Functions</TextBlock>
7171
<StackPanel Orientation="Horizontal">
72-
<Button x:Name="FixRomsForStreamingCompatibilityButton" Command="{Binding FixRomStreamingCompatibilityCommand}" Margin="0,0,0,0" Padding="3" FontSize="16" Click="FixRomsForStreamingCompatibilityButton_Click">Fix Roms for Streaming Compatibility</Button>
72+
<Button x:Name="FixRomsForStreamingCompatibilityButton" Margin="0,0,0,0" Padding="3" FontSize="16" Click="FixRomsForStreamingCompatibilityButton_Click">Fix Roms for Streaming Compatibility</Button>
7373
<TextBlock VerticalAlignment="Center" Margin="3,0,0,0"><Path Width="16" Height="16" Stretch="Uniform" Data="F1 M 15.6001,5.22C 17.3822,5.2515 18.82,5.87949 19.9133,7.104C 21.0067,8.32849 21.5689,9.96048 21.6,12C 21.5923,14.7711 20.4267,16.468 18.1031,17.0906L 18.1031,19.2L 13.1146,19.2L 13.1146,14.3069C 13.4637,14.3485 13.7175,14.3652 13.8762,14.3569C 15.7127,14.5413 16.6373,13.7557 16.65,12C 16.6584,10.3585 16.2917,9.5585 15.55,9.59998C 14.7667,9.59198 14.3834,10.392 14.4,12L 9.45001,12C 9.47205,7.54944 11.5221,5.28946 15.6001,5.22 Z M 15.6501,21.06C 16.4651,21.0844 17.1408,21.3759 17.6773,21.9342C 18.2138,22.4926 18.4919,23.1713 18.5118,23.9701C 18.492,24.769 18.2138,25.4475 17.6773,26.0059C 17.1408,26.5641 16.4651,26.8555 15.6501,26.88C 14.813,26.8555 14.1151,26.5641 13.5565,26.0059C 12.9979,25.4475 12.7079,24.769 12.6863,23.9701C 12.7079,23.1507 12.9979,22.4662 13.5565,21.9167C 14.1151,21.3671 14.813,21.0815 15.6501,21.06 Z M 15.6501,0C 11.2097,0.105347 7.51904,1.64291 4.57797,4.61276C 1.6369,7.58261 0.110931,11.3527 0,15.9231C 0.110931,20.2214 1.6369,23.8045 4.57797,26.6724C 7.51904,29.5402 11.2097,31.0294 15.6501,31.14C 19.9496,31.0294 23.5613,29.5402 26.4853,26.6724C 29.4093,23.8045 30.9309,20.2214 31.05,15.9231C 30.9309,11.3527 29.4093,7.58264 26.4853,4.61276C 23.5613,1.64291 19.9496,0.105347 15.6501,0 Z " Fill="{DynamicResource {x:Static SystemColors.ActiveCaptionBrushKey}}" Cursor="Hand"/></TextBlock>
74-
<Button x:Name="RevertRomStreamingCompatibilityButton" Command="{Binding RevertRomStreamingCompatibilityCommand}" Margin="10,0,0,0" Padding="3" FontSize="16" Click="RevertRomStreamingCompatibilityButton_Click">Revert Rom Names (Breaks Streaming)</Button>
74+
<Button x:Name="RevertRomStreamingCompatibilityButton" Margin="10,0,0,0" Padding="3" FontSize="16" Click="RevertRomStreamingCompatibilityButton_Click">Revert Rom Names (Breaks Streaming)</Button>
7575
<TextBlock VerticalAlignment="Center" Margin="3,0,0,0"><Path Width="16" Height="16" Stretch="Uniform" Data="F1 M 15.6001,5.22C 17.3822,5.2515 18.82,5.87949 19.9133,7.104C 21.0067,8.32849 21.5689,9.96048 21.6,12C 21.5923,14.7711 20.4267,16.468 18.1031,17.0906L 18.1031,19.2L 13.1146,19.2L 13.1146,14.3069C 13.4637,14.3485 13.7175,14.3652 13.8762,14.3569C 15.7127,14.5413 16.6373,13.7557 16.65,12C 16.6584,10.3585 16.2917,9.5585 15.55,9.59998C 14.7667,9.59198 14.3834,10.392 14.4,12L 9.45001,12C 9.47205,7.54944 11.5221,5.28946 15.6001,5.22 Z M 15.6501,21.06C 16.4651,21.0844 17.1408,21.3759 17.6773,21.9342C 18.2138,22.4926 18.4919,23.1713 18.5118,23.9701C 18.492,24.769 18.2138,25.4475 17.6773,26.0059C 17.1408,26.5641 16.4651,26.8555 15.6501,26.88C 14.813,26.8555 14.1151,26.5641 13.5565,26.0059C 12.9979,25.4475 12.7079,24.769 12.6863,23.9701C 12.7079,23.1507 12.9979,22.4662 13.5565,21.9167C 14.1151,21.3671 14.813,21.0815 15.6501,21.06 Z M 15.6501,0C 11.2097,0.105347 7.51904,1.64291 4.57797,4.61276C 1.6369,7.58261 0.110931,11.3527 0,15.9231C 0.110931,20.2214 1.6369,23.8045 4.57797,26.6724C 7.51904,29.5402 11.2097,31.0294 15.6501,31.14C 19.9496,31.0294 23.5613,29.5402 26.4853,26.6724C 29.4093,23.8045 30.9309,20.2214 31.05,15.9231C 30.9309,11.3527 29.4093,7.58264 26.4853,4.61276C 23.5613,1.64291 19.9496,0.105347 15.6501,0 Z " Fill="{DynamicResource {x:Static SystemColors.ActiveCaptionBrushKey}}" Cursor="Hand"/></TextBlock>
7676
</StackPanel>
7777
</StackPanel>

EmulationManager/EmulationManager/Views/EmuManager.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ private void RevertRomStreamingCompatibilityButton_Click(object sender, RoutedEv
180180
var viewModel = mainGrid.DataContext as ViewModels.EmuManagerViewModel;
181181
if (viewModel != null && viewModel.FixRomStreamingCompatibilityCommand.CanExecute(null))
182182
{
183-
viewModel.FixRomStreamingCompatibilityCommand.Execute(null);
183+
viewModel.RevertRomStreamingCompatibilityCommand.Execute(null);
184184
}
185185
else
186186
{

0 commit comments

Comments
 (0)