public Uploader(WorkshopType type, string path, Options.UploadVerb options, string description = null, string changelog = null) { m_modPath = path; if (ulong.TryParse(m_modPath, out ulong id)) { m_modId = WorkshopIdExtensions.ToWorkshopIds(new[] { id }); } else { m_modId = WorkshopHelper.GetWorkshopIdFromMod(m_modPath); } // Fill defaults before assigning user-defined ones if (m_modId.Length > 0 && m_modId.GetIds()[0] != 0 && !FillPropertiesFromPublished()) { MySandboxGame.Log.WriteLineWarning("Mod has a published ID, but unable to look up properties. This is wrong."); } m_compile = options.Compile; m_dryrun = options.DryRun; // Set visibilty if (options.Visibility != null) { m_visibility = options.Visibility; } else { m_visibility = m_visibility ?? PublishedFileVisibility.Private; // If not already set, set to Private } if (string.IsNullOrEmpty(m_title)) { m_title = Path.GetFileName(path); } m_description = description; m_changelog = changelog; m_type = type; m_force = options.Force; if (options.Thumbnail != null) { m_previewFilename = options.Thumbnail; } var mappedlc = MapDLCStringsToInts(options.DLCs); ProcessDLCs(mappedlc, MapDLCStringsToInts(options.DLCToAdd), MapDLCStringsToInts(options.DLCToRemove)); if (options.Tags != null) { m_tags = options.Tags.ToArray(); } if (options.TagsToAdd != null) { m_tagsToAdd = options.TagsToAdd.ToArray(); } if (options.TagsToRemove != null) { m_tagsToRemove = options.TagsToRemove.ToArray(); } ProcessTags(); ProcessDependencies(options.Dependencies, options.DependenciesToAdd, options.DependenciesToRemove); // This file list should match the PublishXXXAsync methods in MyWorkshop switch (m_type) { case WorkshopType.Mod: m_ignoredPaths.Add("modinfo.sbmi"); break; case WorkshopType.IngameScript: break; case WorkshopType.World: m_ignoredPaths.Add("Backup"); break; case WorkshopType.Blueprint: break; case WorkshopType.Scenario: break; } options.ExcludeExtensions?.Select(s => "." + s.TrimStart(new[] { '.', '*' })).ForEach(s => m_ignoredExtensions.Add(s)); options.IgnorePaths?.ForEach(s => m_ignoredPaths.Add(s)); // Start with the parent file, if it exists. This is at %AppData%\SpaceEngineers\Mods. if (IgnoreFile.TryLoadIgnoreFile(Path.Combine(m_modPath, "..", ".wtignore"), Path.GetFileName(m_modPath), out var extensionsToIgnore, out var pathsToIgnore)) { extensionsToIgnore.ForEach(s => m_ignoredExtensions.Add(s)); pathsToIgnore.ForEach(s => m_ignoredPaths.Add(s)); } if (IgnoreFile.TryLoadIgnoreFile(Path.Combine(m_modPath, ".wtignore"), out extensionsToIgnore, out pathsToIgnore)) { extensionsToIgnore.ForEach(s => m_ignoredExtensions.Add(s)); pathsToIgnore.ForEach(s => m_ignoredPaths.Add(s)); } }
/// <summary> /// Publishes the mod to the workshop /// </summary> /// <returns></returns> public bool Publish() { bool newMod = false; if (!Directory.Exists(m_modPath)) { MySandboxGame.Log.WriteLineWarning(string.Format("Directory does not exist {0}. Wrong option?", m_modPath ?? string.Empty)); return(false); } // Upload/Publish if (((IMod)this).ModId == 0) { MySandboxGame.Log.WriteLineAndConsole(string.Format("Uploading new {0}: {1}", m_type.ToString(), m_title)); newMod = true; if (m_modId.Length == 0) { m_modId = WorkshopIdExtensions.ToWorkshopIds(new ulong[] { 0 }); } } else { MySandboxGame.Log.WriteLineAndConsole(string.Format("Updating {0}: {1}; {2}", m_type.ToString(), m_modId.AsString(), m_title)); } // Add the global game filter for file extensions WorkshopHelper.IgnoredExtensions?.ForEach(s => m_ignoredExtensions.Add(s)); PrintItemDetails(); MyWorkshopItem[] items = null; if (m_dryrun) { MySandboxGame.Log.WriteLineAndConsole("DRY-RUN; Publish skipped"); return(true); } else { InjectedMethod.ChangeLog = m_changelog; if (WorkshopHelper.PublishItemBlocking(m_modPath, m_title, m_description, m_modId, (MyPublishedFileVisibility)m_visibility, m_tags, m_ignoredExtensions, m_ignoredPaths, m_dlcs, out items)) { m_modId = items.ToWorkshopIds(); } else { MySandboxGame.Log.WriteLineError(string.Format(Constants.ERROR_Reflection, "PublishItemBlocking")); } // SE libraries don't support updating dependencies, so we have to do that separately WorkshopHelper.PublishDependencies(m_modId, m_depsToAdd, m_depsToRemove); // SE also doesn't support removing DLC items, so do that too WorkshopHelper.PublishDLC(m_modId, m_dlcsToAdd, m_dlcsToRemove); } if (((IMod)this).ModId == 0 || !WorkshopHelper.PublishSuccess) { MySandboxGame.Log.WriteLineError("Upload/Publish FAILED!"); return(false); } else { MySandboxGame.Log.WriteLineAndConsole(string.Format("Upload/Publish success: {0}", m_modId.AsString())); if (newMod) { if (WorkshopHelper.GenerateModInfo(m_modPath, items, m_modId, MyGameService.UserId)) { MySandboxGame.Log.WriteLineAndConsole(string.Format("Create modinfo.sbmi success: {0}", m_modId.AsString())); } else { MySandboxGame.Log.WriteLineAndConsole(string.Format("Create modinfo.sbmi FAILED: {0}", m_modId.AsString())); return(false); } } } return(true); }