diff --git a/ExeLauncher.GUI/ApplicationModel.cs b/ExeLauncher.GUI/ApplicationModel.cs
index 2aa5a52..821ea36 100644
--- a/ExeLauncher.GUI/ApplicationModel.cs
+++ b/ExeLauncher.GUI/ApplicationModel.cs
@@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace ExeLauncher.GUI
{
- public record ApplicationModel : INotifyPropertyChanged
+ public class ApplicationModel : INotifyPropertyChanged
{
private int _number = 1;
public int Number
@@ -70,7 +70,7 @@ namespace ExeLauncher.GUI
}
}
- public event PropertyChangedEventHandler? PropertyChanged;
+ public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
{
diff --git a/ExeLauncher.GUI/ExeLauncher.GUI.csproj b/ExeLauncher.GUI/ExeLauncher.GUI.csproj
index c39acf1..b0b11fa 100644
--- a/ExeLauncher.GUI/ExeLauncher.GUI.csproj
+++ b/ExeLauncher.GUI/ExeLauncher.GUI.csproj
@@ -2,8 +2,7 @@
WinExe
- net6.0-windows
- enable
+ net48
true
diff --git a/ExeLauncher.GUI/MainWindow.xaml b/ExeLauncher.GUI/MainWindow.xaml
index c3f1af3..4d5cb0f 100644
--- a/ExeLauncher.GUI/MainWindow.xaml
+++ b/ExeLauncher.GUI/MainWindow.xaml
@@ -13,6 +13,7 @@
+
diff --git a/ExeLauncher.GUI/MainWindow.xaml.cs b/ExeLauncher.GUI/MainWindow.xaml.cs
index 6808f22..c8e3543 100644
--- a/ExeLauncher.GUI/MainWindow.xaml.cs
+++ b/ExeLauncher.GUI/MainWindow.xaml.cs
@@ -15,6 +15,7 @@ using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
+using Microsoft.Win32;
namespace ExeLauncher.GUI
{
@@ -23,9 +24,9 @@ namespace ExeLauncher.GUI
///
public partial class MainWindow : Window, INotifyPropertyChanged
{
- public event PropertyChangedEventHandler? PropertyChanged;
+ public event PropertyChangedEventHandler PropertyChanged;
- private string _appName = "";
+ private string _appName = "Run";
public string ApplicationName
{
@@ -59,9 +60,13 @@ namespace ExeLauncher.GUI
public ObservableCollection Applications { get; set; }
+ private readonly ExeGenerator _exeGenerator;
+
public MainWindow()
{
- Applications = new()
+ _exeGenerator = new ExeGenerator();
+
+ Applications = new ObservableCollection()
{
new ApplicationModel()
};
@@ -87,6 +92,73 @@ namespace ExeLauncher.GUI
}
}
+ private void Button_Generate(object sender, RoutedEventArgs e)
+ {
+ if (!CheckApplications())
+ {
+ MessageBox.Show("Path and working directory cannot be empty!", "Invalid path or working directory", MessageBoxButton.OK, MessageBoxImage.Error);
+
+ return;
+ }
+
+ Generate();
+ }
+
+ private void Generate()
+ {
+ var dialog = new SaveFileDialog()
+ {
+ AddExtension = true,
+ DefaultExt = ".exe",
+ FileName = $"{ApplicationName}.exe",
+ Filter = "Executable|*.exe",
+ OverwritePrompt = true
+ };
+
+ if (dialog.ShowDialog() == true)
+ {
+ var paths = string.Join("$", Applications.Select(app => app.Path));
+ var arguments = string.Join("$", Applications.Select(app => app.Arguments));
+ var workingDirectories = string.Join("$", Applications.Select(app => app.WorkingDirectory));
+
+ var errors = _exeGenerator.CreateExecutable(dialog.FileName, paths, arguments, workingDirectories, ApplicationIconPath);
+
+ if (errors != null)
+ {
+ var message = GenerateErrorMessage(errors);
+
+ MessageBox.Show(message, "Compilation error", MessageBoxButton.OK, MessageBoxImage.Error);
+ }
+ }
+ }
+
+ private string GenerateErrorMessage(System.CodeDom.Compiler.CompilerErrorCollection errors)
+ {
+ var builder = new StringBuilder();
+
+ builder.AppendLine("An error occured while compiling the executable: ");
+
+ foreach (var compilerError in errors)
+ {
+ builder.AppendLine($"\t{compilerError}");
+ builder.AppendLine();
+ }
+
+ return builder.ToString();
+ }
+
+ private bool CheckApplications()
+ {
+ foreach (var app in Applications)
+ {
+ if (string.IsNullOrWhiteSpace(app.Path) || string.IsNullOrWhiteSpace(app.WorkingDirectory))
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));