Example #1
0
 static string[] TestPathAndMakeAbsolute(WorkshopType type, string[] paths)
 {
     for (int idx = 0; paths != null && idx < paths.Length; idx++)
     {
         // If the passed in path doesn't exist, and is relative, try to match it with the expected data directory
         if (!Directory.Exists(paths[idx]) && !Path.IsPathRooted(paths[idx]))
         {
             paths[idx] = Path.Combine(WorkshopHelper.GetWorkshopItemPath(type), paths[idx]);
         }
     }
     return(paths);
 }
Example #2
0
        static bool ProcessItemsDownload(WorkshopType type, string[] paths, Options options)
        {
            if (paths == null)
            {
                return(true);
            }

            var items  = new List <MySteamWorkshop.SubscribedItem>();
            var modids = paths.Select(ulong.Parse);

            MySandboxGame.Log.WriteLineAndConsole(string.Format("Processing {0}s...", type.ToString()));

            var downloadPath = WorkshopHelper.GetWorkshopItemPath(type);

            if (MySteamWorkshop.GetItemsBlocking(items, modids))
            {
                bool success = false;
                if (type == WorkshopType.Mod)
                {
                    var result = MySteamWorkshop.DownloadModsBlocking(items);
                    success = result.Success;
                }
                else
                {
                    if (type == WorkshopType.Blueprint)
                    {
                        success = MySteamWorkshop.DownloadBlueprintsBlocking(items);
                    }
                    else if (type == WorkshopType.IngameScript)
                    {
                        var loopsuccess = false;
                        foreach (var item in items)
                        {
                            loopsuccess = MySteamWorkshop.DownloadScriptBlocking(item);
                            if (!loopsuccess)
                            {
                                MySandboxGame.Log.WriteLineAndConsole(string.Format("Download of {0} FAILED!", item.PublishedFileId));
                            }
                            else
                            {
                                success = true;
                            }
                        }
                    }
                    else if (type == WorkshopType.World || type == WorkshopType.Scenario)
                    {
                        var    loopsuccess = false;
                        string path;
                        MySteamWorkshop.MyWorkshopPathInfo pathinfo = type == WorkshopType.World ?
                                                                      MySteamWorkshop.MyWorkshopPathInfo.CreateWorldInfo() :
                                                                      MySteamWorkshop.MyWorkshopPathInfo.CreateScenarioInfo();

                        foreach (var item in items)
                        {
                            // This downloads and extracts automatically, no control over it
                            loopsuccess = MySteamWorkshop.TryCreateWorldInstanceBlocking(item, pathinfo, out path, false);
                            if (!loopsuccess)
                            {
                                MySandboxGame.Log.WriteLineAndConsole(string.Format("Download of {0} FAILED!", item.PublishedFileId));
                            }
                            else
                            {
                                MySandboxGame.Log.WriteLineAndConsole(string.Format("Downloaded '{0}' to {1}", item.Title, path));
                                success = true;
                            }
                        }
                    }
                    else
                    {
                        throw new NotSupportedException(string.Format("Downloading of {0} not yet supported.", type.ToString()));
                    }
                }

                if (success)
                {
                    MySandboxGame.Log.WriteLineAndConsole("Download success!");
                }
                else
                {
                    MySandboxGame.Log.WriteLineAndConsole("Download FAILED!");
                    return(false);
                }

                foreach (var item in items)
                {
                    MySandboxGame.Log.WriteLineAndConsole(string.Format("{0} '{1}' tags: {2}", item.PublishedFileId, item.Title, string.Join(", ", item.Tags)));
                    if (options.Extract)
                    {
                        var mod = new Downloader(downloadPath, item.PublishedFileId, item.Title, item.Tags);
                        mod.Extract();
                    }
                    MySandboxGame.Log.WriteLineAndConsole(string.Empty);
                }
            }
            return(true);
        }
Example #3
0
 string[] GetTags()
 {
     return(WorkshopHelper.GetSubscribedItem(m_modId).Tags);
 }
Example #4
0
        /// <summary>
        /// Publishes the mod to the workshop
        /// </summary>
        /// <returns></returns>
        public bool Publish()
        {
            bool newMod = false;

            if (MySteam.API == null)
            {
                MySandboxGame.Log.WriteLineAndConsole("Cannot publish, Steam not detected!");
                return(false);
            }

            // Upload/Publish
            if (m_modId == 0)
            {
                MySandboxGame.Log.WriteLineAndConsole(string.Format("Uploading new {0}: {1}", m_type.ToString(), m_title));
                newMod = true;
            }
            else
            {
                var title = m_title;
                var item  = WorkshopHelper.GetSubscribedItem(m_modId);

                if (item != null)
                {
                    title = item.Title;
                }

                // Check if the mod owner in the sbmi matches steam owner
                MyDebug.AssertDebug(item.SteamIDOwner == MySteam.UserId);
                if (item.SteamIDOwner != MySteam.UserId)
                {
                    MySandboxGame.Log.WriteLineAndConsole(string.Format("Owner mismatch! Mod owner: {0}; Current user: {1}", item.SteamIDOwner, MySteam.UserId));
                    MySandboxGame.Log.WriteLineAndConsole("Upload/Publish FAILED!");
                    return(false);
                }
                MySandboxGame.Log.WriteLineAndConsole(string.Format("Updating {0}: {1}; {2}", m_type.ToString(), m_modId, title));
            }

            // Process Tags
            ProcessTags();

            if (m_dryrun)
            {
                MySandboxGame.Log.WriteLineAndConsole("DRY-RUN; Publish skipped");
            }
            else
            {
                if (_publishMethod != null)
                {
                    var ret = _publishMethod.Invoke(null, new object[]
                    {
                        m_modPath,
                        m_title,
                        null,
                        new ulong?(m_modId),
                        m_visibility,
                        m_tags,
                        m_ignoredExtensions
                    });

                    MyDebug.AssertDebug(ret is ulong);
                    m_modId = (ulong)ret;
                }
                else
                {
                    MySandboxGame.Log.WriteLineAndConsole(string.Format(Constants.ERROR_Reflection, "PublishItemBlocking"));
                }
            }
            if (m_modId == 0)
            {
                MySandboxGame.Log.WriteLineAndConsole("Upload/Publish FAILED!");
                return(false);
            }
            else
            {
                MySandboxGame.Log.WriteLineAndConsole(string.Format("Upload/Publish success: {0}", m_modId));
                if (newMod)
                {
                    if (MySteamWorkshop.GenerateModInfo(m_modPath, m_modId, MySteam.UserId))
                    {
                        MySandboxGame.Log.WriteLineAndConsole(string.Format("Create modinfo.sbmi success: {0}", m_modId));
                    }
                    else
                    {
                        MySandboxGame.Log.WriteLineAndConsole(string.Format("Create modinfo.sbmi FAILED: {0}", m_modId));
                        return(false);
                    }
                }
            }
            return(true);
        }