示例#1
0
        protected virtual void Dispose(bool disposing)
        {
            // Do not trigger via GC
            if (!disposing)
            {
                return;
            }

            _temporaryDirectory?.Dispose();
        }
示例#2
0
        /// <summary>
        /// Downloads the installer from the web to a temporary file.
        /// </summary>
        /// <param name="url">The URL of the file to download.</param>
        /// <param name="handler">A callback object used when the the user is to be informed about progress.</param>
        /// <exception cref="WebException">A file could not be downloaded from the internet.</exception>
        /// <exception cref="IOException">A downloaded file could not be written to the disk.</exception>
        /// <exception cref="UnauthorizedAccessException">An operation failed due to insufficient rights.</exception>
        /// <remarks>Use either this or <see cref="SetLocal"/>.</remarks>
        public void Download(Uri url, ITaskHandler handler)
        {
            _url = url;

            _tempDir?.Dispose();
            _tempDir = new TemporaryDirectory("0publish");

            try
            {
                _localPath = Path.Combine(_tempDir, url.GetLocalFileName());
                handler.RunTask(new DownloadFile(url, _localPath));
            }
            #region Error handling
            catch (Exception)
            {
                _tempDir.Dispose();
                _tempDir   = null;
                _url       = null;
                _localPath = null;
                throw;
            }
            #endregion
        }
        public static TemporaryDirectory LocalApply([NotNull] this DownloadRetrievalMethod retrievalMethod, string localPath, [NotNull] ITaskHandler handler, [CanBeNull] ICommandExecutor executor = null)
        {
            #region Sanity checks
            if (retrievalMethod == null) throw new ArgumentNullException("retrievalMethod");
            if (string.IsNullOrEmpty(localPath)) throw new ArgumentNullException("localPath");
            if (handler == null) throw new ArgumentNullException("handler");
            #endregion

            if (executor == null) executor = new SimpleCommandExecutor();

            // Set local file size
            long newSize = new FileInfo(localPath).Length;
            if (retrievalMethod.Size != newSize)
                executor.Execute(new SetValueCommand<long>(() => retrievalMethod.Size, value => retrievalMethod.Size = value, newSize));

            var extractionDir = new TemporaryDirectory("0publish");
            try
            {
                new PerTypeDispatcher<DownloadRetrievalMethod>(ignoreMissing: true)
                {
                    // ReSharper disable AccessToDisposedClosure
                    (Archive archive) =>
                    {
                        // Guess MIME types now because the file ending is not known later
                        if (string.IsNullOrEmpty(archive.MimeType))
                        {
                            string mimeType = Archive.GuessMimeType(localPath);
                            executor.Execute(new SetValueCommand<string>(() => archive.MimeType, value => archive.MimeType = value, mimeType));
                        }

                        archive.Apply(localPath, extractionDir, handler);
                    },
                    (SingleFile file) =>
                    {
                        // Guess file name based on local path
                        if (string.IsNullOrEmpty(file.Destination))
                        {
                            string destination = Path.GetFileName(localPath);
                            executor.Execute(new SetValueCommand<string>(() => file.Destination, value => file.Destination = value, destination));
                        }

                        file.Apply(localPath, extractionDir, handler);
                    }
                    // ReSharper restore AccessToDisposedClosure
                }.Dispatch(retrievalMethod);
            }
                #region Error handling
            catch
            {
                extractionDir.Dispose();
                throw;
            }
            #endregion

            return extractionDir;
        }
示例#4
0
 public void Dispose() => m_ConfigurationDirectory.Dispose();
示例#5
0
 public void TearDown()
 {
     _temporaryDirectory.Dispose();
 }
示例#6
0
 public void Dispose()
 {
     temporaryDirectory.Dispose();
 }
示例#7
0
 public void TearDown()
 {
     _tempDir.Dispose();
 }
示例#8
0
        public override void TearDown()
        {
            base.TearDown();

            _destination.Dispose();
        }
