VpnBuilder.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  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. // This program is free software; you can redistribute it and/or
  18. // modify it under the terms of the GNU General Public License
  19. // version 2 as published by the Free Software Foundation.
  20. //
  21. // This program is distributed in the hope that it will be useful,
  22. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. // GNU General Public License for more details.
  25. //
  26. // You should have received a copy of the GNU General Public License version 2
  27. // along with this program; if not, write to the Free Software
  28. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  29. //
  30. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  31. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  32. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  33. // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  34. // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  35. // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  36. // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  37. //
  38. // THE LICENSE AGREEMENT IS ATTACHED ON THE SOURCE-CODE PACKAGE
  39. // AS "LICENSE.TXT" FILE. READ THE TEXT FILE IN ADVANCE TO USE THE SOFTWARE.
  40. //
  41. //
  42. // THIS SOFTWARE IS DEVELOPED IN JAPAN, AND DISTRIBUTED FROM JAPAN,
  43. // UNDER JAPANESE LAWS. YOU MUST AGREE IN ADVANCE TO USE, COPY, MODIFY,
  44. // MERGE, PUBLISH, DISTRIBUTE, SUBLICENSE, AND/OR SELL COPIES OF THIS
  45. // SOFTWARE, THAT ANY JURIDICAL DISPUTES WHICH ARE CONCERNED TO THIS
  46. // SOFTWARE OR ITS CONTENTS, AGAINST US (SOFTETHER PROJECT, SOFTETHER
  47. // CORPORATION, DAIYUU NOBORI OR OTHER SUPPLIERS), OR ANY JURIDICAL
  48. // DISPUTES AGAINST US WHICH ARE CAUSED BY ANY KIND OF USING, COPYING,
  49. // MODIFYING, MERGING, PUBLISHING, DISTRIBUTING, SUBLICENSING, AND/OR
  50. // SELLING COPIES OF THIS SOFTWARE SHALL BE REGARDED AS BE CONSTRUED AND
  51. // CONTROLLED BY JAPANESE LAWS, AND YOU MUST FURTHER CONSENT TO
  52. // EXCLUSIVE JURISDICTION AND VENUE IN THE COURTS SITTING IN TOKYO,
  53. // JAPAN. YOU MUST WAIVE ALL DEFENSES OF LACK OF PERSONAL JURISDICTION
  54. // AND FORUM NON CONVENIENS. PROCESS MAY BE SERVED ON EITHER PARTY IN
  55. // THE MANNER AUTHORIZED BY APPLICABLE LAW OR COURT RULE.
  56. //
  57. // USE ONLY IN JAPAN. DO NOT USE THIS SOFTWARE IN ANOTHER COUNTRY UNLESS
  58. // YOU HAVE A CONFIRMATION THAT THIS SOFTWARE DOES NOT VIOLATE ANY
  59. // CRIMINAL LAWS OR CIVIL RIGHTS IN THAT PARTICULAR COUNTRY. USING THIS
  60. // SOFTWARE IN OTHER COUNTRIES IS COMPLETELY AT YOUR OWN RISK. THE
  61. // SOFTETHER VPN PROJECT HAS DEVELOPED AND DISTRIBUTED THIS SOFTWARE TO
  62. // COMPLY ONLY WITH THE JAPANESE LAWS AND EXISTING CIVIL RIGHTS INCLUDING
  63. // PATENTS WHICH ARE SUBJECTS APPLY IN JAPAN. OTHER COUNTRIES' LAWS OR
  64. // CIVIL RIGHTS ARE NONE OF OUR CONCERNS NOR RESPONSIBILITIES. WE HAVE
  65. // NEVER INVESTIGATED ANY CRIMINAL REGULATIONS, CIVIL LAWS OR
  66. // INTELLECTUAL PROPERTY RIGHTS INCLUDING PATENTS IN ANY OF OTHER 200+
  67. // COUNTRIES AND TERRITORIES. BY NATURE, THERE ARE 200+ REGIONS IN THE
  68. // WORLD, WITH DIFFERENT LAWS. IT IS IMPOSSIBLE TO VERIFY EVERY
  69. // COUNTRIES' LAWS, REGULATIONS AND CIVIL RIGHTS TO MAKE THE SOFTWARE
  70. // COMPLY WITH ALL COUNTRIES' LAWS BY THE PROJECT. EVEN IF YOU WILL BE
  71. // SUED BY A PRIVATE ENTITY OR BE DAMAGED BY A PUBLIC SERVANT IN YOUR
  72. // COUNTRY, THE DEVELOPERS OF THIS SOFTWARE WILL NEVER BE LIABLE TO
  73. // RECOVER OR COMPENSATE SUCH DAMAGES, CRIMINAL OR CIVIL
  74. // RESPONSIBILITIES. NOTE THAT THIS LINE IS NOT LICENSE RESTRICTION BUT
  75. // JUST A STATEMENT FOR WARNING AND DISCLAIMER.
  76. //
  77. //
  78. // SOURCE CODE CONTRIBUTION
  79. // ------------------------
  80. //
  81. // Your contribution to SoftEther VPN Project is much appreciated.
  82. // Please send patches to us through GitHub.
  83. // Read the SoftEther VPN Patch Acceptance Policy in advance:
  84. // http://www.softether.org/5-download/src/9.patch
  85. //
  86. //
  87. // DEAR SECURITY EXPERTS
  88. // ---------------------
  89. //
  90. // If you find a bug or a security vulnerability please kindly inform us
  91. // about the problem immediately so that we can fix the security problem
  92. // to protect a lot of users around the world as soon as possible.
  93. //
  94. // Our e-mail address for security reports is:
  95. // softether-vpn-security [at] softether.org
  96. //
  97. // Please note that the above e-mail address is not a technical support
  98. // inquiry address. If you need technical assistance, please visit
  99. // http://www.softether.org/ and ask your question on the users forum.
  100. //
  101. // Thank you for your cooperation.
  102. //
  103. //
  104. // NO MEMORY OR RESOURCE LEAKS
  105. // ---------------------------
  106. //
  107. // The memory-leaks and resource-leaks verification under the stress
  108. // test has been passed before release this source code.
  109. using System;
  110. using System.Threading;
  111. using System.Text;
  112. using System.Configuration;
  113. using System.Collections;
  114. using System.Collections.Generic;
  115. using System.Collections.Specialized;
  116. using System.Security.Cryptography;
  117. using System.Web;
  118. using System.Web.Security;
  119. using System.Web.UI;
  120. using System.Web.UI.WebControls;
  121. using System.Web.UI.WebControls.WebParts;
  122. using System.Web.UI.HtmlControls;
  123. using System.IO;
  124. using System.Drawing;
  125. using System.Drawing.Imaging;
  126. using System.Drawing.Drawing2D;
  127. using System.Diagnostics;
  128. using System.Net;
  129. using System.Net.Security;
  130. using System.Security.Cryptography.X509Certificates;
  131. using CoreUtil;
  132. namespace BuildUtil
  133. {
  134. // Languages
  135. public class Language
  136. {
  137. public int Number;
  138. public string Id;
  139. public string Title;
  140. public string TitleUnicode;
  141. public string WindowsLocaleIds;
  142. public string UnixLocaleIds;
  143. }
  144. // Build helper class
  145. public static class BuildHelper
  146. {
  147. // loads the language list text file
  148. public static Language[] GetLanguageList()
  149. {
  150. return GetLanguageList(Path.Combine(Paths.BinDirName, @"hamcore\languages.txt"));
  151. }
  152. public static Language[] GetLanguageList(string filename)
  153. {
  154. List<Language> ret = new List<Language>();
  155. string[] lines = File.ReadAllLines(filename, Str.Utf8Encoding);
  156. foreach (string line in lines)
  157. {
  158. string s = line.Trim();
  159. if (Str.IsEmptyStr(s) == false)
  160. {
  161. if (s.StartsWith("#", StringComparison.InvariantCultureIgnoreCase) == false)
  162. {
  163. string[] sps = { " ", "\t", };
  164. string[] tokens = s.Split(sps, StringSplitOptions.RemoveEmptyEntries);
  165. if (tokens.Length == 6)
  166. {
  167. Language e = new Language();
  168. e.Number = Str.StrToInt(tokens[0]);
  169. e.Id = tokens[1];
  170. e.Title = Str.ReplaceStr(tokens[2], "_", " ");
  171. e.TitleUnicode = tokens[3];
  172. e.WindowsLocaleIds = tokens[4];
  173. e.UnixLocaleIds = tokens[5];
  174. ret.Add(e);
  175. Con.WriteLine(tokens.Length);
  176. }
  177. }
  178. }
  179. }
  180. return ret.ToArray();
  181. }
  182. // Build
  183. public static void BuildMain(BuildSoftware soft, bool debugModeIfUnix)
  184. {
  185. int version, build;
  186. string name;
  187. DateTime date;
  188. string title = Console.Title;
  189. Console.Title = string.Format("Building {0}", soft.IDString);
  190. try
  191. {
  192. Win32BuildUtil.ReadBuildInfoFromTextFile(out build, out version, out name, out date);
  193. soft.SetBuildNumberVersionName(build, version, name, date);
  194. Con.WriteLine("Building '{0}' - {1}...", soft.IDString, soft.TitleString);
  195. BuildSoftwareUnix softUnix = soft as BuildSoftwareUnix;
  196. if (softUnix == null)
  197. {
  198. soft.Build();
  199. }
  200. else
  201. {
  202. softUnix.Build(debugModeIfUnix);
  203. }
  204. }
  205. finally
  206. {
  207. Console.Title = title;
  208. }
  209. }
  210. // Convert the number to a version number
  211. public static string VersionIntToString(int version)
  212. {
  213. return string.Format("{0}.{1:D2}", version / 100, version % 100);
  214. }
  215. // Get a product list that is included in the software
  216. public static string GetSoftwareProductList(Software soft)
  217. {
  218. string ret = "";
  219. switch (soft)
  220. {
  221. case Software.vpnbridge:
  222. ret = "PacketiX VPN Bridge";
  223. break;
  224. case Software.vpnclient:
  225. ret = "PacketiX VPN Client, PacketiX VPN Command-Line Admin Utility (vpncmd)";
  226. break;
  227. case Software.vpnserver:
  228. ret = "PacketiX VPN Server, PacketiX VPN Command-Line Admin Utility (vpncmd)";
  229. break;
  230. case Software.vpnserver_vpnbridge:
  231. ret = "PacketiX VPN Server, PacketiX VPN Bridge, PacketiX VPN Server Manager for Windows, PacketiX VPN Command-Line Admin Utility (vpncmd)";
  232. break;
  233. default:
  234. throw new ApplicationException("invalid soft.");
  235. }
  236. #if BU_SOFTETHER
  237. ret = Str.ReplaceStr(ret, "PacketiX", "SoftEther", false);
  238. #endif
  239. return ret;
  240. }
  241. // Get the title of the software
  242. public static string GetSoftwareTitle(Software soft)
  243. {
  244. string ret = "";
  245. switch (soft)
  246. {
  247. case Software.vpnbridge:
  248. ret = "PacketiX VPN Bridge";
  249. break;
  250. case Software.vpnclient:
  251. ret = "PacketiX VPN Client";
  252. break;
  253. case Software.vpnserver:
  254. ret = "PacketiX VPN Server";
  255. break;
  256. case Software.vpnserver_vpnbridge:
  257. ret = "PacketiX VPN Server and VPN Bridge";
  258. break;
  259. default:
  260. throw new ApplicationException("invalid soft.");
  261. }
  262. #if BU_SOFTETHER
  263. ret = Str.ReplaceStr(ret, "PacketiX", "SoftEther", false);
  264. #endif
  265. return ret;
  266. }
  267. }
  268. // Basic path information
  269. public static class Paths
  270. {
  271. public static readonly string ExeFileName = Env.ExeFileName;
  272. public static readonly string ExeDirName = Env.ExeFileDir;
  273. public static readonly string BinDirName = ExeDirName;
  274. public static readonly string BaseDirName = IO.NormalizePath(Path.Combine(BinDirName, @"..\"));
  275. public static readonly string UtilityDirName = IO.NormalizePath(Path.Combine(BinDirName, @"..\BuildFiles\Utility"));
  276. #if !BU_SOFTETHER
  277. // PacketiX VPN (build by SoftEther)
  278. public static readonly string VPN4SolutionFileName = Path.Combine(BaseDirName, "VPN4.sln");
  279. public static readonly string DebugSnapshotBaseDir = @"S:\SE4\DebugFilesSnapshot";
  280. public static readonly string ReleaseDestDir = @"s:\SE4\Releases";
  281. public const string Prefix = "";
  282. #else
  283. #if !BU_OSS
  284. // SoftEther VPN (build by SoftEther)
  285. public static readonly string VPN4SolutionFileName = Path.Combine(BaseDirName, "SEVPN.sln");
  286. public static readonly string DebugSnapshotBaseDir = @"S:\SE4\DebugFilesSnapshot_SEVPN";
  287. public static readonly string ReleaseDestDir = @"s:\SE4\Releases_SEVPN";
  288. public const string Prefix = "softether-";
  289. #else
  290. // SoftEther VPN (build by Open Source Developers)
  291. public static readonly string VPN4SolutionFileName = Path.Combine(BaseDirName, "SEVPN.sln");
  292. public static readonly string DebugSnapshotBaseDir = IO.NormalizePath(Path.Combine(BaseDirName, @"..\output\debug"));
  293. public static readonly string ReleaseDestDir = IO.NormalizePath(Path.Combine(BaseDirName, @"..\output\pkg"));
  294. public const string Prefix = "softether_open-";
  295. #endif
  296. #endif
  297. public static readonly string ReleaseDestDir_SEVPN = @"s:\SE4\Releases_SEVPN";
  298. public static readonly string BuildHamcoreFilesDirName = Path.Combine(BinDirName, "BuiltHamcoreFiles");
  299. public static readonly string VisualStudioVCDir;
  300. public static readonly string VisualStudioVCBatchFileName;
  301. public static readonly string DotNetFramework35Dir;
  302. public static readonly string MSBuildFileName;
  303. public static readonly string TmpDirName;
  304. public static readonly DateTime StartDateTime = DateTime.Now;
  305. public static readonly string StartDateTimeStr;
  306. public static readonly string CmdFileName;
  307. public static readonly string ManifestsDir = Path.Combine(BaseDirName, @"BuildFiles\Manifests");
  308. public static readonly string XCopyExeFileName = Path.Combine(Env.SystemDir, "xcopy.exe");
  309. public static readonly string ReleaseDir = Path.Combine(BaseDirName, @"tmp\Release");
  310. public static readonly string ReleaseSrckitDir = Path.Combine(BaseDirName, @"tmp\ReleaseSrcKit");
  311. public static readonly string StringsDir = Path.Combine(BaseDirName, @"BuildFiles\Strings");
  312. public static readonly string CrossCompilerBaseDir = @"S:\CommomDev\xc";
  313. public static readonly string UnixInstallScript = Path.Combine(BaseDirName, @"BuildFiles\UnixFiles\InstallScript.txt");
  314. public static readonly string OssCommentsFile = Path.Combine(StringsDir, "OssComments.txt");
  315. public static readonly string AutorunSrcDir = IO.NormalizePath(Path.Combine(BaseDirName, @"..\Autorun"));
  316. public static readonly string MicrosoftSDKDir;
  317. public static readonly string MakeCatFilename;
  318. public static readonly string RcFilename;
  319. public static readonly string SoftEtherBuildDir = Env.SystemDir.Substring(0, 2) + @"\tmp\softether_build_dir";
  320. public static readonly string OpenSourceDestDir = Env.SystemDir.Substring(0, 2) + @"\tmp\softether_oss_dest_dir";
  321. // Initialize
  322. static Paths()
  323. {
  324. // Starting date and time string
  325. Paths.StartDateTimeStr = Str.DateTimeToStrShort(Paths.StartDateTime);
  326. // Check whether the execution path is the bin directory in the VPN directory
  327. if (Paths.BinDirName.EndsWith(@"\bin", StringComparison.InvariantCultureIgnoreCase) == false)
  328. {
  329. throw new ApplicationException(string.Format("'{0}' is not a VPN bin directory.", Paths.BinDirName));
  330. }
  331. if (File.Exists(Paths.VPN4SolutionFileName) == false)
  332. {
  333. throw new ApplicationException(string.Format("'{0}' is not a VPN base directory.", Paths.BaseDirName));
  334. }
  335. // Get the VC++ directory
  336. // Visual Studio 2008
  337. if (IntPtr.Size == 4)
  338. {
  339. Paths.VisualStudioVCDir = IO.RemoteLastEnMark(Reg.ReadStr(RegRoot.LocalMachine, @"SOFTWARE\Microsoft\VisualStudio\9.0\Setup\VC", "ProductDir"));
  340. }
  341. else
  342. {
  343. Paths.VisualStudioVCDir = IO.RemoteLastEnMark(Reg.ReadStr(RegRoot.LocalMachine, @"SOFTWARE\Wow6432Node\Microsoft\VisualStudio\9.0\Setup\VC", "ProductDir"));
  344. }
  345. if (Str.IsEmptyStr(Paths.VisualStudioVCDir))
  346. {
  347. throw new ApplicationException("Visual C++ directory not found.\n");
  348. }
  349. if (Directory.Exists(Paths.VisualStudioVCDir) == false)
  350. {
  351. throw new ApplicationException(string.Format("Directory '{0}' not found.", Paths.VisualStudioVCDir));
  352. }
  353. // Get the VC++ batch file name
  354. Paths.VisualStudioVCBatchFileName = Path.Combine(Paths.VisualStudioVCDir, "vcvarsall.bat");
  355. if (File.Exists(Paths.VisualStudioVCBatchFileName) == false)
  356. {
  357. throw new ApplicationException(string.Format("File '{0}' not found.", Paths.VisualStudioVCBatchFileName));
  358. }
  359. bool x86_dir = false;
  360. // Get Microsoft SDK 6.0a directory
  361. if (IntPtr.Size == 4)
  362. {
  363. Paths.MicrosoftSDKDir = IO.RemoteLastEnMark(Reg.ReadStr(RegRoot.LocalMachine, @"SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v6.0A", "InstallationFolder"));
  364. }
  365. else
  366. {
  367. Paths.MicrosoftSDKDir = IO.RemoteLastEnMark(Reg.ReadStr(RegRoot.LocalMachine, @"SOFTWARE\Microsoft\Microsoft SDKs\Windows\v6.0A", "InstallationFolder"));
  368. }
  369. // Get makecat.exe file name
  370. Paths.MakeCatFilename = Path.Combine(Paths.MicrosoftSDKDir, @"bin\" + (x86_dir ? @"x86\" : "") + "makecat.exe");
  371. // Get the rc.exe file name
  372. Paths.RcFilename = Path.Combine(Paths.MicrosoftSDKDir, @"bin\" + (x86_dir ? @"x86\" : "") + "rc.exe");
  373. // Get the cmd.exe file name
  374. Paths.CmdFileName = Path.Combine(Env.SystemDir, "cmd.exe");
  375. if (File.Exists(Paths.CmdFileName) == false)
  376. {
  377. throw new ApplicationException(string.Format("File '{0}' not found.", Paths.CmdFileName));
  378. }
  379. // Get .NET Framework 3.5 directory
  380. Paths.DotNetFramework35Dir = Path.Combine(Env.WindowsDir, @"Microsoft.NET\Framework\v3.5");
  381. // Get msbuild.exe directory
  382. Paths.MSBuildFileName = Path.Combine(Paths.DotNetFramework35Dir, "MSBuild.exe");
  383. if (File.Exists(Paths.MSBuildFileName) == false)
  384. {
  385. throw new ApplicationException(string.Format("File '{0}' not found.", Paths.MSBuildFileName));
  386. }
  387. // Get the TMP directory
  388. Paths.TmpDirName = Path.Combine(Paths.BaseDirName, "tmp");
  389. if (Directory.Exists(Paths.TmpDirName) == false)
  390. {
  391. Directory.CreateDirectory(Paths.TmpDirName);
  392. }
  393. }
  394. public static void DeleteAllReleaseTarGz()
  395. {
  396. if (Directory.Exists(Paths.ReleaseDir))
  397. {
  398. string[] files = Directory.GetFiles(Paths.ReleaseDir, "*.gz", SearchOption.AllDirectories);
  399. foreach (string file in files)
  400. {
  401. File.Delete(file);
  402. }
  403. }
  404. if (Directory.Exists(Paths.ReleaseSrckitDir))
  405. {
  406. string[] files = Directory.GetFiles(Paths.ReleaseSrckitDir, "*.gz", SearchOption.AllDirectories);
  407. foreach (string file in files)
  408. {
  409. File.Delete(file);
  410. }
  411. }
  412. }
  413. public static void DeleteAllReleaseAdminKits()
  414. {
  415. if (Directory.Exists(Paths.ReleaseDir))
  416. {
  417. string[] files = Directory.GetFiles(Paths.ReleaseDir, "*.zip", SearchOption.AllDirectories);
  418. foreach (string file in files)
  419. {
  420. if (Str.InStr(file, "vpnadminpak"))
  421. {
  422. File.Delete(file);
  423. }
  424. }
  425. }
  426. }
  427. public static void DeleteAllReleaseManuals()
  428. {
  429. if (Directory.Exists(Paths.ReleaseDir))
  430. {
  431. string[] files = Directory.GetFiles(Paths.ReleaseDir, "*", SearchOption.AllDirectories);
  432. foreach (string file in files)
  433. {
  434. if (Str.InStr(file, "vpnmanual"))
  435. {
  436. File.Delete(file);
  437. }
  438. }
  439. }
  440. }
  441. public static void DeleteAllReleaseExe()
  442. {
  443. if (Directory.Exists(Paths.ReleaseDir))
  444. {
  445. string[] files = Directory.GetFiles(Paths.ReleaseDir, "*.exe", SearchOption.AllDirectories);
  446. foreach (string file in files)
  447. {
  448. if (Str.InStr(file, "vpnmanual") == false)
  449. {
  450. File.Delete(file);
  451. }
  452. }
  453. }
  454. }
  455. }
  456. // HamCore build utility
  457. public static class HamCoreBuildUtil
  458. {
  459. // Identify whether a file is necessary only in the Win32
  460. public static bool IsFileForOnlyWin32(string filename)
  461. {
  462. string[] filesOnlyWin32 =
  463. {
  464. ".exe",
  465. ".dll",
  466. ".sys",
  467. ".inf",
  468. ".wav",
  469. ".cat",
  470. };
  471. foreach (string ext in filesOnlyWin32)
  472. {
  473. if (filename.EndsWith(ext, StringComparison.InvariantCultureIgnoreCase))
  474. {
  475. return true;
  476. }
  477. }
  478. return false;
  479. }
  480. // Delete svn file
  481. public static void DeleteSVNFilesFromHamCoreBuilder(HamCoreBuilder b)
  482. {
  483. List<string> removeFiles = new List<string>();
  484. foreach (HamCoreBuilderFileEntry f in b.FileList)
  485. {
  486. string name = f.Name;
  487. if (name.StartsWith(".svn", StringComparison.InvariantCultureIgnoreCase) ||
  488. name.IndexOf(@"\.svn", StringComparison.InvariantCultureIgnoreCase) != -1)
  489. {
  490. removeFiles.Add(name);
  491. }
  492. }
  493. foreach (string file in removeFiles)
  494. {
  495. b.DeleteFile(file);
  496. }
  497. }
  498. // Build Hamcore file
  499. public static void BuildHamcore()
  500. {
  501. string srcDirNameBasic = Path.Combine(Paths.BinDirName, "hamcore");
  502. // Create the destination directory
  503. string win32DestDir = Path.Combine(Paths.BuildHamcoreFilesDirName, "hamcore_win32");
  504. string win32DestFileName = Path.Combine(win32DestDir, "hamcore.se2");
  505. string unixDestDir = Path.Combine(Paths.BuildHamcoreFilesDirName, "hamcore_unix");
  506. string unixDestFileName = Path.Combine(unixDestDir, "hamcore.se2");
  507. IO.MakeDir(win32DestDir);
  508. IO.MakeDir(unixDestDir);
  509. BuildHamcoreEx(srcDirNameBasic, win32DestFileName, unixDestFileName);
  510. // Copy to bin\hamcore.se2
  511. try
  512. {
  513. string binHamcoreFileName = Path.Combine(Paths.BinDirName, "hamcore.se2");
  514. try
  515. {
  516. File.Delete(binHamcoreFileName);
  517. }
  518. catch
  519. {
  520. }
  521. File.Copy(win32DestFileName, binHamcoreFileName, true);
  522. }
  523. catch
  524. {
  525. }
  526. }
  527. public static void BuildHamcoreEx(string srcDirNameBasic, string win32DestFileName, string unixDestFileName)
  528. {
  529. HamCoreBuilder b = new HamCoreBuilder();
  530. b.AddDir(srcDirNameBasic);
  531. Con.WriteLine("* Building hamcore ...");
  532. DeleteSVNFilesFromHamCoreBuilder(b);
  533. try
  534. {
  535. File.Delete(win32DestFileName);
  536. }
  537. catch
  538. {
  539. }
  540. b.Build(win32DestFileName);
  541. // unix
  542. List<string> removeFiles = new List<string>();
  543. foreach (HamCoreBuilderFileEntry f in b.FileList)
  544. {
  545. if (IsFileForOnlyWin32(f.Name))
  546. {
  547. removeFiles.Add(f.Name);
  548. }
  549. }
  550. foreach (string removeFile in removeFiles)
  551. {
  552. b.DeleteFile(removeFile);
  553. }
  554. DeleteSVNFilesFromHamCoreBuilder(b);
  555. try
  556. {
  557. File.Delete(unixDestFileName);
  558. }
  559. catch
  560. {
  561. }
  562. b.Build(unixDestFileName);
  563. }
  564. }
  565. // Number of bits
  566. public enum CPUBits
  567. {
  568. Both,
  569. Bits32,
  570. Bits64,
  571. }
  572. // Conversion a string to the number of bits
  573. public static class CPUBitsUtil
  574. {
  575. public static CPUBits StringToCPUBits(string str)
  576. {
  577. if (str.Equals("32bit", StringComparison.InvariantCultureIgnoreCase))
  578. {
  579. return CPUBits.Bits32;
  580. }
  581. else if (str.Equals("64bit", StringComparison.InvariantCultureIgnoreCase))
  582. {
  583. return CPUBits.Bits64;
  584. }
  585. else if (str.Equals("intel", StringComparison.InvariantCultureIgnoreCase))
  586. {
  587. return CPUBits.Both;
  588. }
  589. throw new ApplicationException(string.Format("Invalid bits string '{0}'.", str));
  590. }
  591. public static string CPUBitsToString(CPUBits bits)
  592. {
  593. switch (bits)
  594. {
  595. case CPUBits.Bits32:
  596. return "32bit";
  597. case CPUBits.Bits64:
  598. return "64bit";
  599. case CPUBits.Both:
  600. return "intel";
  601. }
  602. throw new ApplicationException("bits invalid.");
  603. }
  604. }
  605. }