Beispiel #1
0
        public string Run(IParser parser, IFileInspector fileInspector, string[] args)
        {
            var options = parser.Parse(args);

            if (options.ShowUsage)
            {
                //We could be more specific about what was missing, but most command line apps just show you the general usage instructions.
                return("FileData.exe (-s | -v) filenane");
            }

            var fileInfo = fileInspector.InspectFile(options);

            //Format the resuls for the user
            var result = new List <string>();

            if (fileInfo.Size.HasValue)
            {
                result.Add($"Size: {fileInfo.Size.Value}");
            }

            if (!string.IsNullOrEmpty(fileInfo.Version))
            {
                result.Add($"Version: {fileInfo.Version}");
            }

            return(result.Count() > 0 ? string.Join(", ", result.ToArray()) : "No file information");
        }
        public bool IsRecognizedFile(IFileInspector fileInspector)
        {
            Stream stream;

            if (fileInspector.TryGetStream(out stream))
            {
                // Parse PE header/load import table.
                DllInfo info = Gallio.BoostAdapter.Utils.DllParser.GetDllInfo(stream);

                // No import table? Certainly not Boost.Test testable DLL then.
                if (info.ImportedDlls == null)
                {
                    return false;
                }

                // If there's reference to Boost.Test DLL - assume the DLL is testable.
                // This is not 100% correct - presence of test initialization function
                // should also be checked to be completely sure it can be tested, but
                // that would complicate things too much while providing little extra
                // benefits.
                foreach (string DllName in info.ImportedDlls)
                {
                    if (DllName.StartsWith(
                            "boost_unit_test_framework",
                            StringComparison.InvariantCultureIgnoreCase))
                    {
                        return true;
                    }
                }
            }

            return false;
        }
Beispiel #3
0
            public bool IsRecognizedFile(IFileInspector fileInspector)
            {
                if (FileNameRegex != null)
                {
                    FileInfo fileInfo;
                    if (!fileInspector.TryGetFileInfo(out fileInfo))
                    {
                        return(false);
                    }

                    if (!FileNameRegex.IsMatch(fileInfo.Name))
                    {
                        return(false);
                    }
                }

                if (ContentsRegex != null)
                {
                    string contents;
                    if (!fileInspector.TryGetContents(out contents))
                    {
                        return(false);
                    }

                    if (!ContentsRegex.IsMatch(contents))
                    {
                        return(false);
                    }
                }

                IFileTypeRecognizer fileTypeRecognizer = RecognizerHandle.GetComponent();

                return(fileTypeRecognizer.IsRecognizedFile(fileInspector));
            }
Beispiel #4
0
        private static FileType IdentifyFileTypeRecursive(IFileInspector fileInspector, Dictionary <FileType, bool> fileTypeFilter,
                                                          IEnumerable <FileTypeInfo> fileTypeInfos)
        {
            foreach (var fileTypeInfo in fileTypeInfos)
            {
                bool isExplicitCandidate;
                if (fileTypeFilter != null)
                {
                    if (!fileTypeFilter.TryGetValue(fileTypeInfo.FileType, out isExplicitCandidate))
                    {
                        continue; // ignore if not in filter
                    }
                }
                else
                {
                    isExplicitCandidate = true;
                }

                if (fileTypeInfo.IsRecognizedFile(fileInspector))
                {
                    FileType subtype = IdentifyFileTypeRecursive(fileInspector, fileTypeFilter, fileTypeInfo.Subtypes);
                    if (subtype != null)
                    {
                        return(subtype);
                    }

                    if (isExplicitCandidate)
                    {
                        return(fileTypeInfo.FileType);
                    }
                }
            }

            return(null);
        }
Beispiel #5
0
        /// <inheritdoc />
        public FileType IdentifyFileType(IFileInspector fileInspector)
        {
            if (fileInspector == null)
            {
                throw new ArgumentNullException("fileInspector");
            }

            return(IdentifyFileTypeImpl(fileInspector, null));
        }
        /// <inheritdoc />
        public bool IsRecognizedFile(IFileInspector fileInspector)
        {
            Stream stream;
            if (fileInspector.TryGetStream(out stream))
            {
                return AssemblyUtils.IsAssembly(stream);
            }

            return false;
        }
Beispiel #7
0
        /// <inheritdoc />
        public bool IsRecognizedFile(IFileInspector fileInspector)
        {
            Stream stream;

            if (fileInspector.TryGetStream(out stream))
            {
                return(AssemblyUtils.IsAssembly(stream));
            }

            return(false);
        }
