1 // SoftEther VPN Source Code - Stable Edition Repository 2 // Build Utility 3 // 4 // SoftEther VPN Server, Client and Bridge are free software under the Apache License, Version 2.0. 5 // 6 // Copyright (c) Daiyuu Nobori. 7 // Copyright (c) SoftEther VPN Project, University of Tsukuba, Japan. 8 // Copyright (c) SoftEther Corporation. 9 // Copyright (c) all contributors on SoftEther VPN project in GitHub. 10 // 11 // All Rights Reserved. 12 // 13 // http://www.softether.org/ 14 // 15 // This stable branch is officially managed by Daiyuu Nobori, the owner of SoftEther VPN Project. 16 // Pull requests should be sent to the Developer Edition Master Repository on https://github.com/SoftEtherVPN/SoftEtherVPN 17 // 18 // License: The Apache License, Version 2.0 19 // https://www.apache.org/licenses/LICENSE-2.0 20 // 21 // DISCLAIMER 22 // ========== 23 // 24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30 // SOFTWARE. 31 // 32 // THIS SOFTWARE IS DEVELOPED IN JAPAN, AND DISTRIBUTED FROM JAPAN, UNDER 33 // JAPANESE LAWS. YOU MUST AGREE IN ADVANCE TO USE, COPY, MODIFY, MERGE, PUBLISH, 34 // DISTRIBUTE, SUBLICENSE, AND/OR SELL COPIES OF THIS SOFTWARE, THAT ANY 35 // JURIDICAL DISPUTES WHICH ARE CONCERNED TO THIS SOFTWARE OR ITS CONTENTS, 36 // AGAINST US (SOFTETHER PROJECT, SOFTETHER CORPORATION, DAIYUU NOBORI OR OTHER 37 // SUPPLIERS), OR ANY JURIDICAL DISPUTES AGAINST US WHICH ARE CAUSED BY ANY KIND 38 // OF USING, COPYING, MODIFYING, MERGING, PUBLISHING, DISTRIBUTING, SUBLICENSING, 39 // AND/OR SELLING COPIES OF THIS SOFTWARE SHALL BE REGARDED AS BE CONSTRUED AND 40 // CONTROLLED BY JAPANESE LAWS, AND YOU MUST FURTHER CONSENT TO EXCLUSIVE 41 // JURISDICTION AND VENUE IN THE COURTS SITTING IN TOKYO, JAPAN. YOU MUST WAIVE 42 // ALL DEFENSES OF LACK OF PERSONAL JURISDICTION AND FORUM NON CONVENIENS. 43 // PROCESS MAY BE SERVED ON EITHER PARTY IN THE MANNER AUTHORIZED BY APPLICABLE 44 // LAW OR COURT RULE. 45 // 46 // USE ONLY IN JAPAN. DO NOT USE THIS SOFTWARE IN ANOTHER COUNTRY UNLESS YOU HAVE 47 // A CONFIRMATION THAT THIS SOFTWARE DOES NOT VIOLATE ANY CRIMINAL LAWS OR CIVIL 48 // RIGHTS IN THAT PARTICULAR COUNTRY. USING THIS SOFTWARE IN OTHER COUNTRIES IS 49 // COMPLETELY AT YOUR OWN RISK. THE SOFTETHER VPN PROJECT HAS DEVELOPED AND 50 // DISTRIBUTED THIS SOFTWARE TO COMPLY ONLY WITH THE JAPANESE LAWS AND EXISTING 51 // CIVIL RIGHTS INCLUDING PATENTS WHICH ARE SUBJECTS APPLY IN JAPAN. OTHER 52 // COUNTRIES' LAWS OR CIVIL RIGHTS ARE NONE OF OUR CONCERNS NOR RESPONSIBILITIES. 53 // WE HAVE NEVER INVESTIGATED ANY CRIMINAL REGULATIONS, CIVIL LAWS OR 54 // INTELLECTUAL PROPERTY RIGHTS INCLUDING PATENTS IN ANY OF OTHER 200+ COUNTRIES 55 // AND TERRITORIES. BY NATURE, THERE ARE 200+ REGIONS IN THE WORLD, WITH 56 // DIFFERENT LAWS. IT IS IMPOSSIBLE TO VERIFY EVERY COUNTRIES' LAWS, REGULATIONS 57 // AND CIVIL RIGHTS TO MAKE THE SOFTWARE COMPLY WITH ALL COUNTRIES' LAWS BY THE 58 // PROJECT. EVEN IF YOU WILL BE SUED BY A PRIVATE ENTITY OR BE DAMAGED BY A 59 // PUBLIC SERVANT IN YOUR COUNTRY, THE DEVELOPERS OF THIS SOFTWARE WILL NEVER BE 60 // LIABLE TO RECOVER OR COMPENSATE SUCH DAMAGES, CRIMINAL OR CIVIL 61 // RESPONSIBILITIES. NOTE THAT THIS LINE IS NOT LICENSE RESTRICTION BUT JUST A 62 // STATEMENT FOR WARNING AND DISCLAIMER. 63 // 64 // READ AND UNDERSTAND THE 'WARNING.TXT' FILE BEFORE USING THIS SOFTWARE. 65 // SOME SOFTWARE PROGRAMS FROM THIRD PARTIES ARE INCLUDED ON THIS SOFTWARE WITH 66 // LICENSE CONDITIONS WHICH ARE DESCRIBED ON THE 'THIRD_PARTY.TXT' FILE. 67 // 68 // 69 // SOURCE CODE CONTRIBUTION 70 // ------------------------ 71 // 72 // Your contribution to SoftEther VPN Project is much appreciated. 73 // Please send patches to us through GitHub. 74 // Read the SoftEther VPN Patch Acceptance Policy in advance: 75 // http://www.softether.org/5-download/src/9.patch 76 // 77 // 78 // DEAR SECURITY EXPERTS 79 // --------------------- 80 // 81 // If you find a bug or a security vulnerability please kindly inform us 82 // about the problem immediately so that we can fix the security problem 83 // to protect a lot of users around the world as soon as possible. 84 // 85 // Our e-mail address for security reports is: 86 // softether-vpn-security [at] softether.org 87 // 88 // Please note that the above e-mail address is not a technical support 89 // inquiry address. If you need technical assistance, please visit 90 // http://www.softether.org/ and ask your question on the users forum. 91 // 92 // Thank you for your cooperation. 93 // 94 // 95 // NO MEMORY OR RESOURCE LEAKS 96 // --------------------------- 97 // 98 // The memory-leaks and resource-leaks verification under the stress 99 // test has been passed before release this source code. 100 101 102 using System; 103 using System.Threading; 104 using System.Text; 105 using System.Configuration; 106 using System.Collections; 107 using System.Collections.Generic; 108 using System.Collections.Specialized; 109 using System.Security.Cryptography; 110 using System.Web; 111 using System.Web.Security; 112 using System.Web.UI; 113 using System.Web.UI.WebControls; 114 using System.Web.UI.WebControls.WebParts; 115 using System.Web.UI.HtmlControls; 116 using System.IO; 117 using System.Drawing; 118 using System.Drawing.Imaging; 119 using System.Drawing.Drawing2D; 120 using System.Diagnostics; 121 using System.Net; 122 using System.Net.Security; 123 using System.Security.Cryptography.X509Certificates; 124 using CoreUtil; 125 126 namespace BuildUtil 127 { 128 public static class BuildUtilCommands 129 { 130 // Perform all 131 [ConsoleCommandMethod( 132 "Builds all sources and releases all packages.", 133 "All [yes|no] [/NORMALIZESRC:yes|no] [/IGNOREERROR:yes|no] [/DEBUG:yes|no] [/SERIAL:yes|no]", 134 "Builds all sources and releases all packages.", 135 "[yes|no]:Specify 'yes' if you'd like to increment the build number.", 136 "NORMALIZESRC:Specity 'yes' if you'd like to normalize the build infomations in the source codes and resource scripts.", 137 "IGNOREERROR:Specify yes if you'd like to ignore the child process to show the error message.", 138 "SERIAL:Specify yes not to use parallel mode.", 139 "DEBUG:Specity yes to enable debug mode. (UNIX only)" 140 #if !BU_SOFTETHER 141 , "SEVPN:Build SoftEther VPN Automatically After PacketiX VPN Build" 142 #endif 143 )] All(ConsoleService c, string cmdName, string str)144 static int All(ConsoleService c, string cmdName, string str) 145 { 146 ConsoleParam[] args = 147 { 148 #if !BU_SOFTETHER 149 new ConsoleParam("[yes|no]", ConsoleService.Prompt, "Increments build number (y/n) ? ", ConsoleService.EvalNotEmpty, null), 150 new ConsoleParam("SEVPN", ConsoleService.Prompt, "Build SoftEther VPN automatically after PacketiX VPN Build (y/n) ? ", ConsoleService.EvalNotEmpty, null), 151 #else 152 new ConsoleParam("[yes|no]"), 153 #endif 154 new ConsoleParam("IGNOREERROR"), 155 new ConsoleParam("DEBUG"), 156 new ConsoleParam("SERIAL"), 157 }; 158 ConsoleParamValueList vl = c.ParseCommandList(cmdName, str, args); 159 160 DateTime start = Time.NowDateTime; 161 162 Win32BuildUtil.ExecCommand(Env.ExeFileName, string.Format("/CMD:BuildWin32 {0} /NORMALIZESRC:{1}", 163 vl["[yes|no]"].BoolValue ? "yes" : "no", 164 "yes")); 165 166 Win32BuildUtil.ExecCommand(Env.ExeFileName, string.Format("/CMD:ReleaseWin32 all /IGNOREERROR:{0} /SERIAL:{1}", 167 vl["IGNOREERROR"].BoolValue ? "yes" : "no", 168 vl["SERIAL"].BoolValue ? "yes" : "no")); 169 170 #if !BU_OSS 171 Win32BuildUtil.ExecCommand(Env.ExeFileName, string.Format("/CMD:ReleaseUnix all /IGNOREERROR:{0} /DEBUG:{1} /SERIAL:{2}", 172 vl["IGNOREERROR"].BoolValue ? "yes" : "no", 173 vl["DEBUG"].BoolValue ? "yes" : "no", 174 vl["SERIAL"].BoolValue ? "yes" : "no")); 175 #endif 176 177 Win32BuildUtil.ExecCommand(Env.ExeFileName, string.Format("/CMD:CopyRelease")); 178 179 #if !BU_SOFTETHER 180 Win32BuildUtil.ExecCommand(Env.ExeFileName, string.Format("/CMD:MakeSoftEtherDir")); 181 182 if (vl["SEVPN"].BoolValue) 183 { 184 // Build SEVPN 185 Win32BuildUtil.ExecCommand(Paths.CmdFileName, string.Format("/C \"{0}\"", Path.Combine(Paths.SoftEtherBuildDir, @"Main\BuildAll.cmd"))); 186 } 187 188 Win32BuildUtil.ExecCommand(Env.ExeFileName, string.Format("/CMD:MakeOpenSource")); 189 #endif 190 191 DateTime end = Time.NowDateTime; 192 193 Con.WriteLine("Taken time: {0}.", (end - start)); 194 195 return 0; 196 } 197 198 #if !BU_SOFTETHER 199 // Create SoftEther Edition source 200 [ConsoleCommandMethod( 201 "Make MakeSoftEtherDir Source Dir.", 202 "MakeSoftEtherDir", 203 "Make MakeSoftEtherDir Source Dir." 204 )] MakeSoftEtherDir(ConsoleService c, string cmdName, string str)205 static int MakeSoftEtherDir(ConsoleService c, string cmdName, string str) 206 { 207 ConsoleParam[] args = 208 { 209 }; 210 ConsoleParamValueList vl = c.ParseCommandList(cmdName, str, args); 211 212 OpenSourceUtil.MakeSoftEtherDir(); 213 214 return 0; 215 } 216 217 // Create an open source version of source 218 [ConsoleCommandMethod( 219 "Make MakeOpenSource Source Dir.", 220 "MakeOpenSource", 221 "Make MakeOpenSource Source Dir." 222 )] MakeOpenSource(ConsoleService c, string cmdName, string str)223 static int MakeOpenSource(ConsoleService c, string cmdName, string str) 224 { 225 ConsoleParam[] args = 226 { 227 }; 228 ConsoleParamValueList vl = c.ParseCommandList(cmdName, str, args); 229 230 OpenSourceUtil.MakeOpenSource(); 231 232 return 0; 233 } 234 #endif 235 236 // Copy the released files 237 [ConsoleCommandMethod( 238 "Copies all release files.", 239 "CopyRelease", 240 "Copies all release files." 241 )] CopyRelease(ConsoleService c, string cmdName, string str)242 static int CopyRelease(ConsoleService c, string cmdName, string str) 243 { 244 ConsoleParam[] args = 245 { 246 }; 247 ConsoleParamValueList vl = c.ParseCommandList(cmdName, str, args); 248 249 int build, version; 250 string name; 251 DateTime date; 252 Win32BuildUtil.ReadBuildInfoFromTextFile(out build, out version, out name, out date); 253 254 string baseName = string.Format("v{0}-{1}-{2}-{3:D4}.{4:D2}.{5:D2}", 255 BuildHelper.VersionIntToString(version), 256 build, 257 name, 258 date.Year, date.Month, date.Day); 259 260 #if !BU_OSS 261 string destDirName = Path.Combine(Paths.ReleaseDestDir, 262 string.Format(@"{0}-{1}-{2}-{3}", 263 Str.DateToStrShort(BuildSoftwareList.ListCreatedDateTime), 264 baseName, 265 Env.MachineName, Env.UserName)); 266 #else // !BU_OSS 267 string destDirName = Path.Combine(Paths.ReleaseDestDir, 268 string.Format(@"{1}", 269 Str.DateToStrShort(BuildSoftwareList.ListCreatedDateTime), 270 baseName, 271 Env.MachineName, Env.UserName)); 272 #endif 273 274 #if !BU_OSS 275 string publicDir = Path.Combine(destDirName, "Public"); 276 #else // !BU_OSS 277 string publicDir = destDirName; 278 #endif 279 280 #if !BU_OSS 281 string filesReleaseDir = Path.Combine(publicDir, baseName); 282 #else // !BU_OSS 283 string filesReleaseDir = publicDir; 284 #endif 285 286 string autorunReleaseSrcDir = Path.Combine(publicDir, "autorun"); 287 288 IO.CopyDir(Paths.ReleaseDir, filesReleaseDir, null, false, true); 289 290 #if !BU_OSS 291 IO.CopyDir(Paths.ReleaseSrckitDir, Path.Combine(destDirName, "Private"), null, false, true); 292 IO.CopyDir(Path.Combine(Paths.BaseDirName, @"tmp\lib"), Path.Combine(destDirName, @"Private\lib"), null, false, true); 293 #endif 294 295 //IO.MakeDir(autorunReleaseSrcDir); 296 297 /* 298 File.Copy(Path.Combine(Paths.AutorunSrcDir, "Project1.exe"), 299 Path.Combine(autorunReleaseSrcDir, "autorun.exe"), true); 300 301 File.Copy(Path.Combine(Paths.AutorunSrcDir, "autorun.inf"), 302 Path.Combine(autorunReleaseSrcDir, "autorun.inf"), true); 303 304 File.Copy(Path.Combine(Paths.AutorunSrcDir, "packetix.ico"), 305 Path.Combine(autorunReleaseSrcDir, "autorun.ico"), true);*/ 306 307 // Create a batch file 308 string batchFileName = Path.Combine(publicDir, "MakeCD.cmd"); 309 #if !BU_OSS 310 StreamWriter w = new StreamWriter(batchFileName); 311 #else // !BU_OSS 312 StringWriter w = new StringWriter(); 313 #endif 314 w.WriteLine(@"SETLOCAL"); 315 w.WriteLine(@"SET BATCH_FILE_NAME=%0"); 316 w.WriteLine(@"SET BATCH_DIR_NAME=%0\.."); 317 w.WriteLine(@"SET NOW_TMP=%time:~0,2%"); 318 w.WriteLine(@"SET NOW=%date:~0,4%%date:~5,2%%date:~8,2%_%NOW_TMP: =0%%time:~3,2%%time:~6,2%"); 319 w.WriteLine(); 320 w.WriteLine(); 321 322 string[] files = Directory.GetFiles(filesReleaseDir, "*", SearchOption.AllDirectories); 323 324 string cddir = "CD"; 325 /*string.Format("CD-v{0}.{1}-{2}-{3}-{4:D4}.{5:D2}.{6:D2}", 326 version / 100, version % 100, build, name, 327 date.Year, date.Month, date.Day);*/ 328 329 StringWriter txt = new StringWriter(); 330 331 foreach (string filename in files) 332 { 333 string file = filename; 334 335 BuildSoftware s = new BuildSoftware(file); 336 337 // Software\Windows\PacketiX VPN Server 4.0\32bit (Intel x86)\filename.exe 338 string cpustr = string.Format("{0} - {1}", CPUBitsUtil.CPUBitsToString(s.Cpu.Bits), s.Cpu.Title).Replace("/", "or"); 339 string cpustr2 = cpustr; 340 341 if (s.Cpu == CpuList.intel) 342 { 343 cpustr2 = ""; 344 cpustr = "Intel"; 345 } 346 347 string tmp = string.Format(@"{1}\{2}\{3}\{5}{4}", 348 0, 349 s.Os.Title, 350 BuildHelper.GetSoftwareTitle(s.Software), 351 cpustr2, 352 Path.GetFileName(file), 353 "" 354 ); 355 356 tmp = Str.ReplaceStr(tmp, "\\\\", "\\"); 357 358 tmp = Str.ReplaceStr(tmp, " ", "_"); 359 360 w.WriteLine("mkdir \"{1}\\{0}\"", Path.GetDirectoryName(tmp), cddir); 361 w.WriteLine("copy /b /y \"{2}\\{0}\" \"{3}\\{1}\"", IO.GetRelativeFileName(file, filesReleaseDir), tmp, baseName, cddir); 362 w.WriteLine(); 363 364 string txt_filename = tmp; 365 txt_filename = Str.ReplaceStr(txt_filename, "\\", "/"); 366 367 string txt_description = BuildHelper.GetSoftwareTitle(s.Software); 368 369 string txt_products = BuildHelper.GetSoftwareProductList(s.Software); 370 371 string txt_os = s.Os.Title; 372 373 string txt_cpu = s.Cpu.Title; 374 if (s.Cpu.Bits != CPUBits.Both) 375 { 376 txt_cpu += " (" + CPUBitsUtil.CPUBitsToString(s.Cpu.Bits) + ")"; 377 } 378 else 379 { 380 txt_cpu += " (x86 and x64)"; 381 } 382 383 string txt_version = BuildHelper.VersionIntToString(version); 384 385 string txt_build = build.ToString(); 386 387 string txt_verstr = name; 388 389 string txt_date = Str.DateTimeToStrShortWithMilliSecs(date); 390 391 string txt_lang = "English, Japanese, Simplified Chinese"; 392 393 string txt_category = "PacketiX VPN (Commercial)"; 394 395 #if BU_SOFTETHER 396 txt_category = "SoftEther VPN (Freeware)"; 397 #endif 398 399 txt.WriteLine("FILENAME\t" + txt_filename); 400 txt.WriteLine("DESCRIPTION\t" + txt_description); 401 txt.WriteLine("CATEGORY\t" + txt_category); 402 txt.WriteLine("PRODUCT\t" + txt_products); 403 txt.WriteLine("OS\t" + txt_os); 404 txt.WriteLine("OSLIST\t" + s.Os.OSSimpleList); 405 txt.WriteLine("CPU\t" + txt_cpu); 406 txt.WriteLine("VERSION\t" + txt_version); 407 txt.WriteLine("BUILD\t" + txt_build); 408 txt.WriteLine("VERSTR\t" + txt_verstr); 409 txt.WriteLine("DATE\t" + txt_date); 410 txt.WriteLine("LANGUAGE\t" + txt_lang); 411 txt.WriteLine("*"); 412 txt.WriteLine(); 413 } 414 415 #if BU_OSS 416 Con.WriteLine("Installer packages are built on '{0}'. Enjoy it !!", publicDir); 417 418 return 0; 419 #endif // BU_OSS 420 421 /* 422 w.WriteLine("mkdir \"{0}\\autorun\"", cddir); 423 w.WriteLine("copy /b /y autorun\\autorun.ico \"{0}\\autorun\"", cddir); 424 w.WriteLine("copy /b /y autorun\\autorun.exe \"{0}\\autorun\"", cddir); 425 w.WriteLine("copy /b /y autorun\\autorun.inf \"{0}\\autorun.inf\"", cddir); 426 * */ 427 428 string zipFileName = string.Format("VPN-CD-v{0}.{1:D2}-{2}-{3}-{4:D4}.{5:D2}.{6:D2}.zip", 429 version / 100, version % 100, build, name, 430 date.Year, date.Month, date.Day); 431 w.WriteLine("del {0}", zipFileName); 432 w.WriteLine("CD {0}", cddir); 433 w.WriteLine("zip -r -0 ../{0} *", zipFileName); 434 w.WriteLine("cd .."); 435 w.WriteLine("move {0} CD\\", zipFileName); 436 w.WriteLine("rename CD {0}-tree", baseName); 437 w.WriteLine(); 438 439 w.Close(); 440 441 // Copy of fastcopy 442 string fastcopy_dest = Path.Combine(destDirName, @"Private\fastcopy_bin"); 443 IO.MakeDirIfNotExists(fastcopy_dest); 444 File.Copy(Path.Combine(Paths.UtilityDirName, "FastCopy.exe"), Path.Combine(fastcopy_dest, "FastCopy.exe"), true); 445 File.Copy(Path.Combine(Paths.UtilityDirName, "FastEx64.dll"), Path.Combine(fastcopy_dest, "FastEx64.dll"), true); 446 File.Copy(Path.Combine(Paths.UtilityDirName, "FastExt1.dll"), Path.Combine(fastcopy_dest, "FastExt1.dll"), true); 447 448 string fastcopy_exe = @"..\Private\fastcopy_bin\FastCopy.exe"; 449 450 // Create a upload batch 451 string uploadBatchFileName = Path.Combine(publicDir, "UploadNow.cmd"); 452 #if !BU_OSS 453 w = new StreamWriter(uploadBatchFileName); 454 #endif // !BU_OSS 455 456 string folder_name = "packetix"; 457 #if BU_SOFTETHER 458 folder_name = "softether"; 459 #endif 460 w.WriteLine(@"mkdir \\download\FILES\{1}\{0}-tree", baseName, folder_name); 461 w.WriteLine(@"{0} /cmd=force_copy /exclude={3} /auto_close /force_start /estimate /open_window /error_stop=TRUE /bufsize=128 /disk_mode=diff /speed=full /verify {1}-tree /to=\\download\FILES\{2}\{1}-tree", fastcopy_exe, baseName, folder_name, 462 "\"*files.txt*\""); 463 464 w.WriteLine(); 465 /* 466 w.WriteLine(@"mkdir \\downloadjp\FILES\{1}\{0}-tree", baseName, folder_name); 467 w.WriteLine(@"{0} /cmd=force_copy /exclude={3} /auto_close /force_start /estimate /open_window /error_stop=TRUE /bufsize=128 /disk_mode=diff /speed=full /verify {1}-tree /to=\\downloadjp\FILES\{2}\{1}-tree", fastcopy_exe, baseName, folder_name, 468 "\"*files.txt*\""); 469 470 w.WriteLine();*/ 471 472 w.WriteLine(@"copy /y /b {0}-tree\files.txt \\download\FILES\{1}\{0}-tree\files.txt", baseName, folder_name); 473 //w.WriteLine(@"copy /y /b {0}-tree\files.txt \\downloadjp\FILES\{1}\{0}-tree\files.txt", baseName, folder_name); 474 475 476 w.WriteLine(); 477 w.WriteLine(@"pause"); 478 w.WriteLine(); 479 480 w.Close(); 481 482 483 txt.WriteLine("FILENAME\t" + zipFileName); 484 #if BU_SOFTETHER 485 txt.WriteLine("DESCRIPTION\t" + "ZIP CD-ROM Image Package of SoftEther VPN (for Admins)"); 486 txt.WriteLine("CATEGORY\t" + "SoftEther VPN (Freeware)"); 487 txt.WriteLine("PRODUCT\t" + "ZIP CD-ROM Image Package of SoftEther VPN"); 488 #else // BU_SOFTETHER 489 txt.WriteLine("DESCRIPTION\t" + "ZIP CD-ROM Image Package of PacketiX VPN (for Admins)"); 490 txt.WriteLine("CATEGORY\t" + "PacketiX VPN (Commercial)"); 491 txt.WriteLine("PRODUCT\t" + "ZIP CD-ROM Image Package of PacketiX VPN"); 492 #endif // BU_SOFTETHER 493 txt.WriteLine("OS\t" + "Any"); 494 txt.WriteLine("OSLIST\t" + "Any"); 495 txt.WriteLine("CPU\t" + "CD-ROM"); 496 txt.WriteLine("VERSION\t" + BuildHelper.VersionIntToString(version)); 497 txt.WriteLine("BUILD\t" + build.ToString()); 498 txt.WriteLine("VERSTR\t" + name); 499 txt.WriteLine("DATE\t" + Str.DateTimeToStrShortWithMilliSecs(date)); 500 txt.WriteLine("LANGUAGE\t" + "English, Japanese, Simplified Chinese"); 501 txt.WriteLine("*"); 502 txt.WriteLine(); 503 504 string src_bindir = Path.Combine(Paths.BaseDirName, "bin"); 505 string vpnsmgr_zip_filename_relative = @"Windows\Admin_Tools\VPN_Server_Manager_and_Command-line_Utility_Package\"; 506 vpnsmgr_zip_filename_relative += 507 #if BU_SOFTETHER 508 "softether-" + 509 #endif // BU_SOFTETHER 510 string.Format("vpn_admin_tools-v{0}.{1:D2}-{2}-{3}-{4:D4}.{5:D2}.{6:D2}-win32.zip", 511 version / 100, version % 100, build, name, 512 date.Year, date.Month, date.Day); 513 514 string vpnsmgr_zip_filename_full = Path.Combine(Path.Combine(publicDir, cddir), vpnsmgr_zip_filename_relative); 515 516 ZipPacker zip = new ZipPacker(); 517 zip.AddFileSimple("vpnsmgr.exe", DateTime.Now, FileAttributes.Normal, 518 IO.ReadFile(Path.Combine(src_bindir, "vpnsmgr.exe")), true); 519 zip.AddFileSimple("vpncmd.exe", DateTime.Now, FileAttributes.Normal, 520 IO.ReadFile(Path.Combine(src_bindir, "vpncmd.exe")), true); 521 zip.AddFileSimple("hamcore.se2", DateTime.Now, FileAttributes.Normal, 522 IO.ReadFile(Path.Combine(src_bindir, @"BuiltHamcoreFiles\hamcore_win32\hamcore.se2")), true); 523 zip.AddFileSimple("ReadMeFirst_License.txt", DateTime.Now, FileAttributes.Normal, 524 IO.ReadFile(Path.Combine(src_bindir, @"hamcore\eula.txt")), true); 525 zip.AddFileSimple("ReadMeFirst_Important_Notices_ja.txt", DateTime.Now, FileAttributes.Normal, 526 IO.ReadFile(Path.Combine(src_bindir, @"hamcore\warning_ja.txt")), true); 527 zip.AddFileSimple("ReadMeFirst_Important_Notices_en.txt", DateTime.Now, FileAttributes.Normal, 528 IO.ReadFile(Path.Combine(src_bindir, @"hamcore\warning_en.txt")), true); 529 zip.AddFileSimple("ReadMeFirst_Important_Notices_cn.txt", DateTime.Now, FileAttributes.Normal, 530 IO.ReadFile(Path.Combine(src_bindir, @"hamcore\warning_cn.txt")), true); 531 zip.Finish(); 532 byte[] zip_data = zip.GeneratedData.Read(); 533 IO.MakeDirIfNotExists(Path.GetDirectoryName(vpnsmgr_zip_filename_full)); 534 IO.SaveFile(vpnsmgr_zip_filename_full, zip_data); 535 536 // ZIP package for VPN Server Manager GUI 537 txt.WriteLine("FILENAME\t" + Str.ReplaceStr(vpnsmgr_zip_filename_relative, @"\", "/")); 538 #if BU_SOFTETHER 539 txt.WriteLine("DESCRIPTION\t" + "ZIP Package of vpnsmgr.exe and vpncmd.exe (without installers)"); 540 txt.WriteLine("CATEGORY\t" + "SoftEther VPN (Freeware)"); 541 txt.WriteLine("PRODUCT\t" + "SoftEther VPN Server Manager for Windows, SoftEther VPN Command-Line Admin Utility (vpncmd)"); 542 #else // BU_SOFTETHER 543 txt.WriteLine("DESCRIPTION\t" + "ZIP Package of vpnsmgr.exe and vpncmd.exe (without installers)"); 544 txt.WriteLine("CATEGORY\t" + "PacketiX VPN (Commercial)"); 545 txt.WriteLine("PRODUCT\t" + "PacketiX VPN Server Manager for Windows, PacketiX VPN Command-Line Admin Utility (vpncmd)"); 546 #endif // BU_SOFTETHER 547 txt.WriteLine("OS\t" + "Windows (.zip package without installers)"); 548 txt.WriteLine("OSLIST\t" + OSList.Windows.OSSimpleList); 549 txt.WriteLine("CPU\t" + "Intel (x86 and x64)"); 550 txt.WriteLine("VERSION\t" + BuildHelper.VersionIntToString(version)); 551 txt.WriteLine("BUILD\t" + build.ToString()); 552 txt.WriteLine("VERSTR\t" + name); 553 txt.WriteLine("DATE\t" + Str.DateTimeToStrShortWithMilliSecs(date)); 554 txt.WriteLine("LANGUAGE\t" + "English, Japanese, Simplified Chinese"); 555 txt.WriteLine("*"); 556 txt.WriteLine(); 557 558 IO.MakeDirIfNotExists(Path.Combine(publicDir, cddir)); 559 File.WriteAllText(Path.Combine(Path.Combine(publicDir, cddir), "files.txt"), txt.ToString(), Str.Utf8Encoding); 560 561 562 // Execution of batch file 563 string old_cd = Environment.CurrentDirectory; 564 565 try 566 { 567 Environment.CurrentDirectory = Path.GetDirectoryName(batchFileName); 568 } 569 catch 570 { 571 } 572 573 Win32BuildUtil.ExecCommand(Paths.CmdFileName, string.Format("/C \"{0}\"", batchFileName)); 574 575 try 576 { 577 Environment.CurrentDirectory = old_cd; 578 } 579 catch 580 { 581 } 582 583 Con.WriteLine(); 584 Con.WriteLine("'{0}' に出力されました。", destDirName); 585 586 return 0; 587 } 588 589 // UNIX release 590 [ConsoleCommandMethod( 591 "Builds UNIX installer package files.", 592 "ReleaseUnix [id] [/IGNOREERROR:yes|no] [/DEBUG:yes|no] [/SERIAL:yes|no]", 593 "Builds Unix installer package files.", 594 "[id]:Specify target package ID which you'd like to build. If you'd like to erase and rebuild all packages, specify 'all'. Specify 'clean' to delete all release files.", 595 "IGNOREERROR:Specify yes if you'd like to ignore the child process to show the error message.", 596 "SERIAL:Specify yes not to use parallel mode.", 597 "DEBUG:Specity yes to enable debug mode." 598 )] ReleaseUnix(ConsoleService c, string cmdName, string str)599 static int ReleaseUnix(ConsoleService c, string cmdName, string str) 600 { 601 ConsoleParam[] args = 602 { 603 new ConsoleParam("[id]"), 604 new ConsoleParam("IGNOREERROR"), 605 new ConsoleParam("DEBUG"), 606 new ConsoleParam("SERIAL"), 607 }; 608 ConsoleParamValueList vl = c.ParseCommandList(cmdName, str, args); 609 610 int version, build; 611 string name; 612 DateTime date; 613 Win32BuildUtil.ReadBuildInfoFromTextFile(out build, out version, out name, out date); 614 BuildSoftware[] softs = BuildSoftwareList.List; 615 bool serial = vl["SERIAL"].BoolValue; 616 617 if (Str.IsEmptyStr(vl.DefaultParam.StrValue)) 618 { 619 Con.WriteLine("IDs:"); 620 foreach (BuildSoftware soft in softs) 621 { 622 if (soft.Os.IsWindows == false) 623 { 624 soft.SetBuildNumberVersionName(build, version, name, date); 625 Con.WriteLine(" {0}", soft.IDString); 626 Con.WriteLine(" - \"{0}\"", soft.OutputFileName); 627 } 628 } 629 } 630 else 631 { 632 string key = vl.DefaultParam.StrValue; 633 bool all = false; 634 635 if ("all".StartsWith(key, StringComparison.InvariantCultureIgnoreCase)) 636 { 637 all = true; 638 } 639 640 if ("clean".StartsWith(key, StringComparison.InvariantCultureIgnoreCase)) 641 { 642 // Delete the release directory 643 Paths.DeleteAllReleaseTarGz(); 644 Con.WriteLine("Clean completed."); 645 return 0; 646 } 647 648 List<BuildSoftware> o = new List<BuildSoftware>(); 649 650 foreach (BuildSoftware soft in softs) 651 { 652 soft.SetBuildNumberVersionName(build, version, name, date); 653 654 if (soft.Os.IsWindows == false) 655 { 656 if (all || soft.IDString.IndexOf(key, StringComparison.InvariantCultureIgnoreCase) != -1) 657 { 658 o.Add(soft); 659 } 660 } 661 } 662 663 if (o.Count == 0) 664 { 665 throw new ApplicationException(string.Format("Software ID '{0}' not found.", key)); 666 } 667 else 668 { 669 if (all) 670 { 671 // Delete the release directory 672 Paths.DeleteAllReleaseTarGz(); 673 } 674 else 675 { 676 IO.MakeDir(Paths.ReleaseDir); 677 } 678 679 if (serial) 680 { 681 // Build in series 682 int i; 683 for (i = 0; i < o.Count; i++) 684 { 685 Con.WriteLine("{0} / {1}: Executing for '{2}'...", 686 i + 1, o.Count, o[i].IDString); 687 688 BuildHelper.BuildMain(o[i], vl["DEBUG"].BoolValue); 689 } 690 } 691 else if (o.Count == 1) 692 { 693 // To build 694 BuildHelper.BuildMain(o[0], vl["DEBUG"].BoolValue); 695 } 696 else 697 { 698 // Make a child process build 699 Process[] procs = new Process[o.Count]; 700 701 int i; 702 703 for (i = 0; i < o.Count; i++) 704 { 705 Con.WriteLine("{0} / {1}: Executing for '{2}'...", 706 i + 1, o.Count, o[i].IDString); 707 708 procs[i] = Kernel.Run(Env.ExeFileName, 709 string.Format("/PAUSEIFERROR:{1} /DT:{2} /CMD:ReleaseUnix /DEBUG:{3} {0}", 710 o[i].IDString, vl["IGNOREERROR"].BoolValue ? "no" : "yes", Str.DateTimeToStrShort(BuildSoftwareList.ListCreatedDateTime), vl["DEBUG"].BoolValue ? "yes" : "no") 711 ); 712 } 713 714 Con.WriteLine("Waiting child processes..."); 715 716 int numError = 0; 717 718 for (i = 0; i < o.Count; i++) 719 { 720 procs[i].WaitForExit(); 721 722 bool ok = procs[i].ExitCode == 0; 723 724 if (ok == false) 725 { 726 numError++; 727 } 728 729 Con.WriteLine("{0} / {1} ({2}):", i + 1, o.Count, o[i].IDString); 730 Con.WriteLine(" {0}", ok ? "Success" : "* Error *"); 731 } 732 733 Con.WriteLine(); 734 if (numError != 0) 735 { 736 throw new ApplicationException(string.Format("{0} Errors.", numError)); 737 } 738 Con.WriteLine("No Errors."); 739 } 740 } 741 } 742 743 return 0; 744 } 745 746 // Win32 Release 747 [ConsoleCommandMethod( 748 "Builds Win32 installer package files.", 749 "ReleaseWin32 [id] [/IGNOREERROR:yes|no] [/SERIAL:yes|no]", 750 "Builds Win32 installer package files.", 751 "[id]:Specify target package ID which you'd like to build. If you'd like to erase and rebuild all packages, specify 'all'. Specify 'clean' to delete all release files.", 752 "SERIAL:Specify yes not to use parallel mode.", 753 "IGNOREERROR:Specify yes if you'd like to ignore the child process to show the error message." 754 )] ReleaseWin32(ConsoleService c, string cmdName, string str)755 static int ReleaseWin32(ConsoleService c, string cmdName, string str) 756 { 757 ConsoleParam[] args = 758 { 759 new ConsoleParam("[id]"), 760 new ConsoleParam("IGNOREERROR"), 761 new ConsoleParam("SERIAL"), 762 }; 763 ConsoleParamValueList vl = c.ParseCommandList(cmdName, str, args); 764 765 bool serial = vl["SERIAL"].BoolValue; 766 int version, build; 767 string name; 768 DateTime date; 769 Win32BuildUtil.ReadBuildInfoFromTextFile(out build, out version, out name, out date); 770 BuildSoftware[] softs = BuildSoftwareList.List; 771 772 if (Str.IsEmptyStr(vl.DefaultParam.StrValue)) 773 { 774 Con.WriteLine("IDs:"); 775 foreach (BuildSoftware soft in softs) 776 { 777 if (soft.Os.IsWindows) 778 { 779 soft.SetBuildNumberVersionName(build, version, name, date); 780 Con.WriteLine(" {0}", soft.IDString); 781 Con.WriteLine(" - \"{0}\"", soft.OutputFileName); 782 } 783 } 784 } 785 else 786 { 787 string key = vl.DefaultParam.StrValue; 788 bool all = false; 789 790 if ("all".StartsWith(key, StringComparison.InvariantCultureIgnoreCase)) 791 { 792 all = true; 793 } 794 795 if ("clean".StartsWith(key, StringComparison.InvariantCultureIgnoreCase)) 796 { 797 // Delete the release directory 798 Paths.DeleteAllReleaseExe(); 799 Con.WriteLine("Clean completed."); 800 return 0; 801 } 802 803 List<BuildSoftware> o = new List<BuildSoftware>(); 804 805 foreach (BuildSoftware soft in softs) 806 { 807 soft.SetBuildNumberVersionName(build, version, name, date); 808 809 if (soft.Os.IsWindows) 810 { 811 if (all || soft.IDString.IndexOf(key, StringComparison.InvariantCultureIgnoreCase) != -1) 812 { 813 o.Add(soft); 814 } 815 } 816 } 817 818 if (o.Count == 0) 819 { 820 throw new ApplicationException(string.Format("Software ID '{0}' not found.", key)); 821 } 822 else 823 { 824 if (all) 825 { 826 // Delete the release directory 827 Paths.DeleteAllReleaseExe(); 828 } 829 else 830 { 831 IO.MakeDir(Paths.ReleaseDir); 832 } 833 834 if (serial) 835 { 836 // Build in series 837 int i; 838 for (i = 0; i < o.Count; i++) 839 { 840 Con.WriteLine("{0} / {1}: Executing for '{2}'...", 841 i + 1, o.Count, o[i].IDString); 842 843 BuildHelper.BuildMain(o[i], false); 844 } 845 } 846 else if (o.Count == 1) 847 { 848 // To build 849 BuildHelper.BuildMain(o[0], false); 850 } 851 else 852 { 853 // Make a child process build 854 Process[] procs = new Process[o.Count]; 855 856 int i; 857 858 for (i = 0; i < o.Count; i++) 859 { 860 Con.WriteLine("{0} / {1}: Executing for '{2}'...", 861 i + 1, o.Count, o[i].IDString); 862 863 procs[i] = Kernel.Run(Env.ExeFileName, 864 string.Format("/PAUSEIFERROR:{1} /CMD:ReleaseWin32 {0}", 865 o[i].IDString, vl["IGNOREERROR"].BoolValue ? "no" : "yes")); 866 } 867 868 Con.WriteLine("Waiting child processes..."); 869 870 int numError = 0; 871 872 for (i = 0; i < o.Count; i++) 873 { 874 procs[i].WaitForExit(); 875 876 bool ok = procs[i].ExitCode == 0; 877 878 if (ok == false) 879 { 880 numError++; 881 } 882 883 Con.WriteLine("{0} / {1} ({2}):", i + 1, o.Count, o[i].IDString); 884 Con.WriteLine(" {0}", ok ? "Success" : "* Error *"); 885 } 886 887 Con.WriteLine(); 888 if (numError != 0) 889 { 890 throw new ApplicationException(string.Format("{0} Errors.", numError)); 891 } 892 Con.WriteLine("No Errors."); 893 } 894 } 895 } 896 897 return 0; 898 } 899 900 // Copy the Unix source 901 [ConsoleCommandMethod( 902 "Copies source codes for Unix.", 903 "CopyUnixSrc [destdir]", 904 "Copies source codes for Unix.", 905 "[destdir]:Specify the destination directory." 906 )] CopyUnixSrc(ConsoleService c, string cmdName, string str)907 static int CopyUnixSrc(ConsoleService c, string cmdName, string str) 908 { 909 ConsoleParam[] args = 910 { 911 new ConsoleParam("[destdir]", ConsoleService.Prompt, "Destination directory : ", ConsoleService.EvalNotEmpty, null), 912 }; 913 ConsoleParamValueList vl = c.ParseCommandList(cmdName, str, args); 914 915 ((BuildSoftwareUnix)BuildSoftwareList.vpnbridge_linux_x86_ja).CopyUnixSrc(vl.DefaultParam.StrValue); 916 917 return 0; 918 } 919 920 // Driver package build 921 // Win32 build 922 [ConsoleCommandMethod( 923 "Builds the driver package.", 924 "BuildDriverPackage", 925 "Builds the driver package.")] BuildDriverPackage(ConsoleService c, string cmdName, string str)926 static int BuildDriverPackage(ConsoleService c, string cmdName, string str) 927 { 928 Win32BuildUtil.MakeDriverPackage(); 929 930 return 0; 931 } 932 933 // Win32 build 934 [ConsoleCommandMethod( 935 "Builds all executable files for win32 and HamCore for all OS.", 936 "BuildWin32 [yes|no] [/NORMALIZESRC:yes|no]", 937 "Builds all executable files for win32 and HamCore for all OS.", 938 "[yes|no]:Specify 'yes' if you'd like to increment the build number.", 939 "NORMALIZESRC:Specity 'yes' if you'd like to normalize the build infomations in the source codes and resource scripts." 940 )] BuildWin32(ConsoleService c, string cmdName, string str)941 static int BuildWin32(ConsoleService c, string cmdName, string str) 942 { 943 ConsoleParam[] args = 944 { 945 new ConsoleParam("[yes|no]", ConsoleService.Prompt, "Increments build number (y/n) ? ", ConsoleService.EvalNotEmpty, null), 946 new ConsoleParam("NORMALIZESRC", ConsoleService.Prompt, "Normalizes source codes (y/n) ? ", ConsoleService.EvalNotEmpty, null) 947 }; 948 ConsoleParamValueList vl = c.ParseCommandList(cmdName, str, args); 949 950 if (vl.DefaultParam.BoolValue) 951 { 952 Win32BuildUtil.IncrementBuildNumber(); 953 } 954 if (vl.DefaultParam.BoolValue || vl["NORMALIZESRC"].BoolValue) 955 { 956 Win32BuildUtil.NormalizeBuildInfo(); 957 } 958 959 Paths.DeleteAllReleaseTarGz(); 960 Paths.DeleteAllReleaseExe(); 961 Paths.DeleteAllReleaseManuals(); 962 Paths.DeleteAllReleaseAdminKits(); 963 964 Win32BuildUtil.BuildMain(); 965 Win32BuildUtil.SignAllBinaryFiles(); 966 HamCoreBuildUtil.BuildHamcore(); 967 Win32BuildUtil.CopyDebugSnapshot(); 968 969 return 0; 970 } 971 972 // Process of post-build 973 [ConsoleCommandMethod( 974 "Process necessary tasks after building.", 975 "PostBuild", 976 "Process necessary tasks after building." 977 )] PostBuild(ConsoleService c, string cmdName, string str)978 static int PostBuild(ConsoleService c, string cmdName, string str) 979 { 980 ConsoleParam[] args = 981 { 982 }; 983 ConsoleParamValueList vl = c.ParseCommandList(cmdName, str, args); 984 985 Win32BuildUtil.SignAllBinaryFiles(); 986 HamCoreBuildUtil.BuildHamcore(); 987 988 return 0; 989 } 990 991 // Increment the build number 992 [ConsoleCommandMethod( 993 "Increments the build number.", 994 "IncrementBuildNumber", 995 "Increments the build number written in 'CurrentBuild.txt' text file." 996 )] IncrementBuildNumber(ConsoleService c, string cmdName, string str)997 static int IncrementBuildNumber(ConsoleService c, string cmdName, string str) 998 { 999 ConsoleParam[] args = 1000 { 1001 }; 1002 ConsoleParamValueList vl = c.ParseCommandList(cmdName, str, args); 1003 1004 Win32BuildUtil.IncrementBuildNumber(); 1005 1006 return 0; 1007 } 1008 1009 1010 // Test processing 1011 [ConsoleCommandMethod( 1012 "Run Test Procedure.", 1013 "Test", 1014 "Run Test Procedure." 1015 )] Test(ConsoleService c, string cmdName, string str)1016 static int Test(ConsoleService c, string cmdName, string str) 1017 { 1018 ConsoleParam[] args = 1019 { 1020 }; 1021 ConsoleParamValueList vl = c.ParseCommandList(cmdName, str, args); 1022 1023 TestClass.Test(); 1024 1025 return 0; 1026 } 1027 1028 // Build a HamCore 1029 [ConsoleCommandMethod( 1030 "Builds a HamCore file.", 1031 "BuildHamCore", 1032 "Builds a HamCore file." 1033 )] BuildHamCore(ConsoleService c, string cmdName, string str)1034 static int BuildHamCore(ConsoleService c, string cmdName, string str) 1035 { 1036 ConsoleParam[] args = 1037 { 1038 }; 1039 ConsoleParamValueList vl = c.ParseCommandList(cmdName, str, args); 1040 1041 HamCoreBuildUtil.BuildHamcore(); 1042 1043 return 0; 1044 } 1045 1046 // Sign a binary file 1047 [ConsoleCommandMethod( 1048 "Sign all binary files.", 1049 "SignAll", 1050 "Sign all binary files." 1051 )] SignAll(ConsoleService c, string cmdName, string str)1052 static int SignAll(ConsoleService c, string cmdName, string str) 1053 { 1054 ConsoleParam[] args = 1055 { 1056 }; 1057 ConsoleParamValueList vl = c.ParseCommandList(cmdName, str, args); 1058 1059 Win32BuildUtil.SignAllBinaryFiles(); 1060 1061 return 0; 1062 } 1063 1064 // Create and sign a Inf file of SeLow for Windows 8 1065 [ConsoleCommandMethod( 1066 "Generate INF files for SeLow.", 1067 "SignSeLowInfFiles", 1068 "Generate INF files for SeLow." 1069 )] SignSeLowInfFiles(ConsoleService c, string cmdName, string str)1070 static int SignSeLowInfFiles(ConsoleService c, string cmdName, string str) 1071 { 1072 ConsoleParam[] args = 1073 { 1074 new ConsoleParam("[cpu]", ConsoleService.Prompt, "x86 / x64: ", ConsoleService.EvalNotEmpty, null) 1075 }; 1076 ConsoleParamValueList vl = c.ParseCommandList(cmdName, str, args); 1077 1078 #if !BU_OSS 1079 1080 Win32BuildUtil.SignSeLowInfFiles(vl.DefaultParam.StrValue); 1081 1082 #endif 1083 1084 return 0; 1085 } 1086 1087 // Create Inf file for Windows 8 1088 [ConsoleCommandMethod( 1089 "Generate INF files for Windows 8.", 1090 "GenerateWin8InfFiles", 1091 "Generate INF files for Windows 8." 1092 )] GenerateWin8InfFiles(ConsoleService c, string cmdName, string str)1093 static int GenerateWin8InfFiles(ConsoleService c, string cmdName, string str) 1094 { 1095 ConsoleParam[] args = 1096 { 1097 new ConsoleParam("[cpu]", ConsoleService.Prompt, "x86 / x64: ", ConsoleService.EvalNotEmpty, null) 1098 }; 1099 ConsoleParamValueList vl = c.ParseCommandList(cmdName, str, args); 1100 1101 #if !BU_OSS 1102 1103 Win32BuildUtil.GenerateINFFilesForWindows8(vl.DefaultParam.StrValue); 1104 1105 #endif 1106 1107 return 0; 1108 } 1109 1110 // Set the version of the PE to 4 1111 [ConsoleCommandMethod( 1112 "Set the version of the PE file to 4.", 1113 "SetPE4 [filename]", 1114 "Set the version of the PE file to 4.", 1115 "[filename]:Specify the target filename." 1116 )] SetPE4(ConsoleService c, string cmdName, string str)1117 static int SetPE4(ConsoleService c, string cmdName, string str) 1118 { 1119 ConsoleParam[] args = 1120 { 1121 new ConsoleParam("[filename]", ConsoleService.Prompt, "Filename: ", ConsoleService.EvalNotEmpty, null) 1122 }; 1123 ConsoleParamValueList vl = c.ParseCommandList(cmdName, str, args); 1124 1125 PEUtil.SetPEVersionTo4(vl.DefaultParam.StrValue); 1126 1127 return 0; 1128 } 1129 1130 // Set the Manifest 1131 [ConsoleCommandMethod( 1132 "Set the manifest to the executable file.", 1133 "SetManifest [filename] [/MANIFEST:manifest_file_name]", 1134 "Set the manifest to the executable file.", 1135 "[filename]:Specify the target executable filename.", 1136 "MANIFEST:Specify the manifest XML file." 1137 )] SetManifest(ConsoleService c, string cmdName, string str)1138 static int SetManifest(ConsoleService c, string cmdName, string str) 1139 { 1140 ConsoleParam[] args = 1141 { 1142 new ConsoleParam("[filename]", ConsoleService.Prompt, "Target Filename: ", ConsoleService.EvalNotEmpty, null), 1143 new ConsoleParam("MANIFEST", ConsoleService.Prompt, "Manifest Filename: ", ConsoleService.EvalNotEmpty, null), 1144 }; 1145 ConsoleParamValueList vl = c.ParseCommandList(cmdName, str, args); 1146 1147 PEUtil.SetManifest(vl.DefaultParam.StrValue, vl["MANIFEST"].StrValue); 1148 1149 return 0; 1150 } 1151 1152 // Generate a version information resource 1153 [ConsoleCommandMethod( 1154 "Generate a Version Information Resource File.", 1155 "GenerateVersionResource [targetFileName] [/OUT:destFileName]", 1156 "Generate a Version Information Resource File.", 1157 "[targetFileName]:Specify the target exe/dll file name.", 1158 "OUT:Specify the output .res file.", 1159 "RC:Specify a template RC file name.")] GenerateVersionResource(ConsoleService c, string cmdName, string str)1160 static int GenerateVersionResource(ConsoleService c, string cmdName, string str) 1161 { 1162 ConsoleParam[] args = 1163 { 1164 new ConsoleParam("[targetFileName]", ConsoleService.Prompt, "Target Filename: ", ConsoleService.EvalNotEmpty, null), 1165 new ConsoleParam("OUT", ConsoleService.Prompt, "Dst Filename: ", ConsoleService.EvalNotEmpty, null), 1166 new ConsoleParam("PRODUCT"), 1167 new ConsoleParam("RC"), 1168 }; 1169 ConsoleParamValueList vl = c.ParseCommandList(cmdName, str, args); 1170 1171 string targetFilename = vl.DefaultParam.StrValue; 1172 string outFilename = vl["OUT"].StrValue; 1173 string product_name = vl["PRODUCT"].StrValue; 1174 1175 Win32BuildUtil.GenerateVersionInfoResource(targetFilename, outFilename, vl["RC"].StrValue, product_name); 1176 1177 return 0; 1178 } 1179 1180 // Measure the number of lines of code 1181 [ConsoleCommandMethod( 1182 "Count the number of lines of the sources.", 1183 "Count [DIR]", 1184 "Count the number of lines of the sources.", 1185 "[DIR]:dir name.")] Count(ConsoleService c, string cmdName, string str)1186 static int Count(ConsoleService c, string cmdName, string str) 1187 { 1188 ConsoleParam[] args = 1189 { 1190 new ConsoleParam("[DIR]", null, null, null, null), 1191 }; 1192 ConsoleParamValueList vl = c.ParseCommandList(cmdName, str, args); 1193 1194 string dir = vl.DefaultParam.StrValue; 1195 if (Str.IsEmptyStr(dir)) 1196 { 1197 dir = Paths.BaseDirName; 1198 } 1199 1200 string[] files = Directory.GetFiles(dir, "*", SearchOption.AllDirectories); 1201 1202 int numLines = 0; 1203 int numBytes = 0; 1204 int numComments = 0; 1205 int totalLetters = 0; 1206 1207 Dictionary<string, int> commentsDict = new Dictionary<string, int>(); 1208 1209 foreach (string file in files) 1210 { 1211 string ext = Path.GetExtension(file); 1212 1213 if (Str.StrCmpi(ext, ".c") || Str.StrCmpi(ext, ".cpp") || Str.StrCmpi(ext, ".h") || 1214 Str.StrCmpi(ext, ".rc") || Str.StrCmpi(ext, ".stb") || Str.StrCmpi(ext, ".cs") 1215 || Str.StrCmpi(ext, ".fx") || Str.StrCmpi(ext, ".hlsl")) 1216 { 1217 if (Str.InStr(file, "\\.svn\\") == false && Str.InStr(file, "\\seedll\\") == false && Str.InStr(file, "\\see\\") == false && Str.InStr(file, "\\openssl\\") == false) 1218 { 1219 string[] lines = File.ReadAllLines(file); 1220 1221 numLines += lines.Length; 1222 numBytes += (int)new FileInfo(file).Length; 1223 1224 foreach (string line in lines) 1225 { 1226 if (Str.InStr(line, "//") && Str.InStr(line, "// Validate arguments") == false) 1227 { 1228 if (commentsDict.ContainsKey(line) == false) 1229 { 1230 commentsDict.Add(line, 1); 1231 } 1232 numComments++; 1233 1234 totalLetters += line.Trim().Length - 3; 1235 } 1236 } 1237 } 1238 } 1239 } 1240 1241 Con.WriteLine("{0} Lines, {1} Bytes. {2} Comments ({3} distinct, aver: {4})", Str.ToStr3(numLines), Str.ToStr3(numBytes), 1242 Str.ToStr3(numComments), commentsDict.Count, totalLetters / numComments); 1243 1244 return 0; 1245 } 1246 1247 // Add to Cab by compressing OCX 1248 [ConsoleCommandMethod( 1249 "Compress a OCX and Generate a Cab file.", 1250 "GenerateVpnWebOcxCab [src] [/DEST:dest]", 1251 "Compress a OCX and Generate a Cab file.", 1252 "[src]:Specify the ocx file.", 1253 "DEST:Specify the destination cab file.")] GenerateVpnWebOcxCab(ConsoleService c, string cmdName, string str)1254 static int GenerateVpnWebOcxCab(ConsoleService c, string cmdName, string str) 1255 { 1256 ConsoleParam[] args = 1257 { 1258 new ConsoleParam("[src]", ConsoleService.Prompt, "Src Filename: ", ConsoleService.EvalNotEmpty, null), 1259 new ConsoleParam("DEST", ConsoleService.Prompt, "Dst Filename: ", ConsoleService.EvalNotEmpty, null), 1260 }; 1261 ConsoleParamValueList vl = c.ParseCommandList(cmdName, str, args); 1262 1263 #if !BU_OSS 1264 string destFileName = vl["DEST"].StrValue; 1265 string srcFileName = vl.DefaultParam.StrValue; 1266 1267 Win32BuildUtil.GenerateVpnWebOcxCab(destFileName, srcFileName); 1268 #endif 1269 1270 return 0; 1271 } 1272 1273 1274 // Copy the file 1275 [ConsoleCommandMethod( 1276 "Copy a File.", 1277 "FileCopy [src] [/DEST:dest]", 1278 "Copy a File.", 1279 "[src]:Specify the source file.", 1280 "DEST:Specify the destination file.")] FileCopy(ConsoleService c, string cmdName, string str)1281 static int FileCopy(ConsoleService c, string cmdName, string str) 1282 { 1283 ConsoleParam[] args = 1284 { 1285 new ConsoleParam("[src]", ConsoleService.Prompt, "Src Filename: ", ConsoleService.EvalNotEmpty, null), 1286 new ConsoleParam("DEST", ConsoleService.Prompt, "Dst Filename: ", ConsoleService.EvalNotEmpty, null), 1287 }; 1288 ConsoleParamValueList vl = c.ParseCommandList(cmdName, str, args); 1289 1290 string destFileName = vl["DEST"].StrValue; 1291 string srcFileName = vl.DefaultParam.StrValue; 1292 1293 IO.FileCopy(srcFileName, destFileName, true, false); 1294 1295 return 0; 1296 } 1297 1298 // Sign the file 1299 [ConsoleCommandMethod( 1300 "Sign files using Authenticode certificates.", 1301 "SignCode [filename] [/DEST:destfilename] [/COMMENT:comment] [/KERNEL:yes|no]", 1302 "Sign files using Authenticode certificates.", 1303 "[filename]:Specify the target filename.", 1304 "DEST:Specify the destination filename. If this parameter is not specified, the target file will be overwritten.", 1305 "COMMENT:Provide a description of the signed content.", 1306 "KERNEL:Specify \"yes\" if Windows Vista / 7 Kernel Mode Driver Signing is needed." 1307 )] SignCode(ConsoleService c, string cmdName, string str)1308 static int SignCode(ConsoleService c, string cmdName, string str) 1309 { 1310 ConsoleParam[] args = 1311 { 1312 new ConsoleParam("[filename]", ConsoleService.Prompt, "Filename: ", ConsoleService.EvalNotEmpty, null), 1313 new ConsoleParam("DEST"), 1314 new ConsoleParam("COMMENT", ConsoleService.Prompt, "Comment: ", ConsoleService.EvalNotEmpty, null), 1315 new ConsoleParam("KERNEL"), 1316 new ConsoleParam("CERTID"), 1317 new ConsoleParam("SHAMODE"), 1318 }; 1319 ConsoleParamValueList vl = c.ParseCommandList(cmdName, str, args); 1320 1321 string destFileName = vl["DEST"].StrValue; 1322 string srcFileName = vl.DefaultParam.StrValue; 1323 if (Str.IsEmptyStr(destFileName)) 1324 { 1325 destFileName = srcFileName; 1326 } 1327 string comment = vl["COMMENT"].StrValue; 1328 bool kernel = vl["KERNEL"].BoolValue; 1329 1330 int certid = vl["CERTID"].IntValue; 1331 int shamode = vl["SHAMODE"].IntValue; 1332 1333 CodeSign.SignFile(destFileName, srcFileName, comment, kernel, false, false); 1334 1335 return 0; 1336 } 1337 1338 // Sign the file 1339 [ConsoleCommandMethod( 1340 "Sign files using Authenticode certificates.", 1341 "SignCode2 [filename] [/DEST:destfilename] [/COMMENT:comment] [/KERNEL:yes|no] [/CERT:certname]", 1342 "Sign files using Authenticode certificates.", 1343 "[filename]:Specify the target filename.", 1344 "DEST:Specify the destination filename. If this parameter is not specified, the target file will be overwritten.", 1345 "COMMENT:Provide a description of the signed content.", 1346 "KERNEL:Specify \"yes\" if Windows Vista / 7 Kernel Mode Driver Signing is needed." 1347 )] SignCode2(ConsoleService c, string cmdName, string str)1348 static int SignCode2(ConsoleService c, string cmdName, string str) 1349 { 1350 ConsoleParam[] args = 1351 { 1352 new ConsoleParam("[filename]", ConsoleService.Prompt, "Filename: ", ConsoleService.EvalNotEmpty, null), 1353 new ConsoleParam("DEST"), 1354 new ConsoleParam("COMMENT", ConsoleService.Prompt, "Comment: ", ConsoleService.EvalNotEmpty, null), 1355 new ConsoleParam("KERNEL"), 1356 new ConsoleParam("CERT"), 1357 }; 1358 ConsoleParamValueList vl = c.ParseCommandList(cmdName, str, args); 1359 1360 string destFileName = vl["DEST"].StrValue; 1361 string srcFileName = vl.DefaultParam.StrValue; 1362 if (Str.IsEmptyStr(destFileName)) 1363 { 1364 destFileName = srcFileName; 1365 } 1366 string comment = vl["COMMENT"].StrValue; 1367 bool kernel = vl["KERNEL"].BoolValue; 1368 1369 string cert = vl["CERT"].StrValue; 1370 1371 CodeSign.SignFile2(destFileName, srcFileName, comment, kernel, cert); 1372 1373 return 0; 1374 } 1375 } 1376 } 1377 1378