Compare commits
9 Commits
14fb199206
...
8e3724d733
| Author | SHA1 | Date | |
|---|---|---|---|
| 8e3724d733 | |||
| c717adeba0 | |||
| 86bc48d647 | |||
| 52b7e10da1 | |||
| 6df7c2885b | |||
| 321e67e400 | |||
| 5d761a5920 | |||
| 0d2f2a6653 | |||
| 3795774023 |
9
ExeLauncher.GUI/App.xaml
Normal file
9
ExeLauncher.GUI/App.xaml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<Application x:Class="ExeLauncher.GUI.App"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:local="clr-namespace:ExeLauncher.GUI"
|
||||||
|
StartupUri="MainWindow.xaml">
|
||||||
|
<Application.Resources>
|
||||||
|
|
||||||
|
</Application.Resources>
|
||||||
|
</Application>
|
||||||
17
ExeLauncher.GUI/App.xaml.cs
Normal file
17
ExeLauncher.GUI/App.xaml.cs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Configuration;
|
||||||
|
using System.Data;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows;
|
||||||
|
|
||||||
|
namespace ExeLauncher.GUI
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Interaction logic for App.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class App : Application
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
34
ExeLauncher.GUI/AppControl.xaml
Normal file
34
ExeLauncher.GUI/AppControl.xaml
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<UserControl x:Class="ExeLauncher.GUI.AppControl"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:local="clr-namespace:ExeLauncher.GUI"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
d:DataContext="{d:DesignInstance local:ApplicationModel}"
|
||||||
|
d:DesignHeight="450" d:DesignWidth="800">
|
||||||
|
<Grid>
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="Auto" />
|
||||||
|
<ColumnDefinition Width="*" />
|
||||||
|
<ColumnDefinition Width="Auto" />
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="35" />
|
||||||
|
<RowDefinition Height="35" />
|
||||||
|
<RowDefinition Height="35" />
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<!--Path-->
|
||||||
|
<TextBlock Grid.Column="0" Grid.Row="0" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="5" Text="Path:" />
|
||||||
|
<TextBox Grid.Column="1" Grid.Row="0" Margin="5" VerticalContentAlignment="Center" Text="{Binding Path}" />
|
||||||
|
<Button Grid.Column="2" Grid.Row="0" Margin="5" Padding="5,2" Content="Browse" Click="Button_Path" />
|
||||||
|
|
||||||
|
<!--Arguments-->
|
||||||
|
<TextBlock Grid.Column="0" Grid.Row="1" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="5" Text="Arugments:" />
|
||||||
|
<TextBox Grid.Column="1" Grid.Row="1" Grid.ColumnSpan="2" Margin="5" VerticalContentAlignment="Center" Text="{Binding Arguments}" />
|
||||||
|
|
||||||
|
<!--Working Directory-->
|
||||||
|
<TextBlock Grid.Column="0" Grid.Row="2" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="5" Text="Working Directory:" />
|
||||||
|
<TextBox Grid.Column="1" Grid.Row="2" Grid.ColumnSpan="2" Margin="5" VerticalContentAlignment="Center" Text="{Binding WorkingDirectory}" />
|
||||||
|
</Grid>
|
||||||
|
</UserControl>
|
||||||
77
ExeLauncher.GUI/AppControl.xaml.cs
Normal file
77
ExeLauncher.GUI/AppControl.xaml.cs
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Data;
|
||||||
|
using System.Windows.Documents;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
using System.Windows.Navigation;
|
||||||
|
using Microsoft.Win32;
|
||||||
|
|
||||||
|
namespace ExeLauncher.GUI
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Logique d'interaction pour AppControl.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class AppControl : UserControl
|
||||||
|
{
|
||||||
|
public string ApplicationPath
|
||||||
|
{
|
||||||
|
get { return (string)GetValue(ApplicationPathProperty); }
|
||||||
|
set { SetValue(ApplicationPathProperty, value); }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Using a DependencyProperty as the backing store for ApplicationPath. This enables animation, styling, binding, etc...
|
||||||
|
public static readonly DependencyProperty ApplicationPathProperty =
|
||||||
|
DependencyProperty.Register("ApplicationPath", typeof(string), typeof(AppControl), new PropertyMetadata(""));
|
||||||
|
|
||||||
|
public string ApplicationArguments
|
||||||
|
{
|
||||||
|
get { return (string)GetValue(ApplicationArgumentsProperty); }
|
||||||
|
set { SetValue(ApplicationArgumentsProperty, value); }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Using a DependencyProperty as the backing store for ApplicationArguments. This enables animation, styling, binding, etc...
|
||||||
|
public static readonly DependencyProperty ApplicationArgumentsProperty =
|
||||||
|
DependencyProperty.Register("ApplicationArguments", typeof(string), typeof(AppControl), new PropertyMetadata(""));
|
||||||
|
|
||||||
|
public string ApplicationWorkingDirectory
|
||||||
|
{
|
||||||
|
get { return (string)GetValue(ApplicationWorkingDirectoryProperty); }
|
||||||
|
set { SetValue(ApplicationWorkingDirectoryProperty, value); }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Using a DependencyProperty as the backing store for ApplicationWorkingDirectory. This enables animation, styling, binding, etc...
|
||||||
|
public static readonly DependencyProperty ApplicationWorkingDirectoryProperty =
|
||||||
|
DependencyProperty.Register("ApplicationWorkingDirectory", typeof(string), typeof(AppControl), new PropertyMetadata(""));
|
||||||
|
|
||||||
|
public AppControl()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Button_Path(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
var dialog = new OpenFileDialog()
|
||||||
|
{
|
||||||
|
AddExtension = true,
|
||||||
|
DefaultExt = ".exe",
|
||||||
|
FileName = "Run.exe",
|
||||||
|
Filter = "Executable|*.exe"
|
||||||
|
};
|
||||||
|
|
||||||
|
if (dialog.ShowDialog() == true)
|
||||||
|
{
|
||||||
|
ApplicationPath = dialog.FileName;
|
||||||
|
|
||||||
|
ApplicationWorkingDirectory = Path.GetDirectoryName(ApplicationPath) ?? "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
81
ExeLauncher.GUI/ApplicationModel.cs
Normal file
81
ExeLauncher.GUI/ApplicationModel.cs
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ExeLauncher.GUI
|
||||||
|
{
|
||||||
|
public class ApplicationModel : INotifyPropertyChanged
|
||||||
|
{
|
||||||
|
private int _number = 1;
|
||||||
|
public int Number
|
||||||
|
{
|
||||||
|
get => _number;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (_number != value)
|
||||||
|
{
|
||||||
|
_number = value;
|
||||||
|
|
||||||
|
NotifyPropertyChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private string _path = "";
|
||||||
|
public string Path
|
||||||
|
{
|
||||||
|
get => _path;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (_path != value)
|
||||||
|
{
|
||||||
|
_path = value;
|
||||||
|
|
||||||
|
NotifyPropertyChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private string _arguments = "";
|
||||||
|
public string Arguments
|
||||||
|
{
|
||||||
|
get => _arguments;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (_arguments != value)
|
||||||
|
{
|
||||||
|
_arguments = value;
|
||||||
|
|
||||||
|
NotifyPropertyChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private string _workingDirectory = "";
|
||||||
|
public string WorkingDirectory
|
||||||
|
{
|
||||||
|
get => _workingDirectory;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (_workingDirectory != value)
|
||||||
|
{
|
||||||
|
_workingDirectory = value;
|
||||||
|
|
||||||
|
NotifyPropertyChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public event PropertyChangedEventHandler PropertyChanged;
|
||||||
|
|
||||||
|
private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
|
||||||
|
{
|
||||||
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
10
ExeLauncher.GUI/AssemblyInfo.cs
Normal file
10
ExeLauncher.GUI/AssemblyInfo.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
using System.Windows;
|
||||||
|
|
||||||
|
[assembly: ThemeInfo(
|
||||||
|
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
|
||||||
|
//(used if a resource is not found in the page,
|
||||||
|
// or application resource dictionaries)
|
||||||
|
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
|
||||||
|
//(used if a resource is not found in the page,
|
||||||
|
// app, or any theme specific resource dictionaries)
|
||||||
|
)]
|
||||||
22
ExeLauncher.GUI/ExeLauncher.GUI.csproj
Normal file
22
ExeLauncher.GUI/ExeLauncher.GUI.csproj
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>WinExe</OutputType>
|
||||||
|
<TargetFramework>net48</TargetFramework>
|
||||||
|
<UseWPF>true</UseWPF>
|
||||||
|
<ApplicationIcon>icon.ico</ApplicationIcon>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Remove="icon.ico" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="icon.ico" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\ExeLauncher\ExeLauncher.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
66
ExeLauncher.GUI/MainWindow.xaml
Normal file
66
ExeLauncher.GUI/MainWindow.xaml
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
<Window x:Class="ExeLauncher.GUI.MainWindow"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:local="clr-namespace:ExeLauncher.GUI"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
DataContext="{Binding RelativeSource={RelativeSource Self}}"
|
||||||
|
Title="ExeLauncher" MinHeight="335" Height="480" Width="800">
|
||||||
|
<DockPanel LastChildFill="True">
|
||||||
|
<!--Controls-->
|
||||||
|
<Grid DockPanel.Dock="Bottom" Background="#F5F5F5">
|
||||||
|
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="4,0">
|
||||||
|
<Button HorizontalAlignment="Right" Margin="0,8" Padding="6,4" Content="Remove" Click="Button_Remove" />
|
||||||
|
<Button HorizontalAlignment="Right" Margin="4,8" Padding="6,4" Content="Add" Click="Button_Add" />
|
||||||
|
<Button HorizontalAlignment="Right" Margin="8,8,4,8" Padding="6,4" Content="Generate" Click="Button_Generate" />
|
||||||
|
</StackPanel>
|
||||||
|
</Grid>
|
||||||
|
<!--Apps-->
|
||||||
|
<DockPanel LastChildFill="True" Margin="10">
|
||||||
|
<GroupBox DockPanel.Dock="Top" Header="Application Info">
|
||||||
|
<Grid>
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="Auto" />
|
||||||
|
<ColumnDefinition Width="*" />
|
||||||
|
<ColumnDefinition Width="Auto" />
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="35" />
|
||||||
|
<RowDefinition Height="35" />
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<!--Name-->
|
||||||
|
<TextBlock Grid.Column="0" Grid.Row="0" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="5" Text="Name:" />
|
||||||
|
<TextBox Grid.Column="1" Grid.Row="0" Grid.ColumnSpan="2" Margin="5" VerticalContentAlignment="Center" Text="{Binding ApplicationName}" />
|
||||||
|
|
||||||
|
<!--Icon-->
|
||||||
|
<TextBlock Grid.Column="0" Grid.Row="1" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="5" Text="Icon:" />
|
||||||
|
<TextBox Grid.Column="1" Grid.Row="1" Margin="5" VerticalContentAlignment="Center" Text="{Binding ApplicationIconPath}" />
|
||||||
|
<Button Grid.Column="2" Grid.Row="1" Margin="5" Padding="5,2" Content="Browse" Click="Button_Icon" />
|
||||||
|
</Grid>
|
||||||
|
</GroupBox>
|
||||||
|
<ListView HorizontalContentAlignment="Stretch" ItemsSource="{Binding Applications}" BorderThickness="0">
|
||||||
|
<ListView.ItemContainerStyle>
|
||||||
|
<Style TargetType="ListViewItem">
|
||||||
|
<Setter Property="Focusable" Value="false"/>
|
||||||
|
<Setter Property="Background" Value="Transparent" />
|
||||||
|
<Setter Property="Template">
|
||||||
|
<Setter.Value>
|
||||||
|
<ControlTemplate TargetType="{x:Type ListViewItem}">
|
||||||
|
<ContentPresenter />
|
||||||
|
</ControlTemplate>
|
||||||
|
</Setter.Value>
|
||||||
|
</Setter>
|
||||||
|
</Style>
|
||||||
|
</ListView.ItemContainerStyle>
|
||||||
|
<ListView.ItemTemplate>
|
||||||
|
<DataTemplate>
|
||||||
|
<GroupBox Header="{Binding Number}" HeaderStringFormat="Application {0}">
|
||||||
|
<local:AppControl ApplicationPath="{Binding Path, Mode=TwoWay}" ApplicationArguments="{Binding Arguments, Mode=TwoWay}" ApplicationWorkingDirectory="{Binding WorkingDirectory, Mode=TwoWay}" />
|
||||||
|
</GroupBox>
|
||||||
|
</DataTemplate>
|
||||||
|
</ListView.ItemTemplate>
|
||||||
|
</ListView>
|
||||||
|
</DockPanel>
|
||||||
|
</DockPanel>
|
||||||
|
</Window>
|
||||||
171
ExeLauncher.GUI/MainWindow.xaml.cs
Normal file
171
ExeLauncher.GUI/MainWindow.xaml.cs
Normal file
@@ -0,0 +1,171 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Data;
|
||||||
|
using System.Windows.Documents;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
using System.Windows.Navigation;
|
||||||
|
using System.Windows.Shapes;
|
||||||
|
using Microsoft.Win32;
|
||||||
|
|
||||||
|
namespace ExeLauncher.GUI
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Interaction logic for MainWindow.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class MainWindow : Window, INotifyPropertyChanged
|
||||||
|
{
|
||||||
|
public event PropertyChangedEventHandler PropertyChanged;
|
||||||
|
|
||||||
|
private string _appName = "Run";
|
||||||
|
|
||||||
|
public string ApplicationName
|
||||||
|
{
|
||||||
|
get => _appName;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (_appName != value)
|
||||||
|
{
|
||||||
|
_appName = value;
|
||||||
|
|
||||||
|
NotifyPropertyChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private string _applicationIconPath = "";
|
||||||
|
|
||||||
|
public string ApplicationIconPath
|
||||||
|
{
|
||||||
|
get => _applicationIconPath;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (_applicationIconPath != value)
|
||||||
|
{
|
||||||
|
_applicationIconPath = value;
|
||||||
|
|
||||||
|
NotifyPropertyChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObservableCollection<ApplicationModel> Applications { get; set; }
|
||||||
|
|
||||||
|
private readonly ExeGenerator _exeGenerator;
|
||||||
|
|
||||||
|
public MainWindow()
|
||||||
|
{
|
||||||
|
_exeGenerator = new ExeGenerator();
|
||||||
|
|
||||||
|
Applications = new ObservableCollection<ApplicationModel>()
|
||||||
|
{
|
||||||
|
new ApplicationModel()
|
||||||
|
};
|
||||||
|
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Button_Icon(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
ApplicationIconPath = Program.GetIcon();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Button_Add(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
Applications.Add(new ApplicationModel() { Number = Applications.Count + 1 });
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Button_Remove(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if (Applications.Count > 1)
|
||||||
|
{
|
||||||
|
Applications.RemoveAt(Applications.Count - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show($"Successfully generated launcher at: {dialog.FileName}", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
ExeLauncher.GUI/icon.ico
Normal file
BIN
ExeLauncher.GUI/icon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 165 KiB |
@@ -1,10 +1,12 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio Version 16
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 16.0.29609.76
|
VisualStudioVersion = 17.0.31912.275
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExeLauncher", "ExeLauncher\ExeLauncher.csproj", "{E002E8E2-D13A-4995-ABAB-DF7451FDA464}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExeLauncher", "ExeLauncher\ExeLauncher.csproj", "{E002E8E2-D13A-4995-ABAB-DF7451FDA464}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExeLauncher.GUI", "ExeLauncher.GUI\ExeLauncher.GUI.csproj", "{F8F5EFC9-D012-49F5-B6B6-36CA7B33727C}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@@ -15,6 +17,10 @@ Global
|
|||||||
{E002E8E2-D13A-4995-ABAB-DF7451FDA464}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{E002E8E2-D13A-4995-ABAB-DF7451FDA464}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{E002E8E2-D13A-4995-ABAB-DF7451FDA464}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{E002E8E2-D13A-4995-ABAB-DF7451FDA464}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{E002E8E2-D13A-4995-ABAB-DF7451FDA464}.Release|Any CPU.Build.0 = Release|Any CPU
|
{E002E8E2-D13A-4995-ABAB-DF7451FDA464}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{F8F5EFC9-D012-49F5-B6B6-36CA7B33727C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{F8F5EFC9-D012-49F5-B6B6-36CA7B33727C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{F8F5EFC9-D012-49F5-B6B6-36CA7B33727C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{F8F5EFC9-D012-49F5-B6B6-36CA7B33727C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
66
ExeLauncher/ExeGenerator.cs
Normal file
66
ExeLauncher/ExeGenerator.cs
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
using System;
|
||||||
|
using System.CodeDom.Compiler;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.CSharp;
|
||||||
|
|
||||||
|
namespace ExeLauncher.GUI
|
||||||
|
{
|
||||||
|
public class ExeGenerator
|
||||||
|
{
|
||||||
|
static ExeGenerator()
|
||||||
|
{
|
||||||
|
var file = Assembly.GetExecutingAssembly().GetManifestResourceStream("ExeLauncher.Code.cs");
|
||||||
|
var reader = new StreamReader(file);
|
||||||
|
|
||||||
|
Code = reader.ReadToEnd();
|
||||||
|
|
||||||
|
reader.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
const string Paths = "%Paths%";
|
||||||
|
const string Arguments = "%Arguments%";
|
||||||
|
const string WorkingDirectories = "%WorkingDirectories%";
|
||||||
|
|
||||||
|
private static string Code { get; }
|
||||||
|
|
||||||
|
private string _code;
|
||||||
|
|
||||||
|
public ExeGenerator()
|
||||||
|
{
|
||||||
|
_code = Code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompilerErrorCollection CreateExecutable(string location, string paths, string arguments, string workingDirectories, string icon)
|
||||||
|
{
|
||||||
|
_code = _code.Replace(Paths, paths);
|
||||||
|
_code = _code.Replace(Arguments, arguments);
|
||||||
|
_code = _code.Replace(WorkingDirectories, workingDirectories);
|
||||||
|
|
||||||
|
using (var codeProvider = new CSharpCodeProvider())
|
||||||
|
{
|
||||||
|
var compilerParameters = new CompilerParameters()
|
||||||
|
{
|
||||||
|
CompilerOptions = string.IsNullOrWhiteSpace(icon) ? "-target:winexe" : $" -target:winexe -win32icon:\"{icon}\"",
|
||||||
|
GenerateExecutable = true,
|
||||||
|
OutputAssembly = location
|
||||||
|
};
|
||||||
|
compilerParameters.ReferencedAssemblies.Add("System.dll");
|
||||||
|
|
||||||
|
var result = codeProvider.CompileAssemblyFromSource(compilerParameters, _code);
|
||||||
|
|
||||||
|
if (result.Errors.HasErrors)
|
||||||
|
{
|
||||||
|
return result.Errors;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -66,6 +66,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<EmbeddedResource Include="Code.cs" />
|
<EmbeddedResource Include="Code.cs" />
|
||||||
|
<Compile Include="ExeGenerator.cs" />
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Microsoft.CSharp;
|
using ExeLauncher.GUI;
|
||||||
|
using Microsoft.CSharp;
|
||||||
using System;
|
using System;
|
||||||
using System.CodeDom.Compiler;
|
using System.CodeDom.Compiler;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
@@ -8,24 +9,13 @@ using System.Windows.Forms;
|
|||||||
|
|
||||||
namespace ExeLauncher
|
namespace ExeLauncher
|
||||||
{
|
{
|
||||||
class Program
|
public class Program
|
||||||
{
|
{
|
||||||
const string Paths = "%Paths%";
|
|
||||||
const string Arguments = "%Arguments%";
|
|
||||||
const string WorkingDirectories = "%WorkingDirectories%";
|
|
||||||
|
|
||||||
static string code;
|
|
||||||
|
|
||||||
[STAThread]
|
[STAThread]
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
var file = Assembly.GetExecutingAssembly().GetManifestResourceStream("ExeLauncher.Code.cs");
|
|
||||||
var reader = new StreamReader(file);
|
|
||||||
|
|
||||||
code = reader.ReadToEnd();
|
|
||||||
|
|
||||||
reader.Close();
|
|
||||||
|
|
||||||
string path, arguments, workingDirectory, icon;
|
string path, arguments, workingDirectory, icon;
|
||||||
|
|
||||||
Console.Write("Path: ");
|
Console.Write("Path: ");
|
||||||
@@ -55,44 +45,25 @@ namespace ExeLauncher
|
|||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
Console.WriteLine("Generating file...");
|
Console.WriteLine("Generating file...");
|
||||||
|
|
||||||
CreateExecutable(location, path, arguments, workingDirectory, icon);
|
var errors = new ExeGenerator().CreateExecutable(location, path, arguments, workingDirectory, icon);
|
||||||
|
|
||||||
|
if (errors != null)
|
||||||
|
{
|
||||||
|
Console.WriteLine("An error occured while compiling the executable: ");
|
||||||
|
|
||||||
|
foreach (var compilerError in errors)
|
||||||
|
{
|
||||||
|
Console.WriteLine("\t{0}", compilerError.ToString());
|
||||||
|
Console.WriteLine();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
Console.WriteLine("Done.");
|
Console.WriteLine("Done.");
|
||||||
Console.ReadKey(true);
|
Console.ReadKey(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void CreateExecutable(string location, string paths, string arguments, string workingDirectories, string icon)
|
public static string GetIcon()
|
||||||
{
|
|
||||||
code = code.Replace(Paths, paths);
|
|
||||||
code = code.Replace(Arguments, arguments);
|
|
||||||
code = code.Replace(WorkingDirectories, workingDirectories);
|
|
||||||
|
|
||||||
using (var codeProvider = new CSharpCodeProvider())
|
|
||||||
{
|
|
||||||
var compilerParameters = new CompilerParameters()
|
|
||||||
{
|
|
||||||
CompilerOptions = $"-target:winexe -win32icon:\"{icon}\"",
|
|
||||||
GenerateExecutable = true,
|
|
||||||
OutputAssembly = location
|
|
||||||
};
|
|
||||||
compilerParameters.ReferencedAssemblies.Add("System.dll");
|
|
||||||
|
|
||||||
var result = codeProvider.CompileAssemblyFromSource(compilerParameters, code);
|
|
||||||
|
|
||||||
if (result.Errors.HasErrors)
|
|
||||||
{
|
|
||||||
Console.WriteLine("An error occured while compiling the executable: ");
|
|
||||||
foreach (var compilerError in result.Errors)
|
|
||||||
{
|
|
||||||
Console.WriteLine("\t{0}", compilerError.ToString());
|
|
||||||
Console.WriteLine();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string GetIcon()
|
|
||||||
{
|
{
|
||||||
var dialog = new OpenFileDialog()
|
var dialog = new OpenFileDialog()
|
||||||
{
|
{
|
||||||
@@ -108,7 +79,7 @@ namespace ExeLauncher
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetLocation()
|
public static string GetLocation()
|
||||||
{
|
{
|
||||||
var dialog = new SaveFileDialog()
|
var dialog = new SaveFileDialog()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user