Ejemplo n.º 1
0
        /// <summary>
        /// Ensures the specified version exists in the local cache, downloading it if necessary.
        /// </summary>
        /// <param name="version">The version to cache.</param>
        /// <returns>The full path to the local cache directory.</returns>
        public async Task <string> Cache(Version version)
        {
            var cacheDir = new DirectoryInfo(Path.Combine(PathManager.CachePath, ConfigurationManager.PluginPath, this.name.Vendor, this.name.Project, version.ToString()));

            if (cacheDir.Exists)
            {
                return(cacheDir.FullName);
            }

            cacheDir.Create();

            var releases = await GetReleases();

            var release = releases.First(r => r.Version.ToString() == version.ToString());             // TODO: IComparable

            var file = Path.Combine(cacheDir.FullName, Path.GetFileName(release.DownloadUrl));

            using (var client = new WebClient())
            {
                await client.DownloadFileTaskAsync(release.DownloadUrl, file);
            }

            using (var zip = ZipArchive.Open(file))
            {
                zip.WriteToDirectory(cacheDir.FullName, new ExtractionOptions
                {
                    Overwrite       = true,
                    ExtractFullPath = true
                });
            }

            File.Delete(file);

            return(cacheDir.FullName);
        }
Ejemplo n.º 2
0
        public async Task Download(Version version)
        {
            var cacheDir  = new DirectoryInfo(Path.Combine(PathManager.CachePath, ConfigurationManager.PluginPath, this.name.Vendor, this.name.Project, version.ToString()));
            var targetDir = new DirectoryInfo(Path.Combine(Environment.CurrentDirectory, ConfigurationManager.PluginPath, this.name.Vendor, this.name.Project));

            if (!cacheDir.Exists)
            {
                await Cache(version);
            }

            targetDir.Copy(cacheDir.FullName);

            var pluginConfigDir = new DirectoryInfo(Path.Combine(targetDir.FullName, ConfigurationManager.ConfigurationPath));

            if (!pluginConfigDir.Exists)
            {
                return;
            }
            var targetConfigDir = new DirectoryInfo(Path.Combine(Environment.CurrentDirectory, ConfigurationManager.ConfigurationPath, this.name.Vendor, this.name.Project));

            foreach (var file in pluginConfigDir.EnumerateFiles())
            {
                var targetFile = Path.Combine(targetConfigDir.FullName, file.Name);
                if (File.Exists(targetFile))
                {
                    continue;
                }
                file.CopyTo(targetFile);
            }
        }
Ejemplo n.º 3
0
        public async Task Download(Version version)
        {
            var cacheDir  = new DirectoryInfo(Path.Combine(PathManager.CachePath, ConfigurationManager.PluginPath, this.name.Vendor, this.name.Project, version.ToString()));
            var targetDir = new DirectoryInfo(Path.Combine(Environment.CurrentDirectory, ConfigurationManager.PluginPath, this.name.Vendor, this.name.Project));

            if (!cacheDir.Exists)
            {
                await Cache(version);
            }

            cacheDir.Copy(targetDir.FullName);
        }
Ejemplo n.º 4
0
        public async Task <string> Cache(Version version)
        {
            var cacheDir = new DirectoryInfo(Path.Combine(PathManager.CachePath, ConfigurationManager.PluginPath, this.name.Vendor, this.name.Project, version.ToString()));

            if (cacheDir.Exists)
            {
                return(cacheDir.FullName);
            }

            cacheDir.Create();

            var releases = await GetReleases();

            var release = releases.First(r => !r.Prerelease && !r.Draft && r.Assets.Any(a => a.Name.EndsWith(".zip")));
            var asset   = release.Assets.First(a => a.Name.EndsWith(".zip"));

            var file = Path.Combine(cacheDir.FullName, asset.Name);

            using (var client = new WebClient())
            {
                await client.DownloadFileTaskAsync(asset.BrowserDownloadUrl, file);
            }

            using (var zip = ZipArchive.Open(file))
            {
                zip.WriteToDirectory(cacheDir.FullName, new ExtractionOptions
                {
                    Overwrite       = true,
                    ExtractFullPath = true
                });
            }

            File.Delete(file);

            return(cacheDir.FullName);
        }
Ejemplo n.º 5
0
        /// <inheritdoc />
        /// <summary>
        /// Downloads and unpacks the specified plugin version.
        /// </summary>
        /// <param name="version">The version to download.</param>
        public async Task Download(Version version)
        {
            var src = Path.Combine(Path.GetFullPath(this.repo.Path), this.repo.Path);
            var dst = Path.Combine(Environment.CurrentDirectory, ConfigurationManager.PluginPath, this.name.Vendor, this.name.Project);

            var path = Path.Combine(Path.GetFullPath(this.repo.Path), ConfigurationManager.DefinitionFile);

            if (!File.Exists(path))
            {
                throw new FileNotFoundException("Unable to find definition file", path);
            }

            var definition = Plugin.Load(path);

            var stockFiles = new List <string>
            {
                "nfive.yml",
                "nfive.lock",
                "README.md",
                "README",
                "LICENSE.md",
                "LICENSE"
            };

            var files = new List <string>();

            if (definition.Client != null)
            {
                if (definition.Client.Main != null && definition.Client.Main.Any())
                {
                    files.AddRange(definition.Client.Main.Select(f => $"{f}.net.dll"));
                }

                if (definition.Client.Include != null && definition.Client.Include.Any())
                {
                    files.AddRange(definition.Client.Include.Select(f => $"{f}.net.dll"));
                }

                if (definition.Client.Files != null && definition.Client.Files.Any())
                {
                    files.AddRange(definition.Client.Files);
                }

                if (definition.Client.Overlays != null && definition.Client.Overlays.Any())
                {
                    files.AddRange(definition.Client.Overlays);
                }
            }

            if (definition.Server != null)
            {
                if (definition.Server.Main != null && definition.Server.Main.Any())
                {
                    files.AddRange(definition.Server.Main.Select(f => $"{f}.net.dll"));
                }

                if (definition.Server.Include != null && definition.Server.Include.Any())
                {
                    files.AddRange(definition.Server.Include.Select(f => $"{f}.net.dll"));
                }
            }

            files = files.Distinct().ToList();

            foreach (var file in stockFiles)
            {
                if (!File.Exists(Path.Combine(src, file)))
                {
                    continue;
                }

                File.Copy(Path.Combine(src, file), Path.Combine(dst, file), true);
            }

            foreach (var file in files)
            {
                Directory.CreateDirectory(Path.GetDirectoryName(Path.Combine(dst, file).Replace(Path.DirectorySeparatorChar, '/')));

                File.Copy(Path.Combine(src, file).Replace(Path.DirectorySeparatorChar, '/'), Path.Combine(dst, file).Replace(Path.DirectorySeparatorChar, '/'), true);
            }

            await Task.FromResult(0);
        }
Ejemplo n.º 6
0
 public Task <string> Cache(Version version) => Task.FromResult(Path.Combine(Path.GetFullPath(this.repo.Path), this.repo.Path));