Exemple #1
0
        private void btnOpenCatalog_Click(object sender, EventArgs e)
        {
            _disableFilterFunction = true;
            btnClearFilter.Enabled = false;
            btnFilter.Enabled      = false;
            trvCatalog.Nodes.Clear();
            ClearUpdateInformations();
            lblProgress.Text        = resMan.GetString("UncompressingFile");
            prgBarProgression.Value = 0;
            btnBrowse.Enabled       = false;
            btnOpenCatalog.Enabled  = false;
            btnImport.Enabled       = false;
            btnClose.Enabled        = false;
            _selectedUpdates.Clear();

            catalogHelper = new CatalogHelper(txtBxFilepath.Text);
            catalogHelper.UnpackArchiveProgression += new CatalogHelper.UnpackArchiveProgressionEventHandler(catalogHelper_UnpackArchiveProgression);
            catalogHelper.UnpackArchiveFinished    += new CatalogHelper.UnpackArchiveFinishedEventHandler(catalogHelper_UnpackArchiveFinished);
            catalogHelper.OpenCatalogProgression   += new CatalogHelper.OpenCatalogProgressionEventHandler(catalogHelper_OpenCatalogProgression);
            catalogHelper.OpenCatalogFinished      += new CatalogHelper.OpenCatalogFinishedEventHandler(catalogHelper_OpenCatalogFinished);

            System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(catalogHelper.OpenCatalog));
            t.Start();
        }
Exemple #2
0
        /// <summary>
        /// Check if an updated catalog is available on Internet.
        /// </summary>
        /// <returns>Retrun true if an update is available, otherwise false (can mean that something wrong happened).</returns>
        internal bool CheckUpdateAvailability()
        {
            Logger.EnteringMethod(this.Address + "/" + this.CatalogName);

            this.LastCheckDate = DateTime.Now.Date;
            string addressToCheck = this.Address.ToLower();

            try
            {
                DirectoryInfo destinationFolder = new DirectoryInfo(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + "\\" + _subscribedCatalogsFolder);
                FileInfo      tempOldCatalog    = new FileInfo(Tools.Utilities.GetTempFolder() + this.CatalogName);

                if (File.Exists(destinationFolder.FullName + "\\" + this.CatalogName))
                {
                    File.Copy(destinationFolder.FullName + "\\" + this.CatalogName, tempOldCatalog.FullName);
                }
                DownloadFile(destinationFolder.FullName + "\\" + this.CatalogName);
                string newHash = GetFileHash(destinationFolder.FullName + "\\" + this.CatalogName);
                this.LastCheckResult = true;
                bool newCatalogAvailable = IsNewer(this.Hash, newHash);
                if (newCatalogAvailable)
                {
                    CatalogHelper           oldCatalog           = new CatalogHelper(tempOldCatalog.FullName);
                    System.Threading.Thread openOldCatalogThread = new System.Threading.Thread(new System.Threading.ThreadStart(() => { oldCatalog.OpenCatalog(); }));
                    if (!Closing)
                    {
                        openOldCatalogThread.Start();
                    }

                    CatalogHelper           newCatalog           = new CatalogHelper(destinationFolder.FullName + "\\" + this.CatalogName);
                    System.Threading.Thread openNewCatalogThread = new System.Threading.Thread(new System.Threading.ThreadStart(() => { newCatalog.OpenCatalog(); }));
                    if (!Closing)
                    {
                        openNewCatalogThread.Start();
                    }

                    if (openOldCatalogThread.ThreadState == System.Threading.ThreadState.Running)
                    {
                        openOldCatalogThread.Join();
                    }
                    if (openNewCatalogThread.ThreadState == System.Threading.ThreadState.Running)
                    {
                        openNewCatalogThread.Join();
                    }

                    CompareCatalogs(oldCatalog, newCatalog);
                }
                this.Hash         = newHash;
                LastDownloadDate  = DateTime.Now.Date;
                IsUpdateAvailable = newCatalogAvailable;

                Tools.Utilities.DeleteFolder(tempOldCatalog.DirectoryName);
                return(newCatalogAvailable);
            }
            catch (Exception ex)
            {
                Logger.Write("**** " + ex.Message);
                this.LastCheckResult = false;
            }
            return(false);
        }