Esempio n. 1
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. 2
0
        async void Install(object sender, EventArgs e)
        {
            var item = ProjectHelpers.GetSelectedItems().FirstOrDefault();

            if (item == null)
                return;

            var dir = new DirectoryInfo(item.GetFullPath());
            string installDir;
            var package = GetPackage(dir.Name, out installDir);

            if (package == null || package.Files == null || !package.Files.Any())
                return;

            string manifestPath = item.ContainingProject.GetConfigFile();

            var settings = new InstallSettings
            {
                InstallDirectory = Path.Combine(item.GetFullPath(), installDir),
                SaveManifest = VSPackage.Options.SaveManifestFile
            };

            await VSPackage.Manager.Install(manifestPath, package, settings);

            var props = new Dictionary<string, string> {
                { "name", package.Name.ToLowerInvariant().Trim()}                ,
                { "version", package.Version}
            };

            Telemetry.TrackEvent("Package installed", props);

            if (settings.SaveManifest)
                await item.ContainingProject.AddFileToProjectAsync(manifestPath, "None");
        }
Esempio n. 3
0
        public async Task InstallAll(Manifest manifest)
        {
            foreach (var name in manifest.Packages.Keys)
            {
                var entry = manifest.Packages[name];

                if (entry.Urls != null)
                {
                    await InstallUrls(manifest, entry);
                }
                else
                {
                    var package = await Provider.GetInstallablePackageAsync(name, entry.Version);

                    if (package == null)
                        throw new PackageNotFoundException(name, entry.Version);

                    if (entry.Files != null && entry.Files.Count() != package.Files.Count())
                        package.Files = entry.Files;

                    var file = new FileInfo(manifest.FileName);

                    var settings = new InstallSettings
                    {
                        InstallDirectory = Path.Combine(file.DirectoryName, entry.Path.Replace("/", "\\")),
                        SaveManifest = false
                    };

                    await Install(manifest, package, settings);
                }
            }
        }
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 InstallAll(Manifest manifest)
        {
            foreach (var name in manifest.Packages.Keys)
            {
                var entry = manifest.Packages[name];

                if (entry.Urls != null)
                {
                    await InstallUrls(manifest, entry);
                }
                else
                {
                    var package = await Provider.GetInstallablePackageAsync(name, entry.Version);

                    if (package == null)
                    {
                        throw new PackageNotFoundException(name, entry.Version);
                    }

                    if (entry.Files != null && entry.Files.Count() != package.Files.Count())
                    {
                        package.Files = entry.Files;
                    }

                    var file = new FileInfo(manifest.FileName);

                    var settings = new InstallSettings
                    {
                        InstallDirectory = Path.Combine(file.DirectoryName, entry.Path.Replace("/", "\\")),
                        SaveManifest     = false
                    };

                    await Install(manifest, package, settings);
                }
            }
        }
Esempio n. 9
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. 10
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. 11
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. 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
        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;
        }