Skip to content
This repository was archived by the owner on Sep 11, 2023. It is now read-only.

Commit a61c536

Browse files
committed
added pawn icon next to smdirs with compiler found in configs window
1 parent e472693 commit a61c536

File tree

5 files changed

+67
-26
lines changed

5 files changed

+67
-26
lines changed

Resources/Icons/icon-pawn.png

1.14 KB
Loading

Spcode.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@
469469
<Resource Include="Resources\Icons\icon-add.png" />
470470
<Resource Include="Resources\Icons\icon-duplicate.png" />
471471
<Resource Include="Resources\Icons\icon-trash.png" />
472+
<Resource Include="Resources\Icons\icon-pawn.png" />
472473
<Content Include="Resources\License.txt" />
473474
<Content Include="Resources\Misc\Configurations\sm_1_10_0_6509\include\admin.inc" />
474475
<Content Include="Resources\Misc\Configurations\sm_1_10_0_6509\include\adminmenu.inc" />

UI/MainWindow/MainWindowSPCompiler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ private async void Compile_SPScripts(bool compileAll = true)
7777
// Searches for the spcomp.exe compiler
7878
foreach (var dir in currentConfig.SMDirectories)
7979
{
80-
spCompInfo = new FileInfo(Path.Combine(dir, "spcomp.exe"));
80+
spCompInfo = new FileInfo(Path.Combine(dir, Constants.SPCompiler));
8181
if (spCompInfo.Exists)
8282
{
8383
SpCompFound = true;

UI/Windows/ConfigWindow.xaml.cs

Lines changed: 64 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using System.Windows;
1111
using System.Windows.Controls;
1212
using System.Windows.Input;
13+
using System.Windows.Media.Imaging;
1314
using System.Windows.Threading;
1415
using System.Xml;
1516
using MahApps.Metro;
@@ -229,8 +230,9 @@ private void LoadConfigToUI(int index)
229230
AllowChange = false;
230231
var c = Program.Configs[index];
231232

233+
C_SMDir.Items.Clear();
234+
c.SMDirectories.ForEach(x => C_SMDir.Items.Add(CreateDirItem(x)));
232235
C_Name.Text = c.Name;
233-
C_SMDir.ItemsSource = c.SMDirectories;
234236
C_AutoCopy.IsChecked = c.AutoCopy;
235237
C_AutoUpload.IsChecked = c.AutoUpload;
236238
C_AutoRCON.IsChecked = c.AutoRCON;
@@ -313,42 +315,51 @@ private void AddSMDirButton_Click(object sender, RoutedEventArgs e)
313315
IsFolderPicker = true
314316
};
315317

316-
if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
318+
if (dialog.ShowDialog() != CommonFileDialogResult.Ok)
317319
{
318-
var c = Program.Configs[ConfigListBox.SelectedIndex];
320+
return;
321+
}
319322

320-
if (c.SMDirectories.Contains(dialog.FileName))
321-
{
322-
return;
323-
}
323+
// Get selected config
324+
var c = Program.Configs[ConfigListBox.SelectedIndex];
324325

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+
}
335331

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);
339336
}
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;
340351
}
341352

342353
private void RemoveSMDirButton_Click(object sender, RoutedEventArgs e)
343354
{
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)
346358
{
347359
return;
348360
}
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);
352363
}
353364

354365
private void C_Name_TextChanged(object sender, TextChangedEventArgs e)
@@ -742,6 +753,34 @@ await this.ShowMessageAsync(Translate("ErrorSavingConfigs"),
742753
});
743754
}
744755

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+
745784
private void Language_Translate()
746785
{
747786
Title = Translate("Configs");

Utils/Constants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public static class Constants
2828
public const string LicenseFile = "License.txt";
2929
public const string LanguagesFile = "lang_0_spcode.xml";
3030
public const string DefaultTranslationsFile = "default.xml";
31+
public const string SPCompiler = "spcomp.exe";
3132
#endregion
3233

3334
#region Filters

0 commit comments

Comments
 (0)