コード例 #1
0
        private void HandleDefaultSelection(string file, IArchiveReader reader)
        {
            IEnumerable <IArchiveEntry> filteredEntries = reader.Entries.Where(x => !string.IsNullOrEmpty(x.Name) && !x.Name.EndsWith(Path.PathSeparator.ToString()) &&
                                                                               m_supportedExtensions.Any(y => y.Equals(Path.GetExtension(x.Name), StringComparison.OrdinalIgnoreCase))).OrderBy(x => x.Name, StringComparer.OrdinalIgnoreCase).ToList();

            if (chkPkContents.Checked)
            {
                IEnumerable <IArchiveEntry> pk3Entries = Util.GetEntriesByExtension(reader, Util.GetPkExtenstions()); //should check for MAPINFO (e.g. joyofmapping)

                foreach (IArchiveEntry entry in pk3Entries)
                {
                    string extractedFile = Util.ExtractTempFile(m_temp.GetFullPath(), entry);
                    using (IArchiveReader zaInner = ArchiveReader.Create(extractedFile))
                    {
                        HandleDefaultSelection(extractedFile, zaInner);
                    }
                }
            }

            foreach (IArchiveEntry entry in reader.Entries)
            {
                if (!string.IsNullOrEmpty(entry.Name))
                {
                    if (m_ct.IsCancellationRequested)
                    {
                        break;
                    }
                    HandleAddItem(file, entry.FullName, entry.Name, filteredEntries.Contains(entry));
                }
            }
        }
コード例 #2
0
        private string ParseMapInfoInclude(IArchiveReader reader, string mapinfo)
        {
            StringBuilder   sb       = new StringBuilder();
            Regex           mapRegex = new Regex(@"\s*include\s+(\S+)");
            MatchCollection matches  = mapRegex.Matches(mapinfo);

            foreach (Match match in matches)
            {
                if (match.Groups.Count < 2)
                {
                    continue;
                }

                string file = match.Groups[1].Value.Trim();
                if (m_includeFiles.Contains(file))
                {
                    continue;
                }

                m_includeFiles.Add(file);

                var entry = reader.Entries.FirstOrDefault(x => x.FullName.Equals(file, StringComparison.OrdinalIgnoreCase));
                if (entry == null)
                {
                    continue;
                }

                AppendMapSet(sb, MapStringFromMapInfo(reader, entry));
            }

            return(sb.ToString());
        }
コード例 #3
0
ファイル: IndexVolumeReader.cs プロジェクト: vnau/duplicati
 public IndexBlocklist(IArchiveReader compression, string filename, long size, long hashsize)
 {
     m_compression = compression;
     m_filename    = filename;
     m_size        = size;
     m_hashsize    = hashsize;
 }
コード例 #4
0
ファイル: VolumeReaderBase.cs プロジェクト: vnau/duplicati
        public VolumeReaderBase(string compressor, string file, Options options)
            : base(options)
        {
            m_compression = LoadCompressor(compressor, file, options, out m_stream);
            ReadManifests(options);

            m_disposeCompression = true;
        }
コード例 #5
0
 private void FillMapInfo(IGameFile file, IArchiveReader reader)
 {
     file.Map = GetMaps(reader);
     if (!string.IsNullOrEmpty(file.Map))
     {
         file.MapCount = file.Map.Count(x => x == ',') + 1;
     }
 }
コード例 #6
0
ファイル: VolumeReaderBase.cs プロジェクト: vnau/duplicati
        public virtual void Dispose()
        {
            if (m_disposeCompression && m_compression != null)
            {
                m_compression.Dispose();
                m_compression = null;

                m_stream?.Dispose();
                m_stream = null;
            }
        }
コード例 #7
0
 public ExtractOperation(
     IArchiveReader archiveReader,
     IDirectoryService directoryService,
     string archiveFilePath,
     string outputDirectory)
 {
     _archiveReader    = archiveReader;
     _directoryService = directoryService;
     _archiveFilePath  = archiveFilePath;
     _outputDirectory  = outputDirectory;
 }
コード例 #8
0
ファイル: Util.cs プロジェクト: nstlaurent/DoomLauncher
        public static IEnumerable <IArchiveEntry> GetEntriesByExtension(IArchiveReader reader, string[] extensions)
        {
            List <IArchiveEntry> entries = new List <IArchiveEntry>();

            foreach (var ext in extensions)
            {
                entries.AddRange(reader.Entries
                                 .Where(x => x.Name.Contains('.') && Path.GetExtension(x.Name).Equals(ext, StringComparison.OrdinalIgnoreCase)));
            }

            return(entries);
        }
