Ejemplo n.º 1
0
        /// <summary>
        /// Adds a locally compiled plugin and optionally publishes it.
        /// </summary>
        public static void AddLocallyCompiledPlugin(PluginBuilder builder)
        {
            if (_instance == null)
            {
                new Loader(false);
            }

            GitHubClient client = null;

            if (builder.publish)
            {
                client = new GitHubClient(new PluginName(builder.author, builder.repository), builder.oAuthToken);
            }

            if (builder.version.CompareTo(default(Version)) <= 0)
            {
                foreach (string file in builder.files.Select(f => f.source))
                {
                    Version fileVersion = new Version(FileVersionInfo.GetVersionInfo(file), builder.version.SeVersion);
                    if (builder.version.CompareTo(fileVersion) < 0)
                    {
                        builder.version = fileVersion;
                    }
                }
                Logger.WriteLine("Got plugin version from files: " + builder.version);
            }

            if (builder.version.SeVersion < 0)
            {
                builder.version.SeVersion = 0;
            }
            else if (builder.version.SeVersion == 0)
            {
                builder.version.SeVersion = GetCurrentSEVersion();
            }

            _instance._task.Wait();
            Plugin plugin = _instance.AddLocallyCompiled(builder);

            if (builder.publish && GitChecks.Check(builder, _instance._data.PathToGit))
            {
                Release[] releases = client.GetReleases();
                if (releases == null)
                {
                    Logger.WriteLine("Failed to connect to GitHub, cannot publish");
                    return;
                }
                if (releases.Length == 0 && builder.version.SeVersion > 0 && MessageBox.Show("This is your first release, mark it compatible with older versions of SE?" + Environment.NewLine +
                                                                                             "If you intend to upload releases for older versions of SE choose No." + Environment.NewLine +
                                                                                             "This will not affect future releases", "SE Compatibility", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    plugin.version.SeVersion = 0;
                }
                client.Publish(plugin, builder);
            }

            _instance._data.Save();
        }
Ejemplo n.º 2
0
        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);
        }
        private GitChecks(PluginBuilder builder, string pathToGit)
        {
            this._builder   = builder;
            this._pathToGit = pathToGit;

            foreach (string path in PathExtensions.PathsToRoot(builder.files.First().source))
            {
                string gitDirectory = PathExtensions.Combine(path, ".git");
                if (Directory.Exists(gitDirectory))
                {
                    _repoDirectory = path;
                    break;
                }
            }
        }
Ejemplo n.º 4
0
        internal void Publish(Plugin plugin, PluginBuilder pluginBuilder)
        {
            if (!HasOAuthToken)
            {
                throw new ArgumentException("Need oAuthToken");
            }

            CreateRelease release = new CreateRelease(plugin.version, pluginBuilder.release);

            string zipFileName;

            if (pluginBuilder.zipFileName != null)
            {
                zipFileName = Path.GetFileName(pluginBuilder.zipFileName);
            }
            else
            {
                zipFileName = plugin.name.repository;
            }

            if (!zipFileName.EndsWith(".zip"))
            {
                zipFileName = zipFileName + ".zip";
            }

            string zipFilePath = PathExtensions.Combine(plugin.directory, zipFileName);

            try
            {
                plugin.Zip(zipFilePath);
                if (PublishRelease(release, zipFilePath))
                {
                    MessageBox.Show("Release posted");
                }
            }
            finally
            {
                if (File.Exists(zipFilePath))
                {
                    File.Delete(zipFilePath);
                }
            }
        }
 /// <summary>
 /// Tests for being on the default branch, the branch being up-to-date, and the branch not being dirty.
 /// </summary>
 /// <param name="directory">Any directory that is part of the repository</param>
 /// <param name="pathToGit">Path to git.exe</param>
 /// <returns>True if all the tests were passed or the user skipped them.</returns>
 public static bool Check(PluginBuilder builder, string pathToGit)
 {
     return((new GitChecks(builder, pathToGit)).Check());
 }