예제 #1
0
        private bool SetupNewSoft()
        {
            bool bIsSetupDone = true;

            try
            {
                string szFile = string.Format("{0}\\{1}", DOWNPATH, m_pFileName);
                if (File.Exists(szFile))
                {
                    Unrar unrar = new Unrar();
                    unrar.DestinationPath = APPPATH;
                    unrar.Open(szFile, Unrar.OpenMode.Extract);
                    while (unrar.ReadHeader())
                    {
                        unrar.Extract();
                    }
                    if (unrar != null)
                    {
                        unrar.Close();
                    }
                }
            }
            catch (Exception e)
            {
                bIsSetupDone = false;
                AddMsg("解压缩失败原因:" + e.Message);
            }
            return(bIsSetupDone);
        }
예제 #2
0
        /// <summary>
        /// Attempts to unrar a rar archive and to copy its content into a folder.
        /// If it succeeds, the resulting images are added to the files to be added into the generation.
        /// </summary>
        /// <param name="path">Path of the rar archive to be checked.</param>
        private void CheckRarArchive(string path)
        {
            try
            {
                using (Unrar rarFile = new Unrar())
                {
                    int    pathIndex = Data.Files.IndexOf(path);
                    string rarPath   = GenerateArchivePath(path);

                    rarFile.DestinationPath = rarPath;
                    rarFile.Open(path, Unrar.OpenMode.Extract);

                    while (rarFile.ReadHeader())
                    {
                        rarFile.Extract();
                    }

                    List <string> newFiles = new List <string>();
                    ParseExtractedElements(newFiles, new DirectoryInfo(rarPath));

                    InsertArchiveFiles(pathIndex, newFiles);
                }
            }
            catch
            {
                rarErrors.Add(path);
                Data.Files.Remove(path);
            }
        }
예제 #3
0
    public void CheckPass()
    {
        Unrar tmpRar = UnrarObj;

        //Unrar tmpRar = new Unrar(UnrarObj.ArchivePathName);
        //tmpRar.DestinationPath = @"E:\";
        //tmpRar.Open(UnrarObj.DestinationPath, Unrar.OpenMode.Extract);

        while (!IsCompleted || tmpRar.Password != "DONE")
        {
            try
            {
                tmpRar.Password = PasswdList.GetNextPasswd();
                while (UnrarObj.ReadHeader())
                {
                    tmpRar.Extract();
                }
                System.Diagnostics.Debug.WriteLine("Pass found:" + tmpRar.Password);
                IsCompleted = true;
            }
            catch
            {
                System.Diagnostics.Debug.WriteLine("Wrong pass:" + tmpRar.Password);
                if (tmpRar != null)
                {
                    tmpRar.Close();
                }
                continue;
            }
        }
    }
예제 #4
0
파일: Engine.cs 프로젝트: willman0982/code
        private bool ExtractRARContent(string rarFilePath, RootPath rootPath, Record record)
        {
            bool      success   = true;
            SubRecord subRecord = null;

            _lastRARVolume = string.Empty;
            Unrar unrar = new Unrar(rarFilePath)
            {
                DestinationPath = (EngineSettings.UseSpecificOutputFolder
                                        ? Path.Combine(EngineSettings.OutputFolder, FileHandler.GetDeltaPath(Path.GetDirectoryName(rarFilePath), rootPath.Path))
                                        : Path.GetDirectoryName(rarFilePath))
            };

            unrar.ExtractionProgress += unrar_ExtractionProgress;
            unrar.MissingVolume      += unrar_MissingVolume;
            unrar.NewVolume          += unrar_NewVolume;
            unrar.PasswordRequired   += unrar_PasswordRequired;
            try
            {
                unrar.Open(Unrar.OpenMode.Extract);
                while (success && unrar.ReadHeader())
                {
                    WriteLogEntry("Extracting file, name=" + unrar.CurrentFile.FileName + ", size=" + unrar.CurrentFile.UnpackedSize + ", path=" + unrar.DestinationPath);
                    subRecord = new SubRecord(unrar.DestinationPath, unrar.CurrentFile.FileName, unrar.CurrentFile.UnpackedSize);
                    AddSubRecord(record.ID, subRecord);
                    unrar.Extract();
                    success = ValidateExtractedFile(Path.Combine(unrar.DestinationPath, unrar.CurrentFile.FileName),
                                                    unrar.CurrentFile.UnpackedSize, GetRARFileCRC(_lastRARVolume, unrar.CurrentFile.FileName));
                    if (!success)
                    {
                        WriteLogEntry(LogType.Warning, "Validation FAILED, aborting extraction");
                    }
                    AddSubRecord(record.ID, (success ? subRecord.Succeed() : subRecord.Fail()));
                }
            }
            catch (Exception ex)
            {
                WriteLogEntry("An exception occurred while extracting from RAR file, path=" + rarFilePath + ", destination=" + unrar.DestinationPath, ex);
                if (subRecord != null)
                {
                    AddSubRecord(record.ID, subRecord.Fail());
                }
                success = false;
            }
            finally
            {
                unrar.Close();
                unrar.ExtractionProgress -= unrar_ExtractionProgress;
                unrar.MissingVolume      -= unrar_MissingVolume;
                unrar.NewVolume          -= unrar_NewVolume;
                unrar.PasswordRequired   -= unrar_PasswordRequired;
            }
            return(success);
        }
