built-in dll embedder

This commit is contained in:
AsvalGTA 2019-03-22 01:28:50 +01:00
parent f1c7012c97
commit 9c35c8a446
3 changed files with 115 additions and 65 deletions

View File

@ -5,7 +5,7 @@
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{71A31C47-30BC-4CB5-AD89-81E5008F4BEB}</ProjectGuid>
<OutputType>Exe</OutputType>
<OutputType>WinExe</OutputType>
<RootNamespace>FModel</RootNamespace>
<AssemblyName>FModel</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
@ -56,7 +56,7 @@
<ApplicationIcon>FNTools_Logo.ico</ApplicationIcon>
</PropertyGroup>
<PropertyGroup>
<StartupObject />
<StartupObject>FModel.Program</StartupObject>
</PropertyGroup>
<PropertyGroup>
<ManifestCertificateThumbprint>3ED5A42E3C4689AF46F18366F8BF30D245116948</ManifestCertificateThumbprint>
@ -174,4 +174,11 @@
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="AfterResolveReferences">
<ItemGroup>
<EmbeddedResource Include="@(ReferenceCopyLocalPaths)" Condition="'%(ReferenceCopyLocalPaths.Extension)' == '.dll'">
<LogicalName>%(ReferenceCopyLocalPaths.DestinationSubDirectory)%(ReferenceCopyLocalPaths.Filename)%(ReferenceCopyLocalPaths.Extension)</LogicalName>
</EmbeddedResource>
</ItemGroup>
</Target>
</Project>

View File

