Utilities.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. using Microsoft.Win32;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Management.Automation;
  9. using System.Net;
  10. using System.Net.NetworkInformation;
  11. using System.Reflection;
  12. using System.Security.Principal;
  13. using System.ServiceProcess;
  14. using System.Threading.Tasks;
  15. using System.Windows.Forms;
  16. namespace Optimizer
  17. {
  18. internal static class Utilities
  19. {
  20. internal static readonly string LocalMachineRun = "Software\\Microsoft\\Windows\\CurrentVersion\\Run";
  21. internal static readonly string LocalMachineRunOnce = "Software\\Microsoft\\Windows\\CurrentVersion\\RunOnce";
  22. internal static readonly string LocalMachineRunWoW = "Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Run";
  23. internal static readonly string LocalMachineRunOnceWow = "Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\RunOnce";
  24. internal static readonly string CurrentUserRun = "Software\\Microsoft\\Windows\\CurrentVersion\\Run";
  25. internal static readonly string CurrentUserRunOnce = "Software\\Microsoft\\Windows\\CurrentVersion\\RunOnce";
  26. internal static readonly string LocalMachineStartupFolder = CleanHelper.ProgramData + "\\Microsoft\\Windows\\Start Menu\\Programs\\Startup";
  27. internal static readonly string CurrentUserStartupFolder = CleanHelper.ProfileAppDataRoaming + "\\Microsoft\\Windows\\Start Menu\\Programs\\Startup";
  28. // DEPRECATED
  29. //internal readonly static string DefaultEdgeDownloadFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Downloads");
  30. internal static WindowsVersion CurrentWindowsVersion = WindowsVersion.Unsupported;
  31. internal static Ping pinger = new Ping();
  32. internal delegate void SetControlPropertyThreadSafeDelegate(Control control, string propertyName, object propertyValue);
  33. internal static void SetControlPropertyThreadSafe(Control control, string propertyName, object propertyValue)
  34. {
  35. if (control.InvokeRequired)
  36. {
  37. control.Invoke(new SetControlPropertyThreadSafeDelegate(SetControlPropertyThreadSafe), new object[] { control, propertyName, propertyValue });
  38. }
  39. else
  40. {
  41. control.GetType().InvokeMember(propertyName, BindingFlags.SetProperty, null, control, new object[] { propertyValue });
  42. }
  43. }
  44. internal static IEnumerable<Control> GetSelfAndChildrenRecursive(Control parent)
  45. {
  46. List<Control> controls = new List<Control>();
  47. foreach (Control child in parent.Controls)
  48. {
  49. controls.AddRange(GetSelfAndChildrenRecursive(child));
  50. }
  51. controls.Add(parent);
  52. return controls;
  53. }
  54. internal static Color ToGrayScale(this Color originalColor)
  55. {
  56. if (originalColor.Equals(Color.Transparent))
  57. return originalColor;
  58. int grayScale = (int)((originalColor.R * .299) + (originalColor.G * .587) + (originalColor.B * .114));
  59. return Color.FromArgb(grayScale, grayScale, grayScale);
  60. }
  61. internal static string GetOS()
  62. {
  63. string os = (string)Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "ProductName", "");
  64. if (os.Contains("Windows 7"))
  65. {
  66. CurrentWindowsVersion = WindowsVersion.Windows7;
  67. }
  68. if ((os.Contains("Windows 8")) || (os.Contains("Windows 8.1")))
  69. {
  70. CurrentWindowsVersion = WindowsVersion.Windows8;
  71. }
  72. if (os.Contains("Windows 10"))
  73. {
  74. CurrentWindowsVersion = WindowsVersion.Windows10;
  75. }
  76. if (Program.UNSAFE_MODE)
  77. {
  78. if (os.Contains("Windows Server 2008"))
  79. {
  80. CurrentWindowsVersion = WindowsVersion.Windows7;
  81. }
  82. if (os.Contains("Windows Server 2012"))
  83. {
  84. CurrentWindowsVersion = WindowsVersion.Windows8;
  85. }
  86. if (os.Contains("Windows Server 2016") || os.Contains("Windows Server 2019"))
  87. {
  88. CurrentWindowsVersion = WindowsVersion.Windows10;
  89. }
  90. }
  91. return os;
  92. }
  93. internal static string GetBitness()
  94. {
  95. string bitness = string.Empty;
  96. if (Environment.Is64BitOperatingSystem)
  97. {
  98. bitness = "You are working with 64-bit";
  99. }
  100. else
  101. {
  102. bitness = "You are working with 32-bit";
  103. }
  104. return bitness;
  105. }
  106. internal static bool IsAdmin()
  107. {
  108. return new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator);
  109. }
  110. internal static bool IsCompatible()
  111. {
  112. bool legit;
  113. string os = GetOS();
  114. if ((os.Contains("XP")) || (os.Contains("Vista")) || os.Contains("Server 2003"))
  115. {
  116. legit = false;
  117. }
  118. else
  119. {
  120. legit = true;
  121. }
  122. return legit;
  123. }
  124. // DEPRECATED
  125. //internal static string GetEdgeDownloadFolder()
  126. //{
  127. // string current = string.Empty;
  128. // try
  129. // {
  130. // current = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Edge", "DownloadDirectory", DefaultEdgeDownloadFolder).ToString();
  131. // }
  132. // catch (Exception ex)
  133. // {
  134. // current = DefaultEdgeDownloadFolder;
  135. // ErrorLogger.LogError("Utilities.GetEdgeDownloadFolder", ex.Message, ex.StackTrace);
  136. // }
  137. // return current;
  138. //}
  139. // DEPRECATED
  140. //internal static void SetEdgeDownloadFolder(string path)
  141. //{
  142. // Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Edge", "DownloadDirectory", path, RegistryValueKind.String);
  143. //}
  144. internal static void RunBatchFile(string batchFile)
  145. {
  146. try
  147. {
  148. using (Process p = new Process())
  149. {
  150. p.StartInfo.CreateNoWindow = true;
  151. p.StartInfo.FileName = batchFile;
  152. p.StartInfo.UseShellExecute = false;
  153. p.Start();
  154. p.WaitForExit();
  155. p.Close();
  156. }
  157. }
  158. catch (Exception ex)
  159. {
  160. ErrorLogger.LogError("Utilities.RunBatchFile", ex.Message, ex.StackTrace);
  161. }
  162. }
  163. internal static void ImportRegistryScript(string scriptFile)
  164. {
  165. string path = "\"" + scriptFile + "\"";
  166. Process p = new Process();
  167. try
  168. {
  169. p.StartInfo.FileName = "regedit.exe";
  170. p.StartInfo.UseShellExecute = false;
  171. p = Process.Start("regedit.exe", "/s " + path);
  172. p.WaitForExit();
  173. }
  174. catch (Exception ex)
  175. {
  176. p.Dispose();
  177. ErrorLogger.LogError("Utilities.ImportRegistryScript", ex.Message, ex.StackTrace);
  178. }
  179. finally
  180. {
  181. p.Dispose();
  182. }
  183. }
  184. internal static void Reboot()
  185. {
  186. Utilities.RunCommand("shutdown /r /t 0");
  187. }
  188. internal static void ActivateMainForm()
  189. {
  190. Program.MainForm.Activate();
  191. }
  192. internal static bool ServiceExists(string serviceName)
  193. {
  194. return ServiceController.GetServices().Any(serviceController => serviceController.ServiceName.Equals(serviceName));
  195. }
  196. internal static void StopService(string serviceName)
  197. {
  198. if (ServiceExists(serviceName))
  199. {
  200. ServiceController sc = new ServiceController(serviceName);
  201. if (sc.CanStop)
  202. {
  203. sc.Stop();
  204. }
  205. }
  206. }
  207. internal static void StartService(string serviceName)
  208. {
  209. if (ServiceExists(serviceName))
  210. {
  211. ServiceController sc = new ServiceController(serviceName);
  212. try
  213. {
  214. sc.Start();
  215. }
  216. catch (Exception ex)
  217. {
  218. ErrorLogger.LogError("Utilities.StartService", ex.Message, ex.StackTrace);
  219. }
  220. }
  221. }
  222. private static void GetRegistryStartupItemsHelper(ref List<StartupItem> list, StartupItemLocation location, StartupItemType type)
  223. {
  224. string keyPath = string.Empty;
  225. RegistryKey hive = null;
  226. if (location == StartupItemLocation.HKLM)
  227. {
  228. hive = Registry.LocalMachine;
  229. if (type == StartupItemType.Run)
  230. {
  231. keyPath = LocalMachineRun;
  232. }
  233. else if (type == StartupItemType.RunOnce)
  234. {
  235. keyPath = LocalMachineRunOnce;
  236. }
  237. }
  238. else if (location == StartupItemLocation.HKLMWoW)
  239. {
  240. hive = Registry.LocalMachine;
  241. if (type == StartupItemType.Run)
  242. {
  243. keyPath = LocalMachineRunWoW;
  244. }
  245. else if (type == StartupItemType.RunOnce)
  246. {
  247. keyPath = LocalMachineRunOnceWow;
  248. }
  249. }
  250. else if (location == StartupItemLocation.HKCU)
  251. {
  252. hive = Registry.CurrentUser;
  253. if (type == StartupItemType.Run)
  254. {
  255. keyPath = CurrentUserRun;
  256. }
  257. else if (type == StartupItemType.RunOnce)
  258. {
  259. keyPath = CurrentUserRunOnce;
  260. }
  261. }
  262. if (hive != null)
  263. {
  264. try
  265. {
  266. RegistryKey key = hive.OpenSubKey(keyPath, true);
  267. if (key != null)
  268. {
  269. string[] valueNames = key.GetValueNames();
  270. foreach (string x in valueNames)
  271. {
  272. try
  273. {
  274. RegistryStartupItem item = new RegistryStartupItem();
  275. item.Name = x;
  276. item.FileLocation = key.GetValue(x).ToString();
  277. item.Key = key;
  278. item.RegistryLocation = location;
  279. item.StartupType = type;
  280. list.Add(item);
  281. }
  282. catch (Exception ex)
  283. {
  284. ErrorLogger.LogError("Utilities.GetRegistryStartupItemsHelper", ex.Message, ex.StackTrace);
  285. }
  286. }
  287. }
  288. }
  289. catch (Exception ex)
  290. {
  291. ErrorLogger.LogError("Utilities.GetRegistryStartupItemsHelper", ex.Message, ex.StackTrace);
  292. }
  293. }
  294. }
  295. private static void GetFolderStartupItemsHelper(ref List<StartupItem> list, string[] files, string[] shortcuts)
  296. {
  297. foreach (string file in files)
  298. {
  299. try
  300. {
  301. FolderStartupItem item = new FolderStartupItem();
  302. item.Name = Path.GetFileNameWithoutExtension(file);
  303. item.FileLocation = file;
  304. item.Shortcut = file;
  305. item.RegistryLocation = StartupItemLocation.Folder;
  306. list.Add(item);
  307. }
  308. catch (Exception ex)
  309. {
  310. ErrorLogger.LogError("Utilities.GetFolderStartupItemsHelper", ex.Message, ex.StackTrace);
  311. }
  312. }
  313. foreach (string shortcut in shortcuts)
  314. {
  315. try
  316. {
  317. FolderStartupItem item = new FolderStartupItem();
  318. item.Name = Path.GetFileNameWithoutExtension(shortcut);
  319. item.FileLocation = GetShortcutTargetFile(shortcut);
  320. item.Shortcut = shortcut;
  321. item.RegistryLocation = StartupItemLocation.Folder;
  322. list.Add(item);
  323. }
  324. catch (Exception ex)
  325. {
  326. ErrorLogger.LogError("Utilities.GetFolderStartupItemsHelper", ex.Message, ex.StackTrace);
  327. }
  328. }
  329. }
  330. internal static List<StartupItem> GetStartupItems()
  331. {
  332. List<StartupItem> startupItems = new List<StartupItem>();
  333. GetRegistryStartupItemsHelper(ref startupItems, StartupItemLocation.HKLM, StartupItemType.Run);
  334. GetRegistryStartupItemsHelper(ref startupItems, StartupItemLocation.HKLM, StartupItemType.RunOnce);
  335. GetRegistryStartupItemsHelper(ref startupItems, StartupItemLocation.HKCU, StartupItemType.Run);
  336. GetRegistryStartupItemsHelper(ref startupItems, StartupItemLocation.HKCU, StartupItemType.RunOnce);
  337. if (Environment.Is64BitOperatingSystem)
  338. {
  339. GetRegistryStartupItemsHelper(ref startupItems, StartupItemLocation.HKLMWoW, StartupItemType.Run);
  340. GetRegistryStartupItemsHelper(ref startupItems, StartupItemLocation.HKLMWoW, StartupItemType.RunOnce);
  341. }
  342. if (Directory.Exists(CurrentUserStartupFolder))
  343. {
  344. string[] currentUserFiles = Directory.EnumerateFiles(CurrentUserStartupFolder, "*.*", SearchOption.AllDirectories)
  345. .Where(s => s.EndsWith(".exe") || s.EndsWith(".bat")).ToArray();
  346. string[] currentUserShortcuts = Directory.GetFiles(CurrentUserStartupFolder, "*.lnk", SearchOption.AllDirectories);
  347. GetFolderStartupItemsHelper(ref startupItems, currentUserFiles, currentUserShortcuts);
  348. }
  349. if (Directory.Exists(LocalMachineStartupFolder))
  350. {
  351. string[] localMachineFiles = Directory.EnumerateFiles(LocalMachineStartupFolder, "*.*", SearchOption.AllDirectories)
  352. .Where(s => s.EndsWith(".exe") || s.EndsWith(".bat")).ToArray();
  353. string[] localMachineShortcuts = Directory.GetFiles(LocalMachineStartupFolder, "*.lnk", SearchOption.AllDirectories);
  354. GetFolderStartupItemsHelper(ref startupItems, localMachineFiles, localMachineShortcuts);
  355. }
  356. return startupItems;
  357. }
  358. internal static void EnableFirewall()
  359. {
  360. RunCommand("netsh advfirewall set currentprofile state on");
  361. }
  362. internal static void EnableCommandPrompt()
  363. {
  364. using (RegistryKey key = Registry.CurrentUser.CreateSubKey("Software\\Policies\\Microsoft\\Windows\\System"))
  365. {
  366. key.SetValue("DisableCMD", 0, RegistryValueKind.DWord);
  367. }
  368. }
  369. internal static void EnableControlPanel()
  370. {
  371. using (RegistryKey key = Registry.CurrentUser.CreateSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer"))
  372. {
  373. key.SetValue("NoControlPanel", 0, RegistryValueKind.DWord);
  374. }
  375. }
  376. internal static void EnableFolderOptions()
  377. {
  378. using (RegistryKey key = Registry.CurrentUser.CreateSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer"))
  379. {
  380. key.SetValue("NoFolderOptions", 0, RegistryValueKind.DWord);
  381. }
  382. }
  383. internal static void EnableRunDialog()
  384. {
  385. using (RegistryKey key = Registry.CurrentUser.CreateSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer"))
  386. {
  387. key.SetValue("NoRun", 0, RegistryValueKind.DWord);
  388. }
  389. }
  390. internal static void EnableContextMenu()
  391. {
  392. using (RegistryKey key = Registry.CurrentUser.CreateSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer"))
  393. {
  394. key.SetValue("NoViewContextMenu", 0, RegistryValueKind.DWord);
  395. }
  396. }
  397. internal static void EnableTaskManager()
  398. {
  399. using (RegistryKey key = Registry.CurrentUser.CreateSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System"))
  400. {
  401. key.SetValue("DisableTaskMgr", 0, RegistryValueKind.DWord);
  402. }
  403. }
  404. internal static void EnableRegistryEditor()
  405. {
  406. using (RegistryKey key = Registry.CurrentUser.CreateSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System"))
  407. {
  408. key.SetValue("DisableRegistryTools", 0, RegistryValueKind.DWord);
  409. }
  410. }
  411. internal static void RunCommand(string command)
  412. {
  413. using (Process p = new Process())
  414. {
  415. p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
  416. p.StartInfo.FileName = "cmd.exe";
  417. p.StartInfo.Arguments = "/C " + command;
  418. try
  419. {
  420. p.Start();
  421. p.WaitForExit();
  422. p.Close();
  423. }
  424. catch (Exception ex)
  425. {
  426. ErrorLogger.LogError("Utilities.RunCommand", ex.Message, ex.StackTrace);
  427. }
  428. }
  429. }
  430. internal static void FindFile(string fileName)
  431. {
  432. if (File.Exists(fileName))
  433. {
  434. Process.Start("explorer.exe", "/select, " + fileName);
  435. }
  436. }
  437. internal static string GetShortcutTargetFile(string shortcutFilename)
  438. {
  439. string pathOnly = Path.GetDirectoryName(shortcutFilename);
  440. string filenameOnly = Path.GetFileName(shortcutFilename);
  441. Shell32.Shell shell = new Shell32.Shell();
  442. Shell32.Folder folder = shell.NameSpace(pathOnly);
  443. Shell32.FolderItem folderItem = folder.ParseName(filenameOnly);
  444. if (folderItem != null)
  445. {
  446. Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)folderItem.GetLink;
  447. return link.Path;
  448. }
  449. return string.Empty;
  450. }
  451. internal static void RestartExplorer()
  452. {
  453. const string explorer = "explorer.exe";
  454. string explorerPath = string.Format("{0}\\{1}", Environment.GetEnvironmentVariable("WINDIR"), explorer);
  455. foreach (Process process in Process.GetProcesses())
  456. {
  457. try
  458. {
  459. if (string.Compare(process.MainModule.FileName, explorerPath, StringComparison.OrdinalIgnoreCase) == 0)
  460. {
  461. process.Kill();
  462. }
  463. }
  464. catch (Exception ex)
  465. {
  466. ErrorLogger.LogError("Utilities.RestartExplorer", ex.Message, ex.StackTrace);
  467. }
  468. }
  469. Process.Start(explorer);
  470. }
  471. internal static void FindKeyInRegistry(string key)
  472. {
  473. try
  474. {
  475. Registry.SetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit", "LastKey", key);
  476. Process.Start("regedit");
  477. }
  478. catch (Exception ex)
  479. {
  480. ErrorLogger.LogError("Utilities.FindKeyInRegistry", ex.Message, ex.StackTrace);
  481. }
  482. }
  483. internal static List<string> GetModernApps(bool showAll)
  484. {
  485. List<string> modernApps = new List<string>();
  486. using (PowerShell script = PowerShell.Create())
  487. {
  488. if (showAll)
  489. {
  490. script.AddScript("Get-AppxPackage -AllUsers | Select -Unique Name | Out-String -Stream");
  491. }
  492. else
  493. {
  494. script.AddScript(@"Get-AppxPackage -AllUsers | Where {$_.NonRemovable -like ""False""} | Select -Unique Name | Out-String -Stream");
  495. }
  496. string tmp = string.Empty;
  497. foreach (PSObject x in script.Invoke())
  498. {
  499. tmp = x.ToString().Trim();
  500. if (!string.IsNullOrEmpty(tmp) && !tmp.Contains("---") && !tmp.Equals("Name"))
  501. {
  502. modernApps.Add(tmp);
  503. }
  504. }
  505. }
  506. return modernApps;
  507. }
  508. internal static bool UninstallModernApp(string appName)
  509. {
  510. using (PowerShell script = PowerShell.Create())
  511. {
  512. script.AddScript(string.Format("Get-AppxPackage -AllUsers *{0}* | Remove-AppxPackage", appName));
  513. script.Invoke();
  514. return script.Streams.Error.Count > 0;
  515. // not working on Windows 7 anymore
  516. //return script.HadErrors;
  517. }
  518. }
  519. internal static void ResetConfiguration(bool withoutRestart = false)
  520. {
  521. try
  522. {
  523. Directory.Delete(Required.CoreFolder, true);
  524. }
  525. catch (Exception ex)
  526. {
  527. ErrorLogger.LogError("Utilities.ResetConfiguration", ex.Message, ex.StackTrace);
  528. }
  529. finally
  530. {
  531. if (withoutRestart == false) Application.Restart();
  532. }
  533. }
  534. internal static Task RunAsync(this Process process)
  535. {
  536. var tcs = new TaskCompletionSource<object>();
  537. process.EnableRaisingEvents = true;
  538. process.Exited += (s, e) => tcs.TrySetResult(null);
  539. if (!process.Start()) tcs.SetException(new Exception("Failed to start process."));
  540. return tcs.Task;
  541. }
  542. internal static PingReply PingHost(string nameOrAddress)
  543. {
  544. PingReply reply;
  545. try
  546. {
  547. reply = pinger.Send(nameOrAddress);
  548. return reply;
  549. }
  550. catch
  551. {
  552. return null;
  553. }
  554. }
  555. internal static bool IsInternetAvailable()
  556. {
  557. const int timeout = 1000;
  558. const string host = "1.1.1.1";
  559. var ping = new Ping();
  560. var buffer = new byte[32];
  561. var pingOptions = new PingOptions();
  562. try
  563. {
  564. var reply = ping.Send(host, timeout, buffer, pingOptions);
  565. return (reply != null && reply.Status == IPStatus.Success);
  566. }
  567. catch (Exception)
  568. {
  569. return false;
  570. }
  571. }
  572. internal static void FlushDNSCache()
  573. {
  574. Utilities.RunCommand("ipconfig /release && ipconfig /flushdns && ipconfig /renew");
  575. }
  576. internal static string SanitizeFileFolderName(string fileName)
  577. {
  578. char[] invalids = Path.GetInvalidFileNameChars();
  579. return string.Join("_", fileName.Split(invalids, StringSplitOptions.RemoveEmptyEntries)).TrimEnd('.');
  580. }
  581. internal static void SpeedTest()
  582. {
  583. byte[] data;
  584. WebClient client = new WebClient();
  585. client.Encoding = System.Text.Encoding.UTF8;
  586. Stopwatch sw = Stopwatch.StartNew();
  587. data = client.DownloadData("https://github-releases.githubusercontent.com/95730276/f421f880-bfcd-11eb-82bb-2f6f76a46055?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20210603%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20210603T202732Z&X-Amz-Expires=300&X-Amz-Signature=97db99e398122aa3b582884f6aab00447d76130ec80951764cbd204a6455f920&X-Amz-SignedHeaders=host&actor_id=3146835&key_id=0&repo_id=95730276&response-content-disposition=attachment%3B%20filename%3D91.0.4472.77_ungoogled_mini_installer.exe&response-content-type=application%2Foctet-stream");
  588. sw.Stop();
  589. var speed = (long)(data.LongLength / sw.Elapsed.TotalSeconds);
  590. MessageBox.Show(ByteSize.FromBytes(speed).KiloBytes.ToString());
  591. }
  592. }
  593. }