Ejemplo n.º 1
0
        // This can process passed in dependencies, either as the workshop id (ulong), or a path.
        // If a path is passed in, then an attempt will be made to grab the workshop id from the local mod.
        // Mod must be published for that to work.
        void ProcessDependencies(IEnumerable <string> deps, IEnumerable <string> add, IEnumerable <string> remove)
        {
            var existingDeps = m_workshopItems.GetValueOrDefault(m_modId.FirstOrDefault())?.Dependencies.ToList() ?? new List <ulong>();

            // Check if the deps contains exactly one element, and that element is a 0 or "none",
            // if so, set the result to a list of a single ulong value of 0
            // Otherwise, just fill it with the contents transformed to ids.
            var explicitDeps = (deps?.Count() == 1 && (deps.First() == "0" || deps.First().Equals("none", StringComparison.InvariantCultureIgnoreCase)))
                                    ? new List <ulong>()
            {
                0
            } : new List <ulong>(deps?.Select(id => ParseOrGetWorkshopID(id)) ?? new List <ulong>());
            var depsToAdd    = new List <ulong>(add.Select(id => ParseOrGetWorkshopID(id)));
            var depsToRemove = new List <ulong>(remove.Select(id => ParseOrGetWorkshopID(id)));

            // Steam actually requests the list of deps to add and remove explicitly, so we have to figure it out
            if (explicitDeps?.Count > 0)
            {
                if (explicitDeps.Count == 1 && explicitDeps[0] == 0)
                {
                    // Remove ALL dependencies
                    depsToRemove.AddRange(existingDeps);
                    explicitDeps.Clear();
                }
                else if (existingDeps?.Count > 0)
                {
                    // Any dependencies that existed, but weren't specified, will be removed
                    depsToRemove.AddRange(existingDeps.Except(explicitDeps));
                    depsToAdd.AddRange(explicitDeps.Except(existingDeps));
                }
            }

            // Remove from add list any that already exist
            depsToAdd.RemoveAll(d => existingDeps.Contains(d));
            // Remove from remove list any dependencies that don't exist, or aren't configured to set
            depsToRemove.RemoveAll(d => !existingDeps.Contains(d) && !(explicitDeps?.Contains(d) == true));

            // Filter out items that aren't actually mods, these can crash the game if set
            // Don't check depsToRemove though, so users can remove invalid ones that already exist
            WorkshopHelper.GetItemsBlocking(explicitDeps).ForEach(i => { if (!CheckDependency(i))
                                                                         {
                                                                             explicitDeps.Remove(i.Id);
                                                                         }
                                                                  });
            WorkshopHelper.GetItemsBlocking(depsToAdd).ForEach(i => { if (!CheckDependency(i))
                                                                      {
                                                                          depsToAdd.Remove(i.Id);
                                                                      }
                                                               });

            // Add all explicit deps to the add list that don't already exist
            depsToAdd.AddRange(explicitDeps.Except(existingDeps));

            m_deps         = existingDeps.Union(explicitDeps ?? new List <ulong>()).Union(depsToAdd).Except(depsToRemove).Where(i => i != 0).Distinct().ToArray();
            m_depsToAdd    = depsToAdd.Distinct().ToArray();
            m_depsToRemove = depsToRemove.Distinct().ToArray();
        }
