26
26
using System . Net . Http ;
27
27
using System . Text ;
28
28
using System . Text . Json ;
29
- using System . Security . Cryptography . X509Certificates ;
30
- using Microsoft . Win32 ;
31
29
32
30
namespace CustomBuildTool
33
31
{
@@ -169,7 +167,7 @@ public static void SetupBuildEnvironment(bool ShowBuildInfo)
169
167
if ( ShowBuildInfo )
170
168
{
171
169
Program . PrintColorMessage ( "Windows: " , ConsoleColor . DarkGray , false ) ;
172
- Program . PrintColorMessage ( "Windows NT " + Environment . OSVersion . Version . ToString ( ) , ConsoleColor . Green , true ) ;
170
+ Program . PrintColorMessage ( Win32 . GetKernelVersion ( ) , ConsoleColor . Green , true ) ;
173
171
174
172
var instance = VisualStudio . GetVisualStudioInstance ( ) ;
175
173
if ( instance != null )
@@ -824,6 +822,7 @@ public static bool BuildSolution(string Solution, BuildFlags Flags)
824
822
if ( ( Flags & BuildFlags . Build32bit ) == BuildFlags . Build32bit )
825
823
{
826
824
StringBuilder compilerOptions = new StringBuilder ( ) ;
825
+ StringBuilder commandLine = new StringBuilder ( ) ;
827
826
Program . PrintColorMessage ( BuildTimeStamp ( ) , ConsoleColor . DarkGray , false , Flags ) ;
828
827
Program . PrintColorMessage ( "Building " + Path . GetFileNameWithoutExtension ( Solution ) + " (" , ConsoleColor . Cyan , false , Flags ) ;
829
828
Program . PrintColorMessage ( "x32" , ConsoleColor . Green , false , Flags ) ;
@@ -838,13 +837,17 @@ public static bool BuildSolution(string Solution, BuildFlags Flags)
838
837
if ( ! string . IsNullOrEmpty ( BuildCount ) )
839
838
compilerOptions . Append ( $ "PHAPP_VERSION_BUILD=\" { BuildCount } \" ") ;
840
839
840
+ commandLine . Append ( "/m /nologo /nodereuse:false /verbosity:quiet " ) ;
841
+ commandLine . Append ( "/p:Configuration=" + ( Flags . HasFlag ( BuildFlags . BuildDebug ) ? "Debug " : "Release " ) ) ;
842
+ commandLine . Append ( "/p:Platform=Win32 " ) ;
843
+ commandLine . Append ( "/p:ExternalCompilerOptions=\" " + compilerOptions . ToString ( ) + "\" " ) ;
844
+ if ( File . Exists ( "tools\\ versioning\\ version.res" ) )
845
+ commandLine . Append ( $ "/p:ExternalAdditionalDependencies=\" { Path . GetFullPath ( "tools\\ versioning\\ version.res" ) } \" ") ;
846
+ commandLine . Append ( Solution ) ;
847
+
841
848
int errorcode = Win32 . CreateProcess (
842
849
msbuildExePath ,
843
- "/m /nologo /nodereuse:false /verbosity:quiet " +
844
- "/p:Configuration=" + ( Flags . HasFlag ( BuildFlags . BuildDebug ) ? "Debug " : "Release " ) +
845
- "/p:Platform=Win32 " +
846
- "/p:ExternalCompilerOptions=\" " + compilerOptions . ToString ( ) + "\" " +
847
- Solution ,
850
+ commandLine . ToString ( ) ,
848
851
out string errorstring
849
852
) ;
850
853
@@ -858,6 +861,7 @@ out string errorstring
858
861
if ( ( Flags & BuildFlags . Build64bit ) == BuildFlags . Build64bit )
859
862
{
860
863
StringBuilder compilerOptions = new StringBuilder ( ) ;
864
+ StringBuilder commandLine = new StringBuilder ( ) ;
861
865
Program . PrintColorMessage ( BuildTimeStamp ( ) , ConsoleColor . DarkGray , false , Flags ) ;
862
866
Program . PrintColorMessage ( "Building " + Path . GetFileNameWithoutExtension ( Solution ) + " (" , ConsoleColor . Cyan , false , Flags ) ;
863
867
Program . PrintColorMessage ( "x64" , ConsoleColor . Green , false , Flags ) ;
@@ -872,13 +876,17 @@ out string errorstring
872
876
if ( ! string . IsNullOrEmpty ( BuildCount ) )
873
877
compilerOptions . Append ( $ "PHAPP_VERSION_BUILD=\" { BuildCount } \" ") ;
874
878
879
+ commandLine . Append ( "/m /nologo /nodereuse:false /verbosity:quiet " ) ;
880
+ commandLine . Append ( "/p:Configuration=" + ( Flags . HasFlag ( BuildFlags . BuildDebug ) ? "Debug " : "Release " ) ) ;
881
+ commandLine . Append ( "/p:Platform=x64 " ) ;
882
+ commandLine . Append ( "/p:ExternalCompilerOptions=\" " + compilerOptions . ToString ( ) + "\" " ) ;
883
+ if ( File . Exists ( "tools\\ versioning\\ version.res" ) )
884
+ commandLine . Append ( $ "/p:ExternalAdditionalDependencies=\" { Path . GetFullPath ( "tools\\ versioning\\ version.res" ) } \" ") ;
885
+ commandLine . Append ( Solution ) ;
886
+
875
887
int errorcode = Win32 . CreateProcess (
876
888
msbuildExePath ,
877
- "/m /nologo /nodereuse:false /verbosity:quiet " +
878
- "/p:Configuration=" + ( Flags . HasFlag ( BuildFlags . BuildDebug ) ? "Debug " : "Release " ) +
879
- "/p:Platform=x64 " +
880
- "/p:ExternalCompilerOptions=\" " + compilerOptions . ToString ( ) + "\" " +
881
- Solution ,
889
+ commandLine . ToString ( ) ,
882
890
out string errorstring
883
891
) ;
884
892
@@ -892,6 +900,51 @@ out string errorstring
892
900
return true ;
893
901
}
894
902
903
+ public static bool BuildVersionInfo ( BuildFlags Flags )
904
+ {
905
+ if ( ! File . Exists ( "tools\\ versioning\\ version.rc" ) )
906
+ return true ;
907
+
908
+ string windowsSdkPath = VisualStudio . GetWindowsSdkPath ( ) ;
909
+ string windowsSdkIncludePath = VisualStudio . GetWindowsSdkIncludePath ( ) ;
910
+ string resIncludePath = Path . GetFullPath ( "processhacker" ) ;
911
+ StringBuilder commandLine = new StringBuilder ( "/nologo /v " ) ;
912
+ string rcExePath = windowsSdkPath + "\\ x64\\ rc.exe" ;
913
+
914
+ if ( ! File . Exists ( rcExePath ) )
915
+ {
916
+ Program . PrintColorMessage ( "Unable to find the resource compiler." , ConsoleColor . Red ) ;
917
+ return false ;
918
+ }
919
+
920
+ commandLine . Append ( $ "/i \" { windowsSdkIncludePath } \\ um\" /i \" { windowsSdkIncludePath } \\ shared\" /i \" { resIncludePath } \" ") ;
921
+
922
+ if ( Flags . HasFlag ( BuildFlags . BuildApi ) )
923
+ commandLine . Append ( " /d \" PH_BUILD_API\" " ) ;
924
+ if ( ! string . IsNullOrEmpty ( BuildCommit ) )
925
+ commandLine . Append ( $ "/d \" PHAPP_VERSION_COMMITHASH=\" { BuildCommit . Substring ( 0 , 7 ) } \" \" ") ;
926
+ if ( ! string . IsNullOrEmpty ( BuildRevision ) )
927
+ commandLine . Append ( $ "/d \" PHAPP_VERSION_REVISION=\" { BuildRevision } \" \" ") ;
928
+ if ( ! string . IsNullOrEmpty ( BuildCount ) )
929
+ commandLine . Append ( $ "/d \" PHAPP_VERSION_BUILD=\" { BuildCount } \" \" ") ;
930
+
931
+ commandLine . Append ( "/fo tools\\ versioning\\ version.res tools\\ versioning\\ version.rc" ) ;
932
+
933
+ int errorcode = Win32 . CreateProcess (
934
+ rcExePath ,
935
+ commandLine . ToString ( ) ,
936
+ out string errorstring
937
+ ) ;
938
+
939
+ if ( errorcode != 0 )
940
+ {
941
+ Program . PrintColorMessage ( "[ERROR] (" + errorcode + ") " + errorstring , ConsoleColor . Red , true , Flags | BuildFlags . BuildVerbose ) ;
942
+ return false ;
943
+ }
944
+
945
+
946
+ return true ;
947
+ }
895
948
public static bool BuildDeployUpdateConfig ( )
896
949
{
897
950
string buildBuildId ;
@@ -900,7 +953,6 @@ public static bool BuildDeployUpdateConfig()
900
953
string buildPostApiKey ;
901
954
string buildPostSfUrl ;
902
955
string buildPostSfApiKey ;
903
- string buildPostString ;
904
956
string buildFilename ;
905
957
string buildBinHash ;
906
958
string buildSetupHash ;
@@ -1021,7 +1073,7 @@ public static bool BuildDeployUpdateConfig()
1021
1073
1022
1074
try
1023
1075
{
1024
- buildPostString = JsonSerializer . Serialize ( new BuildUpdateRequest
1076
+ BuildUpdateRequest buildUpdateRequest = new BuildUpdateRequest
1025
1077
{
1026
1078
BuildUpdated = TimeStart . ToString ( "o" ) ,
1027
1079
BuildVersion = BuildVersion ,
@@ -1035,62 +1087,72 @@ public static bool BuildDeployUpdateConfig()
1035
1087
SetupLength = buildSetupFileLength . ToString ( ) ,
1036
1088
SetupHash = buildSetupHash ,
1037
1089
SetupSig = BuildSetupSig ,
1038
- } , new JsonSerializerOptions { IgnoreNullValues = true , PropertyNameCaseInsensitive = true } ) ;
1090
+ } ;
1091
+
1092
+ byte [ ] buildPostString = JsonSerializer . SerializeToUtf8Bytes ( buildUpdateRequest , BuildUpdateRequestContext . Default . BuildUpdateRequest ) ;
1039
1093
1040
- if ( string . IsNullOrEmpty ( buildPostString ) )
1094
+ if ( buildPostString == null || buildPostString . LongLength == 0 )
1041
1095
return false ;
1042
1096
1043
1097
using ( HttpClientHandler httpClientHandler = new HttpClientHandler ( ) )
1044
1098
{
1045
1099
httpClientHandler . AutomaticDecompression = DecompressionMethods . All ;
1046
1100
1047
1101
using ( HttpClient httpClient = new HttpClient ( httpClientHandler ) )
1048
- using ( StringContent httpContent = new StringContent ( buildPostString , Encoding . UTF8 , "application/json" ) )
1049
1102
{
1050
1103
httpClient . DefaultRequestHeaders . Add ( "X-ApiKey" , buildPostApiKey ) ;
1051
1104
1052
- var httpTask = httpClient . PostAsync ( buildPostUrl , httpContent ) ;
1053
- httpTask . Wait ( ) ;
1054
-
1055
- if ( ! httpTask . Result . IsSuccessStatusCode )
1105
+ using ( ByteArrayContent httpContent = new ByteArrayContent ( buildPostString ) )
1056
1106
{
1057
- Program . PrintColorMessage ( "[UpdateBuildWebService] " + httpTask . Result , ConsoleColor . Red ) ;
1058
- return false ;
1107
+ httpContent . Headers . ContentType = new System . Net . Http . Headers . MediaTypeHeaderValue ( "application/json" ) ;
1108
+
1109
+ var httpTask = httpClient . PostAsync ( buildPostUrl , httpContent ) ;
1110
+ httpTask . Wait ( ) ;
1111
+
1112
+ if ( ! httpTask . Result . IsSuccessStatusCode )
1113
+ {
1114
+ Program . PrintColorMessage ( "[UpdateBuildWebService] " + httpTask . Result , ConsoleColor . Red ) ;
1115
+ return false ;
1116
+ }
1059
1117
}
1060
1118
}
1061
1119
}
1062
- }
1063
- catch ( Exception ex )
1064
- {
1065
- Program . PrintColorMessage ( "[UpdateBuildWebService] " + ex , ConsoleColor . Red ) ;
1066
- return false ;
1067
- }
1068
1120
1069
- try
1070
- {
1071
- using ( HttpClientHandler httpClientHandler = new HttpClientHandler ( ) )
1121
+ try
1072
1122
{
1073
- httpClientHandler . AutomaticDecompression = DecompressionMethods . All ;
1074
-
1075
- using ( HttpClient httpClient = new HttpClient ( httpClientHandler ) )
1076
- using ( StringContent httpContent = new StringContent ( buildPostString , Encoding . UTF8 , "application/json" ) )
1123
+ using ( HttpClientHandler httpClientHandler = new HttpClientHandler ( ) )
1077
1124
{
1078
- httpClient . DefaultRequestHeaders . Add ( "X-ApiKey" , buildPostSfApiKey ) ;
1125
+ httpClientHandler . AutomaticDecompression = DecompressionMethods . All ;
1079
1126
1080
- var httpTask = httpClient . PostAsync ( buildPostSfUrl , httpContent ) ;
1081
- httpTask . Wait ( ) ;
1082
-
1083
- if ( ! httpTask . Result . IsSuccessStatusCode )
1127
+ using ( HttpClient httpClient = new HttpClient ( httpClientHandler ) )
1084
1128
{
1085
- Program . PrintColorMessage ( "[UpdateBuildWebService-SF] " + httpTask . Result , ConsoleColor . Red ) ;
1086
- return false ;
1129
+ httpClient . DefaultRequestHeaders . Add ( "X-ApiKey" , buildPostSfApiKey ) ;
1130
+
1131
+ using ( ByteArrayContent httpContent = new ByteArrayContent ( buildPostString ) )
1132
+ {
1133
+ httpContent . Headers . ContentType = new System . Net . Http . Headers . MediaTypeHeaderValue ( "application/json" ) ;
1134
+
1135
+ var httpTask = httpClient . PostAsync ( buildPostSfUrl , httpContent ) ;
1136
+ httpTask . Wait ( ) ;
1137
+
1138
+ if ( ! httpTask . Result . IsSuccessStatusCode )
1139
+ {
1140
+ Program . PrintColorMessage ( "[UpdateBuildWebService-SF] " + httpTask . Result , ConsoleColor . Red ) ;
1141
+ return false ;
1142
+ }
1143
+ }
1087
1144
}
1088
1145
}
1089
1146
}
1147
+ catch ( Exception ex )
1148
+ {
1149
+ Program . PrintColorMessage ( "[UpdateBuildWebService-SF] " + ex , ConsoleColor . Red ) ;
1150
+ return false ;
1151
+ }
1090
1152
}
1091
1153
catch ( Exception ex )
1092
1154
{
1093
- Program . PrintColorMessage ( "[UpdateBuildWebService-SF ] " + ex , ConsoleColor . Red ) ;
1155
+ Program . PrintColorMessage ( "[UpdateBuildWebService] " + ex , ConsoleColor . Red ) ;
1094
1156
return false ;
1095
1157
}
1096
1158
@@ -1138,7 +1200,9 @@ public static bool BuildDeployUploadArtifacts()
1138
1200
filename = Path . GetFileName ( sourceFile ) ;
1139
1201
//filename = filename.Replace("-build-", $"-{BuildVersion}-", StringComparison.OrdinalIgnoreCase);
1140
1202
1203
+ #pragma warning disable SYSLIB0014 // Type or member is obsolete
1141
1204
request = ( FtpWebRequest ) WebRequest . Create ( buildPostUrl + filename ) ;
1205
+ #pragma warning restore SYSLIB0014 // Type or member is obsolete
1142
1206
request . Credentials = new NetworkCredential ( buildPostKey , buildPostName ) ;
1143
1207
request . Method = WebRequestMethods . Ftp . UploadFile ;
1144
1208
request . Timeout = System . Threading . Timeout . Infinite ;
0 commit comments