Example #1
0
        public bool UpdatePreviewFileOrTags(WorkshopId modId)
        {
            MyWorkshopItemPublisher publisher = WorkshopHelper.GetPublisher(modId);
            var modid = modId.GetId();

            publisher.Id          = modid;
            publisher.Title       = Title;
            publisher.Visibility  = (MyPublishedFileVisibility)(int)(m_visibility ?? GetVisibility());
            publisher.Thumbnail   = m_previewFilename;
            publisher.Tags        = new List <string>(m_tags);
            publisher.Description = m_description;
#if SE
            if (m_dlcs != null)
            {
                publisher.DLCs = new HashSet <uint>(m_dlcs);
            }
#else
            // ME will throw an exception if this isn't set, however setting this in SE
            // will trigger a full change event (with a new change note entry), which we don't want.
            publisher.Folder = m_modPath;
#endif
            if (m_deps != null)
            {
                publisher.Dependencies = new List <ulong>(m_deps);
            }

            AutoResetEvent resetEvent = new AutoResetEvent(false);
            try
            {
                publisher.ItemPublished += ((result, id) =>
                {
                    if (result == MyGameServiceCallResult.OK)
                    {
                        MySandboxGame.Log.WriteLineAndConsole("Published file update successful");

                        if (!string.IsNullOrEmpty(m_previewFilename))
                        {
                            MySandboxGame.Log.WriteLineAndConsole(string.Format("Updated thumbnail: {0}", Title));
                        }
                    }
                    else
                    {
                        MySandboxGame.Log.WriteLineError(string.Format("Error during publishing: {0}", (object)result));
                    }
                    resetEvent.Set();
                });

                PrintItemDetails();

                if (m_dryrun)
                {
                    MySandboxGame.Log.WriteLineAndConsole("DRY-RUN; Publish skipped");
                    return(true);
                }
                publisher.Publish();
                WorkshopHelper.PublishDependencies(m_modId, m_depsToAdd, m_depsToRemove);

                if (!resetEvent.WaitOne())
                {
                    return(false);
                }
            }
            finally
            {
                if (resetEvent != null)
                {
                    resetEvent.Dispose();
                }
            }
            return(true);
        }