Inheritance: IInstallablePackage
Esempio n. 1
0
        public async Task<InstallablePackage> ToInstallablePackageAsync(string version, string providerName)
        {
            string rootCacheDir = Environment.ExpandEnvironmentVariables(Defaults.CachePath);
            string dir = Path.Combine(rootCacheDir, providerName, Name, version);
            var metadata = await GetPackageMetaData(providerName).ConfigureAwait(false);

            if (metadata == null)
                return null;

            var asset = metadata.Assets.FirstOrDefault(a => a.Version.Equals(version, StringComparison.OrdinalIgnoreCase));

            if (asset == null)
                return null;

            var package = new InstallablePackage
            {
                Name = Name,
                Version = asset.Version,
                Files = asset.Files,
                MainFile = metadata.MainFile,
                AllFiles = asset.Files,
                UrlFormat = _downloadUrlFormat

            };

            if (!package.Files.Contains(package.MainFile))
            {
                if (package.Files.Contains(Name))
                    package.MainFile = Name;
                else
                    package.MainFile = package.Files.FirstOrDefault();
            }

            return package;
        }
Esempio n. 2
0
        public async Task<Manifest> Install(Manifest manifest, InstallablePackage entry, InstallSettings settings)
        {
            var relativePath = MakeRelative(manifest.FileName, settings.InstallDirectory);

            if (settings.SaveManifest)
            {
                var package = new ManifestPackage
                {
                    Version = entry.Version,
                    Path = relativePath
                };

                // Only write "files" to the manifest if it's different from all files.
                if (entry.AllFiles.Count() != entry.Files.Count())
                {
                    package.Files = entry.Files;
                }

                manifest.Packages[entry.Name] = package;
                await manifest.Save();
            }

            string cwd = new FileInfo(manifest.FileName).DirectoryName;

            OnInstalling(entry, settings.InstallDirectory);

            await CopyPackageContent(entry, settings);

            OnInstalled(entry, settings.InstallDirectory);

            return manifest;
        }
Esempio n. 3
0
        public async Task <InstallablePackage> ToInstallablePackageAsync(string version, string providerName)
        {
            string rootCacheDir = Environment.ExpandEnvironmentVariables(Defaults.CachePath);
            string dir          = Path.Combine(rootCacheDir, providerName, Name, version);
            var    metadata     = await GetPackageMetaData(providerName).ConfigureAwait(false);

            if (metadata == null)
            {
                return(null);
            }

            var asset = metadata.Assets.FirstOrDefault(a => a.Version.Equals(version, StringComparison.OrdinalIgnoreCase));

            if (asset == null)
            {
                return(null);
            }

            var package = new InstallablePackage
            {
                Name      = Name,
                Version   = asset.Version,
                Files     = asset.Files,
                MainFile  = asset.MainFile ?? metadata.MainFile,
                AllFiles  = asset.Files,
                UrlFormat = _downloadUrlFormat
            };

            return(package);
        }
Esempio n. 4
0
        public static async Task InstallpackageAsync(string manifestFilePath, InstallablePackage entry, InstallSettings settings)
        {
            _files.Clear();
            await VSPackage.Manager.Install(manifestFilePath, entry, settings);

            var project = ProjectHelpers.GetActiveProject();
            project.AddFilesToProject(_files);
        }
Esempio n. 5
0
        public async Task<Manifest> Install(string manifestFilePath, InstallablePackage entry, string installDirectory, bool saveManifest = true)
        {
            Manifest manifest = await Manifest.FromFileOrNewAsync(manifestFilePath);

            var settings = new InstallSettings
            {
                InstallDirectory = installDirectory,
                SaveManifest = saveManifest
            };

            return await Install(manifest, entry, settings);
        }
Esempio n. 6
0
        public async Task <Manifest> Install(string manifestFilePath, InstallablePackage entry, string installDirectory, bool saveManifest = true)
        {
            Manifest manifest = await Manifest.FromFileOrNewAsync(manifestFilePath);

            var settings = new InstallSettings
            {
                InstallDirectory = installDirectory,
                SaveManifest     = saveManifest
            };

            return(await Install(manifest, entry, settings));
        }
