Esempio n. 1
0
        private async Task <(FileStatus status, string reason)> GetFileStatusAsync(RegistryFile file, string fullPath)
        {
            if (!_fs.File.Exists(fullPath))
            {
                if (file.Ignore)
                {
                    return(FileStatus.Ignored, null);
                }
                if (file.Url == null)
                {
                    return(FileStatus.NotDownloadable, $"No URL provided.");
                }
                return(FileStatus.NotInstalled, null);
            }

            if (file.Hash?.Type == null)
            {
                return(FileStatus.Installed, null);
            }

            if (file.Hash.Type != Hashing.Type)
            {
                throw new InvalidOperationException($"Unsupported hash type: {file.Hash.Type}.");
            }

            var hash = await Hashing.GetHashAsync(_fs, fullPath);

            return(hash == file.Hash.Value
                ? (FileStatus.Installed, (string)null)
                : (FileStatus.HashMismatch, $"Expected hash {file.Hash.Value}, file on disk was {hash}."));
        }
Esempio n. 2
0
        private void Register(Action action, string fullPath)
        {
            // Only register if required.

            if (action == Action.Assemble)
            {
                // Load the registry file.

                RegistryFile registryFile = new RegistryFile();
                registryFile.Load(fullPath);

                foreach (RegistryCaptureKey registryKey in registryFile.Keys)
                {
                    Register(registryKey);
                }
            }
        }
Esempio n. 3
0
        public void DoesNotMatchByFilenameWhenMatchedByHash()
        {
            var saves = ResultFactory.SavesMap()
                        .WithScript(new Script($"{_vam}1.cs", "1"), out var local1)
                        .Build();
            RegistryFile           file    = ResultFactory.RegFile("1.cs", "1");
            RegistryPackageVersion version = ResultFactory.RegVer("1.0.0", file);
            RegistryPackage        script  = ResultFactory.RegScript("my-script", version);
            var registry = ResultFactory.Reg(script);

            var result = _handler.Match(saves, registry);

            PartyAssertions.AreDeepEqual(new RegistrySavesMatches
            {
                HashMatches = new[] { new RegistrySavesMatch {
                                          Script = script, Version = version, File = file, Local = local1
                                      } },
                FilenameMatches = new RegistrySavesMatch[0],
                NoMatches       = new Script[0]
            }, result);
        }
Esempio n. 4
0
        private async Task <InstalledFileInfo> GetPackageFileInfo(string packagePath, RegistryFile file)
        {
            if (!RegistryFile.ValidFilename.IsMatch(file.Filename))
            {
                throw new UnauthorizedAccessException($"Only files relative to the package (file.cs) or to vam (/file.cs) are accepted. Value: '{file.Filename}'");
            }
            var fullPath = file.Filename.StartsWith("/")
                ? Path.Combine(_folders.FromRelativeToVam(file.Filename.Substring(1)))
                : Path.Combine(packagePath, file.Filename);

            var info = new InstalledFileInfo
            {
                FullPath     = fullPath,
                RegistryFile = file
            };

            var(status, reason) = await GetFileStatusAsync(file, fullPath).ConfigureAwait(false);

            info.Status = status;
            info.Reason = reason;

            return(info);
        }
Esempio n. 5
0
        private async Task <LocalPackageInfo.InstalledFileInfo> GetPackageFileInfo(string installPath, RegistryFile file)
        {
            var filePath = Path.Combine(installPath, file.Filename);
            var fileInfo = new LocalPackageInfo.InstalledFileInfo
            {
                Path         = filePath,
                RegistryFile = file
            };

            if (_fs.File.Exists(filePath))
            {
                var hash = await Hashing.GetHashAsync(_fs, filePath);

                if (file.Hash.Type != Hashing.Type)
                {
                    throw new InvalidOperationException($"Unsupported hash type: {file.Hash.Type}");
                }
                if (hash == file.Hash.Value)
                {
                    fileInfo.Status = LocalPackageInfo.FileStatus.Installed;
                }
                else
                {
                    fileInfo.Status = LocalPackageInfo.FileStatus.HashMismatch;
                }
            }
            else if (file.Ignore)
            {
                fileInfo.Status = LocalPackageInfo.FileStatus.Ignored;
            }
            else
            {
                fileInfo.Status = LocalPackageInfo.FileStatus.NotInstalled;
            }
            return(fileInfo);
        }
Esempio n. 6
0
 public RegistryPackageFileContext(RegistryPackageVersionContext context, RegistryFile file)
     : this(context.Registry, context.Package, context.Version, file)
 {
 }
Esempio n. 7
0
 public void Deconstruct(out Registry registry, out RegistryPackage package, out RegistryPackageVersion version, out RegistryFile file)
 {
     registry = Registry;
     package  = Package;
     version  = Version;
     file     = File;
 }
Esempio n. 8
0
 public RegistryPackageFileContext(Registry registry, RegistryPackage package, RegistryPackageVersion version, RegistryFile file)
     : base(registry, package, version)
 {
     File = file ?? throw new System.ArgumentNullException(nameof(file));
 }