Beispiel #8
0
        private FileType IdentifyFileTypeImpl(IFileInspector fileInspector, IEnumerable <FileType> candidates)
        {
            Dictionary <FileType, bool> fileTypeFilter = CreateFileTypeFilter(candidates);

            FileType fileType = IdentifyFileTypeRecursive(fileInspector, fileTypeFilter, rootFileTypeInfos);

            if (fileType == null)
            {
                fileType = unknownFileType;
            }
            return(fileType);
        }
        /// <inheritdoc />
        public bool IsRecognizedFile(IFileInspector fileInspector)
        {
            Stream stream;

            if (!fileInspector.TryGetStream(out stream))
                return false;

            using (var reader = new PEImageReader(stream))
            {
                PEImageInfo info = reader.Read();
                return (info != null) && info.Exports.Contains("MbUnitCpp_RunTest");
            }
        }
Beispiel #10
0
        /// <inheritdoc />
        public FileType IdentifyFileType(IFileInspector fileInspector, IEnumerable <FileType> candidates)
        {
            if (fileInspector == null)
            {
                throw new ArgumentNullException("fileInspector");
            }
            if (candidates == null)
            {
                throw new ArgumentNullException("candidates");
            }

            return(IdentifyFileTypeImpl(fileInspector, candidates));
        }
        /// <inheritdoc />
        public bool IsRecognizedFile(IFileInspector fileInspector)
        {
            Stream stream;

            if (!fileInspector.TryGetStream(out stream))
            {
                return(false);
            }

            using (var reader = new PEImageReader(stream))
            {
                PEImageInfo info = reader.Read();
                return((info != null) && info.Exports.Contains("MbUnitCpp_RunTest"));
            }
        }
        private static IList <AssemblyName> GetAssemblyReferences(IFileInspector fileInspector)
        {
            Stream stream;

            if (fileInspector.TryGetStream(out stream))
            {
                AssemblyMetadata assemblyMetadata = AssemblyUtils.GetAssemblyMetadata(stream, AssemblyMetadataFields.AssemblyReferences);
                if (assemblyMetadata != null)
                {
                    return(assemblyMetadata.AssemblyReferences);
                }
            }

            return(EmptyArray <AssemblyName> .Instance);
        }
 /// <inheritdoc />
 public bool IsRecognizedFile(IFileInspector fileInspector)
 {
     return true;
 }
 /// <inheritdoc />
 public bool IsRecognizedFile(IFileInspector fileInspector)
 {
     return(true);
 }
Beispiel #15
0
 public MainForm()
 {
     _inspector = new HardDriveInspector();
     InitializeComponent();
 }
            public bool IsRecognizedFile(IFileInspector fileInspector)
            {
                if (FileNameRegex != null)
                {
                    FileInfo fileInfo;
                    if (!fileInspector.TryGetFileInfo(out fileInfo))
                        return false;

                    if (! FileNameRegex.IsMatch(fileInfo.Name))
                        return false;
                }

                if (ContentsRegex != null)
                {
                    string contents;
                    if (!fileInspector.TryGetContents(out contents))
                        return false;

                    if (! ContentsRegex.IsMatch(contents))
                        return false;
                }

                IFileTypeRecognizer fileTypeRecognizer = RecognizerHandle.GetComponent();
                return fileTypeRecognizer.IsRecognizedFile(fileInspector);
            }
        private FileType IdentifyFileTypeImpl(IFileInspector fileInspector, IEnumerable<FileType> candidates)
        {
            Dictionary<FileType, bool> fileTypeFilter = CreateFileTypeFilter(candidates);

            FileType fileType = IdentifyFileTypeRecursive(fileInspector, fileTypeFilter, rootFileTypeInfos);
            if (fileType == null)
                fileType = unknownFileType;
            return fileType;
        }
        private static FileType IdentifyFileTypeRecursive(IFileInspector fileInspector, Dictionary<FileType, bool> fileTypeFilter,
            IEnumerable<FileTypeInfo> fileTypeInfos)
        {
            foreach (var fileTypeInfo in fileTypeInfos)
            {
                bool isExplicitCandidate;
                if (fileTypeFilter != null)
                {
                    if (! fileTypeFilter.TryGetValue(fileTypeInfo.FileType, out isExplicitCandidate))
                        continue; // ignore if not in filter
                }
                else
                {
                    isExplicitCandidate = true;
                }

                if (fileTypeInfo.IsRecognizedFile(fileInspector))
                {
                    FileType subtype = IdentifyFileTypeRecursive(fileInspector, fileTypeFilter, fileTypeInfo.Subtypes);
                    if (subtype != null)
                        return subtype;

                    if (isExplicitCandidate)
                        return fileTypeInfo.FileType;
                }
            }

            return null;
        }
        /// <inheritdoc />
        public FileType IdentifyFileType(IFileInspector fileInspector, IEnumerable<FileType> candidates)
        {
            if (fileInspector == null)
                throw new ArgumentNullException("fileInspector");
            if (candidates == null)
                throw new ArgumentNullException("candidates");

            return IdentifyFileTypeImpl(fileInspector, candidates);
        }
        /// <inheritdoc />
        public FileType IdentifyFileType(IFileInspector fileInspector)
        {
            if (fileInspector == null)
                throw new ArgumentNullException("fileInspector");

            return IdentifyFileTypeImpl(fileInspector, null);
        }