Example #1
0
        public SevenZipFile(string path)
        {
            if (!Settings.UseZip && !Settings.UseRar)
            {
                throw new InvalidOperationException("Zip/RAR formats are not configured to use.");
            }

            lock (lockObject)
            {
                if (extractors.TryGetValue(path, out extractor))
                {
                    extractor.Count++;
                }
                else
                {
                    extractor = new ExtractorUseCountPair(path);
                    extractors[path] = extractor;
                }
            }
        }
Example #2
0
        private static void TryDisposeExtractor(object data)
        {
            try
            {
                Thread.Sleep(60000);

                string path = (string)data;
                ExtractorUseCountPair extractor;

                if (extractors.TryGetValue(path, out extractor) && extractor.Count == 0 && !extractor.Disposed && DateTime.Now - extractor.LastUsedTime >= TimeSpan.FromSeconds(60))
                {
                    lock (lockObject)
                    {
                        if (extractor.Count == 0 && !extractor.Disposed)
                        {
                            extractor.Dispose();
                            extractors.Remove(path);
                        }

                        extractor = null;
                    }
                }
            }
            catch (Exception ex)
            {
                Utility.TryLogError(ex);
                throw;
            }
        }