示例#9
0
        //FIXME: This is super unsafe right now, as we can copy down into the FS.
        // This should be contained using kinds of destinations.
        private void InstallPackage(Upset package, TemporaryDirectory td, DependencyDefinition dependencyDefinition, bool updateLockfile = false)
        {
            GitIgnorer VCSHandler = new GitIgnorer();

            using (LogAggregator LA = LogAggregator.InUnity(
                       "Package {0} was successfully installed",
                       "Package {0} was successfully installed but raised warnings",
                       "An error occured while installing package {0}",
                       package.PackageName
                       ))
            {
                Upbring upbring = Upbring.Instance();

                // Note: Full package is ALWAYS copied to the upackages directory right now
                string localPackagePath = GetRepositoryInstallPath(package);
                upbring.AddPackage(package);
                if (!Directory.Exists(localPackagePath))
                {
                    Directory.CreateDirectory(localPackagePath);
                }

                Uplift.Common.FileSystemUtil.CopyDirectory(td.Path, localPackagePath);
                upbring.AddLocation(package, InstallSpecType.Root, localPackagePath);

                VCSHandler.HandleDirectory(upfile.GetPackagesRootPath());

                InstallSpecPath[] specArray;
                if (package.Configuration == null)
                {
                    // If there is no Configuration present we assume
                    // that the whole package is wrapped in "InstallSpecType.Base"
                    InstallSpecPath wrapSpec = new InstallSpecPath
                    {
                        Path = "",
                        Type = InstallSpecType.Base
                    };

                    specArray = new[] { wrapSpec };
                }
                else
                {
                    specArray = package.Configuration;
                }

                foreach (InstallSpecPath spec in specArray)
                {
                    if (dependencyDefinition.SkipInstall != null && dependencyDefinition.SkipInstall.Any(skip => skip.Type == spec.Type))
                    {
                        continue;
                    }

                    var sourcePath = Uplift.Common.FileSystemUtil.JoinPaths(td.Path, spec.Path);

                    PathConfiguration PH = upfile.GetDestinationFor(spec);
                    if (dependencyDefinition.OverrideDestination != null && dependencyDefinition.OverrideDestination.Any(over => over.Type == spec.Type))
                    {
                        PH.Location = Uplift.Common.FileSystemUtil.MakePathOSFriendly(dependencyDefinition.OverrideDestination.First(over => over.Type == spec.Type).Location);
                    }

                    var packageStructurePrefix =
                        PH.SkipPackageStructure ? "" : GetPackageDirectory(package);

                    var destination = Path.Combine(PH.Location, packageStructurePrefix);

                    // Working with single file
                    if (File.Exists(sourcePath))
                    {
                        // Working with singular file
                        if (!Directory.Exists(destination))
                        {
                            Directory.CreateDirectory(destination);
                            VCSHandler.HandleFile(destination);
                        }
                        if (Directory.Exists(destination))
                        { // we are copying a file into a directory
                            destination = System.IO.Path.Combine(destination, System.IO.Path.GetFileName(sourcePath));
                        }
                        File.Copy(sourcePath, destination);
                        Uplift.Common.FileSystemUtil.TryCopyMeta(sourcePath, destination);

                        if (destination.StartsWith("Assets"))
                        {
                            TryUpringAddGUID(upbring, sourcePath, package, spec.Type, destination);
                        }
                        else
                        {
                            upbring.AddLocation(package, spec.Type, destination);
                        }
                    }

                    // Working with directory
                    if (Directory.Exists(sourcePath))
                    {
                        // Working with directory
                        Uplift.Common.FileSystemUtil.CopyDirectoryWithMeta(sourcePath, destination);
                        if (!PH.SkipPackageStructure)
                        {
                            VCSHandler.HandleDirectory(destination);
                        }

                        bool useGuid = destination.StartsWith("Assets");
                        foreach (var file in Uplift.Common.FileSystemUtil.RecursivelyListFiles(sourcePath, true))
                        {
                            if (useGuid)
                            {
                                TryUpringAddGUID(upbring, file, package, spec.Type, destination);
                            }
                            else
                            {
                                upbring.AddLocation(package, spec.Type, Path.Combine(destination, file));
                            }

                            if (PH.SkipPackageStructure)
                            {
                                VCSHandler.HandleFile(Path.Combine(destination, file));
                            }
                        }
                    }
                }

                upbring.SaveFile();

                if (updateLockfile)
                {
                    LockfileSnapshot snapshot = LoadLockfile();
                    int  index;
                    bool found = false;
                    for (index = 0; index < snapshot.installableDependencies.Length; index++)
                    {
                        if (snapshot.installableDependencies[index].Package.PackageName == package.PackageName)
                        {
                            found = true;
                            break;
                        }
                    }
                    if (found)
                    {
                        snapshot.installableDependencies[index].Package = package;
                    }
                    else
                    {
                        Array.Resize <PackageRepo>(ref snapshot.installableDependencies, snapshot.installableDependencies.Length + 1);
                        snapshot.installableDependencies[snapshot.installableDependencies.Length] = new PackageRepo {
                            Package = package
                        };
                    }
                    GenerateLockfile(snapshot);
                }

                td.Dispose();
                UnityHacks.BuildSettingsEnforcer.EnforceAssetSave();
            }
        }
示例#10
0
 public virtual void TearDown()
 {
     m_WorkingDirectory.Dispose();
 }
示例#11
0
 public void Dispose()
 {
     _store.Purge(_handler);
     _tempDir.Dispose();
 }
        public override void TearDown()
        {
            _tempDir.Dispose();

            base.TearDown();
        }