Ejemplo n.º 2
0
        void PrintItemDetails()
        {
            const int MAX_LENGTH = 40;

            MySandboxGame.Log.WriteLineAndConsole(string.Format("Visibility: {0}", m_visibility));
            MySandboxGame.Log.WriteLineAndConsole(string.Format("Tags: {0}", string.Join(", ", m_tags)));

            if (!string.IsNullOrEmpty(m_description))
            {
                MySandboxGame.Log.WriteLineAndConsole($"Description: {m_description.Substring(0, Math.Min(m_description.Length, MAX_LENGTH))}{(m_description.Length > MAX_LENGTH ? "..." : "")}");
            }

            if (!string.IsNullOrEmpty(m_changelog))
            {
                MySandboxGame.Log.WriteLineAndConsole($"Changelog: {m_changelog.Substring(0, Math.Min(m_changelog.Length, MAX_LENGTH))}{(m_changelog.Length > MAX_LENGTH ? "..." : "")}");
            }
#if SE
            MySandboxGame.Log.WriteLineAndConsole(string.Format("DLC requirements: {0}",
                                                                (m_dlcs?.Length > 0 ? string.Join(", ", m_dlcs.Select(i =>
            {
                try { return(Sandbox.Game.MyDLCs.DLCs[i].Name); }
                catch { return($"Unknown({i})"); }
            })) : "None")));
#endif
            MySandboxGame.Log.WriteLineAndConsole(string.Format("Dependencies: {0}", (m_deps?.Length > 0 ? string.Empty : "None")));

            if (m_deps?.Length > 0)
            {
                var width = Console.Out.IsInteractive() ? Console.WindowWidth : 256;

                var depIds   = m_deps.ToWorkshopIds();
                var depItems = WorkshopHelper.GetItemsBlocking(depIds.ToArray());

                if (depItems?.Count > 0)
                {
                    depItems.ForEach(i => MySandboxGame.Log.WriteLineAndConsole(string.Format("{0,15} -> {1}",
                                                                                              i.Id, i.Title.Substring(0, Math.Min(i.Title.Length, width - 45)))));
                }
                else
                {
                    MySandboxGame.Log.WriteLineAndConsole(string.Format("     {0}", string.Join(", ", m_deps)));
                }
            }
            MySandboxGame.Log.WriteLineAndConsole(string.Format("Thumbnail: {0}", m_previewFilename ?? "No change"));
            ValidateThumbnail();
        }
Ejemplo n.º 3
0
        PublishedFileVisibility GetVisibility()
        {
            var results = m_workshopItems?.Values ?? (ICollection <MyWorkshopItem>)WorkshopHelper.GetItemsBlocking(m_modId);

            if (results?.Count > 0)
            {
                if (results.Count > 0)
                {
                    return((PublishedFileVisibility)(int)results.First().Visibility);
                }
                else
                {
                    return(PublishedFileVisibility.Private);
                }
            }

            return(PublishedFileVisibility.Private);
        }
Ejemplo n.º 4
0
        string[] GetTags()
        {
            var results = m_workshopItems?.Values ?? (ICollection <MyWorkshopItem>)WorkshopHelper.GetItemsBlocking(m_modId);

            if (results?.Count > 0)
            {
                if (results.Count > 0)
                {
                    return(results.First().Tags.ToArray());
                }
                else
                {
                    return(null);
                }
            }

            return(null);
        }
Ejemplo n.º 5
0
        bool FillPropertiesFromPublished()
        {
            var results = WorkshopHelper.GetItemsBlocking(m_modId);

            if (results?.Count > 0)
            {
                System.Threading.Thread.Sleep(1000); // Fix for DLC not being filled in
                if (results.Count > 0)
                {
                    m_workshopItems[m_modId[0]] = results[0];

                    if (m_modId.Length > 1 && results.Count > 1)
                    {
                        m_workshopItems[m_modId[1]] = results[1];
                    }

                    m_title = results[0].Title;

                    // Check if the mod owner in the sbmi matches steam owner
                    var owner = results[0].OwnerId;

                    if (m_visibility == null)
                    {
                        m_visibility = (PublishedFileVisibility)(int)results[0].Visibility;
                    }

#if SE
                    m_dlcs = results[0].DLCs.ToArray();
#endif
                    m_deps = results[0].Dependencies.ToArray();

                    MyDebug.AssertDebug(owner == MyGameService.UserId);
                    if (owner != MyGameService.UserId)
                    {
                        MySandboxGame.Log.WriteLineError(string.Format("Owner mismatch! Mod owner: {0}; Current user: {1}", owner, MyGameService.UserId));
                        MySandboxGame.Log.WriteLineError("Upload/Publish FAILED!");
                        return(false);
                    }
                    return(true);
                }
                return(false);
            }
            return(false);
        }
Ejemplo n.º 6
0
        uint[] GetDLC()
        {
#if SE
            var results = m_workshopItems?.Values ?? (ICollection <MyWorkshopItem>)WorkshopHelper.GetItemsBlocking(m_modId);

            if (results?.Count > 0)
            {
                if (results.Count > 0)
                {
                    return(results.First().DLCs.ToArray());
                }
                else
                {
                    return(null);
                }
            }
#endif
            return(null);
        }