Ejemplo n.º 1
0
        // ## Class Logic Methods ##

        /**
         * <param name="xml_rarEntry">
         * Rar entry of the xml file obtained from the calling class. The parameter of the same
         * name will be passed from the constructor.
         * </param>
         *
         * <summary>
         * Generate the xml file and then extract the desired properties from it. The desired
         * properties are the ones corresponding to the constants defined in this class.
         * </summary>
         */
        private async void GenerateObjectProperties(RarArchiveEntry xml_rarEntry)
        {
            // create the xml file from rar entry
            string pathToXmlFile = this.CopyRaEntryToXMLFile(xml_rarEntry);

            // extract data from the xml file:
        }
Ejemplo n.º 2
0
        /**
         * <param name="entry"></param>
         * <param name="localFilePath"></param>
         * <summary></summary>
         *
         * Should no longer be necessary if the ResourceGetter functionalities are working as intended.
         */
        private void CopyRarEntryContent(Entry entry, string localFilePath)
        {
            RarArchiveEntry rae = (RarArchiveEntry)entry;

            using (var rarEntryStream = rae.OpenEntryStream())
            {
                using (var targetFileStream = File.Create(localFilePath, (int)rarEntryStream.Length))
                {
                    rarEntryStream.CopyTo(targetFileStream);
                }
            }
        }
Ejemplo n.º 3
0
        /**
         * <param name="xml_rarEntry">
         * Rar entry holding the xml file to be processed. The parameter of the same name will be passed in from
         * GenerateObjectProperties().
         * </param>
         *
         * <summary>
         * Use the Windows file api and Sharpcompress provided functionalities to copy the contents of the
         * rar entry into a temporary xml file to be extracted.
         * </summary>
         *
         * <returns>String path to temporary xml file</returns>
         */
        private string CopyRaEntryToXMLFile(RarArchiveEntry xml_rarEntry)
        {
            string pathToTempFile = this.tempDir.Path + "/tempXml.xml";

            using (var rarStream = xml_rarEntry.OpenEntryStream())
            {
                using (var xmlStream = File.Create(pathToTempFile, (int)rarStream.Length))
                {
                    rarStream.CopyTo(xmlStream);
                }
            }
            return(pathToTempFile);
        }
Ejemplo n.º 4
0
        /**
         * <summary>
         * Copies image from the Entry object as obtained by SharpCompress's RARArchive.Open() and RarArchive.Entries to an image file
         * in the application's local folder. This is done to allow the bitmap image class to access the image inside the rar directory
         * (could not figure out how to do it any other way :( ).
         * </summary>
         * <param name="entry">Entry: the items within the Compressed File as obtained by SharpCompress's read methods.</param>
         * <returns>String : the path to the image in the local directory</returns>
         */
        private string CopyImageToLocalFolder(Entry entry)
        {
            string currentImagePath = this.GenerateImgPath();


            RarArchiveEntry raentry = (RarArchiveEntry)entry;

            using (var raentryStream = raentry.OpenEntryStream())
            {
                using (var imgFileStream = File.Create(currentImagePath, (int)raentryStream.Length))
                {
                    raentryStream.CopyTo(imgFileStream);
                }
            }

            return(currentImagePath);
        }
