Пример #1
0
        private FFMPEGVersion GetCurrentVersion()
        {
            FFMPEGVersion ret = null;

            try
            {
                if (File.Exists(VersionFile))
                {
                    using (StreamReader r = new StreamReader(new FileStream(VersionFile, FileMode.Open, FileAccess.Read)))
                    {
                        ret = JsonConvert.DeserializeObject <FFMPEGVersion>(r.ReadToEnd());
                    }
                }
                else
                {
                    ret = new FFMPEGVersion();

                    using (StreamWriter r = new StreamWriter(new FileStream(VersionFile, FileMode.Create, FileAccess.ReadWrite)))
                    {
                        r.Write(JsonConvert.SerializeObject(ret));
                    }
                }
            }
            catch { }

            return(ret);
        }
Пример #2
0
        private FFMPEGVersion GetLatestVersion()
        {
            FFMPEGVersion ret = null;

            try
            {
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(Url);
                req.UserAgent = UserAgent;

                HtmlDocument doc = new HtmlDocument();
                doc.Load(req.GetResponse().GetResponseStream());

                foreach (HtmlNode n in doc.DocumentNode.SelectNodes("//h2"))
                {
                    if (n.InnerHtml.Contains(H2Contains))
                    {
                        string   v  = n.InnerHtml.Split(':')[1].Replace("(", string.Empty).Replace(")", string.Empty).Trim();
                        string[] vs = v.Split(' ');

                        ret = new FFMPEGVersion
                        {
                            GitVersion  = vs[0],
                            ReleaseDate = DateTime.ParseExact(vs[1], "yyyy-MM-dd", CultureInfo.InvariantCulture)
                        };
                    }
                }
            }
            catch { }

            return(ret);
        }
Пример #3
0
 private void UpdateCurrentVersion(FFMPEGVersion v)
 {
     try
     {
         using (StreamWriter r = new StreamWriter(new FileStream(VersionFile, FileMode.Create, FileAccess.ReadWrite)))
         {
             r.Write(JsonConvert.SerializeObject(v));
         }
     }
     catch { }
 }
Пример #4
0
        private void DownloadStatic(FFMPEGVersion v)
        {
            try
            {
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(v.DownloadUrl);
                req.UserAgent = UserAgent;

                string tmp = string.Format("{0}\\ffmpeg-{1}.7z", Path.GetTempPath(), v.GitVersion);

                using (FileStream fs = new FileStream(tmp, FileMode.Create, FileAccess.ReadWrite))
                {
                    req.GetResponse().GetResponseStream().CopyTo(fs);
                }

                ProcessStartInfo pi = new ProcessStartInfo(Get7ZipPath());
                pi.Arguments       = GetCommandLine(v, tmp);
                pi.UseShellExecute = false;

                Process p = Process.Start(pi);
                p.WaitForExit();
            }
            catch { }
        }
Пример #5
0
        public void Update()
        {
            FFMPEGVersion current = GetCurrentVersion();
            FFMPEGVersion latest  = GetLatestVersion();

            if (current != null && latest != null)
            {
                CheckPath();
                CheckFolder();

                if (latest.ReleaseDate > current.ReleaseDate)
                {
                    //Show toast notification
                    Notification.Send("Updating FFMPEG...");
                    DownloadStatic(latest);
                    UpdateCurrentVersion(latest);
                    Notification.Send(string.Format("FFMPEG is up to date ({0})", latest.ReleaseDate.ToString("dd-MM-yyyy")));
                }
                else
                {
                    Notification.Send(string.Format("FFMPEG is up to date ({0})", latest.ReleaseDate.ToString("dd-MM-yyyy")));
                }
            }
        }
Пример #6
0
 private string GetCommandLine(FFMPEGVersion v, string file)
 {
     return(string.Format("e -y -o{0} \"{1}\" \"{2}\\bin\\ffmpeg.exe\" \"{2}\\bin\\ffplay.exe\" \"{2}\\bin\\ffprobe.exe\"", BinDir, file, v.VersionString));
 }