public static void Publish(LifecycleOptions options) { Logo.Print(); ApplySettings(options); IMinecraftInstance instance = Packsly.Launcher.GetInstance(options.InstanceId); instance.Load(); logger.Debug($"Dispatching lifecycle events specified by command line arguments: {string.Join(", ", options.Events)}"); Packsly.Lifecycle.EventBus.Publish(instance, options.Events); instance.Save(); }
public static IMinecraftInstance CreateFromModpack(string modpackJson) { ModpackDefinition modpackDefinition = JsonConvert.DeserializeObject <ModpackDefinition>(modpackJson); char[] invalidChars = Path.GetInvalidFileNameChars(); // TODO: Allow name overrides string instanceId = new string(modpackDefinition.Name.ToLowerInvariant().Where(m => !invalidChars.Contains(m)).ToArray()); instanceId = instanceId.Replace(" ", "-"); logger.Info($"Modpack name is '{modpackDefinition.Name}' using instance id '{instanceId}'."); IMinecraftInstance instance = CreateMinecraftInstnace(instanceId, modpackDefinition); Packsly.Lifecycle.EventBus.Publish(instance, Lifecycle.PreInstallation); try { // Install modloaders logger.Info("Setting up modloaders..."); foreach (KeyValuePair <string, string> modloaderEntry in modpackDefinition.ModLoaders) { string name = modloaderEntry.Key; string version = modloaderEntry.Value; logger.Info($"Installing modloader '{name}' with version {version}."); instance.ModLoaderManager.Install(name, version); } // Download mods logger.Info("Downloading required files..."); foreach (ModSource mod in modpackDefinition.Mods) { if (mod.CanDownload) { logger.Info($"Downloading mod {mod.FileName}..."); instance.Files.Download(mod, FileManager.GroupType.Mod); } else { logger.Info($"Skipping downloading mod {mod.FileName} since it is {(mod.EnvironmentOnly.IsBlacklist ? "blacklisted" : "whitelisted")} at '{string.Join(", ", mod.EnvironmentOnly.Entries)}'..."); } // Download mod resources foreach (RemoteResource resource in mod.Resources) { if (resource.CanDownload) { logger.Info($" - Downloading resource {resource.FileName}..."); instance.Files.Download(resource, FileManager.GroupType.Resource); } else { logger.Info($" - Skipping downloading resource {resource.FileName} since it is {(resource.EnvironmentOnly.IsBlacklist ? "blacklisted" : "whitelisted")} at '{string.Join(", ", resource.EnvironmentOnly.Entries)}'..."); } } } instance.Save(); logger.Info("Finishing installation."); Packsly.Lifecycle.EventBus.Publish(instance, Lifecycle.PostInstallation); } catch (Exception) { // Delete the instance if creation fails logger.Warn("Modpack installation failed, removing instance files."); instance.Delete(); throw; } return(instance); }