Skip to content

Commit 438d726

Browse files
committed
Fixed crash when user don't have an acccess to the mapping file
1 parent 5da988e commit 438d726

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

MFIGamepadFeeder/MappingEditorWindow.xaml.cs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,22 @@ private async void SaveButton_Click(object sender, RoutedEventArgs e)
130130

131131
if (saveFileDialog.ShowDialog() == true)
132132
{
133-
using (var outputFile = new StreamWriter(saveFileDialog.FileName))
133+
try
134134
{
135-
URLLabel.Content = saveFileDialog.FileName;
136-
var mappingItems = MappingItemsListView.Items.SourceCollection.Cast<ListViewItem>().Select(item => item.Content as GamepadMappingItem).ToList();
137-
var virtualKeysMappingItems = VirtualKeysItemsListView.Items.SourceCollection.Cast<ListViewItem>().Select(item => item.Content as VirtualKeyMappingItem).ToList();
135+
using (var outputFile = new StreamWriter(saveFileDialog.FileName))
136+
{
137+
URLLabel.Content = saveFileDialog.FileName;
138+
var mappingItems = MappingItemsListView.Items.SourceCollection.Cast<ListViewItem>().Select(item => item.Content as GamepadMappingItem).ToList();
139+
var virtualKeysMappingItems = VirtualKeysItemsListView.Items.SourceCollection.Cast<ListViewItem>().Select(item => item.Content as VirtualKeyMappingItem).ToList();
138140

139-
var newMapping = new GamepadMapping(mappingItems, virtualKeysMappingItems);
141+
var newMapping = new GamepadMapping(mappingItems, virtualKeysMappingItems);
140142

141-
await outputFile.WriteAsync(JsonConvert.SerializeObject(newMapping, Formatting.Indented));
143+
await outputFile.WriteAsync(JsonConvert.SerializeObject(newMapping, Formatting.Indented));
144+
}
145+
}
146+
catch (Exception ex)
147+
{
148+
MessageBox.Show(ex.Message);
142149
}
143150
}
144151
}
@@ -292,7 +299,7 @@ private void VirtualSourceKey_SelectionChanged(object sender, SelectionChangedEv
292299

293300
private void SelectVirtualKeyComboBox_Loaded(object sender, RoutedEventArgs e)
294301
{
295-
var keys = new List<object>()
302+
var keys = new List<object>
296303
{
297304
"",
298305
XInputGamepadButtons.Start,
@@ -308,7 +315,7 @@ private void SelectVirtualKeyComboBox_Loaded(object sender, RoutedEventArgs e)
308315
XInputGamepadButtons.DpadUp,
309316
XInputGamepadButtons.DpadDown,
310317
XInputGamepadButtons.DpadLeft,
311-
XInputGamepadButtons.DpadRight,
318+
XInputGamepadButtons.DpadRight
312319
};
313320

314321
((ComboBox) sender).ItemsSource = keys;

0 commit comments

Comments
 (0)