Example #1
0
        /// <summary>

        /// Search a directory or archive and add any files or sub-directories

        /// to the list of candidates currently being resolved

        /// </summary>

        /// <param name="candidates">Candidates currently being resolved</param>
        public void Explode(SubmissionCandidates candidates, string workingDirectory)
        {
            if (IsArchive)
            {
                // Archives in Archives!!
                if (IsArchivedFile)
                {
                    string exportPath = Path.Combine(workingDirectory, HunterConfig.GalileoDefaultDataFolder + Path.DirectorySeparatorChar + "galileo_" + Guid.ToString() + FileExtension);

                    ArchiveInfo.Extract(ReadPath, exportPath);
                    _resolvePath = exportPath;
                }

                if (_fileType == FileTypes.Types.Zip)
                {
                    _archiveInfo     = new ZipArchiveInfo(ReadPath);
                    _archiveChildren = new List <SubmissionCandidate>(10);

                    if (_archiveInfo.IsOpen == false)
                    {
                        // Probably best to do something better than this?
                        throw new Exception("Could not open archive???");
                    }

                    foreach (var fileName in _archiveInfo)
                    {
                        SubmissionCandidate candidate = candidates.Add(fileName, _depth + 1, this);
                        _archiveChildren.Add(candidate);
                    }

                    // We leave _archiveInfo open, because later the files
                    // will want to be inspected and possibly extracted.
                }
            }
            else if (IsDirectory)
            {
                System.IO.DirectoryInfo info = new System.IO.DirectoryInfo(ReadPath);
                foreach (var file in info.EnumerateFiles())
                {
                    candidates.Add(file.FullName, _depth + 1, this);
                }
                foreach (var directory in info.EnumerateDirectories())
                {
                    candidates.Add(directory.FullName, _depth + 1, this);
                }
            }
        }
Example #2
0
        /// <summary>

        /// Export the file for processing, that if it is in an archive. Additionally

        /// final checks on the file so they are ready to become a submission

        /// </summary>
        protected void ExportFile(string workingDirectory, bool ignoreParent = false, bool onlySubmissions = false)
        {
            if (IsExported)
            {
                return;
            }

            _resolution |= SubmissionCandidateResolution.Exported;

            if (ignoreParent == false && Parent != null)
            {
                Parent.ExportFile(workingDirectory, ignoreParent, onlySubmissions);
            }

            if (IsArchive && _archiveChildren != null)
            {
                // Design path here. Using parents if any.

                string basePath = string.Empty;

                if (HasParent)
                {
                    // archive in a folder
                    if (Parent.IsDirectory)
                    {
                        basePath = Path.Combine(workingDirectory, HunterConfig.GalileoDefaultDataFolder);
                    }
                    // archive in a archive
                    else
                    {
                        basePath = Parent.ReadPath;
                    }
                }
                else
                {
                    basePath = Path.Combine(workingDirectory, HunterConfig.GalileoDefaultDataFolder);
                }


                //string basePath = Path.Combine(workingDirectory, HunterConfig.GalileoDefaultDataFolder);
                _resolvePath = Path.Combine(basePath, string.Format("A_{0}_{1}", GuidShorthand, FileName));

                // Create folder here.
                Directory.CreateDirectory(ReadPath);

                if (onlySubmissions == false)
                {
                    foreach (var child in _archiveChildren)
                    {
                        if (child.IsIgnoredButExport)
                        {
                            child.ExportFile(ReadPath, true, onlySubmissions);
                        }
                    }
                }
            }

            if ((IsSubmission || IsIgnoredButExport) && !IsFiltered)
            {
                // @TODO
                //    If in an archive, then export file to readpath.
                if (IsArchivedFile)
                {
                    _fileName = System.IO.Path.GetFileName(ReadPath);
                    _fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(ReadPath);
                    _fileExtension            = System.IO.Path.GetExtension(ReadPath);

                    string[] paths = Platform.SplitArchivePath(ReadPath);
                    paths = Platform.CleanArchivePaths(paths);

                    string exportPath = Path.Combine(workingDirectory, Path.Combine(paths));
                    Directory.CreateDirectory(Path.GetDirectoryName(new DirectoryInfo(exportPath).FullName));

                    ArchiveInfo.Extract(ReadPath, exportPath);

                    _fileInfo    = new System.IO.FileInfo(exportPath);
                    _resolvePath = exportPath;
                }
                else
                {
                    _fileInfo = new System.IO.FileInfo(ReadPath);

                    // Update with new information based on finalized pathing information
                    _fileName = System.IO.Path.GetFileName(ReadPath);
                    _fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(ReadPath);
                    _fileExtension            = System.IO.Path.GetExtension(ReadPath);
                }
                _containerPath = Parent.ContainerPath;
            }
        }