Ejemplo n.º 5
0
        public SqlDumpReader(string filePath)
        {
            string fileExtension = Path.GetExtension(filePath).ToLower();

            if (!SUPPORTED_DUMP_FILE_EXTENSIONS.Contains(fileExtension))
            {
                throw new Exception($"{fileExtension} is not in the list of supported database dump file extensions.");
            }
            switch (fileExtension.ToLower())
            {
            case ".zip":
                zipArchive = ZipArchive.Open(filePath);
                ZipArchiveEntry firstZipArchiveEntry = zipArchive.Entries.First();
                FileSize     = firstZipArchiveEntry.Size;
                streamReader = new StreamReader(firstZipArchiveEntry.OpenEntryStream());
                break;

            case ".rar":
                rarArchive = RarArchive.Open(filePath);
                RarArchiveEntry firstRarArchiveEntry = rarArchive.Entries.First();
                FileSize     = firstRarArchiveEntry.Size;
                streamReader = new StreamReader(firstRarArchiveEntry.OpenEntryStream());
                break;

            case ".gz":
                gZipArchive = GZipArchive.Open(filePath);
                GZipArchiveEntry firstGZipArchiveEntry = gZipArchive.Entries.First();
                FileSize     = firstGZipArchiveEntry.Size;
                streamReader = new StreamReader(firstGZipArchiveEntry.OpenEntryStream());
                break;

            case ".7z":
                sevenZipArchive = SevenZipArchive.Open(filePath);
                SevenZipArchiveEntry firstSevenZipArchiveEntry = sevenZipArchive.Entries.First();
                FileSize     = firstSevenZipArchiveEntry.Size;
                streamReader = new StreamReader(new PositioningStream(firstSevenZipArchiveEntry.OpenEntryStream()));
                break;

            default:
                FileSize     = new FileInfo(filePath).Length;
                streamReader = new StreamReader(filePath);
                break;
            }
            CurrentFilePosition = 0;
        }
Ejemplo n.º 6
0
        public SqlDumpReader(string filePath)
        {
            string fileExtension = Path.GetExtension(filePath);

            switch (fileExtension.ToLower())
            {
            case ".zip":
                zipArchive = ZipArchive.Open(filePath);
                ZipArchiveEntry firstZipArchiveEntry = zipArchive.Entries.First();
                FileSize     = firstZipArchiveEntry.Size;
                streamReader = new StreamReader(firstZipArchiveEntry.OpenEntryStream());
                break;

            case ".rar":
                rarArchive = RarArchive.Open(filePath);
                RarArchiveEntry firstRarArchiveEntry = rarArchive.Entries.First();
                FileSize     = firstRarArchiveEntry.Size;
                streamReader = new StreamReader(firstRarArchiveEntry.OpenEntryStream());
                break;

            case ".gz":
                gZipArchive = GZipArchive.Open(filePath);
                GZipArchiveEntry firstGZipArchiveEntry = gZipArchive.Entries.First();
                FileSize     = firstGZipArchiveEntry.Size;
                streamReader = new StreamReader(firstGZipArchiveEntry.OpenEntryStream());
                break;

            case ".7z":
                sevenZipArchive = SevenZipArchive.Open(filePath);
                SevenZipArchiveEntry firstSevenZipArchiveEntry = sevenZipArchive.Entries.First();
                FileSize     = firstSevenZipArchiveEntry.Size;
                streamReader = new StreamReader(firstSevenZipArchiveEntry.OpenEntryStream());
                break;

            default:
                FileSize     = new FileInfo(filePath).Length;
                streamReader = new StreamReader(filePath);
                break;
            }
            CurrentFilePosition = 0;
        }
