Exemplo n.º 1
0
        protected override void OnClosing(CancelEventArgs e)
        {
            base.OnClosing(e);

            if (!string.IsNullOrEmpty(ViewModel.SearchText))
            {
                RegistryHelp.SetValue(RegistryHelp.ApplicationKey, "LastText", ViewModel.SearchText);
            }
        }
Exemplo n.º 2
0
        void WriteShellRegistryKey()
        {
            string keyPath = @"HKCU\Software\Microsoft\Windows\CurrentVersion\App Paths\" +
                             Path.GetFileName(AppHelp.ExecutablePath);

            if (!File.Exists(RegistryHelp.GetString(keyPath, null)))
            {
                RegistryHelp.SetValue(keyPath, null, AppHelp.ExecutablePath);
            }
        }
Exemplo n.º 3
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.º 4
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");
            }
        }