@ -2353,80 +2353,87 @@ namespace FModel
private void mergeGeneratedImagesToolStripMenuItem_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(Properties.Settings.Default.mergerFileName))
try
{
MessageBox.Show("Please, set a name to your file before trying to merge images\n\nSteps:\n\t- Load button drop down menu\n\t- Options", "FModel Merger File Name Missing", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
OpenFileDialog theDialog = new OpenFileDialog();
theDialog.Multiselect = true;
theDialog.InitialDirectory = docPath + "\\Generated Icons\\";
theDialog.Title = "Choose your images";
theDialog.Filter = "PNG Files (*.png)|*.png|JPEG Files (*.jpg)|*.jpg|BMP Files (*.bmp)|*.bmp|All Files (*.*)|*.*";
if (theDialog.ShowDialog() == DialogResult.OK)
if (string.IsNullOrEmpty(Properties.Settings.Default.mergerFileName))
{
List<Image> selectedImages = new List<Image>();
foreach (var files in theDialog.FileNames)
{
selectedImages.Add(Image.FromFile(files));
}
MessageBox.Show("Please, set a name to your file before trying to merge images\n\nSteps:\n\t- Load button drop down menu\n\t- Options", "FModel Merger File Name Missing", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
OpenFileDialog theDialog = new OpenFileDialog();
theDialog.Multiselect = true;
theDialog.InitialDirectory = docPath + "\\Generated Icons\\";
theDialog.Title = "Choose your images";
theDialog.Filter = "PNG Files (*.png)|*.png|JPEG Files (*.jpg)|*.jpg|BMP Files (*.bmp)|*.bmp|All Files (*.*)|*.*";
if (Properties.Settings.Default.mergerImagesRow == 0)
if (theDialog.ShowDialog() == DialogResult.OK)
{
Properties.Settings.Default.mergerImagesRow = 7;
Properties.Settings.Default.Save();
}
int numperrow = Properties.Settings.Default.mergerImagesRow;
var w = 530 * numperrow;
if (selectedImages.Count * 530 < 530 * numperrow)
{
w = selectedImages.Count * 530;
}
int h = int.Parse(Math.Ceiling(double.Parse(selectedImages.Count.ToString()) / numperrow).ToString()) * 530;
Bitmap bmp = new Bitmap(w - 8, h - 8);
var num = 1;
var cur_w = 0;
var cur_h = 0;
for (int i = 0; i < selectedImages.Count; i++)
{
using (Graphics g = Graphics.FromImage(bmp))
List<Image> selectedImages = new List<Image>();
foreach (var files in theDialog.FileNames)
{
g.DrawImage(selectedImages[i], new PointF(cur_w, cur_h));
if (num % numperrow == 0)
selectedImages.Add(Image.FromFile(files));
}
if (Properties.Settings.Default.mergerImagesRow == 0)
{
Properties.Settings.Default.mergerImagesRow = 7;
Properties.Settings.Default.Save();
}
int numperrow = Properties.Settings.Default.mergerImagesRow;
var w = 530 * numperrow;
if (selectedImages.Count * 530 < 530 * numperrow)
{
w = selectedImages.Count * 530;
}
int h = int.Parse(Math.Ceiling(double.Parse(selectedImages.Count.ToString()) / numperrow).ToString()) * 530;
Bitmap bmp = new Bitmap(w - 8, h - 8);
var num = 1;
var cur_w = 0;
var cur_h = 0;
for (int i = 0; i < selectedImages.Count; i++)
{
using (Graphics g = Graphics.FromImage(bmp))
{
cur_w = 0;
cur_h += 530;
num += 1;
}
else
{
cur_w += 530;
num += 1;
g.DrawImage(selectedImages[i], new PointF(cur_w, cur_h));
if (num % numperrow == 0)
{
cur_w = 0;
cur_h += 530;
num += 1;
}
else
{
cur_w += 530;
num += 1;
}
}
}
bmp.Save(docPath + "\\" + Properties.Settings.Default.mergerFileName + ".png", ImageFormat.Png);
var newForm = new Form();
PictureBox pb = new PictureBox();
pb.Dock = DockStyle.Fill;
pb.Image = bmp;
pb.SizeMode = PictureBoxSizeMode.Zoom;
newForm.WindowState = FormWindowState.Maximized;
newForm.Size = bmp.Size;
newForm.Icon = Properties.Resources.FNTools_Logo_Icon;
newForm.Text = docPath + "\\" + Properties.Settings.Default.mergerFileName + ".png";
newForm.StartPosition = FormStartPosition.CenterScreen;
newForm.Controls.Add(pb);
newForm.Show();
}
bmp.Save(docPath + "\\" + Properties.Settings.Default.mergerFileName + ".png", ImageFormat.Png);
var newForm = new Form();
PictureBox pb = new PictureBox();
pb.Dock = DockStyle.Fill;
pb.Image = bmp;
pb.SizeMode = PictureBoxSizeMode.Zoom;
newForm.WindowState = FormWindowState.Maximized;
newForm.Size = bmp.Size;
newForm.Icon = Properties.Resources.FNTools_Logo_Icon;
newForm.Text = docPath + "\\" + Properties.Settings.Default.mergerFileName + ".png";
newForm.StartPosition = FormStartPosition.CenterScreen;
newForm.Controls.Add(pb);
newForm.Show();
}
}
catch (Exception ex)
{
Console.WriteLine(ex.StackTrace);
}
}
private void optionsToolStripMenuItem_Click(object sender, EventArgs e)

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows.Forms;
@ -14,6 +15,41 @@ namespace FModel
[STAThread]
static void Main()
{
var assemblies = new Dictionary<string, Assembly>();
var executingAssembly = Assembly.GetExecutingAssembly();
var resources = executingAssembly.GetManifestResourceNames().Where(n => n.EndsWith(".dll"));
foreach (string resource in resources)
{
using (var stream = executingAssembly.GetManifestResourceStream(resource))
{
if (stream == null)
continue;
var bytes = new byte[stream.Length];
stream.Read(bytes, 0, bytes.Length);
try
{
assemblies.Add(resource, Assembly.Load(bytes));
}
catch (Exception ex)
{
System.Diagnostics.Debug.Print(string.Format("Failed to load: {0}, Exception: {1}", resource, ex.Message));
}
}
}
AppDomain.CurrentDomain.AssemblyResolve += (s, e) =>
{
var assemblyName = new AssemblyName(e.Name);
var path = string.Format("{0}.dll", assemblyName.Name);
if (assemblies.ContainsKey(path))
{
return assemblies[path];
}
return null;
};
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new PAKWindow());