public static void EnsureObjects(ITheaterConfigurationManager mbtConfig, bool block, IZipClient zipClient)
        {
            try
            {
                string objPath = Path.Combine(mbtConfig.CommonApplicationPaths.ProgramDataPath, OJB_FOLDER);
                string lastCheckedPath = Path.Combine(objPath, LAST_CHECKED);
                bool needsCheck = true;

                if (!Directory.Exists(objPath))
                {
                    Directory.CreateDirectory(objPath);
                }

                DateAndVersion lastCheck = new DateAndVersion(lastCheckedPath);
                if (lastCheck.StoredDate.AddDays(7) > DateTime.Now)
                    needsCheck = false;
                if (lastCheck.VersionNumber != ExeVersion)
                    needsCheck = true;

                if (needsCheck)
                {
                    if (block)
                        CheckObjects(objPath, zipClient);
                    else
                        ThreadPool.QueueUserWorkItem(o => CheckObjects(o, zipClient), objPath);
                }
            }
            catch (Exception ex)
            {

            }
        }
示例#2
0
        private static void CheckObjects(object objDlPath, IZipClient zipClient)
        {
            try
            {
                Uri    objManifest     = new Uri(Path.Combine(System.Configuration.ConfigurationSettings.AppSettings["PrivateObjectsManifest"], "manifest.txt"));
                string dlPath          = objDlPath.ToString();
                string lastCheckedPath = Path.Combine(dlPath, LAST_CHECKED);

                using (WebClient mwc = new WebClient())
                {
                    string dlList = mwc.DownloadString(objManifest);
                    if (!string.IsNullOrWhiteSpace(dlList))
                    {
                        string[] objToCheck = dlList.Split(new string[] { System.Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                        foreach (string toCheck in objToCheck)
                        {
                            string         txtPath    = Path.Combine(dlPath, Path.ChangeExtension(toCheck, "txt"));
                            DateAndVersion lastUpdate = new DateAndVersion(txtPath);
                            Uri            comPath    = new Uri(Path.Combine(Path.Combine(System.Configuration.ConfigurationSettings.AppSettings["PrivateObjectsManifest"], toCheck)));
                            WebRequest     request    = WebRequest.Create(comPath);
                            request.Method = "HEAD";

                            using (WebResponse wr = request.GetResponse())
                            {
                                DateTime lmDate;
                                if (DateTime.TryParse(wr.Headers[HttpResponseHeader.LastModified], out lmDate))
                                {
                                    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)
                                            {
                                                using (MemoryStream ms = new MemoryStream(comBin))
                                                {
                                                    zipClient.ExtractAll(ms, dlPath, true);
                                                }

                                                DateAndVersion.Write(new DateAndVersion(txtPath, lmDate, ExeVersion));
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                DateAndVersion.Write(new DateAndVersion(lastCheckedPath, DateTime.Now, ExeVersion));
            }
            catch (Exception ex)
            {
            }
        }
示例#3
0
        public static void EnsureObjects(ITheaterConfigurationManager mbtConfig, IZipClient zipClient, bool block, bool redownload)
        {
            try
            {
                string objPath         = Path.Combine(mbtConfig.CommonApplicationPaths.ProgramDataPath, OJB_FOLDER);
                string lastCheckedPath = Path.Combine(objPath, LAST_CHECKED);
                bool   needsCheck      = true;

                if (!Directory.Exists(objPath))
                {
                    Directory.CreateDirectory(objPath);
                }
                else if (redownload)
                {
                    foreach (string file in Directory.EnumerateFiles(objPath))
                    {
                        try
                        {
                            File.Delete(file);
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }

                DateAndVersion lastCheck = new DateAndVersion(lastCheckedPath);
                if (lastCheck.StoredDate.AddDays(7) > DateTime.Now)
                {
                    needsCheck = false;
                }
                if (lastCheck.VersionNumber != ExeVersion)
                {
                    needsCheck = true;
                }

                if (needsCheck)
                {
                    if (block)
                    {
                        CheckObjects(objPath, zipClient, mbtConfig);
                    }
                    else
                    {
                        ThreadPool.QueueUserWorkItem(o => CheckObjects(o, zipClient, mbtConfig), objPath);
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
示例#4
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)
     {
     }
 }
示例#5
0
        public bool EnsureObjects(ITheaterConfigurationManager mbtConfig, IZipClient zipClient, bool block, bool redownload)
        {
            bool needsRestart = false;

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

                string objPath = Path.Combine(mbtConfig.CommonApplicationPaths.ProgramDataPath, 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(MediaBrowser.Theater.DirectShow.Properties.Resources.babgvant, objPath, zipClient);
                    ExtractBytes(MediaBrowser.Theater.DirectShow.Properties.Resources.LAV, objPath, zipClient);
                    ExtractBytes(MediaBrowser.Theater.DirectShow.Properties.Resources.madVR, objPath, zipClient);
                    ExtractBytes(MediaBrowser.Theater.DirectShow.Properties.Resources.mpaudio, objPath, zipClient);
                    ExtractBytes(MediaBrowser.Theater.DirectShow.Properties.Resources.XySubFilter, objPath, zipClient);
                    ExtractBytes(MediaBrowser.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, mbtConfig);
                        else
                            ThreadPool.QueueUserWorkItem(o => CheckObjects(o, zipClient, mbtConfig), objPath);
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error("EnsureObjects Error: {0}", ex.Message);
            }

            _logger.Debug("EnsureObjects needsRestart: {0}", needsRestart);
            return needsRestart;
        }
示例#6
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)
     {
     }
 }
示例#7
0
        private void CheckObjects(object objDlPath, IZipClient zipClient, ITheaterConfigurationManager mbtConfig)
        {
            string dsDlPath = Path.Combine(System.Configuration.ConfigurationSettings.AppSettings["PrivateObjectsManifest"], mbtConfig.Configuration.InternalPlayerConfiguration.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();
                }
            }
        }
        private static void CheckObjects(object objDlPath, IZipClient zipClient)
        {
            try
            {
                Uri objManifest = new Uri(Path.Combine(System.Configuration.ConfigurationSettings.AppSettings["PrivateObjectsManifest"], "manifest.txt"));
                string dlPath = objDlPath.ToString();
                string lastCheckedPath = Path.Combine(dlPath, LAST_CHECKED);

                using (WebClient mwc = new WebClient())
                {
                    string dlList = mwc.DownloadString(objManifest);
                    if (!string.IsNullOrWhiteSpace(dlList))
                    {
                        string[] objToCheck = dlList.Split(new string[] { System.Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                        foreach (string toCheck in objToCheck)
                        {
                            string txtPath = Path.Combine(dlPath, Path.ChangeExtension(toCheck, "txt"));
                            DateAndVersion lastUpdate = new DateAndVersion(txtPath);
                            Uri comPath = new Uri(Path.Combine(Path.Combine(System.Configuration.ConfigurationSettings.AppSettings["PrivateObjectsManifest"], toCheck)));
                            WebRequest request = WebRequest.Create(comPath);
                            request.Method = "HEAD";

                            using (WebResponse wr = request.GetResponse())
                            {
                                DateTime lmDate;
                                if (DateTime.TryParse(wr.Headers[HttpResponseHeader.LastModified], out lmDate))
                                {
                                    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)
                                            {
                                                using (MemoryStream ms = new MemoryStream(comBin))
                                                {
                                                    zipClient.ExtractAll(ms, dlPath, true);
                                                }

                                                DateAndVersion.Write(new DateAndVersion(txtPath, lmDate, ExeVersion));
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                DateAndVersion.Write(new DateAndVersion(lastCheckedPath, DateTime.Now, ExeVersion));
            }
            catch (Exception ex)
            {
            }
        }
示例#9
0
 public void Write()
 {
     DateAndVersion.Write(this);
 }