Ejemplo n.º 7
0
        private async Task Extract(String filePath, String destinationFolderPath, String torrentName)
        {
            try
            {
                if (filePath.EndsWith(".rar"))
                {
                    ActiveDownload.NewStatus = DownloadStatus.Unpacking;

                    await using (Stream stream = File.OpenRead(filePath))
                    {
                        using var archive = RarArchive.Open(stream);

                        ActiveDownload.BytesSize = archive.TotalSize;

                        var entries = archive.Entries.Where(entry => !entry.IsDirectory)
                                      .ToList();

                        _rarfileStatus               = entries.ToDictionary(entry => entry.Key, entry => 0L);
                        _rarCurrentEntry             = null;
                        archive.CompressedBytesRead += ArchiveOnCompressedBytesRead;

                        var extractPath = destinationFolderPath;

                        if (!entries.Any(m => m.Key.StartsWith(torrentName + @"\")) && !entries.Any(m => m.Key.StartsWith(torrentName + @"/")))
                        {
                            extractPath = Path.Combine(destinationFolderPath, torrentName);
                        }

                        if (entries.Any(m => m.Key.Contains(".r00")))
                        {
                            extractPath = Path.Combine(extractPath, "Temp");
                        }

                        foreach (var entry in entries)
                        {
                            _rarCurrentEntry = entry;

                            entry.WriteToDirectory(extractPath,
                                                   new ExtractionOptions
                            {
                                ExtractFullPath = true,
                                Overwrite       = true
                            });
                        }
                    }

                    var retryCount = 0;
                    while (File.Exists(filePath) && retryCount < 10)
                    {
                        retryCount++;

                        try
                        {
                            File.Delete(filePath);
                        }
                        catch
                        {
                            await Task.Delay(1000);
                        }
                    }
                }
            }
            catch
            {
                // ignored
            }

            ActiveDownload.Speed           = 0;
            ActiveDownload.BytesDownloaded = ActiveDownload.BytesSize;
            ActiveDownload.NewStatus       = DownloadStatus.Finished;
        }
Ejemplo n.º 8
0
 /**
  * <param name="xml_rarEntry">
  * RAR entry of the xml file; Will be processed in this class.
  * </param>
  *
  * <param name="comicFile">
  * RAR compressed comic file. This class will contain the object to be passed on to other classes.
  * </param>
  *
  * <summary>
  * Creates a ComicMetadata object using xml rar entry and comicFile rar archive. This class has the
  * methods to process these parameters into the necessary data.
  * </summary>
  */
 public ComicMetadata(RarArchiveEntry xml_rarEntry, RarArchive comicFile, StorageFolder tempDir)
 {
     this.cbrFile = comicFile;
     this.tempDir = tempDir;
     // @TODO : Call the class logic methods to extract metadata.
 }
Ejemplo n.º 9
0
 public RarStoreStream(RarArchiveEntry entry)
 {
     this.entry = entry;
 }
Ejemplo n.º 10
0
        private async Task Unpack(String filePath)
        {
            try
            {
                await using (Stream stream = File.OpenRead(filePath))
                {
                    using var archive = RarArchive.Open(stream);

                    BytesTotal = archive.TotalSize;

                    var entries = archive.Entries.Where(entry => !entry.IsDirectory)
                                  .ToList();

                    _rarfileStatus               = entries.ToDictionary(entry => entry.Key, entry => 0L);
                    _rarCurrentEntry             = null;
                    archive.CompressedBytesRead += ArchiveOnCompressedBytesRead;

                    var extractPath = _destinationPath;

                    if (!entries.Any(m => m.Key.StartsWith(_torrent.RdName + @"\")) && !entries.Any(m => m.Key.StartsWith(_torrent.RdName + @"/")))
                    {
                        extractPath = Path.Combine(_destinationPath, _torrent.RdName);
                    }

                    if (entries.Any(m => m.Key.Contains(".r00")))
                    {
                        extractPath = Path.Combine(extractPath, "Temp");
                    }

                    foreach (var entry in entries)
                    {
                        if (_cancelled)
                        {
                            return;
                        }

                        _rarCurrentEntry = entry;

                        entry.WriteToDirectory(extractPath,
                                               new ExtractionOptions
                        {
                            ExtractFullPath = true,
                            Overwrite       = true
                        });
                    }
                }

                var retryCount = 0;
                while (File.Exists(filePath) && retryCount < 10)
                {
                    retryCount++;

                    try
                    {
                        File.Delete(filePath);
                    }
                    catch
                    {
                        await Task.Delay(1000);
                    }
                }
            }
            catch (Exception ex)
            {
                Error = $"An unexpected error occurred downloading {_download.Link} for torrent {_torrent.RdName}: {ex.Message}";
            }
            finally
            {
                Finished = true;
            }
        }
Ejemplo n.º 11
0
 public RarPage(RarArchiveEntry entry)
 {
     this.entry = entry;
 }