105 lines
2.7 KiB
C#
105 lines
2.7 KiB
C#
using ExeLauncher.GUI;
|
|
using Microsoft.CSharp;
|
|
using System;
|
|
using System.CodeDom.Compiler;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
using System.Windows.Forms;
|
|
|
|
namespace ExeLauncher
|
|
{
|
|
public class Program
|
|
{
|
|
|
|
|
|
[STAThread]
|
|
static void Main(string[] args)
|
|
{
|
|
string path, arguments, workingDirectory, icon;
|
|
|
|
Console.Write("Path: ");
|
|
path = Console.ReadLine();
|
|
|
|
Console.Write("Arguments: ");
|
|
arguments = Console.ReadLine();
|
|
|
|
Console.Write("Working Directory: ");
|
|
workingDirectory = Console.ReadLine();
|
|
|
|
Console.WriteLine("Choose an icon for the executable: ");
|
|
icon = GetIcon();
|
|
|
|
Console.WriteLine();
|
|
|
|
Console.WriteLine("Creating launcher with options: ");
|
|
Console.WriteLine($"Path: {path}");
|
|
Console.WriteLine($"Arguments: {arguments}");
|
|
Console.WriteLine($"Working directory: {workingDirectory}");
|
|
|
|
Console.WriteLine();
|
|
Console.WriteLine("Choose a location to save the file.");
|
|
|
|
var location = GetLocation();
|
|
|
|
Console.WriteLine();
|
|
Console.WriteLine("Generating file...");
|
|
|
|
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("Done.");
|
|
Console.ReadKey(true);
|
|
}
|
|
|
|
public static string GetIcon()
|
|
{
|
|
var dialog = new OpenFileDialog()
|
|
{
|
|
CheckFileExists = true,
|
|
Filter = "Icon|*.ico"
|
|
};
|
|
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
return dialog.FileName;
|
|
}
|
|
|
|
return "";
|
|
}
|
|
|
|
public static string GetLocation()
|
|
{
|
|
var dialog = new SaveFileDialog()
|
|
{
|
|
AddExtension = true,
|
|
DefaultExt = ".exe",
|
|
FileName = "Run.exe",
|
|
Filter = "Executable|*.exe",
|
|
OverwritePrompt = true
|
|
};
|
|
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
return dialog.FileName;
|
|
}
|
|
|
|
Environment.Exit(1);
|
|
|
|
// Impossible to reach, but compiler complained, so...
|
|
return null;
|
|
}
|
|
}
|
|
}
|