Esempio n. 7
0
        async Task <bool> CopyPackageContent(InstallablePackage entry, InstallSettings settings)
        {
            string cachePath  = Environment.ExpandEnvironmentVariables(Defaults.CachePath);
            string versionDir = Path.Combine(cachePath, Provider.Name, entry.Name, entry.Version);
            bool   hasCopied  = false;

            await entry.DownloadFilesAsync(versionDir);

            await Task.Run(() =>
            {
                try
                {
                    foreach (string file in entry.Files)
                    {
                        string cleanFile = file.Replace("/", "\\");
                        string src       = Path.Combine(versionDir, cleanFile);
                        string dest      = Path.Combine(settings.InstallDirectory, cleanFile);

                        if (File.Exists(dest))
                        {
                            var srcDate  = File.GetLastWriteTime(src);
                            var destDate = File.GetLastWriteTime(dest);

                            if (srcDate == destDate)
                            {
                                continue;
                            }
                        }

                        string dir = Path.GetDirectoryName(dest);
                        Directory.CreateDirectory(dir);

                        OnCopying(src, dest);
                        File.Copy(src, dest, true);
                        OnCopied(src, dest);
                        hasCopied = true;
                    }
                }
                catch (Exception)
                {
                    try
                    {
                        Directory.Delete(versionDir, true);
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.Write(ex);
                    }
                }
            });

            return(hasCopied);
        }
Esempio n. 8
0
        public async Task <Manifest> Install(Manifest manifest, InstallablePackage entry, InstallSettings settings)
        {
            var relativePath = MakeRelative(manifest.FileName, settings.InstallDirectory);

            if (settings.SaveManifest)
            {
                var package = new ManifestPackage
                {
                    Version = entry.Version,
                    Path    = relativePath
                };

                // Only write "files" to the manifest if it's different from all files.
                if (entry.AllFiles.Count() != entry.Files.Count())
                {
                    package.Files = entry.Files;
                }

                manifest.Packages[entry.Name] = package;
                await manifest.Save();
            }

            string cwd = new FileInfo(manifest.FileName).DirectoryName;

            OnInstalling(manifest, entry, settings.InstallDirectory);

            var copied = await CopyPackageContent(entry, settings);

            // Check if the files where already installed. Skip if they were
            if (copied)
            {
                OnInstalled(manifest, entry, settings.InstallDirectory);
            }

            return(manifest);
        }
Esempio n. 9
0
 public InstallEventArgs(InstallablePackage package, string path)
 {
     Package = package;
     Path = path;
 }
Esempio n. 10
0
        private void RebuildPackageTree(InstallablePackage package)
        {
            if (package != Package)
            {
                return;
            }

            DisplayRoots = null;

            if (package == null)
            {
                return;
            }

            bool canUpdateInstallStatusValue = false;
            Func<bool> canUpdateInstallStatus = () => canUpdateInstallStatusValue;
            HashSet<string> selectedFiles = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
            PackageItem root = new PackageItem(this, null, selectedFiles)
            {
                CanUpdateInstallStatus = canUpdateInstallStatus,
                ItemType = PackageItemType.Folder,
                Name = RootFolderName,
                IsChecked = false
            };

            PackageItem packageItem = new PackageItem(this, root, selectedFiles)
            {
                CanUpdateInstallStatus = canUpdateInstallStatus,
                Name = package.Name,
                ItemType = PackageItemType.Folder,
                IsChecked = false
            };

            //The node that children will be added to
            PackageItem realParent = root;
            //The node that will be set as the parent of the child nodes
            PackageItem virtualParent = packageItem;

            if (IncludePackageName)
            {
                realParent = packageItem;
                root.Children = new[] { packageItem };
            }

            foreach (string file in package.Files)
            {
                string[] parts = file.Split('/');
                PackageItem currentRealParent = realParent;
                PackageItem currentVirtualParent = virtualParent;

                for (int i = 0; i < parts.Length; ++i)
                {
                    bool isFolder = i != parts.Length - 1;

                    if (isFolder)
                    {
                        PackageItem next = currentRealParent.Children.FirstOrDefault(x => x.ItemType == PackageItemType.Folder && string.Equals(x.Name, parts[i]));

                        if (next == null)
                        {
                            next = new PackageItem(this, currentVirtualParent, selectedFiles)
                            {
                                CanUpdateInstallStatus = canUpdateInstallStatus,
                                Name = parts[i],
                                ItemType = PackageItemType.Folder,
                                IsChecked = false
                            };

                            List<PackageItem> children = new List<PackageItem>(currentRealParent.Children)
                            {
                                next
                            };

                            children.Sort((x, y) => x.ItemType == y.ItemType ? StringComparer.OrdinalIgnoreCase.Compare(x.Name, y.Name) : y.ItemType == PackageItemType.Folder ? 1 : -1);

                            currentRealParent.Children = children;

                            if (currentVirtualParent != currentRealParent)
                            {
                                currentVirtualParent.Children = children;
                            }
                        }

                        currentRealParent = next;
                        currentVirtualParent = next;
                    }
                    else
                    {
                        PackageItem next = new PackageItem(this, currentVirtualParent, selectedFiles)
                        {
                            CanUpdateInstallStatus = canUpdateInstallStatus,
                            FullPath = file,
                            Name = parts[i],
                            ItemType = PackageItemType.File,
                            IsChecked = false,
                        };

                        List<PackageItem> children = new List<PackageItem>(currentRealParent.Children)
                        {
                            next
                        };

                        children.Sort((x, y) => x.ItemType == y.ItemType ? StringComparer.OrdinalIgnoreCase.Compare(x.Name, y.Name) : y.ItemType == PackageItemType.Folder ? -1 : 1);

                        currentRealParent.Children = children;

                        if (currentVirtualParent != currentRealParent)
                        {
                            currentVirtualParent.Children = children;
                        }

                        next.IsMain = string.Equals(package.MainFile, file, StringComparison.OrdinalIgnoreCase);
                    }
                }
            }

            SetNodeOpenStates(root);

            Dispatcher.Invoke(() =>
            {
                if (package == Package)
                {
                    canUpdateInstallStatusValue = true;
                    _packageItem = packageItem;
                    DisplayRoots = new[] { root };
                    SelectedFiles = selectedFiles;
                    InstallPackageCommand.CanExecute(null);
                }
            });
        }
