Example #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;
        }
Example #2
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);
                }
            }
        }
Example #3
0
 void OnInstalled(Manifest manifest, IInstallablePackage package, string path)
 {
     if (Installed != null)
         Installed(this, new InstallEventArgs(manifest, package, path));
 }
Example #4
0
        public async Task<ManifestPackage> UninstallAsync(Manifest manifest, string name, bool saveManifest)
        {
            var package = manifest.Packages.FirstOrDefault(p => p.Key == name).Value;

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

            if (saveManifest)
            {
                manifest.Packages.Remove(name);
                await manifest.Save();
            }

            string cwd = Path.GetDirectoryName(manifest.FileName);
            var installDir = Path.Combine(cwd, package.Path);

            var files = package.Files;

            // If no files are specified in the entry, then find all files from package
            if (files == null)
            {
                var installable = await Provider.GetInstallablePackageAsync(name, package.Version);

                if (installable != null)
                    files = installable.AllFiles;
            }

            if (files != null)
            {
                foreach (string file in files)
                {
                    string path = Path.Combine(installDir, file);
                    File.Delete(path);
                }
            }

            return package;
        }
Example #5
0
        async Task InstallUrls(Manifest manifest, ManifestPackage package)
        {
            string dir = Path.GetDirectoryName(manifest.FileName);
            string path = Path.Combine(dir, package.Path).Replace("\\", "/");
            var files = new List<string>();

            var urlPackage = new UrlPackage
            {
                Name = package.Name,
                Files = files
            };

            OnInstalling(manifest, urlPackage, path);

            foreach (string url in package.Urls)
            {
                string fileName = Path.GetFileName(url);
                string filePath = new FileInfo(Path.Combine(dir, package.Path, fileName)).FullName;
                Directory.CreateDirectory(Path.GetDirectoryName(filePath));

                files.Add(fileName);

                using (WebClient client = new WebClient())
                {
                    OnCopying(url, filePath);
                    await client.DownloadFileTaskAsync(url, filePath);
                    OnCopied(url, filePath);
                }
            }

            OnInstalled(manifest, urlPackage, path);
        }
 public InstallEventArgs(Manifest manifest, IInstallablePackage package, string path)
 {
     Manifest = manifest;
     Package = package;
     Path = path;
 }