예제 #5
0
        public void ConvertToImage(string rarPath, string imageOutputDirPath)
        {
            try
            {
                Unrar tmp = new Unrar(rarPath);
                tmp.Open(Unrar.OpenMode.List);
                string[] files = tmp.ListFiles();
                tmp.Close();

                int total = files.Length;
                int done  = 0;

                Unrar unrar = new Unrar(rarPath);
                unrar.Open(Unrar.OpenMode.Extract);
                unrar.DestinationPath = imageOutputDirPath;

                while (unrar.ReadHeader() && !cancelled)
                {
                    if (unrar.CurrentFile.IsDirectory)
                    {
                        unrar.Skip();
                    }
                    else
                    {
                        unrar.Extract();
                        ++done;

                        if (this.ProgressChanged != null)
                        {
                            this.ProgressChanged(done, total);
                        }
                    }
                }
                unrar.Close();

                if (this.ConvertSucceed != null)
                {
                    this.ConvertSucceed();
                }
            }
            catch (Exception ex)
            {
                if (this.ConvertFailed != null)
                {
                    this.ConvertFailed(ex.Message);
                }
            }
        }
예제 #6
0
 private void UnRarFile(FiasFileInfo aFileInfo)
 {
     using (var unrar = new Unrar())
     {
         unrar.Open(aFileInfo.FileName, Unrar.OpenMode.Extract);
         unrar.DestinationPath     = Path.GetDirectoryName(aFileInfo.FileName) + "\\Extracted.tmp";
         unrar.ExtractionProgress += unrar_ExtractionProgress;
         while (unrar.ReadHeader())
         {
             if (stopEvent.WaitOne(0))
             {
                 throw new StopException();
             }
             unrar.Extract();
         }
     }
     Directory.Move(Path.GetDirectoryName(aFileInfo.FileName) + "\\Extracted.tmp", Path.GetDirectoryName(aFileInfo.FileName) + "\\Extracted");
     aFileInfo.Checked   = false;
     aFileInfo.Extracted = true;
 }
        protected void unrar(string filename, string destination, List <string> extensions)
        {
            Unrar unrar = null;

            try {
                // Create new unrar class and attach event handlers for
                // progress, missing volumes, and password
                unrar = new Unrar();
                //AttachHandlers(unrar);

                // Set destination path for all files
                unrar.DestinationPath = destination;

                // Open archive for extraction
                unrar.Open(filename, Unrar.OpenMode.Extract);

                // SEASON_NR_EXTRACTION_PATTERNS_KEY each file with subtitle extension
                while (unrar.ReadHeader())
                {
                    string extension = Path.GetExtension(unrar.CurrentFile.FileName).Substring(1).ToLower().Replace(".", "");
                    if (extensions.Contains(extension))
                    {
                        unrar.Extract();
                    }
                    else
                    {
                        unrar.Skip();
                    }
                }
            }
            catch (Exception ex) {
                Logger.Instance.LogMessage("Error during unpack of file: " + filename + " (" + ex.Message + ")", LogLevel.ERROR);
            }
            finally {
                if (unrar != null)
                {
                    unrar.Close();
                }
            }
        }
예제 #8
0
 private void UnRarFile(FiasFileInfo aFileInfo)
 {
     using (var unrar = new Unrar())
     {
         unrar.Open(aFileInfo.FileName, Unrar.OpenMode.Extract);
         unrar.DestinationPath = Path.GetDirectoryName(aFileInfo.FileName) + "\\Extracted.tmp";
         unrar.ExtractionProgress += unrar_ExtractionProgress;
         while (unrar.ReadHeader())
         {
             if (stopEvent.WaitOne(0))
                 throw new StopException();
             unrar.Extract();
         }
     }
     Directory.Move(Path.GetDirectoryName(aFileInfo.FileName) + "\\Extracted.tmp", Path.GetDirectoryName(aFileInfo.FileName) + "\\Extracted");
     aFileInfo.Checked = false;
     aFileInfo.Extracted = true;
 }