Beispiel #1
0
        /// <summary>
        /// Create a GitHubClient and start downloading release information.
        /// </summary>
        /// <param name="plugin">Name of the plugin</param>
        /// <param name="oAuthToken">Authentication token for GitHub, not required for updating.</param>
        /// <param name="userAgent">Name of the application</param>
        public GitHubClient(PluginName plugin, string oAuthToken = null, string userAgent = "Rynchodon:" + Loader.SeplShort)
        {
            this.name        = plugin;
            this._oAuthToken = oAuthToken ?? Environment.GetEnvironmentVariable("oAuthToken");
            this._userAgent  = userAgent;

            _releaseDownload = new Task <Release[]>(DownloadReleases);
            _releaseDownload.Start();
        }
        private Plugin AddLocallyCompiled(PluginBuilder builder)
        {
            PluginName name = new PluginName(builder.author, builder.repository);
            Plugin     plugin;

            if (!_data.TryGetDownloaded(name, out plugin))
            {
                plugin = new Plugin(_directory, new PluginConfig(name, true));
            }
            else
            {
                plugin.EraseAllFiles();
            }

            plugin.version = builder.version;
            Logger.WriteLine("plugin: " + name.fullName + ", compiled version: " + plugin.version);

            plugin.requiredPlugins = builder.requires;

            Directory.CreateDirectory(plugin.directory);

            foreach (var fileSource in builder.files)
            {
                string fileDestination = fileSource.targetFolder == null?
                                         PathExtensions.Combine(plugin.directory, Path.GetFileName(fileSource.source)) :
                                             PathExtensions.Combine(plugin.directory, fileSource.targetFolder, Path.GetFileName(fileSource.source));

                if (!Path.GetFullPath(fileDestination).StartsWith(plugin.directory))
                {
                    throw new Exception(Path.GetFullPath(fileDestination) + " is outside of plugin's directory");
                }

                Logger.WriteLine("Copy: " + fileSource.source + " to " + fileDestination);
                Directory.CreateDirectory(Path.GetDirectoryName(fileDestination));
                File.Copy(fileSource.source, fileDestination, true);
                plugin.AddFile(fileDestination, fileSource.requires);
            }

            plugin.locallyCompiled = true;

            _data.AddConfig(plugin.config);
            _data.AddDownloaded(plugin);

            if (name.author == "Rynchodon" && name.repository == SeplRepo)
            {
                Robocopy();
            }

            return(plugin);
        }
        /// <summary>
        /// Update PluginLoader.dll and PluginManager.exe from download folder using robocopy.
        /// </summary>
        private void Robocopy()
        {
            if (_instance != this || _startedRobocopy)
            {
                return;
            }
            _startedRobocopy = true;

            PluginName seplName         = new PluginName("Rynchodon", SeplRepo);
            string     seplDownloadPath = PathExtensions.Combine(_directory, "plugin", seplName.fullName);

            string license = PathExtensions.Combine(seplDownloadPath, "License.rtf");

            if (File.Exists(license))
            {
                File.Copy(license, PathExtensions.Combine(_directory, "License.rtf"), true);
            }

            string readme = PathExtensions.Combine(seplDownloadPath, "Readme.txt");

            if (File.Exists(readme))
            {
                File.Copy(readme, PathExtensions.Combine(_directory, "Readme.txt"), true);
            }

            Logger.WriteLine("starting robocopy");

            string first = '"' + seplDownloadPath + "\" \"";

            string copyDll = first + _directory + "\" " + Dll + " /COPY:DATSO /W:1 /xx";
            string copyExe = first + _directory + "\" " + Exe + " /COPY:DATSO /W:1 /xx";

            Process robocopy = new Process();

            robocopy.StartInfo.FileName    = "cmd.exe";
            robocopy.StartInfo.Arguments   = "/C robocopy " + copyDll + " & robocopy " + copyExe;
            robocopy.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            robocopy.Start();
        }
 public PluginConfig(PluginName name, bool downloadPrerelease, bool enabled = true)
 {
     this.name = name;
     this.downloadPrerelease = downloadPrerelease;
     this.enabled            = enabled;
 }
Beispiel #5
0
 public bool TryGetDownloaded(PluginName name, out Plugin plugin)
 {
     return(_downloaded.TryGetValue(name, out plugin));
 }