Beispiel #1
0
        public static void Install(CraftitudeProfile profile, string groupId, string artifactId, string version, string jarFile, bool copy = false)
        {
            var javaDirectory = profile.Directory.CreateSubdirectory("java");
            javaDirectory = groupId.Split('.').Aggregate(javaDirectory, (current, groupPart) => current.CreateSubdirectory(groupPart));
            javaDirectory = javaDirectory.CreateSubdirectory(artifactId);
            javaDirectory = javaDirectory.CreateSubdirectory(version);

            var targetJarPath = javaDirectory.GetFile(string.Format("{0}-{1}.jar", artifactId, version)).FullName;

            if (copy)
                File.Copy(jarFile, targetJarPath, true);
            else
            {
                if(File.Exists(targetJarPath))
                    File.Delete(targetJarPath);
                File.Move(jarFile, targetJarPath);
            }
        }
Beispiel #2
0
        public static void Uninstall(CraftitudeProfile profile, string groupId, string artifactId, string version)
        {
            var javaDirectory = profile.Directory.CreateSubdirectory("java");
            javaDirectory = groupId.Split('.').Aggregate(javaDirectory, (current, groupPart) => current.CreateSubdirectory(groupPart));
            javaDirectory = javaDirectory.CreateSubdirectory(artifactId);
            javaDirectory = javaDirectory.CreateSubdirectory(version);

            var targetJarPath = javaDirectory.GetFile(string.Format("{0}-{1}.jar", artifactId, version)).FullName;

            // First, delete the jar itself.
            File.Delete(targetJarPath);

            // Delete all now empty directories.
            while (javaDirectory != null && !javaDirectory.EnumerateFiles().Any())
            {
                javaDirectory.Delete();
                javaDirectory = javaDirectory.Parent;
            }
        }
Beispiel #3
0
 public static void UninstallMod(CraftitudeProfile profile, PackageMetadata metadata)
 {
     File.Delete(GenerateModPath(profile, metadata));
 }
Beispiel #4
0
 public static void InstallMod(CraftitudeProfile profile, PackageMetadata metadata, string jarFile)
 {
     File.Copy(jarFile, GenerateModPath(profile, metadata), true);
 }
Beispiel #5
0
 public static string GenerateModPath(CraftitudeProfile profile, PackageMetadata metadata)
 {
     return Path.Combine(profile.Directory.CreateSubdirectory("mods").FullName + Path.DirectorySeparatorChar, CoerceValidFileName((metadata.Id + "-" + metadata.Version + ".jar").Replace(" ", "")));
 }
Beispiel #6
0
        protected void RunSteps(CraftitudeProfile profile, IEnumerable<SetupStep> steps)
        {
            foreach (var step in steps)
            {
                var stepName = step.Name.Split(':');
                switch (stepName[0].ToLower())
                {
                    case "target":
                        if (stepName.Length != 2)
                            throw new InvalidOperationException("Invalid step name syntax. Syntax of target step name is: Name=target:<target name>");
                        RunTarget(profile, stepName[1]);
                        break;
                    case "plugin":
                        if (stepName.Length != 2)
                            throw new InvalidOperationException("Invalid step name syntax. Syntax of plugin step name is: Name=plugin:<setup handler name>");

                        // Define where to get assemblies from
                        var pluginCatalog = new AggregateCatalog();
                        pluginCatalog.Catalogs.Add(new DirectoryCatalog(".")); // ./*.dll
                        if (System.IO.Directory.Exists("plugins"))
                            pluginCatalog.Catalogs.Add(new DirectoryCatalog("plugins")); // plugins/*.dll
                        if (profile.Directory.GetDirectories("plugins").Any())
                            pluginCatalog.Catalogs.Add(new DirectoryCatalog(profile.Directory.GetDirectories("plugins").Single().FullName)); // <profile>/plugins/*.dll
                        pluginCatalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly())); // this assembly

                        var container = new CompositionContainer(pluginCatalog, true);
                        var setuphelper = container.GetExportedValue<SetupHelper>(stepName[1]);

                        setuphelper.Package = this;
                        setuphelper.Profile = profile;
                        setuphelper.Run(step.Arguments.ToArray());
                        break;
                }
            }
        }
Beispiel #7
0
 public void RunTarget(CraftitudeProfile profile, string target)
 {
     RunSteps(profile, Metadata.Targets[target]);
 }
Beispiel #8
0
 public static void Uninstall(CraftitudeProfile profile, string groupId, string artifactId, string versionId)
 {
     Java.Uninstall(profile, groupId, artifactId, versionId);
 }
Beispiel #9
0
 public static void Install(CraftitudeProfile profile, string groupId, string artifactId, string versionId, string repository = "http://repo1.maven.org/maven2/")
 {
     Java.Install(profile, groupId, artifactId, versionId, Http.Download(ComposeUrl(groupId, artifactId, versionId, false, repository)));
 }
Beispiel #10
0
 public static void UnAutoload(CraftitudeProfile profile, string groupId, string artifactId, string version)
 {
     profile.ProfileInfo.Libraries.RemoveAll(e => e.GroupId == groupId && e.ArtifactId == artifactId && e.VersionId == version);
 }
Beispiel #11
0
 public static void Autoload(CraftitudeProfile profile, string groupId, string artifactId, string version, double weight = 50)
 {
     profile.ProfileInfo.Libraries.Add(new PathLibraryEntry(groupId, artifactId, version, weight));
 }
Beispiel #12
0
 public static void UnAutoload(CraftitudeProfile profile, string path)
 {
     path = new Uri(path).MakeRelativeUri(new Uri(profile.Directory.FullName)).ToString();
     profile.ProfileInfo.NativePaths.RemoveAll(p => p.Path == path);
 }
Beispiel #13
0
 public static void Autoload(CraftitudeProfile profile, string path, double weight = 50)
 {
     path = new Uri(path).MakeRelativeUri(new Uri(profile.Directory.FullName)).ToString();
     profile.ProfileInfo.NativePaths.Add(new PathEntry(path, weight));
 }