private static async void CheckUpdates(RegExToolDialog dialog) { double hoursFromLastCheck = Math.Abs((DateTime.Now - Config.Instance.LastUpdateCheck).TotalHours); //if (hoursFromLastCheck > 8) if (true) { ServicePointManager.ServerCertificateValidationCallback += (_, __, ___, ____) => true; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls; try { HttpClient client = new HttpClient(); client.DefaultRequestHeaders.Add("Accept-Language", "en-US;q=0.5,en;q=0.3"); client.DefaultRequestHeaders.Add("User-Agent", "C# App"); var response = await client.GetAsync("https://api.github.com/repos/codingseb/CSharpRegexTools4Npp/releases/latest").ConfigureAwait(true); string responseText = await response.Content.ReadAsStringAsync(); var jsonResult = JObject.Parse(responseText); int[] latestVersion = jsonResult["name"].ToString().Split('.').Select(digit => int.Parse(digit.Trim())).ToArray(); int[] currentVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString().Split('.').Select(digit => int.Parse(digit.Trim())).ToArray(); Debug.WriteLine($"{latestVersion} - {currentVersion}"); for (int i = 0; i < latestVersion.Length && i < currentVersion.Length; i++) { if (latestVersion[i] > currentVersion[i]) { Config.Instance.UpdateAvailable = true; Config.Instance.UpdateURL = "https://github.com/codingseb/CSharpRegexTools4Npp/releases"; break; } else if (latestVersion[i] < currentVersion[i]) { break; } } } catch { } } }
public static void ShowTheDialog() { try { IntPtr hWnd = FindWindow(null, "C# Regex Tools"); if (hWnd.ToInt64() > 0) { SetForegroundWindow(hWnd); } else { var dialog = new RegExToolDialog { GetText = () => BNpp.Text, SetText = (string text) => { if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)) { BNpp.NotepadPP.FileNew(); } BNpp.Text = text; }, SetTextInNew = (string text) => { BNpp.NotepadPP.FileNew(); BNpp.Text = text; }, GetSelectedText = () => BNpp.SelectedText, SetPosition = (int index, int length) => BNpp.SelectTextAndShow(index, index + length), SetSelection = (int index, int length) => BNpp.AddSelection(index, index + length), GetSelectionStartIndex = () => BNpp.SelectionStart, GetSelectionLength = () => BNpp.SelectionLength, SaveCurrentDocument = () => BNpp.NotepadPP.SaveCurrentFile(), TryOpen = (string fileName, bool onlyIfAlreadyOpen) => { try { bool result = false; if (BNpp.NotepadPP.CurrentFileName.ToLower().Equals(fileName.ToLower())) { result = true; } else if (BNpp.NotepadPP.GetAllOpenedDocuments.Any((string s) => s.Equals(fileName, StringComparison.OrdinalIgnoreCase))) { BNpp.NotepadPP.ShowOpenedDocument(fileName); result = true; } else if (!onlyIfAlreadyOpen) { result = BNpp.NotepadPP.OpenFile(fileName); } else { result = false; } hWnd = FindWindow(null, "C# Regex Tool"); if (hWnd.ToInt64() > 0) { SetForegroundWindow(hWnd); } return(result); } catch { return(false); } }, GetCurrentFileName = () => BNpp.NotepadPP.CurrentFileName }; dialog.Show(); SetWindowLong(new WindowInteropHelper(dialog).Handle, (int)WindowLongFlags.GWLP_HWNDPARENT, PluginBase.nppData._nppHandle); SetLayeredWindowAttributes(new WindowInteropHelper(dialog).Handle, 0, 128, LWA_ALPHA); } } catch (Exception exception) { MessageBox.Show(exception.Message + "\r\n" + exception.StackTrace, "Erreur", MessageBoxButton.OK, MessageBoxImage.Error); } }
public static void ShowTheDialog() { try { AppDomain.CurrentDomain.SetupInformation.PrivateBinPath = @"plugins\CSharpRegexTools4Npp"; IntPtr hWnd = FindWindow(null, "C# Regex Tools - " + Assembly.GetExecutingAssembly().GetName().Version.ToString()); if (hWnd.ToInt64() > 0) { SetForegroundWindow(hWnd); } else { RegExToolDialog dialog = null; RegExToolDialog.InitIsOK = () => CheckUpdates(dialog); dialog = new RegExToolDialog { GetText = () => Npp.Text, SetText = text => { if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)) { Npp.NotepadPP.FileNew(); } Npp.Text = text; }, SetTextInNew = text => { Npp.NotepadPP.FileNew(); Npp.Text = text; }, GetSelectedText = () => Npp.SelectedText, SetPosition = (index, length) => Npp.SelectTextAndShow(index, index + length), SetSelection = (index, length) => Npp.AddSelection(index, index + length), GetSelectionStartIndex = () => Npp.SelectionStart, GetSelectionLength = () => Npp.SelectionLength, SaveCurrentDocument = () => Npp.NotepadPP.SaveCurrentFile(), SetCurrentTabInCSharpHighlighting = () => Npp.NotepadPP.SetCurrentLanguage(LangType.L_CS), TryOpen = (fileName, onlyIfAlreadyOpen) => { try { bool result = false; if (Npp.NotepadPP.CurrentFileName.Equals(fileName, StringComparison.OrdinalIgnoreCase)) { result = true; } else if (Npp.NotepadPP.GetAllOpenedDocuments.Any(s => s.Equals(fileName, StringComparison.OrdinalIgnoreCase))) { Npp.NotepadPP.ShowTab(fileName); result = true; } else if (!onlyIfAlreadyOpen) { result = Npp.NotepadPP.OpenFile(fileName); } else { result = false; } hWnd = FindWindow(null, "C# Regex Tool - " + Assembly.GetExecutingAssembly().GetName().Version.ToString()); if (hWnd.ToInt64() > 0) { SetForegroundWindow(hWnd); } return(result); } catch { return(false); } }, GetCurrentFileName = () => Npp.NotepadPP.CurrentFileName }; dialog.Show(); SetWindowLong(new WindowInteropHelper(dialog).Handle, (int)WindowLongFlags.GWLP_HWNDPARENT, PluginBase.nppData._nppHandle); SetLayeredWindowAttributes(new WindowInteropHelper(dialog).Handle, 0, 128, LWA_ALPHA); } } catch (Exception exception) { MessageBox.Show(exception.Message + "\r\n" + exception.StackTrace, "Erreur", MessageBoxButton.OK, MessageBoxImage.Error); } }