示例#13
0
 public virtual void TearDown()
 {
     TempDir.Dispose();
 }
示例#14
0
 public void Dispose()
 {
     m_LocalRepository?.Dispose();
     m_RepositoryDirectory?.Dispose();
 }
 public void Cleanup()
 {
     _targetDir.Dispose();
     _backupDir.Dispose();
     _tempDir.Dispose();
 }
 public static void ClassCleanup()
 {
     _patchDir.Dispose();
 }
示例#17
0
        /// <summary>
        /// Downloads the installer from the web to a temporary file.
        /// </summary>
        /// <param name="url">The URL of the file to download.</param>
        /// <param name="handler">A callback object used when the the user is to be informed about progress.</param>
        /// <exception cref="WebException">A file could not be downloaded from the internet.</exception>
        /// <exception cref="IOException">A downloaded file could not be written to the disk.</exception>
        /// <exception cref="UnauthorizedAccessException">An operation failed due to insufficient rights.</exception>
        /// <remarks>Use either this or <see cref="SetLocal"/>.</remarks>
        public void Download([NotNull] Uri url, [NotNull] ITaskHandler handler)
        {
            _url = url;

            _tempDir?.Dispose();
            _tempDir = new TemporaryDirectory("0publish");

            try
            {
                _localPath = Path.Combine(_tempDir, url.GetLocalFileName());
                handler.RunTask(new DownloadFile(url, _localPath));
            }
                #region Error handling
            catch (Exception)
            {
                _tempDir.Dispose();
                _tempDir = null;
                _url = null;
                _localPath = null;
                throw;
            }
            #endregion
        }
示例#18
0
        public static TemporaryDirectory Apply([NotNull] this Recipe recipe, [NotNull, ItemNotNull] IEnumerable<TemporaryFile> downloadedFiles, [NotNull] ITaskHandler handler, [CanBeNull] object tag = null)
        {
            #region Sanity checks
            if (recipe == null) throw new ArgumentNullException("recipe");
            if (downloadedFiles == null) throw new ArgumentNullException("downloadedFiles");
            if (handler == null) throw new ArgumentNullException("handler");
            #endregion

            if (recipe.UnknownElements != null && recipe.UnknownElements.Length != 0)
                throw new NotSupportedException(string.Format(Resources.UnknownRecipeStepType, recipe.UnknownElements[0].Name));

            var workingDir = new TemporaryDirectory("0install-recipe");

            try
            {
                IEnumerator<TemporaryFile> downloadedEnum = downloadedFiles.GetEnumerator();
                // ReSharper disable AccessToDisposedClosure
                new PerTypeDispatcher<IRecipeStep>(ignoreMissing: false)
                {
                    (Archive step) =>
                    {
                        downloadedEnum.MoveNext();
                        if (downloadedEnum.Current == null) throw new ArgumentException(Resources.RecipeFileNotDownloaded, "downloadedFiles");
                        step.Apply(downloadedEnum.Current, workingDir, handler, tag);
                    },
                    (SingleFile step) =>
                    {
                        downloadedEnum.MoveNext();
                        if (downloadedEnum.Current == null) throw new ArgumentException(Resources.RecipeFileNotDownloaded, "downloadedFiles");
                        step.Apply(downloadedEnum.Current, workingDir, handler, tag);
                    },
                    (RemoveStep step) => step.Apply(workingDir),
                    (RenameStep step) => step.Apply(workingDir)
                }.Dispatch(recipe.Steps);
                // ReSharper restore AccessToDisposedClosure
                return workingDir;
            }
                #region Error handling
            catch
            {
                workingDir.Dispose();
                throw;
            }
            #endregion
        }
