/// <summary> /// Initializes a new instance of the <see cref="WebClientEx"/> class. /// </summary> /// <param name="allowAutoRedirect"> /// <see langword="true"/> to indicate that the request should follow /// redirection responses; otherwise, <see langword="false"/>. /// </param> /// <param name="cookieContainer"> /// The cookies associated with the request. /// </param> /// <param name="timeout"> /// The time-out value in milliseconds for the /// <see cref="HttpWebRequest.GetResponse()"/> and /// <see cref="HttpWebRequest.GetRequestStream()"/> methods. /// </param> public WebClientEx(bool allowAutoRedirect = true, CookieContainer cookieContainer = null, int timeout = 60000) { NetEx.EnsureDefaultSecurityProtocol(); AllowAutoRedirect = allowAutoRedirect; CookieContainer = cookieContainer; Timeout = timeout; }
private void DownloadForm_Load(object sender, EventArgs e) { try { string source; if (!NetEx.InternetIsAvailable() || string.IsNullOrWhiteSpace(source = NetEx.Transfer.DownloadString($"{Resources.UpdateUrl}/{Resources.HashFile}"))) { MessageBoxEx.Show(this, Resources.Msg_Err_00, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning); Application.Exit(); return; } var file = string.Empty; foreach (var str in source.Split(' ')) { if (string.IsNullOrWhiteSpace(str) || str.ContainsEx(Resources.SearchBlacklist.SplitNewLine()) || !str.ContainsEx(Resources.SearchMatch)) { continue; } file = str; } if (!file.EndsWithEx(".zip")) { file = file.Substring(0, file.Length - new Crypto.Sha1().HashLength).Trim(); } _transfer.DownloadFile($"{Resources.UpdateUrl}/{file}", PathEx.Combine(PathEx.LocalDir, file)); CheckDownload.Enabled = true; } catch { Process.Start(Resources.UpdateUrl); } }
static void Main(string[] args) { XmlConfigurator.ConfigureAndWatch(new FileInfo("_trace.config")); var options = new StartOptions(); options.Urls.Add("http://" + NetEx.GetCurrentHostName() + ":8077"); options.Urls.Add("http://localhost:8077"); options.Urls.Add("http://*:8077"); #if DEBUG WatchViews(); #endif using (WebApp.Start <Startup>(options)) { Logging.Log.Info("Starter server at : " + options.Urls.ToCsv()); new Monitor().Start(); var e = new Exception("something wrong has happened"); Logging.Log.Error("Exception", e); string entered = ""; while (entered != "q") { Console.Write("enter a message to broadcast, 'q' to quit : "); entered = Console.ReadLine(); var context = GlobalHost.ConnectionManager.GetHubContext <notifyhub>(); context.Clients.All.show("server", entered); Logging.Log.Info(entered); } } }
private void SetUpdateInfo(bool final, params string[] mirrors) { if (mirrors?.Any() != true) { return; } foreach (var mirror in mirrors) { try { var path = PathEx.AltCombine(mirror, "Last.ini"); if (!NetEx.FileIsAvailable(path, 60000, UserAgents.Internal)) { throw new PathNotFoundException(path); } var data = WebTransfer.DownloadString(path, 60000, UserAgents.Internal); if (string.IsNullOrWhiteSpace(data)) { throw new ArgumentNullException(nameof(data)); } var lastStamp = Ini.ReadOnly("Info", "LastStamp", data); if (string.IsNullOrWhiteSpace(lastStamp)) { throw new ArgumentNullException(nameof(lastStamp)); } path = PathEx.AltCombine(mirror, $"{lastStamp}.ini"); if (!NetEx.FileIsAvailable(path, 60000, UserAgents.Internal)) { throw new PathNotFoundException(path); } data = WebTransfer.DownloadString(path, 60000, UserAgents.Internal); if (string.IsNullOrWhiteSpace(data)) { throw new ArgumentNullException(nameof(data)); } HashInfo = data; if (final) { LastFinalStamp = lastStamp; } else { LastStamp = lastStamp; } } catch (Exception ex) when(ex.IsCaught()) { Log.Write(ex); } if (!string.IsNullOrWhiteSpace(HashInfo)) { break; } } }
private void UpdateBtn_Click(object sender, EventArgs e) { var dialog = MessageBoxEx.Show(this, Resources.Msg_Ask_01, Resources.WindowTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dialog != DialogResult.Yes) { MessageBoxEx.Show(this, Resources.Msg_Hint_02, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } if (!NetEx.InternetIsAvailable()) { MessageBoxEx.Show(this, Resources.Msg_Err_00, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } try { var source = NetEx.Transfer.DownloadString($"{Resources.UpdateUrl}/{Resources.HashFile}"); var version = FileVersionInfo.GetVersionInfo(_appPath).ProductVersion; if (source.Contains($"{Resources.AppName}-{version}-")) { throw new ArgumentException(); } dialog = MessageBoxEx.Show(this, Resources.Msg_Ask_02, Resources.WindowTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk); if (dialog != DialogResult.Yes) { throw new WarningException(); } var dir = Path.GetDirectoryName(_appPath); if (Directory.Exists(dir)) { Directory.Delete(dir, true); } if (!CheckDownload.Enabled) { CheckDownload.Enabled = true; } _downloadForm.Show(this); WinApi.NativeHelper.CenterWindow(_downloadForm.Handle, Handle); } catch (WarningException) { MessageBoxEx.Show(this, Resources.Msg_Hint_02, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } catch (Exception) { MessageBoxEx.Show(this, Resources.Msg_Hint_00, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } }
public void StartDownload(bool force = false) { DownloadStarted = false; if (Transfer.IsBusy) { if (!force) { return; } Transfer.CancelAsync(); } for (var i = 0; i < SrcData.Count; i++) { var(item1, item2, item3, item4) = SrcData[i]; if (item4) { continue; } if (!FileEx.Delete(DestPath)) { throw new InvalidOperationException(); } SrcData[i] = Tuple.Create(item1, item2, item3, true); var userAgent = item3; if (!NetEx.FileIsAvailable(item1, UserData.Item1, UserData.Item2, 60000, userAgent)) { userAgent = UserAgents.WindowsChrome; if (!NetEx.FileIsAvailable(item1, UserData.Item1, UserData.Item2, 60000, userAgent)) { if (Log.DebugMode > 0) { Log.Write($"Transfer: Could not find target '{item1}'."); } continue; } } if (Log.DebugMode > 0) { Log.Write($"Transfer{(!string.IsNullOrEmpty(userAgent) ? $" [{userAgent}]" : string.Empty)}: '{item1}' has been found."); } Transfer.DownloadFile(item1, DestPath, UserData.Item1, UserData.Item2, true, 60000, userAgent, false); DownloadStarted = true; } }
private static void UpdateAppImagesFile(bool large) { var filePath = large ? CachePaths.AppImagesLarge : CachePaths.AppImages; var fileName = Path.GetFileName(filePath); if (string.IsNullOrEmpty(fileName)) { return; } var fileDate = File.Exists(filePath) ? File.GetLastWriteTime(filePath) : DateTime.MinValue; foreach (var mirror in AppSupply.GetMirrors(AppSuppliers.Internal)) { var link = PathEx.AltCombine(mirror, ".free", fileName); if (Log.DebugMode > 0) { Log.Write($"Cache: Looking for '{link}'."); } if (!NetEx.FileIsAvailable(link, 30000, UserAgents.Internal)) { continue; } if (!((NetEx.GetFileDate(link, 30000, UserAgents.Internal) - fileDate).TotalSeconds > 0d)) { break; } NetEx.Transfer.DownloadFile(link, filePath, 60000, UserAgents.Internal, false); if (!File.Exists(filePath)) { continue; } File.SetLastWriteTime(filePath, DateTime.Now); if (Log.DebugMode > 0) { Log.Write($"Cache: '{filePath}' has been updated."); } break; } }
private void MainForm_Load(object sender, EventArgs e) { Text = Resources.WindowTitle; TaskBar.Progress.SetState(Handle, TaskBar.Progress.Flags.Indeterminate); if (!NetEx.InternetIsAvailable()) { if (!_silent || !File.Exists(_appPath)) { MessageBoxEx.Show(Resources.Msg_Err_00, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } Application.Exit(); return; } var localDate = File.GetLastWriteTime(_appPath); var onlineDate = NetEx.GetFileDate(Resources.UpdateUrl, Resources.UserAgent); if ((onlineDate - localDate).Days > 0) { if (_silent || MessageBoxEx.Show(Resources.Msg_Hint_00, Resources.WindowTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { var archivePath = PathEx.Combine(PathEx.LocalDir, $"..\\{PathEx.GetTempFileName()}"); if (!File.Exists(archivePath)) { _transfer.DownloadFile(Resources.UpdateUrl, archivePath); Opacity = 1f; CheckDownload.Enabled = true; return; } ExtractDownload.RunWorkerAsync(); } Application.Exit(); return; } if (!_silent) { MessageBoxEx.Show(Resources.Msg_Hint_01, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Information); } Application.Exit(); }
internal static void DownloadArchiver() { var notifyBox = new NotifyBox(); notifyBox.Show(Language.GetText(nameof(en_US.InitRequirementsNotify)), Resources.GlobalTitle, NotifyBoxStartPosition.Center); var mirrors = NetEx.InternalDownloadMirrors; var verMap = new Dictionary <string, string>(); foreach (var mirror in mirrors) { try { var url = PathEx.AltCombine(mirror, ".redists", "Extra", "Last.ini"); if (!NetEx.FileIsAvailable(url, 30000)) { throw new PathNotFoundException(url); } var data = WebTransfer.DownloadString(url); if (string.IsNullOrWhiteSpace(data)) { throw new ArgumentNullException(nameof(data)); } const string name = "7z"; if (string.IsNullOrEmpty(name)) { continue; } var version = Ini.ReadOnly(name, "Version", data); if (string.IsNullOrWhiteSpace(version)) { continue; } verMap.Add(name, version); } catch (Exception ex) when(ex.IsCaught()) { Log.Write(ex); } if (verMap.Count > 0) { break; } } foreach (var map in verMap) { var file = $"{map.Value}.zip"; var path = PathEx.Combine(CachePaths.UpdateDir, file); foreach (var mirror in mirrors) { try { var url = PathEx.AltCombine(mirror, ".redists", "Extra", map.Key, file); if (!NetEx.FileIsAvailable(url, 30000)) { throw new PathNotFoundException(url); } WebTransfer.DownloadFile(url, path); Compaction.Unzip(path, CachePaths.UpdateDir); } catch (Exception ex) when(ex.IsCaught()) { Log.Write(ex); } if (File.Exists(path)) { break; } } } notifyBox.Close(); }
private void MainForm_Load(object sender, EventArgs e) { Text = Resources.WindowTitle; TaskBar.Progress.SetState(Handle, TaskBar.Progress.Flags.Indeterminate); if (!NetEx.InternetIsAvailable()) { if (!_silent || !File.Exists(_appPath)) { MessageBoxEx.Show(Resources.Msg_Err_00, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } Application.Exit(); return; } string updUrl = null; try { var regexUrl = Resources.RegexUrl; if (!Ini.ReadDirect("Settings", "BetaUpdates").EqualsEx("1", "True")) { regexUrl += "/latest"; } var source = NetEx.Transfer.DownloadString(regexUrl); if (string.IsNullOrWhiteSpace(source)) { throw new ArgumentNullException(nameof(source)); } source = TextEx.FormatNewLine(source); #if x86 const string arch = "32"; #else const string arch = "64"; #endif source = source.SplitNewLine().Where(x => x.ContainsEx(Resources.SearchPrefix) && x.ContainsEx(string.Format(Resources.SearchSuffix, arch))).Take(1).Join(); foreach (Match match in Regex.Matches(source, Resources.RegexPattern, RegexOptions.Singleline)) { var mPath = match.Groups[1].ToString(); if (string.IsNullOrWhiteSpace(mPath) || mPath.Count(c => c == '/') != 1) { continue; } updUrl = string.Format(Resources.UpdateUrl, mPath); break; } if (!NetEx.FileIsAvailable(updUrl, 60000, Resources.UserAgent)) { throw new PathNotFoundException(updUrl); } } catch (Exception ex) { Log.Write(ex); if (!_silent || !File.Exists(_appPath)) { MessageBoxEx.Show(Resources.Msg_Warn_01, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning); } Application.Exit(); } var localDate = File.GetLastWriteTime(_appPath); var onlineDate = NetEx.GetFileDate(updUrl, Resources.UserAgent); if ((onlineDate - localDate).Days > 0) { if (_silent || MessageBoxEx.Show(Resources.Msg_Hint_00, Resources.WindowTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { var archivePath = PathEx.Combine(PathEx.LocalDir, $"..\\{PathEx.GetTempFileName()}"); if (!File.Exists(archivePath)) { _tmpDir = PathEx.Combine(Path.GetTempPath(), PathEx.GetTempDirName(Resources.AppName)); var hlpPath = Path.Combine(_tmpDir, "7z.zip"); ResourcesEx.Extract(Resources._7z, hlpPath, true); Compaction.Unzip(hlpPath, _tmpDir); _transfer.DownloadFile(updUrl, archivePath); Opacity = 1f; CheckDownload.Enabled = true; return; } ExtractDownload.RunWorkerAsync(); } Application.Exit(); return; } if (!_silent) { MessageBoxEx.Show(Resources.Msg_Hint_01, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Information); } Application.Exit(); }
private void UpdateBtn_Click(object sender, EventArgs e) { var owner = sender as Button; if (owner == null) { return; } owner.Enabled = false; string downloadPath = null; if (!string.IsNullOrWhiteSpace(_lastStamp)) { try { downloadPath = PathEx.AltCombine(Resources.GitRawProfileUri, Resources.GitSnapshotsPath, $"{_lastStamp}.7z"); if (!NetEx.FileIsAvailable(downloadPath, 60000)) { throw new PathNotFoundException(downloadPath); } } catch (Exception ex) { Log.Write(ex); downloadPath = null; } } if (string.IsNullOrWhiteSpace(downloadPath)) { try { var exist = false; foreach (var mirror in DownloadMirrors) { downloadPath = PathEx.AltCombine(mirror, Resources.ReleasePath, $"{_lastFinalStamp}.7z"); exist = NetEx.FileIsAvailable(downloadPath, 60000); if (exist) { break; } } if (!exist) { throw new PathNotFoundException(downloadPath); } } catch (Exception ex) { Log.Write(ex); downloadPath = null; } } if (!string.IsNullOrWhiteSpace(downloadPath)) { try { if (_updatePath.ContainsEx(HomeDir)) { throw new NotSupportedException(); } var updDir = Path.GetDirectoryName(UpdateDir); if (!string.IsNullOrEmpty(updDir)) { foreach (var dir in Directory.GetDirectories(updDir, "PortableAppsSuite-{*}", SearchOption.TopDirectoryOnly)) { Directory.Delete(dir, true); } } if (!Directory.Exists(UpdateDir)) { Directory.CreateDirectory(UpdateDir); } foreach (var file in new[] { "7z.dll", "7zG.exe" }) { var path = PathEx.Combine(PathEx.LocalDir, "Helper\\7z"); if (Environment.Is64BitOperatingSystem) { path = Path.Combine(path, "x64"); } path = Path.Combine(path, file); File.Copy(path, Path.Combine(UpdateDir, file)); } } catch (Exception ex) { Log.Write(ex, true); return; } } try { _transfer.DownloadFile(downloadPath, _updatePath); checkDownload.Enabled = true; } catch (Exception ex) { Log.Write(ex, true); } }
private void MainForm_Load(object sender, EventArgs e) { FormEx.Dockable(this); Lang.SetControlLang(this); // Check internet connection if (!(_ipv4 = NetEx.InternetIsAvailable()) && !(_ipv6 = NetEx.InternetIsAvailable(true))) { Environment.ExitCode = 1; Application.Exit(); return; } // Get update infos from GitHub if enabled if (Ini.Read("Settings", "UpdateChannel", 0) > 0) { if (!_ipv4 && _ipv6) { Environment.ExitCode = 1; Application.Exit(); return; } try { var path = PathEx.AltCombine(Resources.GitRawProfileUri, Resources.GitSnapshotsPath, "Last.ini"); if (!NetEx.FileIsAvailable(path, 60000)) { throw new PathNotFoundException(path); } var data = NetEx.Transfer.DownloadString(path); if (string.IsNullOrWhiteSpace(data)) { throw new ArgumentNullException(nameof(data)); } _lastStamp = Ini.ReadOnly("Info", "LastStamp", data); if (string.IsNullOrWhiteSpace(_lastStamp)) { throw new ArgumentNullException(_lastStamp); } path = PathEx.AltCombine(Resources.GitRawProfileUri, Resources.GitSnapshotsPath, $"{_lastStamp}.ini"); if (!NetEx.FileIsAvailable(path, 60000)) { throw new PathNotFoundException(path); } data = NetEx.Transfer.DownloadString(path); if (string.IsNullOrWhiteSpace(data)) { throw new ArgumentNullException(nameof(data)); } _hashInfo = data; } catch (Exception ex) { Log.Write(ex); } } // Get update infos if not already set if (string.IsNullOrWhiteSpace(_hashInfo)) { // Get available download mirrors var dnsInfo = string.Empty; for (var i = 0; i < 3; i++) { if (!_ipv4 && _ipv6) { dnsInfo = Resources.IPv6DNS; break; } try { var path = PathEx.AltCombine(Resources.GitRawProfileUri, Resources.GitDnsPath); if (!NetEx.FileIsAvailable(path, 60000)) { throw new PathNotFoundException(path); } var data = NetEx.Transfer.DownloadString(path); if (string.IsNullOrWhiteSpace(data)) { throw new ArgumentNullException(nameof(data)); } dnsInfo = data; } catch (Exception ex) { Log.Write(ex); } if (string.IsNullOrWhiteSpace(dnsInfo) && i < 2) { Thread.Sleep(1000); continue; } break; } if (!string.IsNullOrWhiteSpace(dnsInfo)) { foreach (var section in Ini.GetSections(dnsInfo)) { var addr = Ini.Read(section, _ipv4 ? "addr" : "ipv6", dnsInfo); if (string.IsNullOrEmpty(addr)) { continue; } var domain = Ini.Read(section, "domain", dnsInfo); if (string.IsNullOrEmpty(domain)) { continue; } var ssl = Ini.ReadOnly(section, "ssl", false, dnsInfo); domain = PathEx.AltCombine(ssl ? "https:" : "http:", domain); if (!DownloadMirrors.ContainsEx(domain)) { DownloadMirrors.Add(domain); } } } if (DownloadMirrors.Count == 0) { Environment.ExitCode = 1; Application.Exit(); return; } // Get file hashes foreach (var mirror in DownloadMirrors) { try { var path = PathEx.AltCombine(mirror, Resources.ReleasePath, "Last.ini"); if (!NetEx.FileIsAvailable(path, 60000)) { throw new PathNotFoundException(path); } var data = NetEx.Transfer.DownloadString(path); if (string.IsNullOrWhiteSpace(data)) { throw new ArgumentNullException(nameof(data)); } _lastFinalStamp = Ini.ReadOnly("Info", "LastStamp", data); if (string.IsNullOrWhiteSpace(_lastFinalStamp)) { throw new ArgumentNullException(nameof(_lastFinalStamp)); } path = PathEx.AltCombine(mirror, Resources.ReleasePath, $"{_lastFinalStamp}.ini"); if (!NetEx.FileIsAvailable(path, 60000)) { throw new PathNotFoundException(path); } data = NetEx.Transfer.DownloadString(path); if (string.IsNullOrWhiteSpace(data)) { throw new ArgumentNullException(nameof(data)); } _hashInfo = data; } catch (Exception ex) { Log.Write(ex); } if (!string.IsNullOrWhiteSpace(_hashInfo)) { break; } } } if (string.IsNullOrWhiteSpace(_hashInfo)) { Environment.ExitCode = 1; Application.Exit(); return; } // Compare hashes var updateAvailable = false; try { foreach (var key in Ini.GetKeys("SHA256", _hashInfo)) { var file = Path.Combine(HomeDir, $"{key}.exe"); if (!File.Exists(file)) { file = PathEx.Combine(PathEx.LocalDir, $"{key}.exe"); } if (Ini.Read("SHA256", key, _hashInfo).EqualsEx(Crypto.EncryptFileToSha256(file))) { continue; } updateAvailable = true; break; } } catch (Exception ex) { Log.Write(ex); Environment.ExitCode = 1; Application.Exit(); return; } // Install updates if (updateAvailable) { if (MessageBox.Show(Lang.GetText(nameof(en_US.UpdateAvailableMsg)), Text, MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { // Update changelog if (DownloadMirrors.Count > 0) { var changes = string.Empty; foreach (var mirror in DownloadMirrors) { var path = PathEx.AltCombine(mirror, Resources.ReleasePath, "ChangeLog.txt"); if (string.IsNullOrWhiteSpace(path)) { continue; } if (!NetEx.FileIsAvailable(path, 60000)) { continue; } changes = NetEx.Transfer.DownloadString(path); if (!string.IsNullOrWhiteSpace(changes)) { break; } } if (!string.IsNullOrWhiteSpace(changes)) { changeLog.Font = new Font("Consolas", 8.25f); changeLog.Text = TextEx.FormatNewLine(changes); var colorMap = new Dictionary <Color, string[]> { { Color.PaleGreen, new[] { " PORTABLE APPS SUITE", " UPDATED:", " CHANGES:" } }, { Color.SkyBlue, new[] { " Global:", " Apps Launcher:", " Apps Downloader:", " Apps Suite Updater:" } }, { Color.Khaki, new[] { "Version History:" } }, { Color.Plum, new[] { "{", "}", "(", ")", "|", ".", "-" } }, { Color.Tomato, new[] { " * " } }, { Color.Black, new[] { new string('_', 84) } } }; foreach (var line in changeLog.Text.Split('\n')) { if (line.Length < 1 || !DateTime.TryParseExact(line.Trim(' ', ':'), "d MMMM yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime _)) { continue; } changeLog.MarkText(line, Color.Khaki); } foreach (var color in colorMap) { foreach (var s in color.Value) { changeLog.MarkText(s, color.Key); } } } } else { changeLog.Dock = DockStyle.None; changeLog.Size = new Size(changeLogPanel.Width, TextRenderer.MeasureText(changeLog.Text, changeLog.Font).Height); changeLog.Location = new Point(0, changeLogPanel.Height / 2 - changeLog.Height - 16); changeLog.SelectAll(); changeLog.SelectionAlignment = HorizontalAlignment.Center; changeLog.DeselectAll(); } ShowInTaskbar = true; return; } } // Exit the application if no updates were found Environment.ExitCode = 2; Application.Exit(); }
private static void Main() { Log.AllowLogging(); using (new Mutex(true, Process.GetCurrentProcess().ProcessName, out bool newInstance)) { if (!newInstance) { return; } #if x86 var curPath64 = PathEx.Combine(PathEx.LocalDir, "TS3Client64Portable.exe"); if (Environment.Is64BitOperatingSystem && File.Exists(curPath64)) { ProcessEx.Start(curPath64, EnvironmentEx.CommandLine()); return; } var appDir = PathEx.Combine(PathEx.LocalDir, "App\\ts3_x86"); var appPath = PathEx.Combine(appDir, "ts3client_win32.exe"); const string appName = "ts3client_win32"; #else var appDir = PathEx.Combine(PathEx.LocalDir, "App\\ts3_x64"); var appPath = PathEx.Combine(appDir, "ts3client_win64.exe"); const string appName = "ts3client_win64"; #endif var updPath = PathEx.Combine(appDir, "update.exe"); if (!File.Exists(updPath) || ProcessEx.IsRunning(appName)) { return; } var iniPath = Path.ChangeExtension(PathEx.LocalPath, ".ini"); if (string.IsNullOrEmpty(iniPath)) { return; } if (!File.Exists(iniPath)) { var iniContent = new[] { "[Settings]", "", "; True to hide TeamSpeak on the Windows taskbar; otherwise, False.", "HideInTaskBar=False", "", "; Time (in milliseconds) to wait for a network connection before TeamSpeak is started.", "; This option can be useful for the Windows autorun feature. If TeamSpeak is started", "; before the network connection is available, the connection is failed and no replay", "; occurs.", "WaitForNetwork=0", "", "; Sets the window state of TeamSpeak. Options: Maximized, Minimized or Normal.", "WinState=Normal" }; File.WriteAllLines(iniPath, iniContent); } var time = Ini.Read("Settings", "WaitForNetwork", 0, iniPath); if (time > 300000) { time = 300000; } if (time.IsBetween(1, 300000)) { for (var i = 0; i < time; i++) { if (NetEx.InternetIsAvailable()) { break; } Thread.Sleep(1); } } var dirMap = new Dictionary <string, string> { { PathEx.Combine(appDir, "config"), "%CurDir%\\Data" }, { "%LocalAppData%\\TeamSpeak 3", "%CurDir%\\Data\\Temp" }, { "%UserProfile%\\.TeamSpeak 3", "%CurDir%\\Data\\Temp\\.TeamSpeak 3" } }; Helper.DirectoryForwarding(Helper.Options.Start, dirMap); var regKeys = new[] { "HKCU\\Software\\TeamSpeak 3 Client", "HKCR\\.ts3_addon", "HKCR\\.ts3_iconpack", "HKCR\\.ts3_plugin", "HKCR\\.ts3_soundpack", "HKCR\\.ts3_style", "HKCR\\.ts3_translation", "HKCR\\ts3addon" }; var firstKey = regKeys.LastOrDefault(); Helper.RegForwarding(Helper.Options.Start, firstKey); Reg.Write(firstKey, null, appDir); Reg.Write(firstKey, "ConfigLocation", 1, RegistryValueKind.String); Process appProcess = null; if (File.Exists(appPath)) { appProcess = ProcessEx.Start(appPath, EnvironmentEx.CommandLine(false), Elevation.IsAdministrator, false); } else { ProcessEx.Start(updPath, Elevation.IsAdministrator, false)?.WaitForExit(); } var wrapper = PathEx.Combine(appDir, "createfileassoc.exe"); var hide = Ini.Read("Settings", "HideInTaskBar", false, iniPath); var state = Ini.Read("Settings", "WinState", iniPath); var enable = state.EqualsEx("Maximized", "Minimized", iniPath); if (appProcess == null) { goto Second; } First: while (!appProcess.HasExited) { appProcess.WaitForExit(1000); if (File.Exists(wrapper) && !Crypto.EncryptFileToMd5(wrapper).EqualsEx("cdbe3628ca898a852502c8ae897e5a54")) { try { File.WriteAllBytes(wrapper, Resources.EmptyWrapper); } catch (Exception ex) { Log.Write(ex); } } if (!hide && !enable) { continue; } var hWnd = WinApi.NativeHelper.FindWindowByCaption("TeamSpeak 3"); if (hWnd == IntPtr.Zero) { continue; } if (hide) { hide = false; TaskBar.DeleteTab(hWnd); } if (!enable) { continue; } enable = false; WinApi.NativeHelper.ShowWindowAsync(hWnd, state.EqualsEx("Minimized") ? WinApi.ShowWindowFlags.ShowMinimized : WinApi.ShowWindowFlags.ShowMaximized); } while (ProcessEx.IsRunning(appName)) { Thread.Sleep(200); } Second: for (var i = 0; i < 10; i++) { while (ProcessEx.IsRunning(updPath) || WinApi.NativeHelper.FindWindowByCaption("TeamSpeak 3 Client Update") != IntPtr.Zero) { Thread.Sleep(200); } if (ProcessEx.IsRunning(appName)) { appProcess = Process.GetProcessesByName(appName).FirstOrDefault(); if (appProcess == null) { break; } hide = Ini.Read("Settings", "HideInTaskBar", false, iniPath); enable = state.EqualsEx("Maximized", "Minimized", iniPath); goto First; } Thread.Sleep(250); } Helper.DirectoryForwarding(Helper.Options.Exit, dirMap); Helper.RegForwarding(Helper.Options.Exit, firstKey); var rootKeys = regKeys.Skip(1).ToArray(); if (rootKeys.Any(Reg.SubKeyExists)) { var regSecureMap = rootKeys.ToDictionary <string, string, Dictionary <string, string> >(x => $"-{x}", x => null); Helper.RegSecureOverwrite(regSecureMap, true); } try { var qtWebEngineCacheDir = PathEx.Combine("%UserProfile%\\.QtWebEngineProcess"); if (Directory.Exists(qtWebEngineCacheDir)) { Directory.Delete(qtWebEngineCacheDir, true); } var owInstallerPath = Path.Combine(appDir, "OverwolfTeamSpeakInstaller.exe"); if (File.Exists(owInstallerPath)) { File.Delete(owInstallerPath); } } catch (Exception ex) { Log.Write(ex); } } }
private void MainForm_Load(object sender, EventArgs e) { Text = Resources.WindowTitle; TaskBar.Progress.SetState(Handle, TaskBar.Progress.Flags.Indeterminate); if (!NetEx.InternetIsAvailable()) { if (!_silent || !File.Exists(_appPath)) { MessageBoxEx.Show(Resources.Msg_Err_00, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } Application.Exit(); return; } string updUrl = null; try { var source = NetEx.Transfer.DownloadString(Resources.RegexUrl); if (string.IsNullOrWhiteSpace(source)) { throw new ArgumentNullException(nameof(source)); } var paths = new Dictionary <Version, string>(); foreach (Match match in Regex.Matches(source, Resources.RegexPattern, RegexOptions.Singleline)) { var mPath = match.Groups[1].ToString(); if (string.IsNullOrWhiteSpace(mPath) || mPath.Count(c => c == '/') != 1) { continue; } var mVer = mPath.Split('/').FirstOrDefault(); if (string.IsNullOrEmpty(mVer) || !mVer.All(c => char.IsDigit(c) || c == '.')) { continue; } if (!Version.TryParse(mVer, out Version ver) || paths.ContainsKey(ver)) { continue; } paths.Add(ver, mPath); } updUrl = string.Format(Resources.UpdateUrl, paths[paths.Keys.Max()]); if (!NetEx.FileIsAvailable(updUrl, 60000, Resources.UserAgent)) { throw new PathNotFoundException(updUrl); } } catch (Exception ex) { Log.Write(ex); if (!_silent || !File.Exists(_appPath)) { MessageBoxEx.Show(Resources.Msg_Warn_01, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning); } Application.Exit(); } var localDate = File.GetLastWriteTime(_appPath); var onlineDate = NetEx.GetFileDate(updUrl, Resources.UserAgent); if ((onlineDate - localDate).Days > 0) { if (_silent || MessageBoxEx.Show(Resources.Msg_Hint_00, Resources.WindowTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { var archivePath = PathEx.Combine(PathEx.LocalDir, $"..\\{PathEx.GetTempFileName()}"); if (!File.Exists(archivePath)) { _tmpDir = PathEx.Combine(Path.GetTempPath(), PathEx.GetTempDirName(Resources.AppName)); var hlpPath = Path.Combine(_tmpDir, "iu.zip"); ResourcesEx.Extract(Resources.iu, hlpPath, true); Compaction.Unzip(hlpPath, _tmpDir); _transfer.DownloadFile(updUrl, archivePath); Opacity = 1f; CheckDownload.Enabled = true; return; } ExtractDownload.RunWorkerAsync(); } Application.Exit(); return; } if (!_silent) { MessageBoxEx.Show(Resources.Msg_Hint_01, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Information); } Application.Exit(); }
private void MainForm_Load(object sender, EventArgs e) { Text = Resources.WindowTitle; TaskBar.Progress.SetState(Handle, TaskBar.Progress.Flags.Indeterminate); if (!NetEx.InternetIsAvailable()) { if (!_silent || !File.Exists(_appPath)) { MessageBoxEx.Show(Resources.Msg_Err_00, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } Application.Exit(); return; } var source = NetEx.Transfer.DownloadString(Resources.RegexUrl); string updUrl = null; try { var urls = new List <string>(); var vers = new List <Version>(); var pattern = string.Format(Resources.RegexFileNamePattern, #if !x86 "64", "and 64 bit games" #else "32", "bit games only" #endif ); foreach (Match match in Regex.Matches(source, pattern, RegexOptions.Multiline)) { var mName = match.Groups[1].ToString(); if (string.IsNullOrWhiteSpace(mName) || !mName.ContainsEx(Resources.AppName)) { continue; } var mVer = mName.Split('/').FirstOrDefault()?.Trim(); if (string.IsNullOrWhiteSpace(mVer)) { continue; } if (!Version.TryParse(mVer, out Version ver)) { continue; } urls.Add(string.Format(Resources.UpdateUrl, mName, #if !x86 "64" #else "32" #endif )); vers.Add(ver); } updUrl = urls.First(x => x.ContainsEx(vers.Max().ToString())); if (!NetEx.FileIsAvailable(updUrl, 60000, Resources.UserAgent)) { throw new PathNotFoundException(updUrl); } } catch (Exception ex) { Log.Write(ex); if (!_silent || !File.Exists(_appPath)) { MessageBoxEx.Show(Resources.Msg_Warn_01, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning); } Application.Exit(); } var localDate = File.GetLastWriteTime(_appPath); var onlineDate = NetEx.GetFileDate(updUrl, Resources.UserAgent); if ((onlineDate - localDate).Days > 0) { if (_silent || MessageBoxEx.Show(Resources.Msg_Hint_00, Resources.WindowTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { var archivePath = PathEx.Combine(PathEx.LocalDir, $"..\\{PathEx.GetTempFileName()}"); if (!File.Exists(archivePath)) { _tmpDir = PathEx.Combine(Path.GetTempPath(), PathEx.GetTempDirName(Resources.AppName)); _transfer.DownloadFile(updUrl, archivePath); Opacity = 1f; CheckDownload.Enabled = true; return; } ExtractDownload.RunWorkerAsync(); } Application.Exit(); return; } if (!_silent) { MessageBoxEx.Show(Resources.Msg_Hint_01, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Information); } Application.Exit(); }
private void MainForm_Load(object sender, EventArgs e) { Text = Resources.WindowTitle; TaskBar.Progress.SetState(Handle, TaskBar.Progress.Flags.Indeterminate); if (!NetEx.InternetIsAvailable()) { if (!_silent || !File.Exists(_appPath)) { MessageBoxEx.Show(Resources.Msg_Err_00, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } Application.Exit(); return; } var iniFile = Path.ChangeExtension(PathEx.LocalPath, ".ini"); if (!File.Exists(iniFile)) { Ini.SetFile(iniFile); Ini.Write("Settings", "Language", "English"); Ini.Write("Settings", "Architecture", Environment.Is64BitProcess ? "64 bit" : "32 bit"); Ini.Write("Settings", "DoNotAskAgain", false); } else { Ini.SetFile(iniFile); } if (!Ini.Read("Settings", "DoNotAskAgain", false)) { Form langSelection = new LangSelectionForm(); if (langSelection.ShowDialog() != DialogResult.OK) { MessageBoxEx.Show(Resources.Msg_Hint_03, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Information); Application.Exit(); return; } } var lang = $"{Ini.Read<string>("Settings", "Language", "English")} ({Ini.Read<string>("Settings", "Architecture", Environment.Is64BitProcess ? "64 bit" : "32 bit")})"; var source = NetEx.Transfer.DownloadString(Resources.RegexUrl); string updUrl = null; try { foreach (Match match in Regex.Matches(source, Resources.RegexLinePattern, RegexOptions.Singleline)) { var mLine = match.Groups[1].ToString(); var mLang = Regex.Match(mLine, Resources.RegexLanguagePattern, RegexOptions.Singleline).Groups[1].ToString(); if (string.IsNullOrWhiteSpace(mLang) || !mLang.EqualsEx(lang)) { continue; } var mVer = Regex.Match(mLine, Resources.RegexVersionPattern, RegexOptions.Singleline).Groups[1].ToString(); if (string.IsNullOrWhiteSpace(mVer) || mVer.ContainsEx("trial", "free", "beta")) { continue; } var mName = Regex.Match(mLine, Resources.RegexFileNamePattern, RegexOptions.Singleline).Groups[1].ToString(); if (string.IsNullOrWhiteSpace(mName)) { continue; } updUrl = string.Format(Resources.UpdateUrl, mName); if (!NetEx.FileIsAvailable(updUrl, 60000, Resources.UserAgent)) { updUrl = null; continue; } break; } if (string.IsNullOrEmpty(updUrl)) { throw new ArgumentNullException(nameof(updUrl)); } } catch (Exception ex) { Log.Write(ex); if (!_silent || !File.Exists(_appPath)) { MessageBoxEx.Show(Resources.Msg_Warn_02, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning); } Application.Exit(); return; } var localDate = File.GetLastWriteTime(_appPath); var onlineDate = NetEx.GetFileDate(updUrl, Resources.UserAgent); if ((onlineDate - localDate).Days > 0) { if (_silent || MessageBoxEx.Show(Resources.Msg_Hint_00, Resources.WindowTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { var archivePath = PathEx.Combine(PathEx.LocalDir, $"..\\{PathEx.GetTempFileName()}"); if (!File.Exists(archivePath)) { _tmpDir = PathEx.Combine(Path.GetTempPath(), PathEx.GetTempDirName(Resources.AppName)); var hlpPath = Path.Combine(_tmpDir, "7z.zip"); ResourcesEx.Extract(Resources._7z, hlpPath, true); Compaction.Unzip(hlpPath, _tmpDir); _transfer.DownloadFile(updUrl, archivePath); Opacity = 1f; CheckDownload.Enabled = true; return; } ExtractDownload.RunWorkerAsync(); } Application.Exit(); return; } if (!_silent) { MessageBoxEx.Show(Resources.Msg_Hint_01, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Information); } Application.Exit(); }
private void MainForm_Load(object sender, EventArgs e) { Text = Resources.WindowTitle; TaskBar.Progress.SetState(Handle, TaskBar.Progress.Flags.Indeterminate); if (!NetEx.InternetIsAvailable()) { if (!_silent || !File.Exists(_appPath)) { MessageBoxEx.Show(Resources.Msg_Err_00, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } Application.Exit(); return; } var source = NetEx.Transfer.DownloadString(Resources.RegexUrl); string updUrl = null; try { foreach (Match match in Regex.Matches(source, Resources.RegexFileNamePattern, RegexOptions.Singleline)) { var mName = match.Groups[1].ToString(); if (string.IsNullOrWhiteSpace(mName) || !mName.ContainsEx(Resources.AppName)) { continue; } updUrl = string.Format(Resources.UpdateUrl, mName); break; } if (!NetEx.FileIsAvailable(updUrl, 60000, Resources.UserAgent)) { throw new PathNotFoundException(updUrl); } } catch (Exception ex) { Log.Write(ex); if (!_silent || !File.Exists(_appPath)) { MessageBoxEx.Show(Resources.Msg_Warn_01, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning); } Application.Exit(); return; } var appPath = PathEx.Combine(Resources.AppPath); var localDate = File.GetLastWriteTime(appPath); var onlineDate = NetEx.GetFileDate(updUrl, Resources.UserAgent); if ((onlineDate - localDate).Days > 0) { if (_silent || MessageBoxEx.Show(Resources.Msg_Hint_00, Resources.WindowTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { var archivePath = PathEx.Combine(PathEx.LocalDir, $"..\\{PathEx.GetTempFileName()}"); if (!File.Exists(archivePath)) { _transfer.DownloadFile(updUrl, archivePath); Opacity = 1f; CheckDownload.Enabled = true; return; } ExtractDownload.RunWorkerAsync(); } Application.Exit(); return; } if (!_silent) { MessageBoxEx.Show(Resources.Msg_Hint_01, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Information); } Application.Exit(); }
private void MainForm_Load(object sender, EventArgs e) { Text = Resources.WindowTitle; TaskBar.Progress.SetState(Handle, TaskBar.Progress.Flags.Indeterminate); if (!NetEx.InternetIsAvailable()) { if (!_silent || !File.Exists(_appPath)) { MessageBoxEx.Show(Resources.Msg_Err_00, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } Application.Exit(); return; } string updUrl; try { updUrl = string.Format(Resources.UpdateUrl, #if x86 "x86" #else "x64" #endif ); if (!NetEx.FileIsAvailable(updUrl, 60000, Resources.UserAgent)) { throw new PathNotFoundException(updUrl); } } catch (Exception ex) { Log.Write(ex); if (!_silent || !File.Exists(_appPath)) { MessageBoxEx.Show(Resources.Msg_Warn_01, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning); } Application.Exit(); return; } var appPath = PathEx.Combine(Resources.AppPath); var localDate = File.GetLastWriteTime(appPath); var onlineDate = NetEx.GetFileDate(updUrl, Resources.UserAgent); if ((onlineDate - localDate).Days > 0) { if (_silent || MessageBoxEx.Show(Resources.Msg_Hint_00, Resources.WindowTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { var archivePath = PathEx.Combine(PathEx.LocalDir, $"..\\{PathEx.GetTempFileName()}"); if (!File.Exists(archivePath)) { _tmpDir = PathEx.Combine(Path.GetTempPath(), PathEx.GetTempDirName(Resources.AppName)); var hlpPath = Path.Combine(_tmpDir, "iu.zip"); ResourcesEx.Extract(Resources.iu, hlpPath, true); Compaction.Unzip(hlpPath, _tmpDir); _transfer.DownloadFile(updUrl, archivePath); Opacity = 1f; CheckDownload.Enabled = true; return; } ExtractDownload.RunWorkerAsync(); } Application.Exit(); return; } if (!_silent) { MessageBoxEx.Show(Resources.Msg_Hint_01, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Information); } Application.Exit(); }
internal static List <string> GetMirrors(AppSuppliers supplier) { if (_mirrors == default) { _mirrors = new Dictionary <AppSuppliers, List <string> >(); } if (!_mirrors.ContainsKey(supplier)) { _mirrors.Add(supplier, new List <string>()); } if (_mirrors[supplier].Any()) { return(_mirrors[supplier]); } switch (supplier) { // PortableApps.com case AppSuppliers.PortableApps: { var mirrors = new[] { // IPv4 "http://portableapps.com", "http://downloads.portableapps.com", "http://downloads2.portableapps.com", "http://download3.portableapps.com" }; _mirrors[supplier].AddRange(mirrors); break; } // SourceForge.net case AppSuppliers.SourceForge: { var mirrors = new[] { // IPv4 + IPv6 (however, a download via IPv6 doesn't work) "https://netcologne.dl.sourceforge.net", "https://freefr.dl.sourceforge.net", "https://heanet.dl.sourceforge.net", // IPv4 "https://kent.dl.sourceforge.net", "https://netix.dl.sourceforge.net", "https://vorboss.dl.sourceforge.net", "https://downloads.sourceforge.net" }; if (NetEx.IPv4IsAvalaible) { var sortHelper = new Dictionary <string, long>(); if (Log.DebugMode > 0) { Log.Write($"{nameof(AppSuppliers.SourceForge)}: Try to find the best server . . ."); } foreach (var mirror in mirrors) { if (sortHelper.Keys.ContainsItem(mirror)) { continue; } var time = NetEx.Ping(mirror); if (Log.DebugMode > 0) { Log.Write($"{nameof(AppSuppliers.SourceForge)}: Reply from '{mirror}'; time={time}ms."); } sortHelper.Add(mirror, time); } mirrors = sortHelper.OrderBy(x => x.Value).ToDictionary(x => x.Key, x => x.Value).Keys.ToArray(); if (Log.DebugMode > 0) { Log.Write($"{nameof(AppSuppliers.SourceForge)}: New sort order: '{mirrors.Join("'; '")}'."); } } _mirrors[supplier].AddRange(mirrors); break; } // Internal - port-a.de | p-able.de default: { // IPv4 + IPv6 var mirrors = new[] { "https://port-a.de", "https://p-able.de", // Backup "https://dl.si13n7.de/Port-Able", "https://dl.si13n7.com/Port-Able", // Reserved "http://dl-0.de/Port-Able", "http://dl-1.de/Port-Able", "http://dl-2.de/Port-Able", "http://dl-3.de/Port-Able", "http://dl-4.de/Port-Able", "http://dl-5.de/Port-Able" }; _mirrors[supplier].AddRange(mirrors); break; } } return(_mirrors[supplier]); }
private void MainForm_Load(object sender, EventArgs e) { Text = Resources.WindowTitle; TaskBar.Progress.SetState(Handle, TaskBar.Progress.Flags.Indeterminate); if (!NetEx.InternetIsAvailable()) { if (!_silent || !File.Exists(_appPath)) { MessageBoxEx.Show(Resources.Msg_Err_00, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } Application.Exit(); return; } string updUrl; try { var mirrors = Resources.UpdateMirrors.SplitNewLine(); var mirrorMap = new Dictionary <long, string>(); foreach (var url in mirrors) { var ping = NetEx.Ping(url); while (mirrorMap.ContainsKey(ping)) { ping++; } mirrorMap.Add(ping, url); } var sortedPings = mirrorMap.Keys.ToList(); sortedPings.Sort(); var bestPing = sortedPings.Min(); var mirror = mirrorMap[bestPing]; var source = NetEx.Transfer.DownloadString(string.Format(Resources.RegexUrl, mirror)); if (string.IsNullOrWhiteSpace(source)) { foreach (var ping in sortedPings) { source = NetEx.Transfer.DownloadString(string.Format(Resources.RegexUrl, ping)); break; } } if (string.IsNullOrWhiteSpace(source)) { throw new ArgumentNullException(nameof(source)); } var vers = new List <Version>(); foreach (Match match in Regex.Matches(source, Resources.RegexVersionPattern, RegexOptions.Singleline)) { var mVer = match.Groups[1].ToString(); if (string.IsNullOrWhiteSpace(mVer)) { continue; } var cVer = mVer.ToCharArray(); if (!cVer.Count(char.IsDigit).IsBetween(3, 16) || !cVer.Count(c => c == '.').IsBetween(2, 3)) { continue; } mVer = new string(mVer.Where(c => char.IsDigit(c) || c == '.').ToArray()); if (!Version.TryParse(mVer, out Version ver)) { continue; } vers.Add(ver); } _ver = vers.Max(); updUrl = string.Format(Resources.UpdateUrl, mirror, _ver, #if x86 "32" #else "64" #endif ); var exists = NetEx.FileIsAvailable(updUrl, 60000, Resources.UserAgent); if (!exists) { foreach (var ping in sortedPings) { updUrl = string.Format(Resources.UpdateUrl, mirrorMap[ping], _ver, #if x86 "32" #else "64" #endif ); exists = NetEx.FileIsAvailable(updUrl, 60000, Resources.UserAgent); if (exists) { break; } } } if (!exists) { throw new PathNotFoundException(updUrl); } } catch (Exception ex) { Log.Write(ex); if (!_silent || !File.Exists(_appPath)) { MessageBoxEx.Show(Resources.Msg_Warn_01, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning); } Application.Exit(); return; } var localDate = File.GetLastWriteTime(_appPath); var onlineDate = NetEx.GetFileDate(updUrl, Resources.UserAgent); if ((onlineDate - localDate).Days > 0) { if (_silent || MessageBoxEx.Show(Resources.Msg_Hint_00, Resources.WindowTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { var archivePath = PathEx.Combine(PathEx.LocalDir, $"..\\{PathEx.GetTempFileName()}"); if (!File.Exists(archivePath)) { _tmpDir = PathEx.Combine(Path.GetTempPath(), PathEx.GetTempDirName(Resources.AppName)); var hlpPath = Path.Combine(_tmpDir, "7z.zip"); ResourcesEx.Extract(Resources._7z, hlpPath, true); Compaction.Unzip(hlpPath, _tmpDir); _transfer.DownloadFile(updUrl, archivePath); Opacity = 1f; CheckDownload.Enabled = true; return; } ExtractDownload.RunWorkerAsync(); } Application.Exit(); return; } if (!_silent) { MessageBoxEx.Show(Resources.Msg_Hint_01, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Information); } Application.Exit(); }
private void MainForm_Load(object sender, EventArgs e) { Text = Resources.WindowTitle; TaskBar.Progress.SetState(Handle, TaskBar.Progress.Flags.Indeterminate); if (!NetEx.InternetIsAvailable()) { if (!_silent || !File.Exists(_appPath)) { MessageBoxEx.Show(Resources.Msg_Err_00, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } Application.Exit(); return; } string updUrl = null; try { _tmpDir = PathEx.Combine(Path.GetTempPath(), PathEx.GetTempDirName(Resources.AppDisplayName)); var hlpPath = Path.Combine(_tmpDir, "js.zip"); ResourcesEx.Extract(Resources.js, hlpPath, true); Compaction.Unzip(hlpPath, _tmpDir); Thread.Sleep(200); var helperPath = Path.Combine(_tmpDir, "read.js"); var source = Path.Combine(_tmpDir, "source.txt"); File.WriteAllText(helperPath, Resources.JsScript); using (var p = ProcessEx.Send(string.Format(Resources.RunScript, _tmpDir), Elevation.IsAdministrator, ProcessWindowStyle.Hidden, false)) if (p?.HasExited == false) { p.WaitForExit(); } source = File.ReadAllText(source); if (string.IsNullOrWhiteSpace(source)) { throw new ArgumentNullException(nameof(source)); } source = TextEx.FormatNewLine(source).SplitNewLine().SkipWhile(x => !x.ContainsEx(".exe")).Take(1).Join(); foreach (Match match in Regex.Matches(source, Resources.RegexUrlPattern, RegexOptions.Singleline)) { var mUrl = match.Groups[1].ToString(); if (string.IsNullOrWhiteSpace(mUrl)) { continue; } updUrl = mUrl.Trim('"'); break; } if (!NetEx.FileIsAvailable(updUrl, 60000, Resources.UserAgent)) { throw new PathNotFoundException(updUrl); } } catch (Exception ex) { Log.Write(ex); if (!_silent || !File.Exists(_appPath)) { MessageBoxEx.Show(Resources.Msg_Warn_01, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning); } Application.Exit(); return; } var localDate = File.GetLastWriteTime(_appPath); var onlineDate = NetEx.GetFileDate(updUrl, Resources.UserAgent); if ((onlineDate - localDate).Days > 0) { if (_silent || MessageBoxEx.Show(Resources.Msg_Hint_00, Resources.WindowTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { var archivePath = PathEx.Combine(PathEx.LocalDir, $"..\\{PathEx.GetTempFileName()}"); if (!File.Exists(archivePath)) { var hlpPath = Path.Combine(_tmpDir, "iu.zip"); ResourcesEx.Extract(Resources.iu, hlpPath, true); Compaction.Unzip(hlpPath, _tmpDir); _transfer.DownloadFile(updUrl, archivePath); Opacity = 1f; CheckDownload.Enabled = true; return; } ExtractDownload.RunWorkerAsync(); } Application.Exit(); return; } if (!_silent) { MessageBoxEx.Show(Resources.Msg_Hint_01, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Information); } Application.Exit(); }
private void MainForm_Load(object sender, EventArgs e) { Text = Resources.WindowTitle; TaskBar.Progress.SetState(Handle, TaskBar.Progress.Flags.Indeterminate); if (!NetEx.InternetIsAvailable()) { if (!_silent || !File.Exists(_appPath)) { MessageBoxEx.Show(Resources.Msg_Err_00, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } Application.Exit(); return; } string updUrl = null; try { var source = NetEx.Transfer.DownloadString(Resources.RegexFirstUrl); if (string.IsNullOrWhiteSpace(source)) { throw new ArgumentNullException(nameof(source)); } source = TextEx.FormatNewLine(source).SplitNewLine().SkipWhile(x => !x.ContainsEx(Resources.RegexSecBtnMatch)).Take(1).Join(); foreach (Match match in Regex.Matches(source, Resources.RegexSecUrlPattern, RegexOptions.Singleline)) { var mUrl = match.Groups[1].ToString(); if (string.IsNullOrWhiteSpace(mUrl)) { continue; } source = NetEx.Transfer.DownloadString(mUrl); if (string.IsNullOrWhiteSpace(source)) { throw new ArgumentNullException(nameof(source)); } source = TextEx.FormatNewLine(source).SplitNewLine().SkipWhile(x => !x.ContainsEx(Resources.RegexThirdBtnMatch) || !Resources.RegexThirdExtMatch.SplitNewLine().Any(y => x.ContainsEx(y))).Take(1).Join(); foreach (Match match2 in Regex.Matches(source, Resources.RegexThirdUrlPattern, RegexOptions.Singleline)) { mUrl = match2.Groups[1].ToString(); if (string.IsNullOrWhiteSpace(mUrl)) { continue; } if (mUrl.ContainsEx("/show/")) { mUrl = mUrl.Replace("/show/", "/get/"); } updUrl = mUrl; break; } break; } if (!NetEx.FileIsAvailable(updUrl, 60000, Resources.UserAgent)) { throw new PathNotFoundException(updUrl); } } catch (Exception ex) { Log.Write(ex); if (!_silent || !File.Exists(_appPath)) { MessageBoxEx.Show(Resources.Msg_Warn_01, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning); } Application.Exit(); return; } var localDate = File.GetLastWriteTime(_appPath); var onlineDate = NetEx.GetFileDate(updUrl, Resources.UserAgent); if ((onlineDate - localDate).Days > 0) { if (_silent || MessageBoxEx.Show(Resources.Msg_Hint_00, Resources.WindowTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { var archivePath = PathEx.Combine(PathEx.LocalDir, $"..\\{PathEx.GetTempFileName()}"); if (!File.Exists(archivePath)) { _tmpDir = PathEx.Combine(Path.GetTempPath(), PathEx.GetTempDirName(Resources.AppName)); var hlpPath = Path.Combine(_tmpDir, "iu.zip"); ResourcesEx.Extract(Resources.iu, hlpPath, true); Compaction.Unzip(hlpPath, _tmpDir); _transfer.DownloadFile(updUrl, archivePath); Opacity = 1f; CheckDownload.Enabled = true; return; } ExtractDownload.RunWorkerAsync(); } Application.Exit(); return; } if (!_silent) { MessageBoxEx.Show(Resources.Msg_Hint_01, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Information); } Application.Exit(); }
private void MainForm_Load(object sender, EventArgs e) { Text = Resources.WindowTitle; TaskBar.Progress.SetState(Handle, TaskBar.Progress.Flags.Indeterminate); if (!NetEx.InternetIsAvailable()) { if (!_silent || !File.Exists(_appPath)) { MessageBoxEx.Show(Resources.Msg_Err_00, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } Application.Exit(); return; } Version localVersion; try { var version = FileVersionInfo.GetVersionInfo(_appPath).FileVersion; if (version.Contains(',')) { version = version.Split(',').Select(c => c.Trim()).Join('.'); } localVersion = Version.Parse(version); } catch { localVersion = new Version("0.0.0.0"); } Version onlineVersion; try { var source = NetEx.Transfer.DownloadString(Resources.VersionUrl); if (string.IsNullOrEmpty(source)) { throw new ArgumentNullException(nameof(source)); } source = TextEx.FormatNewLine(source).SplitNewLine().SkipWhile(x => !x.ContainsEx(Resources.VersionHeader)).Take(1).Join(); var inner = Regex.Match(source, Resources.VersionRegex).Groups[1].ToString(); if (string.IsNullOrEmpty(inner)) { throw new ArgumentNullException(nameof(inner)); } var index = inner.IndexOf('('); if (index < 0) { throw new ArgumentOutOfRangeException(nameof(index)); } var ver = inner.Substring(0, index).Trim(' ', 'v').Split('.'); if (!Version.TryParse($"{ver.Take(2).Join('.')}.0.{ver.Last()}", out onlineVersion)) { throw new ArgumentNullException(nameof(onlineVersion)); } } catch (Exception ex) { Log.Write(ex); if (!_silent || !File.Exists(_appPath)) { MessageBoxEx.Show(Resources.Msg_Warn_01, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning); } Application.Exit(); return; } if (localVersion < onlineVersion) { if (_silent || MessageBoxEx.Show(Resources.Msg_Hint_00, Resources.WindowTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { var archivePath = PathEx.Combine(PathEx.LocalDir, $"..\\{PathEx.GetTempFileName()}"); if (!File.Exists(archivePath)) { _transfer.DownloadFile(Resources.UpdateUrl, archivePath); Opacity = 1f; CheckDownload.Enabled = true; return; } ExtractDownload.RunWorkerAsync(); } Application.Exit(); return; } if (!_silent) { MessageBoxEx.Show(Resources.Msg_Hint_01, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Information); } Application.Exit(); }
private void MainForm_Load(object sender, EventArgs e) { Text = Resources.WindowTitle; TaskBar.Progress.SetState(Handle, TaskBar.Progress.Flags.Indeterminate); if (!NetEx.InternetIsAvailable()) { if (!_silent || !File.Exists(_appPath)) { MessageBoxEx.Show(Resources.Msg_Err_00, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } Application.Exit(); return; } var source = NetEx.Transfer.DownloadString(Resources.UpdateUrl); string updUrl; try { source = TextEx.FormatNewLine(source).SplitNewLine().SkipWhile(x => !x.ContainsEx(Resources.AppName) && !x.ContainsEx(".zip")).FirstOrDefault(); source = source.Split("\"").SkipWhile(x => !x.ContainsEx(Resources.AppName) && !x.ContainsEx(".zip")).FirstOrDefault(); if (string.IsNullOrEmpty(source)) { throw new ArgumentNullException(nameof(source)); } updUrl = source; if (!NetEx.FileIsAvailable(updUrl, 60000, Resources.UserAgent)) { throw new PathNotFoundException(updUrl); } } catch (Exception ex) { Log.Write(ex); if (!_silent || !File.Exists(_appPath)) { MessageBoxEx.Show(Resources.Msg_Warn_01, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning); } Application.Exit(); return; } var localDate = File.GetLastWriteTime(_appPath); var onlineDate = NetEx.GetFileDate(updUrl, Resources.UserAgent); if ((onlineDate - localDate).Days > 0) { if (_silent || MessageBoxEx.Show(Resources.Msg_Hint_00, Resources.WindowTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { var archivePath = PathEx.Combine(PathEx.LocalDir, $"..\\{PathEx.GetTempFileName()}"); if (!File.Exists(archivePath)) { _transfer.DownloadFile(updUrl, archivePath); Opacity = 1f; CheckDownload.Enabled = true; return; } ExtractDownload.RunWorkerAsync(); } Application.Exit(); return; } if (!_silent) { MessageBoxEx.Show(Resources.Msg_Hint_01, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Information); } Application.Exit(); }
private static void UpdateAppInfoFile() { ResetAppInfoFile(); if (_appInfo?.Count > 430) { goto Shareware; } foreach (var mirror in AppSupply.GetMirrors(AppSuppliers.Internal)) { var link = PathEx.AltCombine(mirror, ".free", "AppInfo.ini"); if (Log.DebugMode > 0) { Log.Write($"Cache: Looking for '{link}'."); } if (NetEx.FileIsAvailable(link, 30000, UserAgents.Internal)) { NetEx.Transfer.DownloadFile(link, CachePaths.AppInfo, 60000, UserAgents.Internal, false); } if (!File.Exists(CachePaths.AppInfo)) { continue; } break; } var blacklist = Array.Empty <string>(); if (File.Exists(CachePaths.AppInfo)) { blacklist = Ini.GetSections(CachePaths.AppInfo).Where(x => Ini.Read(x, "Disabled", false, CachePaths.AppInfo)).ToArray(); UpdateAppInfoData(CachePaths.AppInfo, blacklist); } var tmpDir = Path.Combine(CorePaths.TempDir, PathEx.GetTempDirName()); if (!DirectoryEx.Create(tmpDir)) { return; } var tmpZip = Path.Combine(tmpDir, "AppInfo.7z"); foreach (var mirror in AppSupply.GetMirrors(AppSuppliers.Internal)) { var link = PathEx.AltCombine(mirror, ".free", "AppInfo.7z"); if (Log.DebugMode > 0) { Log.Write($"Cache: Looking for '{link}'."); } if (NetEx.FileIsAvailable(link, 30000, UserAgents.Internal)) { NetEx.Transfer.DownloadFile(link, tmpZip, 60000, UserAgents.Internal, false); } if (!File.Exists(tmpZip)) { continue; } break; } if (!File.Exists(tmpZip)) { var link = PathEx.AltCombine(AppSupplierHosts.PortableApps, "updater", "update.7z"); if (Log.DebugMode > 0) { Log.Write($"Cache: Looking for '{link}'."); } if (NetEx.FileIsAvailable(link, 60000, UserAgents.Empty)) { NetEx.Transfer.DownloadFile(link, tmpZip, 60000, UserAgents.Empty, false); } } if (File.Exists(tmpZip)) { using (var process = Compaction.SevenZipHelper.Unzip(tmpZip, tmpDir)) if (process?.HasExited == false) { process.WaitForExit(); } FileEx.TryDelete(tmpZip); } var tmpIni = DirectoryEx.GetFiles(tmpDir, "*.ini").FirstOrDefault(); if (!File.Exists(tmpIni)) { DirectoryEx.TryDelete(tmpDir); return; } UpdateAppInfoData(tmpIni, blacklist); FileEx.Serialize(CachePaths.AppInfo, AppInfo, true); DirectoryEx.TryDelete(tmpDir); Shareware: if (!Shareware.Enabled) { return; } foreach (var srv in Shareware.GetAddresses()) { var key = Shareware.FindAddressKey(srv); var usr = Shareware.GetUser(srv); var pwd = Shareware.GetPassword(srv); var url = PathEx.AltCombine(srv, "AppInfo.ini"); if (Log.DebugMode > 0) { Log.Write($"Shareware: Looking for '{{{key.Encode()}}}/AppInfo.ini'."); } if (!NetEx.FileIsAvailable(url, usr, pwd, 60000, UserAgents.Default)) { continue; } var appInfo = NetEx.Transfer.DownloadString(url, usr, pwd, 60000, UserAgents.Default); if (string.IsNullOrWhiteSpace(appInfo)) { continue; } UpdateAppInfoData(appInfo, null, key.Decode(BinaryToTextEncodings.Base85)); } }
private void SetChangeLog(params string[] mirrors) { if (mirrors?.Any() == true) { var changes = string.Empty; foreach (var mirror in mirrors) { var path = PathEx.AltCombine(mirror, "ChangeLog.txt"); if (string.IsNullOrWhiteSpace(path)) { continue; } if (!NetEx.FileIsAvailable(path, 60000, UserAgents.Internal)) { continue; } changes = WebTransfer.DownloadString(path, 60000, UserAgents.Internal); if (!string.IsNullOrWhiteSpace(changes)) { break; } } if (SetChangeLogText(changes)) { return; } } else { try { var atom = WebTransfer.DownloadString(CorePaths.RepoCommitsUrl, 60000, UserAgents.Default); if (string.IsNullOrEmpty(atom)) { throw new ArgumentNullException(nameof(atom)); } const string nspace = "{http://www.w3.org/2005/Atom}"; var document = XDocument.Parse(atom); var changes = new Dictionary <string, List <string> >(); foreach (var entry in document.Descendants($"{nspace}feed").Descendants($"{nspace}entry")) { var time = DateTime.Parse(entry.Descendants($"{nspace}updated").Single().Value, CultureInfo.InvariantCulture); var timeStr = time.ToString("dd MMMM yyyy", CultureInfo.CreateSpecificCulture("en-US")); if (!changes.ContainsKey(timeStr)) { changes.Add(timeStr, new List <string>()); } var title = entry.Descendants($"{nspace}title").Single().Value.Trim(); if (title.ContainsEx("http://", "https://")) { title = title.Replace("https://", "http://"); title = title.Substring(0, title.IndexOf("http://", StringComparison.Ordinal)).Trim(); } changes[timeStr].Add(title.TrimEnd('.')); } var builder = new StringBuilder(); var lastKey = changes.Keys.Last(); foreach (var key in changes.Keys) { var values = changes[key]; if (!values.Any()) { continue; } builder.AppendFormatLine(" {0}:", key); builder.AppendLine(); foreach (var value in values) { builder.AppendFormatLine(" * {0}", value); } builder.AppendLine(); if (key != lastKey) { builder.Append('_', 84); builder.AppendLine(); builder.AppendLine(); } builder.AppendLine(); } if (SetChangeLogText(string.Format(CultureInfo.InvariantCulture, Resources.ChangeLogTemplate, builder))) { return; } } catch (Exception ex) when(ex.IsCaught()) { Log.Write(ex); } } changeLog.Dock = DockStyle.None; changeLog.Size = new Size(changeLogPanel.Width, TextRenderer.MeasureText(changeLog.Text, changeLog.Font).Height); changeLog.Location = new Point(0, changeLogPanel.Height / 2 - changeLog.Height - 16); changeLog.SelectAll(); changeLog.SelectionAlignment = HorizontalAlignment.Center; changeLog.DeselectAll(); }
private void UpdateBtn_Click(object sender, EventArgs e) { if (!(sender is Button owner)) { return; } owner.Enabled = false; var downloadPath = default(string); if (!string.IsNullOrWhiteSpace(LastStamp)) { try { downloadPath = PathEx.AltCombine(CorePaths.RepoSnapshotsUrl, $"{LastStamp}.7z"); if (!NetEx.FileIsAvailable(downloadPath, 60000, UserAgents.Default)) { throw new PathNotFoundException(downloadPath); } } catch (Exception ex) when(ex.IsCaught()) { Log.Write(ex); downloadPath = null; } } if (string.IsNullOrWhiteSpace(downloadPath)) { try { var exist = false; foreach (var mirror in DownloadMirrors) { downloadPath = PathEx.AltCombine(mirror, $"{LastFinalStamp}.7z"); exist = NetEx.FileIsAvailable(downloadPath, 60000, UserAgents.Internal); if (exist) { break; } } if (!exist) { throw new PathNotFoundException(downloadPath); } } catch (Exception ex) when(ex.IsCaught()) { Log.Write(ex); downloadPath = null; } } if (string.IsNullOrWhiteSpace(downloadPath)) { return; } try { Transferor.DownloadFile(downloadPath, CachePaths.UpdatePath, 60000, !string.IsNullOrWhiteSpace(LastStamp) ? UserAgents.Default : UserAgents.Internal); checkDownload.Enabled = true; } catch (Exception ex) when(ex.IsCaught()) { Log.Write(ex, true); } }
public AppTransferor(AppData appData) { AppData = appData ?? throw new ArgumentNullException(nameof(appData)); DestPath = default; SrcData = new List <Tuple <string, string, string, bool> >(); UserData = Tuple.Create(default(string), default(string)); var downloadCollection = AppData.DownloadCollection; var packageVersion = default(string); if (ActionGuid.IsUpdateInstance && AppData?.UpdateCollection?.SelectMany(x => x.Value).All(x => x?.Item1?.StartsWithEx("http") == true) == true) { var appIniDir = Path.Combine(appData.InstallDir, "App", "AppInfo"); var appIniPath = Path.Combine(appIniDir, "appinfo.ini"); if (!File.Exists(appIniPath)) { appIniPath = Path.Combine(appIniDir, "plugininstaller.ini"); } packageVersion = Ini.Read("Version", nameof(appData.PackageVersion), default(string), appIniPath); if (!string.IsNullOrEmpty(packageVersion) && AppData?.UpdateCollection?.ContainsKey(packageVersion) == true) { downloadCollection = AppData.UpdateCollection; } } foreach (var pair in downloadCollection) { if (!pair.Key.EqualsEx(AppData.Settings.ArchiveLang) && (string.IsNullOrEmpty(packageVersion) || !pair.Key.EqualsEx(packageVersion))) { continue; } foreach (var(item1, item2) in pair.Value) { var srcUrl = item1; if (srcUrl.StartsWith("{", StringComparison.InvariantCulture) && srcUrl.EndsWith("}", StringComparison.InvariantCulture)) { srcUrl = FindArchivePath(srcUrl).Item2; } if (DestPath == default) { if (!DirectoryEx.Create(Settings.TransferDir)) { continue; } var fileName = Path.GetFileName(srcUrl); if (string.IsNullOrEmpty(fileName)) { continue; } DestPath = PathEx.Combine(Settings.TransferDir, fileName); } var shortHost = NetEx.GetShortHost(srcUrl); var redirect = Settings.ForceTransferRedirection || !NetEx.IPv4IsAvalaible && !string.IsNullOrWhiteSpace(shortHost) && !shortHost.EqualsEx(AppSupplierHosts.Internal); string userAgent; List <string> mirrors; switch (shortHost) { case AppSupplierHosts.Internal: userAgent = UserAgents.Internal; mirrors = AppSupply.GetMirrors(AppSuppliers.Internal); break; case AppSupplierHosts.PortableApps: userAgent = UserAgents.Empty; mirrors = AppSupply.GetMirrors(AppSuppliers.PortableApps); break; case AppSupplierHosts.SourceForge: userAgent = UserAgents.Default; mirrors = AppSupply.GetMirrors(AppSuppliers.SourceForge); break; default: userAgent = UserAgents.Default; if (AppData.ServerKey != default) { var srv = Shareware.GetAddresses().FirstOrDefault(x => Shareware.FindAddressKey(x) == AppData.ServerKey.ToArray().Encode(BinaryToTextEncoding.Base85)); if (srv != default) { if (!srcUrl.StartsWithEx("http://", "https://")) { srcUrl = PathEx.AltCombine(srv, srcUrl); } UserData = Tuple.Create(Shareware.GetUser(srv), Shareware.GetPassword(srv)); } } SrcData.Add(Tuple.Create(srcUrl, item2, userAgent, false)); continue; } var sHost = NetEx.GetShortHost(srcUrl); var fhost = srcUrl.Substring(0, srcUrl.IndexOf(sHost, StringComparison.OrdinalIgnoreCase) + sHost.Length); foreach (var mirror in mirrors) { if (!fhost.EqualsEx(mirror)) { srcUrl = srcUrl.Replace(fhost, mirror); } if (SrcData.Any(x => x.Item1.EqualsEx(srcUrl))) { continue; } if (redirect) { userAgent = UserAgents.Internal; srcUrl = CorePaths.RedirectUrl + srcUrl.Encode(); } SrcData.Add(Tuple.Create(srcUrl, item2, userAgent, false)); if (Log.DebugMode > 1) { Log.Write($"Transfer: '{srcUrl}' has been added."); } } } break; } Transfer = new WebTransferAsync(); }