|
10 | 10 | using System.Windows;
|
11 | 11 | using System.Windows.Controls;
|
12 | 12 | using System.Windows.Input;
|
| 13 | +using System.Windows.Media.Imaging; |
13 | 14 | using System.Windows.Threading;
|
14 | 15 | using System.Xml;
|
15 | 16 | using MahApps.Metro;
|
@@ -229,8 +230,9 @@ private void LoadConfigToUI(int index)
|
229 | 230 | AllowChange = false;
|
230 | 231 | var c = Program.Configs[index];
|
231 | 232 |
|
| 233 | + C_SMDir.Items.Clear(); |
| 234 | + c.SMDirectories.ForEach(x => C_SMDir.Items.Add(CreateDirItem(x))); |
232 | 235 | C_Name.Text = c.Name;
|
233 |
| - C_SMDir.ItemsSource = c.SMDirectories; |
234 | 236 | C_AutoCopy.IsChecked = c.AutoCopy;
|
235 | 237 | C_AutoUpload.IsChecked = c.AutoUpload;
|
236 | 238 | C_AutoRCON.IsChecked = c.AutoRCON;
|
@@ -313,42 +315,51 @@ private void AddSMDirButton_Click(object sender, RoutedEventArgs e)
|
313 | 315 | IsFolderPicker = true
|
314 | 316 | };
|
315 | 317 |
|
316 |
| - if (dialog.ShowDialog() == CommonFileDialogResult.Ok) |
| 318 | + if (dialog.ShowDialog() != CommonFileDialogResult.Ok) |
317 | 319 | {
|
318 |
| - var c = Program.Configs[ConfigListBox.SelectedIndex]; |
| 320 | + return; |
| 321 | + } |
319 | 322 |
|
320 |
| - if (c.SMDirectories.Contains(dialog.FileName)) |
321 |
| - { |
322 |
| - return; |
323 |
| - } |
| 323 | + // Get selected config |
| 324 | + var c = Program.Configs[ConfigListBox.SelectedIndex]; |
324 | 325 |
|
325 |
| - try |
326 |
| - { |
327 |
| - Directory.GetAccessControl(dialog.FileName); |
328 |
| - } |
329 |
| - catch (UnauthorizedAccessException) |
330 |
| - { |
331 |
| - this.ShowMessageAsync(Translate("PermissionAccessError"), |
332 |
| - Translate("PermissionAcessErrorMessage"), |
333 |
| - MessageDialogStyle.Affirmative, Program.MainWindow.MetroDialogOptions); |
334 |
| - } |
| 326 | + // If it already has that scripting dir, return |
| 327 | + if (c.SMDirectories.Contains(dialog.FileName)) |
| 328 | + { |
| 329 | + return; |
| 330 | + } |
335 | 331 |
|
336 |
| - c.SMDirectories.Add(dialog.FileName); |
337 |
| - C_SMDir.Items.Refresh(); |
338 |
| - NeedsSMDefInvalidation = true; |
| 332 | + // Test for access permissions and flag as rejected directory if necessary |
| 333 | + try |
| 334 | + { |
| 335 | + Directory.GetAccessControl(dialog.FileName); |
339 | 336 | }
|
| 337 | + catch (UnauthorizedAccessException) |
| 338 | + { |
| 339 | + this.ShowMessageAsync(Translate("PermissionAccessError"), |
| 340 | + Translate("PermissionAcessErrorMessage"), |
| 341 | + MessageDialogStyle.Affirmative, Program.MainWindow.MetroDialogOptions); |
| 342 | + } |
| 343 | + |
| 344 | + // Add to dirs of that config |
| 345 | + c.SMDirectories.Add(dialog.FileName); |
| 346 | + |
| 347 | + // Add list item |
| 348 | + C_SMDir.Items.Add(CreateDirItem(dialog.FileName)); |
| 349 | + |
| 350 | + NeedsSMDefInvalidation = true; |
340 | 351 | }
|
341 | 352 |
|
342 | 353 | private void RemoveSMDirButton_Click(object sender, RoutedEventArgs e)
|
343 | 354 | {
|
344 |
| - var c = Program.Configs[ConfigListBox.SelectedIndex]; |
345 |
| - if (C_SMDir.SelectedItem == null) |
| 355 | + var item = C_SMDir.SelectedIndex; |
| 356 | + var cfg = Program.Configs[ConfigListBox.SelectedIndex]; |
| 357 | + if (item == -1 || cfg == null) |
346 | 358 | {
|
347 | 359 | return;
|
348 | 360 | }
|
349 |
| - c.SMDirectories.Remove(C_SMDir.SelectedItem.ToString()); |
350 |
| - C_SMDir.Items.Refresh(); |
351 |
| - NeedsSMDefInvalidation = true; |
| 361 | + cfg.SMDirectories.RemoveAt(item); |
| 362 | + C_SMDir.Items.RemoveAt(item); |
352 | 363 | }
|
353 | 364 |
|
354 | 365 | private void C_Name_TextChanged(object sender, TextChangedEventArgs e)
|
@@ -742,6 +753,34 @@ await this.ShowMessageAsync(Translate("ErrorSavingConfigs"),
|
742 | 753 | });
|
743 | 754 | }
|
744 | 755 |
|
| 756 | + /// <summary> |
| 757 | + /// Creates the ListBoxItem that will be added to the SM Directories list of the selected config |
| 758 | + /// </summary> |
| 759 | + /// <param name="path">Path of the SM Directory to be added</param> |
| 760 | + /// <returns>The ListBoxItem that will be added to the SM Directories list</returns> |
| 761 | + private ListBoxItem CreateDirItem(string path) |
| 762 | + { |
| 763 | + var item = new ListBoxItem(); |
| 764 | + var stack = new StackPanel(); |
| 765 | + stack.Orientation = Orientation.Horizontal; |
| 766 | + stack.Children.Add(new TextBlock |
| 767 | + { |
| 768 | + Text = path |
| 769 | + }); |
| 770 | + if (File.Exists(Path.Combine(path, Constants.SPCompiler))) |
| 771 | + { |
| 772 | + stack.Children.Add(new Image |
| 773 | + { |
| 774 | + Source = new BitmapImage(new Uri($"/SPCode;component/Resources/Icons/icon-pawn.png", UriKind.Relative)), |
| 775 | + Width = 16, |
| 776 | + Margin = new Thickness(5,0,0,0), |
| 777 | + ToolTip = Translate("SPCompilerFoundHere") |
| 778 | + }); |
| 779 | + } |
| 780 | + item.Content = stack; |
| 781 | + return item; |
| 782 | + } |
| 783 | + |
745 | 784 | private void Language_Translate()
|
746 | 785 | {
|
747 | 786 | Title = Translate("Configs");
|
|
0 commit comments