Ejemplo n.º 1
0
        public void AddToQueue(string source, string destination)
        {
            // Detect if the file has already been added with the same destination.
            if (queue.FirstOrDefault(f => f.FileToExtract == source && f.Destination == destination) != null)
            {
                return;
            }

            // Detect rar archives named *.part01.rar, *.part02.rar etc.
            Regex regexPartRar = new Regex(@"part\d*.rar$", RegexOptions.IgnoreCase);
            Match matchPartRar = regexPartRar.Match(source);
            if (matchPartRar.Success)
            {
                string baseName = source.Substring(0, source.LastIndexOf(matchPartRar.Value));
                regexPartRar = new Regex(baseName.Replace("\\", "\\\\") + regexPartRar.ToString(), RegexOptions.IgnoreCase);
                IEnumerable<QueueItem> items = GetItems().Where(i => regexPartRar.Match(i.FileToExtract.ToLower()).Success).ToList();
                if (items.FirstOrDefault(f => f.Destination == destination) != null)
                {
                    return;
                }
            }

            QueueItem item = new QueueItem() { FileToExtract = source, Destination = destination, ArchiveSize = GetArchiveSize(source) };
            queue.Add(item);
            totalSize += item.ArchiveSize;
            OnStatusChanged(new ItemAdded(item, queue.Count));
        }
Ejemplo n.º 2
0
 public UnpackerError(QueueItem item, string message)
 {
     Item = item;
     ErrorMessage = message;
 }
Ejemplo n.º 3
0
 public ItemProgressChanged(QueueItem item, int percentCompleted, DateTime eta)
 {
     this.Item = item;
     this.PercentCompleted = percentCompleted;
     this.Eta = eta;
 }
Ejemplo n.º 4
0
 public ItemCompleted(QueueItem item, int itemsLeftInQueue)
 {
     Item = item;
     ItemsLeftInQueue = itemsLeftInQueue;
 }
Ejemplo n.º 5
0
 public ItemStarted(QueueItem item)
 {
     Item = item;
 }
Ejemplo n.º 6
0
 public ItemAdded(QueueItem item, int itemsInQueue)
 {
     Item = item;
     ItemsInQueue = itemsInQueue;
 }
Ejemplo n.º 7
0
 public UnpackerError(QueueItem item, string message)
 {
     Item         = item;
     ErrorMessage = message;
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Get the content of the provided queue item and add all files that are archives to UnpackQueue.
 /// </summary>
 /// <param name="item">The item to examine for archive files.</param>
 private void GetAndAddExtractedItems(QueueItem item)
 {
     string[] content = unpacker.GetArchiveContent(item.FileToExtract);
     foreach (var file in content)
     {
         if (REGEX_PART_RAR.IsMatch(file) || REGEX_RAR_RNN.IsMatch(file))
         {
             // File is located in the extraction folder.
             this.AddToQueue(Path.Combine(item.Destination, file), item.Destination);
         }
     }
 }
Ejemplo n.º 9
0
 public ItemProgressChanged(QueueItem item, int percentCompleted, DateTime eta)
 {
     this.Item             = item;
     this.PercentCompleted = percentCompleted;
     this.Eta = eta;
 }
Ejemplo n.º 10
0
 public ItemCompleted(QueueItem item, int itemsLeftInQueue)
 {
     Item             = item;
     ItemsLeftInQueue = itemsLeftInQueue;
 }
Ejemplo n.º 11
0
 public ItemStarted(QueueItem item)
 {
     Item = item;
 }
Ejemplo n.º 12
0
 public ItemAdded(QueueItem item, int itemsInQueue)
 {
     Item         = item;
     ItemsInQueue = itemsInQueue;
 }
Ejemplo n.º 13
0
        public void Run(UnpackMethod unpackMethod, object options)
        {
            if (queue == null)
            {
                return;
            }

            sizeCompleted = 0;
            canceled      = false;
            unpacker      = null;

            switch (unpackMethod)
            {
            case UnpackMethod.UnRAR: unpacker = new UnRAR(); break;
            }

            unpacker.SetOptions(options);
            unpacker.ProgressChanged += new Action <int, DateTime>(unpacker_ProgressChanged);
            unpacker.OutputChanged   += new Action <string>(unpacker_OutputChanged);

            queueStarted = DateTime.Now;
            OnStatusChanged(new QueueStarted());

            int length = queue.Count;

            for (currentPosition = 0; currentPosition < length; currentPosition++)
            {
                if (canceled)
                {
                    break;
                }

                QueueItem item        = queue[currentPosition];
                string    file        = item.FileToExtract;
                string    destination = item.Destination;

                OnStatusChanged(new ItemStarted(item));
                bool success = unpacker.Unpack(file, destination);

                if (canceled)
                {
                    break;
                }

                if (success)
                {
                    if (AutoAddUnpackedFiles)
                    {
                        GetAndAddExtractedItems(item);
                    }
                    queue[currentPosition].ErrorMessage = null;
                    OnStatusChanged(new ItemCompleted(item, CalculateItemsLeft()));
                }
                else
                {
                    OnStatusChanged(new UnpackerError(item, unpacker.ErrorMessage));
                    queue[currentPosition].ErrorMessage = unpacker.ErrorMessage;
                    CalculateAndReportProgress(0);
                }

                length = queue.Count;
            }

            if (canceled)
            {
                OnStatusChanged(new QueueCanceled());
            }
            else
            {
                OnStatusChanged(new QueueCompleted());
            }
        }