示例#19
0
        //FIXME: This is super unsafe right now, as we can copy down into the FS.
        // This should be contained using kinds of destinations.
        public void InstallPackage(Upset package, TemporaryDirectory td, DependencyDefinition dependencyDefinition)
        {
            Upbring upbring = Upbring.Instance();
            // Note: Full package is ALWAYS copied to the upackages directory right now
            string localPackagePath = GetRepositoryInstallPath(package);

            upbring.AddPackage(package);
            FileSystemUtil.CopyDirectory(td.Path, localPackagePath);
            upbring.AddLocation(package, InstallSpecType.Root, localPackagePath);

            InstallSpecPath[] specArray;
            if (package.Configuration == null)
            {
                // If there is no Configuration present we assume
                // that the whole package is wrapped in "InstallSpecType.Base"
                InstallSpecPath wrapSpec = new InstallSpecPath
                {
                    Path = "",
                    Type = InstallSpecType.Base
                };

                specArray = new[] { wrapSpec };
            }
            else
            {
                specArray = package.Configuration;
            }

            foreach (InstallSpecPath spec in specArray)
            {
                if (dependencyDefinition.SkipInstall != null && dependencyDefinition.SkipInstall.Any(skip => skip.Type == spec.Type))
                {
                    continue;
                }

                var sourcePath = Uplift.Common.FileSystemUtil.JoinPaths(td.Path, spec.Path);

                PathConfiguration PH = upfile.GetDestinationFor(spec);
                if (dependencyDefinition.OverrideDestination != null && dependencyDefinition.OverrideDestination.Any(over => over.Type == spec.Type))
                {
                    PH.Location = Uplift.Common.FileSystemUtil.MakePathOSFriendly(dependencyDefinition.OverrideDestination.First(over => over.Type == spec.Type).Location);
                }

                var packageStructurePrefix =
                    PH.SkipPackageStructure ? "" : GetPackageDirectory(package);

                var destination = Path.Combine(PH.Location, packageStructurePrefix);

                // Working with single file
                if (File.Exists(sourcePath))
                {
                    // Working with singular file
                    if (!Directory.Exists(destination))
                    {
                        Directory.CreateDirectory(destination);
                    }
                    File.Copy(sourcePath, destination);
                    FileSystemUtil.TryCopyMeta(sourcePath, destination);

                    if (destination.StartsWith("Assets"))
                    {
                        TryUpringAddGUID(upbring, sourcePath, package, spec.Type, destination);
                    }
                    else
                    {
                        upbring.AddLocation(package, spec.Type, destination);
                    }
                }

                // Working with directory
                if (Directory.Exists(sourcePath))
                {
                    // Working with directory
                    Uplift.Common.FileSystemUtil.CopyDirectoryWithMeta(sourcePath, destination);

                    if (destination.StartsWith("Assets"))
                    {
                        foreach (var file in Uplift.Common.FileSystemUtil.RecursivelyListFiles(sourcePath, true))
                        {
                            TryUpringAddGUID(upbring, file, package, spec.Type, destination);
                        }
                    }
                    else
                    {
                        foreach (var file in Uplift.Common.FileSystemUtil.RecursivelyListFiles(sourcePath, true))
                        {
                            upbring.AddLocation(package, spec.Type, Path.Combine(destination, file));
                        }
                    }
                }
            }

            upbring.SaveFile();

            td.Dispose();
        }
示例#20
0
 public void TearDown()
 {
     _sourceDirectory.Dispose();
 }
示例#21
0
 public override void TearDown()
 {
     _destinationDirectory.Dispose();
     base.TearDown();
 }
示例#22
0
 public void Dispose()
 {
     _outputHelper.WriteLine(_output.ToString());
     _tempDir.Dispose();
 }
示例#23
0
 public override void Dispose()
 {
     base.Dispose();
     _destination.Dispose();
 }
示例#24
0
 public void Dispose() => m_WorkingDirectory.Dispose();
示例#25
0
 public void TearDown()
 {
     _sandbox.Dispose();
 }
 public void Dispose()
 {
     _builder.Dispose();
     _implementationDir.Dispose();
 }
示例#27
0
 public void Dispose()
 {
     _tempDirectory.Dispose();
 }
 public void Dispose() => _tempDir.Dispose();
示例#29
0
 public void Dispose()
 {
     _implementationStore.Purge(_handler);
     _tempDir.Dispose();
 }
示例#30
0
 public void Dispose() => _sandbox.Dispose();
示例#31
0
 public void Dispose()
 {
     tmpDir.Dispose();
 }
示例#32
0
 public Task DisposeAsync()
 {
     m_WorkingDirectory.Dispose();
     return Task.CompletedTask;
 }
示例#33
0
 public void Dispose()
 {
     packageDirectory?.Dispose();
 }
        public static TemporaryDirectory DownloadAndApply([NotNull] this DownloadRetrievalMethod retrievalMethod, [NotNull] ITaskHandler handler, [CanBeNull] ICommandExecutor executor = null)
        {
            #region Sanity checks
            if (retrievalMethod == null) throw new ArgumentNullException("retrievalMethod");
            if (handler == null) throw new ArgumentNullException("handler");
            #endregion

            using (var downloadedFile = retrievalMethod.Download(handler, executor))
            {
                var extractionDir = new TemporaryDirectory("0publish");
                try
                {
                    new PerTypeDispatcher<DownloadRetrievalMethod>(ignoreMissing: false)
                    {
                        // ReSharper disable AccessToDisposedClosure
                        (Archive archive) => archive.Apply(downloadedFile, extractionDir, handler),
                        (SingleFile file) => file.Apply(downloadedFile, extractionDir, handler)
                        // ReSharper restore AccessToDisposedClosure
                    }.Dispatch(retrievalMethod);
                }
                    #region Error handling
                catch
                {
                    extractionDir.Dispose();
                    throw;
                }
                #endregion

                return extractionDir;
            }
        }