Exemplo n.º 1
0
        void SearchTextBox_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Up && SearchTextBox.Text == "")
            {
                string last = RegistryHelp.GetString(RegistryHelp.ApplicationKey, "LastText");

                if (!string.IsNullOrEmpty(last))
                {
                    SearchTextBox.Text       = last;
                    SearchTextBox.CaretIndex = 1000;
                }
            }

            if (DG.Items.Count > 0)
            {
                if (e.Key == Key.Up)
                {
                    int index = DG.SelectedIndex;
                    index--;

                    if (index < 0)
                    {
                        index = 0;
                    }

                    DG.SelectedIndex = index;
                }

                if (e.Key == Key.Down)
                {
                    int index = DG.SelectedIndex;
                    index++;

                    if (index > DG.Items.Count - 1)
                    {
                        index = DG.Items.Count - 1;
                    }

                    DG.SelectedIndex = index;
                }
            }

            if (e.Key == Key.Apps)
            {
                Application.Current.Dispatcher.InvokeAsync(() => {
                    ShowMenu(PointToScreen(new Point(0d, 0d)));
                });
            }
        }
Exemplo n.º 2
0
        public static async void CheckOnline(bool showUpToDateMessage = false)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    RegistryHelp.SetValue(RegistryHelp.ApplicationKey, "UpdateCheckLast", DateTime.Now.DayOfYear);
                    client.DefaultRequestHeaders.Add("User-Agent", "MediaInfo.NET");
                    var response = await client.GetAsync("https://api.github.com/repos/stax76/MediaInfo.NET/releases/latest");

                    response.EnsureSuccessStatusCode();
                    string content = await response.Content.ReadAsStringAsync();

                    Match   match          = Regex.Match(content, @"""MediaInfo\.NET-([\d\.]+)\.zip""");
                    Version onlineVersion  = Version.Parse(match.Groups[1].Value);
                    Version currentVersion = Assembly.GetEntryAssembly()?.GetName().Version;

                    if (onlineVersion <= currentVersion)
                    {
                        if (showUpToDateMessage)
                        {
                            Msg.Show($"{Application.ProductName} is up to date.");
                        }

                        return;
                    }

                    if ((RegistryHelp.GetString(RegistryHelp.ApplicationKey, "UpdateCheckVersion")
                         != onlineVersion.ToString() || showUpToDateMessage) && Msg.ShowQuestion(
                            $"New version {onlineVersion} is available, update now?") == MsgResult.OK)
                    {
                        string url = $"https://github.com/stax76/MediaInfo.NET/releases/download/{onlineVersion}/MediaInfo.NET-{onlineVersion}.zip";

                        using (Process proc = new Process())
                        {
                            proc.StartInfo.UseShellExecute  = true;
                            proc.StartInfo.WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                            proc.StartInfo.FileName         = "powershell.exe";
                            proc.StartInfo.Arguments        = $"-NoLogo -NoExit -NoProfile -ExecutionPolicy Bypass -File \"{Application.StartupPath + @"\Update.ps1"}\" \"{url}\" \"{Application.StartupPath.TrimEnd('\\')}\"";

                            if (Application.StartupPath.Contains("Program Files"))
                            {
                                proc.StartInfo.Verb = "runas";
                            }

                            proc.Start();
                        }

                        Updating?.Invoke();
                    }

                    RegistryHelp.SetValue(RegistryHelp.ApplicationKey, "UpdateCheckVersion", onlineVersion.ToString());
                }
            }
            catch (Exception ex)
            {
                if (showUpToDateMessage)
                {
                    Msg.ShowException(ex);
                }
            }
        }
Exemplo n.º 3
0
        static void Setup(bool install)
        {
            string[] extensions = App.Settings.FileTypes.Split(" \r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            if (install)
            {
                foreach (string ext in extensions)
                {
                    string filekeyName = RegistryHelp.GetString(@"HKCR\." + ext, null);

                    if (filekeyName == "")
                    {
                        RegistryHelp.SetValue(@"HKCR\." + ext, null, ext + "file");
                        filekeyName = ext + "file";
                    }

                    RegistryHelp.SetValue(@"HKCR\" + filekeyName + @"\shell\MediaInfo.NET", null, "MediaInfo");
                    RegistryHelp.SetValue(@"HKCR\" + filekeyName + @"\shell\MediaInfo.NET\command", null, $"\"{AppHelp.ExecutablePath}\" \"%1\"");

                    string userKeyName = RegistryHelp.GetString(@"HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\." + ext + @"\UserChoice", "ProgId");

                    if (RegistryHelp.GetString(@"HKCR\" + userKeyName + @"\shell\open\command", null) != "")
                    {
                        RegistryHelp.SetValue(@"HKCR\" + userKeyName + @"\shell\MediaInfo.NET", null, "MediaInfo");
                        RegistryHelp.SetValue(@"HKCR\" + userKeyName + @"\shell\MediaInfo.NET\command", null, $"\"{AppHelp.ExecutablePath}\" \"%1\"");
                    }
                }

                Msg.Show("Install complete");
            }
            else
            {
                foreach (string name in Registry.ClassesRoot.GetSubKeyNames())
                {
                    if (!name.StartsWith("."))
                    {
                        continue;
                    }

                    RegistryHelp.RemoveKey(@"HKCR\" + RegistryHelp.GetString(@"HKCR\" + name, null) + @"\shell\MediaInfo.NET");
                }

                using (RegistryKey fileExtsKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts"))
                {
                    if (fileExtsKey != null)
                    {
                        foreach (string name in fileExtsKey.GetSubKeyNames())
                        {
                            if (!name.StartsWith("."))
                            {
                                continue;
                            }

                            string userKeyName = RegistryHelp.GetString(@"HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" + name + @"\UserChoice", "ProgId");
                            RegistryHelp.RemoveKey(@"HKCR\" + userKeyName + @"\shell\MediaInfo.NET");
                        }
                    }
                }

                Msg.Show("Uninstall complete");
            }
        }