コード例 #1
0
 public static void Write(DateAndVersion dv)
 {
     try
     {
         using (StreamWriter sw = new StreamWriter(dv.FilePath))
         {
             sw.WriteLine(dv.StoredDate);
             sw.WriteLine(dv.VersionNumber);
         }
     }
     catch (Exception ex)
     {
     }
 }
コード例 #2
0
 public static void Write(DateAndVersion dv)
 {
     try
     {
         using (StreamWriter sw = new StreamWriter(dv.FilePath))
         {
             sw.WriteLine(dv.StoredDate);
             sw.WriteLine(dv.VersionNumber);
         }
     }
     catch (Exception ex)
     {
     }
 }
コード例 #3
0
        private void CheckObjects(object objDlPath, IZipClient zipClient)
        {
            var configuration = GetConfiguration();
            string dsDlPath = Path.Combine(System.Configuration.ConfigurationSettings.AppSettings["PrivateObjectsManifest"], configuration.FilterSet);
            Uri objManifest = new Uri(Path.Combine(dsDlPath, "manifest.txt"));

            //only check if we need to update filters if the CDN is available
            if (CanPing.TryPing(objManifest.Host))
            {
                try
                {
                    _mreFilterBlock.Reset();

                    string dlPath = objDlPath.ToString();
                    string lastCheckedPath = Path.Combine(dlPath, LAST_CHECKED);

                    _logger.Debug("CheckObjects lastCheckedPath: {0}", lastCheckedPath);

                    using (WebClient mwc = new WebClient())
                    {
                        string dlList = mwc.DownloadString(objManifest);
                        if (!string.IsNullOrWhiteSpace(dlList))
                        {
                            _logger.Debug("CheckObjects manifest: {0}", dlList);

                            string[] objToCheck = dlList.Split(new string[] { System.Environment.NewLine, "\n" }, StringSplitOptions.RemoveEmptyEntries);
                            foreach (string toCheck in objToCheck)
                            {
                                try
                                {
                                    string txtPath = Path.Combine(dlPath, Path.ChangeExtension(toCheck, "txt"));
                                    DateAndVersion lastUpdate = new DateAndVersion(txtPath);
                                    Uri comPath = new Uri(Path.Combine(dsDlPath, toCheck));
                                    WebRequest request = WebRequest.Create(comPath);
                                    request.Method = "HEAD";

                                    _logger.Debug("CheckObjects check: {0}", comPath);

                                    using (WebResponse wr = request.GetResponse())
                                    {
                                        DateTime lmDate;
                                        if (DateTime.TryParse(wr.Headers[HttpResponseHeader.LastModified], out lmDate))
                                        {
                                            _logger.Debug("CheckObjects lmDate: {0} StoredDate", lmDate, lastUpdate.StoredDate);
                                            if (lmDate > lastUpdate.StoredDate)
                                            {
                                                //download the updated component
                                                using (WebClient fd = new WebClient())
                                                {
                                                    fd.DownloadProgressChanged += fd_DownloadProgressChanged;
                                                    byte[] comBin = fd.DownloadData(comPath);
                                                    if (comBin.Length > 0)
                                                    {
                                                        try
                                                        {
                                                            string dirPath = Path.Combine(dlPath, Path.GetFileNameWithoutExtension(toCheck));
                                                            if (Directory.Exists(dirPath))
                                                                Directory.Delete(dirPath, true);
                                                        }
                                                        catch (Exception ex)
                                                        {
                                                            _logger.Error("CheckObjects Delete: {0}", ex.Message);
                                                        }

                                                        ExtractBytes(comBin, dlPath, zipClient);
                                                        //using (MemoryStream ms = new MemoryStream(comBin))
                                                        //{
                                                        //    _logger.Debug("CheckObjects extract: {0}", dlPath);
                                                        //    zipClient.ExtractAll(ms, dlPath, true);
                                                        //}

                                                        DateAndVersion.Write(new DateAndVersion(txtPath, lmDate, ExeVersion));
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Debug.WriteLine(ex.Message);
                                }
                            }
                        }
                    }

                    DateAndVersion.Write(new DateAndVersion(lastCheckedPath, DateTime.Now, ExeVersion));
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                }
                finally
                {
                    _mreFilterBlock.Set();
                }
            }
        }
コード例 #4
0
        public bool EnsureObjects(string appProgramDataPath, IZipClient zipClient, bool block, bool redownload)
        {
            bool needsRestart = false;

            try
            {
                _logger.Debug("EnsureObjects: block: {0} redownload: {1}", block, redownload);

                string objPath = Path.Combine(appProgramDataPath, OJB_FOLDER);
                string lastCheckedPath = Path.Combine(objPath, LAST_CHECKED);
                bool needsCheck = true;

                if (!Directory.Exists(objPath) || Directory.GetDirectories(objPath).Length == 0)
                {
                    Directory.CreateDirectory(objPath);
                    //extract embedded filters
                    ExtractBytes(Emby.Theater.DirectShow.Properties.Resources.babgvant, objPath, zipClient);
                    ExtractBytes(Emby.Theater.DirectShow.Properties.Resources.LAV, objPath, zipClient);
                    ExtractBytes(Emby.Theater.DirectShow.Properties.Resources.madVR, objPath, zipClient);
                    ExtractBytes(Emby.Theater.DirectShow.Properties.Resources.mpaudio, objPath, zipClient);
                    ExtractBytes(Emby.Theater.DirectShow.Properties.Resources.XySubFilter, objPath, zipClient);
                    ExtractBytes(Emby.Theater.DirectShow.Properties.Resources.xy_VSFilter, objPath, zipClient);
                }
                else if (redownload)
                {
                    needsRestart = _libsLoaded.Count > 0;

                    foreach (string file in Directory.EnumerateFiles(objPath))
                    {
                        try
                        {
                            //deleting these files will force a redownload later
                            _logger.Debug("EnsureObjects Delete: {0}", file);
                            File.Delete(file);
                        }
                        catch (Exception ex)
                        {
                            _logger.Error("EnsureObjects DeleteError: {0}", ex.Message);
                        }
                    }
                }

                if (!needsRestart)
                {
                    //we can only update the files if no handles are held
                    DateAndVersion lastCheck = new DateAndVersion(lastCheckedPath);
                    if (lastCheck.StoredDate.AddDays(7) > DateTime.Now)
                        needsCheck = false;
                    if (lastCheck.VersionNumber != ExeVersion)
                        needsCheck = true;

                    _logger.Debug("EnsureObjects needsCheck: {0}", needsCheck);

                    if (needsCheck)
                    {
                        if (block)
                            CheckObjects(objPath, zipClient);
                        else
                            ThreadPool.QueueUserWorkItem(o => CheckObjects(o, zipClient), objPath);
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error("EnsureObjects Error: {0}", ex.Message);
            }

            _logger.Debug("EnsureObjects needsRestart: {0}", needsRestart);
            return needsRestart;
        }
コード例 #5
0
 public void Write()
 {
     DateAndVersion.Write(this);
 }
コード例 #6
0
        private void CheckObjects(object objDlPath, IZipClient zipClient)
        {
            var    configuration = GetConfiguration();
            string dsDlPath      = Path.Combine(System.Configuration.ConfigurationSettings.AppSettings["PrivateObjectsManifest"], configuration.FilterSet);
            Uri    objManifest   = new Uri(Path.Combine(dsDlPath, "manifest.txt"));

            //only check if we need to update filters if the CDN is available
            if (CanPing.TryPing(objManifest.Host))
            {
                try
                {
                    _mreFilterBlock.Reset();

                    string dlPath          = objDlPath.ToString();
                    string lastCheckedPath = Path.Combine(dlPath, LAST_CHECKED);

                    _logger.Debug("CheckObjects lastCheckedPath: {0}", lastCheckedPath);

                    using (WebClient mwc = new WebClient())
                    {
                        string dlList = mwc.DownloadString(objManifest);
                        if (!string.IsNullOrWhiteSpace(dlList))
                        {
                            _logger.Debug("CheckObjects manifest: {0}", dlList);

                            string[] objToCheck = dlList.Split(new string[] { System.Environment.NewLine, "\n" }, StringSplitOptions.RemoveEmptyEntries);
                            foreach (string toCheck in objToCheck)
                            {
                                try
                                {
                                    string         txtPath    = Path.Combine(dlPath, Path.ChangeExtension(toCheck, "txt"));
                                    DateAndVersion lastUpdate = new DateAndVersion(txtPath);
                                    Uri            comPath    = new Uri(Path.Combine(dsDlPath, toCheck));
                                    WebRequest     request    = WebRequest.Create(comPath);
                                    request.Method = "HEAD";

                                    _logger.Debug("CheckObjects check: {0}", comPath);

                                    using (WebResponse wr = request.GetResponse())
                                    {
                                        DateTime lmDate;
                                        if (DateTime.TryParse(wr.Headers[HttpResponseHeader.LastModified], out lmDate))
                                        {
                                            _logger.Debug("CheckObjects lmDate: {0} StoredDate", lmDate, lastUpdate.StoredDate);
                                            if (lmDate > lastUpdate.StoredDate)
                                            {
                                                //download the updated component
                                                using (WebClient fd = new WebClient())
                                                {
                                                    fd.DownloadProgressChanged += fd_DownloadProgressChanged;
                                                    byte[] comBin = fd.DownloadData(comPath);
                                                    if (comBin.Length > 0)
                                                    {
                                                        try
                                                        {
                                                            string dirPath = Path.Combine(dlPath, Path.GetFileNameWithoutExtension(toCheck));
                                                            if (Directory.Exists(dirPath))
                                                            {
                                                                Directory.Delete(dirPath, true);
                                                            }
                                                        }
                                                        catch (Exception ex)
                                                        {
                                                            _logger.Error("CheckObjects Delete: {0}", ex.Message);
                                                        }

                                                        ExtractBytes(comBin, dlPath, zipClient);
                                                        //using (MemoryStream ms = new MemoryStream(comBin))
                                                        //{
                                                        //    _logger.Debug("CheckObjects extract: {0}", dlPath);
                                                        //    zipClient.ExtractAll(ms, dlPath, true);
                                                        //}

                                                        DateAndVersion.Write(new DateAndVersion(txtPath, lmDate, ExeVersion));
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Debug.WriteLine(ex.Message);
                                }
                            }
                        }
                    }

                    DateAndVersion.Write(new DateAndVersion(lastCheckedPath, DateTime.Now, ExeVersion));
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                }
                finally
                {
                    _mreFilterBlock.Set();
                }
            }
        }
コード例 #7
0
        public bool EnsureObjects(string appProgramDataPath, IZipClient zipClient, bool block, bool redownload)
        {
            bool needsRestart = false;

            try
            {
                _logger.Debug("EnsureObjects: block: {0} redownload: {1}", block, redownload);

                string objPath         = Path.Combine(appProgramDataPath, OJB_FOLDER);
                string lastCheckedPath = Path.Combine(objPath, LAST_CHECKED);
                bool   needsCheck      = true;

                if (!Directory.Exists(objPath) || Directory.GetDirectories(objPath).Length == 0)
                {
                    Directory.CreateDirectory(objPath);
                    //extract embedded filters
                    ExtractBytes(Emby.Theater.DirectShow.Properties.Resources.babgvant, objPath, zipClient);
                    ExtractBytes(Emby.Theater.DirectShow.Properties.Resources.LAV, objPath, zipClient);
                    ExtractBytes(Emby.Theater.DirectShow.Properties.Resources.madVR, objPath, zipClient);
                    ExtractBytes(Emby.Theater.DirectShow.Properties.Resources.mpaudio, objPath, zipClient);
                    ExtractBytes(Emby.Theater.DirectShow.Properties.Resources.XySubFilter, objPath, zipClient);
                    ExtractBytes(Emby.Theater.DirectShow.Properties.Resources.xy_VSFilter, objPath, zipClient);
                    //extract embedded tracking files
                    WriteResource(Emby.Theater.DirectShow.Properties.Resources.babgvant_txt, Path.Combine(objPath, "babgvant.txt"));
                    WriteResource(Emby.Theater.DirectShow.Properties.Resources.LAV_txt, Path.Combine(objPath, "LAV.txt"));
                    WriteResource(Emby.Theater.DirectShow.Properties.Resources.madVR_txt, Path.Combine(objPath, "madVR.txt"));
                    WriteResource(Emby.Theater.DirectShow.Properties.Resources.mpaudio_txt, Path.Combine(objPath, "mpaudio.txt"));
                    WriteResource(Emby.Theater.DirectShow.Properties.Resources.XySubFilter_txt, Path.Combine(objPath, "XySubFilter.txt"));
                    WriteResource(Emby.Theater.DirectShow.Properties.Resources.xy_VSFilter_txt, Path.Combine(objPath, "xy-VSFilter.txt"));
                }
                else if (redownload)
                {
                    needsRestart = _libsLoaded.Count > 0;

                    foreach (string file in Directory.EnumerateFiles(objPath))
                    {
                        try
                        {
                            //deleting these files will force a redownload later
                            _logger.Debug("EnsureObjects Delete: {0}", file);
                            File.Delete(file);
                        }
                        catch (Exception ex)
                        {
                            _logger.Error("EnsureObjects DeleteError: {0}", ex.Message);
                        }
                    }
                }

                if (!needsRestart)
                {
                    //we can only update the files if no handles are held
                    DateAndVersion lastCheck = new DateAndVersion(lastCheckedPath);
                    if (lastCheck.StoredDate.AddDays(7) > DateTime.Now)
                    {
                        needsCheck = false;
                    }
                    if (lastCheck.VersionNumber != ExeVersion)
                    {
                        needsCheck = true;
                    }

                    _logger.Debug("EnsureObjects needsCheck: {0}", needsCheck);

                    if (needsCheck)
                    {
                        if (block)
                        {
                            CheckObjects(objPath, zipClient);
                        }
                        else
                        {
                            ThreadPool.QueueUserWorkItem(o => CheckObjects(o, zipClient), objPath);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error("EnsureObjects Error: {0}", ex.Message);
            }

            _logger.Debug("EnsureObjects needsRestart: {0}", needsRestart);
            return(needsRestart);
        }