コード例 #9
0
        public static bool TryGetFile(string subpath, IArchiveReader bsaReader, out IArchiveFile?file)
        {
            file = null;
            var files = bsaReader.Files.Where(candidate => candidate.Path.Equals(subpath, StringComparison.OrdinalIgnoreCase));

            if (files.Any())
            {
                file = files.First();
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #10
0
        private List <string> GetFilesFromGameFileSettings(IGameFile gameFile, LauncherPath gameFileDirectory, LauncherPath tempDirectory,
                                                           bool checkSpecific, string[] extensions)
        {
            List <string> files = new List <string>();

            using (IArchiveReader reader = CreateArchiveReader(gameFile, gameFileDirectory))
            {
                IEnumerable <IArchiveEntry> entries;
                if (checkSpecific && SpecificFiles != null && SpecificFiles.Length > 0)
                {
                    entries = reader.Entries;
                }
                else
                {
                    entries = reader.Entries.Where(x => !string.IsNullOrEmpty(x.Name) && x.Name.Contains('.') &&
                                                   extensions.Any(y => y.Equals(Path.GetExtension(x.Name), StringComparison.OrdinalIgnoreCase)));
                }

                foreach (IArchiveEntry entry in entries)
                {
                    bool useFile = true;
                    if (checkSpecific && SpecificFiles != null && SpecificFiles.Length > 0)
                    {
                        useFile = SpecificFiles.Contains(entry.FullName);
                    }

                    if (useFile)
                    {
                        if (entry.ExtractRequired)
                        {
                            string extractFile = Path.Combine(tempDirectory.GetFullPath(), entry.Name);
                            if (ExtractFiles)
                            {
                                entry.ExtractToFile(extractFile, true);
                            }
                            files.Add(extractFile);
                        }
                        else
                        {
                            files.Add(entry.FullName);
                        }
                    }
                }
            }

            return(files);
        }
コード例 #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ProcessCommandHandler"/> class.
        /// </summary>
        /// <param name="module">The command handler module.</param>
        /// <param name="mediator">The mediator.</param>
        /// <param name="configuration">The configuration.</param>
        /// <param name="archiveReader">The archive reader.</param>
        /// <param name="archiveExtractor">The archive extractor.</param>
        /// <param name="fileSystemStrategy">The file system strategy.</param>
        public ProcessCommandHandler(
            ICommandHandlerModule module,
            IMediator mediator,
            IAppConfiguration configuration,
            IArchiveReader archiveReader,
            IArchiveExtractor archiveExtractor,
            IFileSystemStrategy fileSystemStrategy)
            : base(module)
        {
            this.mediator         = mediator ?? throw new ArgumentNullException(nameof(mediator));
            this.configuration    = configuration ?? throw new ArgumentNullException(nameof(configuration));
            this.archiveReader    = archiveReader ?? throw new ArgumentNullException(nameof(archiveReader));
            this.archiveExtractor = archiveExtractor ?? throw new ArgumentNullException(nameof(archiveExtractor));

            Ensure.ArgumentNotNull(fileSystemStrategy, nameof(fileSystemStrategy));
            fileSystem = fileSystemStrategy.Create(configuration.Options.WorkingDirectory);
        }
コード例 #12
0
        private string MapStringFromMapInfo(IArchiveReader reader, IArchiveEntry entry)
        {
            StringBuilder sb            = new StringBuilder();
            string        extractedFile = Util.ExtractTempFile(TempDirectory.GetFullPath(), entry);

            if (File.Exists(extractedFile))
            {
                string mapinfo = File.ReadAllText(extractedFile);
                AppendMapSet(sb, ParseMapInfoInclude(reader, mapinfo));
                if (entry.ExtractRequired)
                {
                    File.Delete(extractedFile);
                }
                AppendMapSet(sb, GetMapStringFromMapInfo(mapinfo));
            }

            return(sb.ToString());
        }
コード例 #13
0
ファイル: VolumeReaderBase.cs プロジェクト: vnau/duplicati
        public static IEnumerable <string> ReadBlocklist(IArchiveReader compression, string filename, long hashsize)
        {
            var buffer = new byte[hashsize];

            using (var fs = compression.OpenRead(filename))
            {
                int s;
                while ((s = Library.Utility.Utility.ForceStreamRead(fs, buffer, buffer.Length)) != 0)
                {
                    if (s != buffer.Length)
                    {
                        throw new InvalidDataException("Premature End-of-stream encountered while reading blocklist hashes");
                    }

                    yield return(Convert.ToBase64String(buffer));
                }
            }
        }
コード例 #14
0
        private string MapStringFromGameFile(IArchiveReader reader)
        {
            List <string> maps = new List <string>();

            IEnumerable <IArchiveEntry> wadEntries = GetEntriesByExtension(reader, ".wad");

            foreach (IArchiveEntry entry in wadEntries)
            {
                string extractFile = Util.ExtractTempFile(TempDirectory.GetFullPath(), entry);
                string mapString   = Util.GetMapStringFromWad(extractFile);
                if (!string.IsNullOrEmpty(mapString))
                {
                    maps.Add(mapString);
                }
            }

            return(string.Join(", ", maps.ToArray()));
        }
コード例 #15
0
        private void FillTextFileInfo(IGameFile gameFile, IArchiveReader reader)
        {
            bool bParsedTxt = false;

            foreach (var entry in reader.Entries)
            {
                if (Path.GetExtension(entry.FullName).Equals(".txt", StringComparison.OrdinalIgnoreCase))
                {
                    byte[] buffer = new byte[entry.Length];
                    try
                    {
                        entry.Read(buffer, 0, Convert.ToInt32(entry.Length));
                    }
                    catch (Exception)
                    {
                        // Do not fail because we couldn't read a text file
                    }

                    IdGamesTextFileParser parser = new IdGamesTextFileParser(DateParseFormats);
                    parser.Parse(Encoding.UTF7.GetString(buffer));

                    bParsedTxt = !string.IsNullOrEmpty(parser.Title) || !string.IsNullOrEmpty(parser.Author) || !string.IsNullOrEmpty(parser.Description);

                    if (bParsedTxt)
                    {
                        gameFile.Title       = parser.Title;
                        gameFile.Author      = parser.Author;
                        gameFile.ReleaseDate = parser.ReleaseDate;
                        gameFile.Description = parser.Description;
                    }
                }

                if (bParsedTxt)
                {
                    break;
                }
            }

            if (string.IsNullOrEmpty(gameFile.Title))
            {
                gameFile.Title = gameFile.FileNameNoPath;
            }
        }
コード例 #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ImageService"/> class.
 /// </summary>
 /// <param name="configuration">The configuration.</param>
 /// <param name="archiveReader">The archive reader.</param>
 /// <param name="archiveExtractor">The archive extractor.</param>
 /// <param name="fileSystemStrategy">The file system strategy.</param>
 /// <param name="appInfoFactory">The application information factory.</param>
 /// <param name="jsonWriter">The JSON writer.</param>
 /// <param name="imageExtractor">The image extractor.</param>
 /// <param name="gifImageWriter">The GIF image writer.</param>
 public ImageService(
     IAppConfiguration configuration,
     IArchiveReader archiveReader,
     IArchiveExtractor archiveExtractor,
     IFileSystemStrategy fileSystemStrategy,
     IAppInfoFactory appInfoFactory,
     IDefaultJsonWriter jsonWriter,
     IImageExtractor imageExtractor,
     IGifImageWriter gifImageWriter)
 {
     this.configuration      = configuration ?? throw new ArgumentNullException(nameof(configuration));
     this.archiveReader      = archiveReader ?? throw new ArgumentNullException(nameof(archiveReader));
     this.archiveExtractor   = archiveExtractor ?? throw new ArgumentNullException(nameof(archiveExtractor));
     this.fileSystemStrategy = fileSystemStrategy ?? throw new ArgumentNullException(nameof(fileSystemStrategy));
     this.appInfoFactory     = appInfoFactory ?? throw new ArgumentNullException(nameof(appInfoFactory));
     this.jsonWriter         = jsonWriter ?? throw new ArgumentNullException(nameof(jsonWriter));
     this.imageExtractor     = imageExtractor ?? throw new ArgumentNullException(nameof(imageExtractor));
     this.gifImageWriter     = gifImageWriter ?? throw new ArgumentNullException(nameof(gifImageWriter));
 }
コード例 #17
0
        private bool HandleGameFileIWad(IGameFile gameFile, ISourcePort sourcePort, StringBuilder sb, LauncherPath gameFileDirectory, LauncherPath tempDirectory)
        {
            try
            {
                using (IArchiveReader reader = ArchiveReader.Create(Path.Combine(gameFileDirectory.GetFullPath(), gameFile.FileName)))
                {
                    IArchiveEntry entry       = reader.Entries.First();
                    string        extractFile = Path.Combine(tempDirectory.GetFullPath(), entry.Name);
                    if (ExtractFiles && entry.ExtractRequired)
                    {
                        entry.ExtractToFile(extractFile, true);
                    }

                    if (!entry.ExtractRequired)
                    {
                        extractFile = entry.FullName;
                    }

                    sb.Append(sourcePort.IwadParameter(new SpData(extractFile, gameFile, AdditionalFiles)));
                }
            }
            catch (FileNotFoundException)
            {
                LastError = string.Format("File not found: {0}", gameFile.FileName);
                return(false);
            }
            catch (IOException)
            {
                LastError = string.Format("File in use: {0}", gameFile.FileName);
                return(false);
            }
            catch (Exception)
            {
                LastError = string.Format("There was an issue with the IWad: {0}. Corrupted file?", gameFile.FileName);
                return(false);
            }

            return(true);
        }
コード例 #18
0
        public static string[] GetSupportedFiles(string gameFileDirectory, IGameFile gameFile, string[] supportedExtensions)
        {
            List <string> ret  = new List <string>();
            string        file = Path.Combine(gameFileDirectory, gameFile.FileName);

            if (File.Exists(file))
            {
                using (IArchiveReader reader = ArchiveReader.Create(file))
                {
                    foreach (IArchiveEntry entry in reader.Entries)
                    {
                        if (!string.IsNullOrEmpty(entry.Name) &&
                            supportedExtensions.Any(x => x.Equals(Path.GetExtension(entry.Name), StringComparison.OrdinalIgnoreCase)))
                        {
                            ret.Add(entry.FullName);
                        }
                    }
                }
            }

            return(ret.ToArray());
        }
コード例 #19
0
        //This function is currently only used for loading files by utility (which also uses ISourcePort).
        //This uses Util.ExtractTempFile to avoid extracting files with the same name where the user can have the previous file locked.
        //E.g. opening MAP01 from a pk3, and then opening another MAP01 from a different pk3
        public bool HandleGameFile(IGameFile gameFile, StringBuilder sb, LauncherPath gameFileDirectory, LauncherPath tempDirectory,
                                   ISourcePort sourcePort, List <SpecificFilesForm.SpecificFilePath> pathFiles)
        {
            try
            {
                List <string> files = new List <string>();

                foreach (var pathFile in pathFiles)
                {
                    if (File.Exists(pathFile.ExtractedFile))
                    {
                        using (IArchiveReader reader = ArchiveReader.Create(pathFile.ExtractedFile))
                        {
                            var entry = reader.Entries.FirstOrDefault(x => x.FullName == pathFile.InternalFilePath);
                            if (entry != null)
                            {
                                files.Add(Util.ExtractTempFile(tempDirectory.GetFullPath(), entry));
                            }
                        }
                    }
                }

                BuildLaunchString(sb, sourcePort, files);
            }
            catch (FileNotFoundException)
            {
                LastError = string.Format("The game file was not found: {0}", gameFile.FileName);
                return(false);
            }
            catch (InvalidDataException)
            {
                LastError = string.Format("The game file does not appear to be a valid zip file: {0}", gameFile.FileName);
                return(false);
            }

            return(true);
        }
コード例 #20
0
        private string GetMaps(IArchiveReader reader)
        {
            var txtEntries = GetEntriesByExtension(reader, ".txt").Where(x => x.Name.Equals("mapinfo.txt", StringComparison.InvariantCultureIgnoreCase));

            if (txtEntries.Any())
            {
                return(MapStringFromMapInfo(txtEntries.First()));
            }

            StringBuilder sb = new StringBuilder();

            sb.Append(MapStringFromGameFile(reader));

            IEnumerable <IArchiveEntry> pk3Entries = Util.GetEntriesByExtension(reader, Util.GetReadablePkExtensions());

            foreach (IArchiveEntry entry in pk3Entries)
            {
                string extractedFile = Util.ExtractTempFile(TempDirectory.GetFullPath(), entry);
                using (var extractedZip = ArchiveReader.Create(extractedFile))
                    sb.Append(GetMaps(extractedZip));
            }

            return(sb.ToString());
        }
コード例 #21
0
ファイル: IndexVolumeReader.cs プロジェクト: vnau/duplicati
 public IndexBlocklistEnumerator(IArchiveReader compression, long hashsize)
 {
     m_compression = compression;
     m_hashsize    = hashsize;
     this.Reset();
 }
コード例 #22
0
ファイル: IndexVolumeReader.cs プロジェクト: vnau/duplicati
 public IndexBlockVolumeEnumerable(IArchiveReader compression)
 {
     m_compression = compression;
 }
コード例 #23
0
ファイル: FilesetVolumeReader.cs プロジェクト: vnau/duplicati
 public FilesetVolumeReader(IArchiveReader compression, Options options)
     : base(compression, options)
 {
 }
コード例 #24
0
ファイル: FilesetVolumeReader.cs プロジェクト: vnau/duplicati
 public ControlFileEnumerable(IArchiveReader compression)
 {
     m_compression = compression;
 }
コード例 #25
0
ファイル: FilesetVolumeReader.cs プロジェクト: vnau/duplicati
 public ControlFileEnumerator(IArchiveReader compression)
 {
     m_compression = compression;
     this.Reset();
 }
コード例 #26
0
ファイル: FilesetVolumeReader.cs プロジェクト: vnau/duplicati
 public FileEntryEnumerable(IArchiveReader compression)
 {
     m_compression = compression;
 }
コード例 #27
0
 private IInternalOperation CreateExtractOperation(IArchiveReader archiveReader,
                                                   string archiveFilePath, string outputDirectory) =>
 new ExtractOperation(archiveReader, _directoryService, archiveFilePath, outputDirectory);
コード例 #28
0
 private IEnumerable <IArchiveEntry> GetEntriesByExtension(IArchiveReader reader, string ext)
 {
     return(reader.Entries.Where(x => x.Name.Contains('.') && Path.GetExtension(x.Name).Equals(ext, StringComparison.OrdinalIgnoreCase)));
 }
コード例 #29
0
        public void Execute(string[] zipFiles)
        {
            m_invalidFiles.Clear();

            SyncFileCount   = zipFiles.Length;
            SyncFileCurrent = 0;

            foreach (string fileName in zipFiles)
            {
                if (SyncFileChange != null)
                {
                    CurrentSyncFileName = fileName;
                    SyncFileChange(this, new EventArgs());
                }

                IGameFile file     = SyncDataSource.GetGameFile(fileName);
                IGameFile existing = DbDataSource.GetGameFile(file.FileName);

                if (existing != null)
                {
                    file = existing;
                }

                if (m_fileManagement == FileManagement.Unmanaged)
                {
                    file.FileName = fileName;
                }

                if (file != null)
                {
                    CurrentGameFile = file;
                    GameFileDataNeeded?.Invoke(this, new EventArgs());
                    file.Downloaded = DateTime.Now;

                    try
                    {
                        using (IArchiveReader reader = ArchiveReader.Create(Path.Combine(GameFileDirectory.GetFullPath(), file.FileName)))
                        {
                            FillTextFileInfo(file, reader);
                            FillMapInfo(file, reader);
                        }
                    }
                    catch (IOException)
                    {
                        file.Map = string.Empty;
                        m_invalidFiles.Add(new InvalidFile(fileName, "File is in use/Not found"));
                    }
                    catch (InvalidDataException)
                    {
                        file.Map = string.Empty;
                        m_invalidFiles.Add(new InvalidFile(fileName, "Zip archive invalid or contained an improper pk3"));
                    }
                    catch (Exception ex)
                    {
                        file.Map = string.Empty;
                        m_invalidFiles.Add(new InvalidFile(fileName, CreateExceptionMsg(ex)));
                    }

                    if (existing == null)
                    {
                        DbDataSource.InsertGameFile(file);
                    }
                    else
                    {
                        DbDataSource.UpdateGameFile(file, Util.GetSyncGameFileUpdateFields());
                    }
                }
                else
                {
                    m_invalidFiles.Add(new InvalidFile(fileName, "Not a valid zip archive"));

                    try
                    {
                        FileInfo fileDelete = new FileInfo(Path.Combine(GameFileDirectory.GetFullPath(), fileName));
                        if (fileDelete.Exists)
                        {
                            fileDelete.Delete();
                        }
                    }
                    catch
                    {
                        //delete failed, just keep going
                    }
                }

                SyncFileCurrent++;
            }
        }
コード例 #30
0
ファイル: IndexVolumeReader.cs プロジェクト: vnau/duplicati
 public BlockEnumerator(IArchiveReader compression, string filename)
 {
     m_compression = compression;
     m_filename    = filename;
     this.Reset();
 }