Esempio n. 11
0
        private async Task CopyPackageContent(InstallablePackage entry, InstallSettings settings)
        {
            string cachePath = Environment.ExpandEnvironmentVariables(Defaults.CachePath);
            string versionDir = Path.Combine(cachePath, Provider.Name, entry.Name, entry.Version);

            await entry.DownloadFiles(versionDir);

            await Task.Run(() =>
            {
                try
                {
                    foreach (string file in entry.Files)
                    {
                        string cleanFile = file.Replace("/", "\\");
                        string src = Path.Combine(versionDir, cleanFile);
                        string dest = Path.Combine(settings.InstallDirectory, cleanFile);

                        string dir = Path.GetDirectoryName(dest);
                        Directory.CreateDirectory(dir);

                        OnCopying(src, dest);
                        File.Copy(src, dest, true);
                        OnCopied(src, dest);
                    }
                }
                catch (Exception)
                {
                    try
                    {
                        Directory.Delete(versionDir, true);
                    }
                    catch
                    {
                    }
                }
            });
        }
Esempio n. 12
0
        public async Task<Manifest> Install(string manifestFilePath, InstallablePackage entry, InstallSettings settings)
        {
            Manifest manifest = await Manifest.FromFileOrNewAsync(manifestFilePath);

            return await Install(manifest, entry, settings);
        }
Esempio n. 13
0
 void OnInstalled(InstallablePackage package, string path)
 {
     if (Installed != null)
         Installed(this, new InstallEventArgs(package, path));
 }
Esempio n. 14
0
        public async Task <Manifest> Install(string manifestFilePath, InstallablePackage entry, InstallSettings settings)
        {
            Manifest manifest = await Manifest.FromFileOrNewAsync(manifestFilePath);

            return(await Install(manifest, entry, settings));
        }
Esempio n. 15
0
        async Task<bool> CopyPackageContent(InstallablePackage entry, InstallSettings settings)
        {
            string cachePath = Environment.ExpandEnvironmentVariables(Defaults.CachePath);
            string versionDir = Path.Combine(cachePath, Provider.Name, entry.Name, entry.Version);
            bool hasCopied = false;

            await entry.DownloadFilesAsync(versionDir);

            await Task.Run(() =>
            {
                try
                {
                    foreach (string file in entry.Files)
                    {
                        string cleanFile = file.Replace("/", "\\");
                        string src = Path.Combine(versionDir, cleanFile);
                        string dest = Path.Combine(settings.InstallDirectory, cleanFile);

                        if (File.Exists(dest))
                        {
                            var srcDate = File.GetLastWriteTime(src);
                            var destDate = File.GetLastWriteTime(dest);

                            if (srcDate == destDate)
                                continue;
                        }

                        string dir = Path.GetDirectoryName(dest);
                        Directory.CreateDirectory(dir);

                        OnCopying(src, dest);
                        File.Copy(src, dest, true);
                        OnCopied(src, dest);
                        hasCopied = true;
                    }
                }
                catch (Exception)
                {
                    try
                    {
                        Directory.Delete(versionDir, true);
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.Write(ex);
                    }
                }
            });

            return hasCopied;
        }