public Task EnableMod(GenericMod mod) { return(_busy.Task(async() => { if (_enabler == null || mod.IsEnabled) { return; } var conflicts = await _enabler.CheckConflictsAsync(mod); if (conflicts.Length > 0 && ModernDialog.ShowMessage( conflicts.Select(x => $@"• “{Path.GetFileName(x.RelativeName)}” has already been altered by the “{x.ModName}” mod;") .JoinToString("\n").ToSentence () + $"\n\nEnabling {BbCodeBlock.Encode(mod.DisplayName)} may have adverse effects. Are you sure you want to enable this mod?", "Conflict", MessageBoxButton.YesNo, "genericMods.conflict") != MessageBoxResult.Yes) { return; } try { using (var waiting = WaitingDialog.Create("Enabling mod…")) { await _enabler.EnableAsync(mod, waiting, waiting.CancellationToken); Changed?.Invoke(this, EventArgs.Empty); if (waiting.CancellationToken.IsCancellationRequested) { waiting.Report(AsyncProgressEntry.FromStringIndetermitate("Cancellation…")); await _enabler.DisableAsync(mod); } } } catch (Exception e) { NonfatalError.Notify("Can’t enable mod", e); } })); }
private string IdToBb(string id, bool car = true) { const string searchIcon = "F1 M 42.5,22C 49.4036,22 55,27.5964 55,34.5C 55,41.4036 49.4036,47 42.5,47C 40.1356,47 37.9245,46.3435 36,45.2426L 26.9749,54.2678C 25.8033,55.4393 23.9038,55.4393 22.7322,54.2678C 21.5607,53.0962 21.5607,51.1967 22.7322,50.0251L 31.7971,40.961C 30.6565,39.0755 30,36.8644 30,34.5C 30,27.5964 35.5964,22 42.5,22 Z M 42.5,26C 37.8056,26 34,29.8056 34,34.5C 34,39.1944 37.8056,43 42.5,43C 47.1944,43 51,39.1944 51,34.5C 51,29.8056 47.1944,26 42.5,26 Z"; const string linkIcon = "F1 M 23.4963,46.1288L 25.0796,48.8712L 29.4053,50.0303L 33.519,47.6553L 34.8902,46.8636L 37.6326,45.2803L 38.4242,46.6515L 37.2652,50.9772L 30.4091,54.9356L 21.7577,52.6174L 18.591,47.1326L 20.9091,38.4811L 27.7652,34.5227L 32.0909,35.6818L 32.8826,37.053L 30.1402,38.6364L 28.769,39.428L 24.6553,41.803L 23.4963,46.1288 Z M 38.7348,28.1895L 45.5908,24.2311L 54.2423,26.5493L 57.409,32.0341L 55.0908,40.6856L 48.2348,44.6439L 43.9091,43.4848L 43.1174,42.1136L 45.8598,40.5303L 47.231,39.7386L 51.3446,37.3636L 52.5037,33.0379L 50.9204,30.2955L 46.5946,29.1364L 42.481,31.5114L 41.1098,32.3031L 38.3674,33.8864L 37.5757,32.5152L 38.7348,28.1895 Z M 33.9006,45.1496L 31.7377,44.5701L 30.5502,42.5133L 31.1298,40.3504L 42.0994,34.0171L 44.2623,34.5966L 45.4498,36.6534L 44.8702,38.8163L 33.9006,45.1496 Z"; if (!car) { id = Regex.Replace(id, @"-([^-]+)$", "/$1"); } var name = $@"“{BbCodeBlock.Encode(id)}”"; var typeLocalized = car ? ToolsStrings.AdditionalContent_Car : ToolsStrings.AdditionalContent_Track; var searchUrl = $"cmd://findmissing/{(car ? "car" : "track")}?param={id}"; var searchLink = string.Format(@"[url={0}][ico={1}]Look for missing {2} online[/ico][/url]", BbCodeBlock.EncodeAttribute(searchUrl), BbCodeBlock.EncodeAttribute(searchIcon), typeLocalized); var version = car ? GetRequiredCarVersion(id) : GetRequiredTrackVersion(); if (OptionIgnoreIndexIfServerProvidesSpecificVersion && version != null || (car ? !IndexDirectDownloader.IsCarAvailable(id) : !IndexDirectDownloader.IsTrackAvailable(id))) { return($@"{name} \[{searchLink}]"); } var downloadUrl = $"cmd://downloadmissing/{(car ? "car" : "track")}?param={(string.IsNullOrWhiteSpace(version) ? id : $@"{id}|{version}")}";
private void OnClosing(object sender, CancelEventArgs e) { if (_closed) { return; } try { if (ServerPresetsManager.Instance.IsScanned) { var running = ServerPresetsManager.Instance.Loaded.Where(x => x.IsRunning).ToList(); if (running.Count > 0 && ModernDialog.ShowMessage( $@"{"If you’ll close app, running servers will be stopped as well. Are you sure?"}{Environment.NewLine}{Environment.NewLine}{ running.Select(x => $@" • {BbCodeBlock.Encode(x.DisplayName)}").JoinToString(Environment.NewLine)}", "Some servers are running", MessageBoxButton.YesNo) != MessageBoxResult.Yes) { e.Cancel = true; return; } } if (ContentInstallationManager.Instance.HasUnfinishedItems && ModernDialog.ShowMessage( "If you’ll close app, installation will be terminated. Are you sure?", "Something is being installed", MessageBoxButton.YesNo) != MessageBoxResult.Yes) { e.Cancel = true; return; } var unsaved = Superintendent.Instance.UnsavedChanges(); if (unsaved.Count > 0) { switch (ModernDialog.ShowMessage( $@"{AppStrings.Main_UnsavedChanges}{Environment.NewLine}{Environment.NewLine}{ unsaved.OrderBy(x => x).Select(x => $@" • {x}").JoinToString(Environment.NewLine)}", AppStrings.Main_UnsavedChangesHeader, MessageBoxButton.YesNoCancel)) { case MessageBoxResult.Yes: Superintendent.Instance.SaveAll(); break; case MessageBoxResult.Cancel: e.Cancel = true; return; } } // Just in case, temporary _closed = true; Application.Current.Shutdown(); } catch (Exception ex) { Logging.Warning(ex); } }
public static string GetVersionInfoDisplay([NotNull] this IAcObjectFullAuthorshipInformation obj) { if (obj == null) { throw new ArgumentNullException(nameof(obj)); } if (obj.Version == null && obj.Author == null) { return(obj.Url != null ? $@"[url={BbCodeBlock.EncodeAttribute(obj.Url)}]{BbCodeBlock.Encode(obj.Url)}[/url]" : null); } var result = obj.Author == null ? obj.Version : obj.Version == null ? obj.Author : $"{obj.Author} ({obj.Version})"; return(obj.Url != null ? $@"[url={BbCodeBlock.EncodeAttribute(obj.Url)}]{BbCodeBlock.Encode(result)}[/url]" : result); }
private static string PrepareLicense(string source) { return(Regex.Replace(BbCodeBlock.Encode(source), @"https?://\S+", x => { var last = x.Value[x.Value.Length - 1]; string url, postfix; if (last == '.' || last == ';' || last == ')' || last == ',') { url = x.Value.Substring(0, x.Value.Length - 1); postfix = last.ToString(); } else { url = x.Value; postfix = ""; } return $"[url={BbCodeBlock.EncodeAttribute(BbCodeBlock.Decode(url))}]{url}[/url]{postfix}"; })); }
private static string BbCodeIcon([Localizable(false)] string icon, [Localizable(false)] string command, string hint) { return($@"[url={BbCodeBlock.EncodeAttribute(command)}][ico={BbCodeBlock.EncodeAttribute(icon)}]{BbCodeBlock.Encode(hint)}[/ico][/url]"); }
protected override void OnMouseMove(MouseEventArgs e) { if (_scrolling) { return; } var size = _size; var width = size.Width; var pos = this.GetMousePosition(); var referenceIconOffset = 22d; for (var i = 0; i < _icons.Length; i++) { var icon = _icons[i]; if (icon == null) { break; } var iconWidth = icon.Width; var rect = new Rect(referenceIconOffset, 5, iconWidth, ReferenceIconSize); if (rect.Contains(pos)) { ShowToolTip($@"ref:{i}", () => _iconToolTips.ArrayElementAtOrDefault(i)); return; } referenceIconOffset += iconWidth + ReferenceIconMargin; } if (!_fullyLoaded) { return; } var pieces = (_bookedForPlayer ? 1 : 0) + (_passwordRequired ? 1 : 0) + (_hasFriends ? 1 : 0); var iconOffset = (60d - pieces * ReferenceIconHeight + (pieces - 1d) * ReferenceIconMargin) / 2d; if (pieces > 0) { const double iconHeight = 12d; const double iconMargin = 4d; if (_bookedForPlayer) { if (new Rect(6, iconOffset, 12, iconHeight).Contains(pos)) { ShowToolTip(@"iconBooked", () => "There is a place booked for you"); return; } iconOffset += iconHeight + iconMargin; } if (_passwordRequired) { if (new Rect(6, iconOffset, 12, iconHeight).Contains(pos)) { ShowToolTip(@"iconPassword", () => ControlsStrings.Online_PasswordRequired); return; } iconOffset += iconHeight + iconMargin; } if (_hasFriends) { if (new Rect(6, iconOffset, 12, iconHeight).Contains(pos)) { ShowToolTip(@"iconFriends", () => "Your friend is here"); return; } // iconOffset += iconHeight + iconMargin; } } if (new Rect(width - 80, 0, 40, 30).Contains(pos)) { ShowToolTip(@"clients", () => FindStaticResource <ToolTip>(@"ClientsTooltip")); return; } if (new Rect(width - 40, 0, 40, 30).Contains(pos)) { if (_errorFlag) { ShowToolTip(@"error", () => _server.ErrorsString?.Trim()); } else { ShowToolTip(@"ping", () => $"Ping: {(_server.Ping.HasValue ? _server.Ping + " ms" : "not checked yet")}"); } return; } if (GetCountryRect(width).Contains(pos)) { ShowToolTip(@"country", () => _server.Country); return; } #if DEBUG if (new Rect(0, 0, width, 30).Contains(pos)) { ShowToolTip(@"name", () => $"Actual name: {BbCodeBlock.Encode(_server.ActualName)}\nSorting name: {_server.SortingName}"); return; } #endif if (GetTrackRect().Contains(pos)) { ShowToolTip(@"track", () => FindStaticResource <ToolTip>(@"TrackPreviewTooltip.Online")); return; } if (new Rect(146d, 35, _sessionsCount * 20 + (_wideMode ? 84d : 0), 20).Contains(pos)) { ShowToolTip(@"sessions", () => FindStaticResource <ToolTip>(@"SessionsItemTooltip")); return; } var carsOffset = _wideMode ? 324d : 240d; if (GetCarsRect(carsOffset, width).Contains(pos)) { var cars = _cars; for (var i = 0; i < cars.Length; i++) { var c = cars[i]; if (c == null || carsOffset > width) { break; } var rect = new Rect(carsOffset, 34, c.Width + 8, 22); if (rect.Contains(pos)) { ShowToolTip($@"car:{i}", () => FindStaticResource <ToolTip>(@"CarPreviewTooltip.Online"), () => _server.Cars?.ElementAtOrDefault(i)); return; } carsOffset += rect.Width + 8; } } ShowToolTip(null, null); }
protected MaterialValueBase(string name) { Id = name; _name = BbCodeBlock.Encode(name); }
private void InnerWrite(string message, string color = null, int level = 0, bool extraHalf = false) { _destination.Add($@"{@" ".RepeatString(level * 2 + (extraHalf ? 1 : 0))}{ (color != null ? $@"[color=#{color}]" : "")}{BbCodeBlock.Encode(message)}{(color != null ? @"[/color]" : "")}"); }