예제 #1
0
        internal static void GetCoreRunExecutableFullPath([NotNull] this Assembly assembly, [NotNull] ISnapFilesystem snapFilesystem,
                                                          [NotNull] ISnapAppReader snapAppReader, out string coreRunFullPath)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException(nameof(assembly));
            }
            if (snapFilesystem == null)
            {
                throw new ArgumentNullException(nameof(snapFilesystem));
            }
            if (snapAppReader == null)
            {
                throw new ArgumentNullException(nameof(snapAppReader));
            }

            var assemblyLocationDirectory = snapFilesystem.PathGetDirectoryName(assembly.Location);
            var snapApp         = assemblyLocationDirectory.GetSnapAppFromDirectory(snapFilesystem, snapAppReader);
            var parentDirectory = snapFilesystem.DirectoryGetParent(assemblyLocationDirectory);

            snapApp.GetCoreRunExecutableFullPath(snapFilesystem, parentDirectory, out coreRunFullPath);
        }
예제 #2
0
        public async Task <List <string> > ExtractAsync(string destinationDirectoryAbsolutePath, [NotNull] SnapRelease snapRelease,
                                                        IAsyncPackageCoreReader asyncPackageCoreReader, CancellationToken cancellationToken = default)
        {
            if (destinationDirectoryAbsolutePath == null)
            {
                throw new ArgumentNullException(nameof(destinationDirectoryAbsolutePath));
            }
            if (snapRelease == null)
            {
                throw new ArgumentNullException(nameof(snapRelease));
            }
            if (asyncPackageCoreReader == null)
            {
                throw new ArgumentNullException(nameof(asyncPackageCoreReader));
            }

            var snapApp = await _snapPack.GetSnapAppAsync(asyncPackageCoreReader, cancellationToken);

            var coreRunExeFilename = _snapEmbeddedResources.GetCoreRunExeFilenameForSnapApp(snapApp);
            var extractedFiles     = new List <string>();

            _snapFilesystem.DirectoryCreateIfNotExists(destinationDirectoryAbsolutePath);

            var files = !snapRelease.IsFull ?
                        snapRelease
                        .New
                        .Concat(snapRelease.Modified)
                        .OrderBy(x => x.NuspecTargetPath, new OrdinalIgnoreCaseComparer())
                        .ToList() :
                        snapRelease.Files;

            foreach (var checksum in files)
            {
                var isSnapRootTargetItem = checksum.NuspecTargetPath.StartsWith(SnapConstants.NuspecAssetsTargetPath);

                string dstFilename;
                if (isSnapRootTargetItem)
                {
                    dstFilename = _snapFilesystem.PathCombine(destinationDirectoryAbsolutePath, checksum.Filename);

                    if (checksum.Filename == coreRunExeFilename)
                    {
                        dstFilename = _snapFilesystem.PathCombine(
                            _snapFilesystem.DirectoryGetParent(destinationDirectoryAbsolutePath), checksum.Filename);
                    }
                }
                else
                {
                    var targetPath = checksum.NuspecTargetPath.Substring(SnapConstants.NuspecRootTargetPath.Length + 1);
                    dstFilename = _snapFilesystem.PathCombine(destinationDirectoryAbsolutePath,
                                                              _snapFilesystem.PathEnsureThisOsDirectoryPathSeperator(targetPath));
                }

                var thisDestinationDir = _snapFilesystem.PathGetDirectoryName(dstFilename);
                _snapFilesystem.DirectoryCreateIfNotExists(thisDestinationDir);

                var srcStream = await asyncPackageCoreReader.GetStreamAsync(checksum.NuspecTargetPath, cancellationToken);

                await _snapFilesystem.FileWriteAsync(srcStream, dstFilename, cancellationToken);

                extractedFiles.Add(dstFilename);
            }

            return(extractedFiles);
        }