FromDirectory() public static method

public static FromDirectory ( string rootPath, ILogger logger ) : Package
rootPath string
logger ILogger
return Package
示例#1
0
        /// <summary>
        /// Extracts and parses the metadata of a downloaded package
        /// </summary>
        /// <param name="dynamoModel">Dynamo model</param>
        /// <param name="installDirectory">If specified, overrides Dynamo's default base folder for packages</param>
        /// <param name="pkg">Metatda parsed from the package</param>
        /// <returns>Whether the operation succeeded or not</returns>
        public bool Extract(DynamoModel dynamoModel, string installDirectory, out Package pkg)
        {
            this.DownloadState = State.Installing;

            // unzip, place files
            var unzipPath = Greg.Utility.FileUtilities.UnZip(DownloadPath);

            if (!Directory.Exists(unzipPath))
            {
                throw new Exception(Properties.Resources.PackageEmpty);
            }

            // provide handle to installed package
            if (Header != null)
            {
                pkg = new Package(unzipPath, Header.name, VersionName, Header.license);
            }
            else
            {
                pkg = Package.FromDirectory(unzipPath, dynamoModel.Logger);
            }

            if (pkg == null)
            {
                return(false);
            }

            if (String.IsNullOrEmpty(installDirectory))
            {
                installDirectory = dynamoModel.PathManager.DefaultPackagesDirectory;
            }

            var installedPath = BuildInstallDirectoryString(installDirectory, pkg.Name);

            Directory.CreateDirectory(installedPath);

            // Now create all of the directories
            foreach (string dirPath in Directory.GetDirectories(unzipPath, "*", SearchOption.AllDirectories))
            {
                Directory.CreateDirectory(dirPath.Replace(unzipPath, installedPath));
            }

            // Copy all the files
            foreach (string newPath in Directory.GetFiles(unzipPath, "*.*", SearchOption.AllDirectories))
            {
                File.Copy(newPath, newPath.Replace(unzipPath, installedPath));
            }

            // Update root directory to final path
            pkg.RootDirectory = installedPath;

            return(true);
        }
示例#2
0
        internal void DownloadAndInstall(PackageDownloadHandle packageDownloadHandle)
        {
            var pkgDownload = new PackageDownload(packageDownloadHandle.Header._id, packageDownloadHandle.VersionName);

            Downloads.Add(packageDownloadHandle);

            ThreadStart start = () =>
            {
                try
                {
                    var response = Client.Execute(pkgDownload);
                    var pathDl   = PackageDownload.GetFileFromResponse(response);

                    dynSettings.Controller.UIDispatcher.BeginInvoke((Action)(() =>
                    {
                        try
                        {
                            packageDownloadHandle.Done(pathDl);

                            Package dynPkg;

                            var firstOrDefault = dynSettings.PackageLoader.LocalPackages.FirstOrDefault(pkg => pkg.Name == packageDownloadHandle.Name);
                            if (firstOrDefault != null)
                            {
                                firstOrDefault.UninstallCommand.Execute();
                            }

                            if (packageDownloadHandle.Extract(out dynPkg))
                            {
                                var downloadPkg = Package.FromDirectory(dynPkg.RootDirectory);
                                downloadPkg.Load();
                                dynSettings.PackageLoader.LocalPackages.Add(downloadPkg);
                                packageDownloadHandle.DownloadState = PackageDownloadHandle.State.Installed;
                            }
                        }
                        catch (Exception e)
                        {
                            packageDownloadHandle.Error(e.Message);
                        }
                    }));
                }
                catch (Exception e)
                {
                    packageDownloadHandle.Error(e.Message);
                }
            };

            new Thread(start).Start();
        }