Пример #1
0
        public override void RefreshValues()
        {
            base.RefreshValues();

            // WORKAROUND IN 1.5.9
            if (_brothel == null)
            {
                _brothel = new CEBrothel(Workshop.Settlement);
            }

            Name = _brothel.Name.ToString();
            WorkshopType workshopType = WorkshopType.Find("pottery_shop");

            WorkshopTypeId = workshopType.StringId;
            Location       = _brothel.Settlement.Name.ToString();
            Income         = (int)(Math.Max(0, _brothel.ProfitMade) / Campaign.Current.Models.ClanFinanceModel.RevenueSmoothenFraction()) * (_brothel.Level + 1);

            IncomeValueText = DetermineIncomeText(Income);
            InputsText      = new TextObject("{=CEBROTHEL0985}Description").ToString();
            OutputsText     = new TextObject("{=CEBROTHEL0994}Notable Prostitutes").ToString();
            ActionList.Clear();
            ItemProperties.Clear();
            PopulateActionList();
            PopulateStatsList();
        }
Пример #2
0
 public WorkshopOwners(Workshop workshop, Hero hero, WorkshopType t, int capital)
 {
     this.workshop     = workshop;
     this.hero         = hero;
     this.workshoptype = t;
     this.capital      = capital;
 }
Пример #3
0
        public static bool IsOperable(Vessel vsl, WorkshopType workshopType, ref string status)
        {
            status = string.Empty;
            switch (workshopType)
            {
            case WorkshopType.OMNI:
                return(true);

            case WorkshopType.GROUND:
                if (vsl.Landed)
                {
                    return(true);
                }
                status = "The workshop can only operate when the vessel is landed";
                return(false);

            case WorkshopType.ORBITAL:
                if (vsl.InOrbit())
                {
                    return(true);
                }
                status = "The workshop can only operate when the vessel is in orbit";
                return(false);
            }
            return(false);
        }
Пример #4
0
        public static bool IsOperable(Vessel vsl, WorkshopType workshopType, out string status)
        {
            status = string.Empty;
            // ReSharper disable once SwitchStatementHandlesSomeKnownEnumValuesWithDefault
            switch (workshopType)
            {
            case WorkshopType.OMNI:
                return(true);

            case WorkshopType.GROUND:
                if (vsl.Landed)
                {
                    return(true);
                }
                status = "The workshop can only operate when the vessel is landed";
                return(false);

            case WorkshopType.ORBITAL:
                if (vsl.InOrbit())
                {
                    return(true);
                }
                status = "The workshop can only operate when the vessel is in orbit";
                return(false);

            default:
                return(false);
            }
        }
Пример #5
0
        //deprecated config coversion
        public override void Load(ConfigNode node)
        {
            workshopType = WorkshopType.GROUND;
            isOperable   = true;
            base.Load(node);
            var kit_name = node.GetValue("KitName");

            if (kit_name != null)
            {
                TaskName = kit_name;
            }
        }
 public static bool TownHasWorkshop(Town town, string workshopId)
 {
     Workshop[] workshops = town.Workshops;
     for (int i = 0; i < workshops.Length; i++)
     {
         if (workshops[i].WorkshopType == WorkshopType.Find(workshopId))
         {
             return(true);
         }
     }
     return(false);
 }
Пример #7
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);
 }
Пример #8
0
        public Uploader(WorkshopType type, string path, string[] tags = null, string[] ignoredExtensions = null, bool compile = false, bool dryrun = false, bool development = false, SteamSDK.PublishedFileVisibility visibility = SteamSDK.PublishedFileVisibility.Public, bool force = false)
        {
            m_modPath    = path;
            m_compile    = compile;
            m_dryrun     = dryrun;
            m_visibility = visibility;
            m_title      = Path.GetFileName(path);
            m_modId      = MySteamWorkshop.GetWorkshopIdFromLocalMod(m_modPath);
            m_type       = type;
            m_isDev      = development;
            m_force      = force;

            if (tags != null)
            {
                m_tags = tags;
            }

            // This file list should match the PublishXXXAsync methods in MySteamWorkshop
            switch (m_type)
            {
            case WorkshopType.Mod:
                m_ignoredExtensions = new string[] { ".sbmi" };
                break;

            case WorkshopType.IngameScript:
                m_ignoredExtensions = new string[] { ".sbmi", ".png", ".jpg" };
                break;

            case WorkshopType.World:
                m_ignoredExtensions = new string[] { ".xmlcache", ".png" };
                break;

            case WorkshopType.Blueprint:
                m_ignoredExtensions = new string[] { };
                break;

            case WorkshopType.Scenario:
                m_ignoredExtensions = new string[] { };
                break;
            }

            if (ignoredExtensions != null)
            {
                ignoredExtensions = ignoredExtensions.Select(s => "." + s.TrimStart(new[] { '.', '*' })).ToArray();
                string[] allIgnoredExtensions = new string[m_ignoredExtensions.Length + ignoredExtensions.Length];
                ignoredExtensions.CopyTo(allIgnoredExtensions, 0);
                m_ignoredExtensions.CopyTo(allIgnoredExtensions, ignoredExtensions.Length);
                m_ignoredExtensions = allIgnoredExtensions;
            }

            SetupReflection();
        }
        public static int OwnsWorkshop(Town town, string workshopId)
        {
            int ret = 0;

            Workshop[] workshops = town.Workshops;
            for (int i = 0; i < workshops.Length; i++)
            {
                if (workshops[i].WorkshopType == WorkshopType.Find(workshopId) && workshops[i].Owner == Hero.MainHero)
                {
                    ret++;
                }
            }
            return(ret);
        }
Пример #10
0
 public static void ApplyByWarDeclaration(
     Workshop workshop,
     Hero newOwner,
     WorkshopType workshopType,
     int capital,
     bool upgradable,
     TextObject customName
     )
 {
     if (!workshopsSaved.Contains(workshop))
     {
         workshopsSaved.Add(workshop);
     }
 }
Пример #11
0
    public void SetupWorkshop(WorkshopType type, string buildingName, int level, GameObject model, GameObject navigationPoint, Professions reqProfession)
    {
        workshopType           = type;
        structureName          = buildingName;
        upgradeLevel           = level;
        buildingModel          = model;
        navPoint               = navigationPoint;
        numberOfWorkersAllowed = 1;
        requiredProfession     = reqProfession;

        villagersWorkingHere = new List <VillagerScript>();
        itemsCraftable       = new List <EquipmentItem>();

        Debug.Log("Setup Completed");
    }
Пример #12
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]))
                {
                    // Check if value is actually a mod id, and work remotely, if so.
                    var newpath = Path.Combine(WorkshopHelper.GetWorkshopItemPath(type), paths[idx]);

                    if (Directory.Exists(newpath) || !ulong.TryParse(paths[idx], out var id))
                    {
                        paths[idx] = newpath;
                    }
                }
            }
            return(paths);
        }
Пример #13
0
        public ProtoWorkshop(WorkshopBase workshop)
        {
            VesselName   = workshop.vessel.name;
            vesselID     = workshop.vessel.id;
            workshopType = workshop.workshopType;
            isOperable   = workshop.isOperable;
            id           = workshop.part.flightID;
            PartName     = workshop.part.partInfo.title;
            Workforce    = workshop.Workforce_Display;
            Stage        = workshop.Stage_Display;
            State        = Status.IDLE;
            EndUT        = workshop.EndUT;
            var task = workshop.GetCurrentTask();

            if (task != null && task.Valid)
            {
                update(task.Name);
            }
        }
Пример #14
0
        static bool ProcessItemsUpload(WorkshopType type, List <string> paths, Options options)
        {
            bool success = true;

            for (int idx = 0; idx < paths.Count; idx++)
            {
                var mod = new Uploader(type, Path.GetFullPath(paths[idx]), options.Tags, options.ExcludeExtensions, options.Compile, options.DryRun, options.Development, options.Visibility, options.Force);
                if (options.UpdateOnly && mod.ModId == 0)
                {
                    MySandboxGame.Log.WriteLineAndConsole(string.Format("--update-only passed, skipping: {0}", mod.Title));
                    continue;
                }
                MySandboxGame.Log.WriteLineAndConsole(string.Format("Processing {0}: {1}", type.ToString(), mod.Title));

                if (mod.Compile())
                {
                    if (options.Upload)
                    {
                        if (mod.Publish())
                        {
                            MySandboxGame.Log.WriteLineAndConsole(string.Format("Complete: {0}", mod.Title));
                        }
                        else
                        {
                            success = false;
                        }
                    }
                    else
                    {
                        MySandboxGame.Log.WriteLineAndConsole(string.Format("Not uploading: {0}", mod.Title));
                        MySandboxGame.Log.WriteLineAndConsole(string.Format("Complete: {0}", mod.Title));
                    }
                }
                else
                {
                    MySandboxGame.Log.WriteLineAndConsole(string.Format("Skipping {0}: {1}", type.ToString(), mod.Title));
                    success = false;
                }
                MySandboxGame.Log.WriteLineAndConsole(string.Empty);
            }
            return(success);
        }
Пример #15
0
        static string[] CombineCollectionWithList(WorkshopType type, List <MyWorkshopItem> items, string[] existingitems)
        {
            var tempList = new List <string>();

            // Check mods
            items.Where(i => i.Tags.Contains(type.ToString(), StringComparer.InvariantCultureIgnoreCase))
            .ForEach(i => tempList.Add(
                         i.Id.ToString()
                         ));

            if (tempList.Count > 0)
            {
                if (existingitems != null)
                {
                    tempList = tempList.Union(existingitems).ToList();
                }

                return(tempList.ToArray());
            }
            return(existingitems);
        }
Пример #16
0
    public void StartBuild(int prefabIndex)
    {
        newBuilding = Instantiate(structurePrefabs[prefabIndex]);
        newBuilding.AddComponent <Workshop>();

        if (newBuilding.GetComponent <Workshop>())
        {
            WorkshopType type             = (WorkshopType)Enum.Parse(typeof(WorkshopType), structureNames[prefabIndex], true);
            Professions  professionNeeded = Professions.Villager;

            switch (type)
            {
            case WorkshopType.Apothecary:
                professionNeeded = Professions.Alchemist;
                break;

            case WorkshopType.Blacksmith:
            case WorkshopType.Bowery:
                professionNeeded = Professions.Blacksmith;
                break;

            case WorkshopType.Brewery:
                professionNeeded = Professions.Brewer;
                break;

            case WorkshopType.Scribe:
                professionNeeded = Professions.Scholar;
                break;

            case WorkshopType.Tannery:
                professionNeeded = Professions.Leatherworker;
                break;

            default: break;
            }

            newBuilding.GetComponent <Workshop>().SetupWorkshop(type, structureNames[prefabIndex], 1, structurePrefabs[prefabIndex], null, professionNeeded);
            placingObject = true;
        }
    }
Пример #17
0
        public static string GetWorkshopItemPath(WorkshopType type, bool local = true)
        {
            // Get proper path to download to
            var downloadPath = MyFileSystem.ModsPath;

            switch (type)
            {
            case WorkshopType.Blueprint:
                downloadPath = Path.Combine(MyFileSystem.UserDataPath, "Blueprints", local ? "local" : "workshop");
                break;

            case WorkshopType.IngameScript:
                downloadPath = Path.Combine(MyFileSystem.UserDataPath, Sandbox.Game.Gui.MyGuiIngameScriptsPage.SCRIPTS_DIRECTORY, local ? "local" : "workshop");
                break;

            case WorkshopType.World:
            case WorkshopType.Scenario:
                downloadPath = Path.Combine(MyFileSystem.UserDataPath, "Saves", MySteam.UserId.ToString());
                break;
            }
            return(downloadPath);
        }
 public static void ApplyByTrade(
     ref Workshop workshop,
     ref Hero newOwner,
     ref WorkshopType workshopType,
     ref int capital,
     ref bool upgradable,
     ref int cost,
     ref TextObject customName)
 {
     try
     {
         if (BannerlordCheatsSettings.Instance?.EveryoneBuysWorkshops == true &&
             workshop.Owner.IsPlayer() &&
             cost > newOwner.Gold)
         {
             newOwner.Gold = cost;
         }
     }
     catch (Exception e)
     {
         SubModule.LogError(e, typeof(EveryoneBuysWorkshopsCost));
     }
 }
Пример #19
0
        public Uploader(WorkshopType type, string path, string[] tags = null, string[] ignoredExtensions = null, string[] ignoredPaths = null, bool compile = false, bool dryrun = false, bool development = false, PublishedFileVisibility?visibility = null, bool force = false, string previewFilename = null, string[] dlcs = null, ulong[] deps = null, string description = null, string changelog = null)
        {
            m_modPath = path;

            if (ulong.TryParse(m_modPath, out ulong id))
#if SE
            { m_modId = new[] { new WorkshopId(id, MyGameService.GetDefaultUGC().ServiceName) } };
#else
            { m_modId = id; }
#endif
            else
#if SE
            { m_modId = MyWorkshop.GetWorkshopIdFromMod(m_modPath); }
#else
            { m_modId = MyWorkshop.GetWorkshopIdFromLocalMod(m_modPath) ?? 0; }
#endif

            // Fill defaults before assigning user-defined ones
            FillPropertiesFromPublished();

            m_compile = compile;
            m_dryrun  = dryrun;

            if (visibility != null)
            {
                m_visibility = visibility;
            }

            if (string.IsNullOrEmpty(m_title))
            {
                m_title = Path.GetFileName(path);
            }

            m_description = description;
            m_changelog   = changelog;

            m_type  = type;
            m_isDev = development;
            m_force = force;

            if (previewFilename != null)
            {
                m_previewFilename = previewFilename;
            }
#if SE
            var mappedlc = MapDLCStringsToInts(dlcs);

            // If user specified "0" or "none" for DLCs, remove all of them
            if (dlcs != null)
            {
                m_dlcs = mappedlc;
            }
#endif
            if (tags != null)
            {
                m_tags = tags;
            }

            if (deps != null)
            {
                // Any dependencies that existed, but weren't specified, will be removed
                if (m_deps != null)
                {
                    m_depsToRemove = m_deps.Except(deps).ToArray();
                }

                m_deps = deps;
            }

            // 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;
            }

            if (ignoredExtensions != null)
            {
                ignoredExtensions = ignoredExtensions.Select(s => "." + s.TrimStart(new[] { '.', '*' })).ToArray();
                ignoredExtensions.ForEach(s => m_ignoredExtensions.Add(s));
            }

            if (ignoredPaths != null)
            {
                ignoredPaths.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));
            }

            SetupReflection();
        }
Пример #20
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);
        }
Пример #21
0
 public DiscordWebhook(WorkshopType type, string title, string changelog)
 {
     m_type      = type;
     m_title     = title;
     m_changelog = changelog;
 }
Пример #22
0
 public static WorkshopQueryAll CreateQueryAll(WorkshopQueryFilterOrder queryType, WorkshopType type)
 {
     return(new WorkshopQueryAll((EUGCQuery)queryType, (EUGCMatchingUGCType)type));
 }
Пример #23
0
 public static WorkshopQueryUser CreateQueryUser(ulong accountID, WorkshopList listType, WorkshopType type, WorkshopSortOrder order)
 {
     return(new WorkshopQueryUser((uint)accountID, (EUserUGCList)listType, (EUGCMatchingUGCType)type, (EUserUGCListSortOrder)order));
 }
Пример #24
0
        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));
            }
        }
Пример #25
0
        static bool ProcessItemsDownload(WorkshopType type, string[] paths, Options options)
        {
            if (paths == null)
            {
                return(true);
            }

            var width = Console.IsOutputRedirected ? 256 : Console.WindowWidth;

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

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

            var downloadPath = WorkshopHelper.GetWorkshopItemPath(type);

#if SE
            var workshopIds = new List <VRage.Game.WorkshopId>();
            foreach (var id in modids)
            {
                workshopIds.Add(new VRage.Game.WorkshopId(id, MyGameService.GetDefaultUGC().ServiceName));
            }

            if (MyWorkshop.GetItemsBlockingUGC(workshopIds, items))
#else
            if (MyWorkshop.GetItemsBlocking(modids, items))
#endif
            {
                System.Threading.Thread.Sleep(1000); // Fix for DLC not being filled in

                bool success = false;
                if (type == WorkshopType.Mod)
                {
#if SE
                    var result = MyWorkshop.DownloadModsBlockingUGC(items, null);
#else
                    var result = MyWorkshop.DownloadModsBlocking(items, null);
#endif
                    success = result.Success;
                }
                else
                {
                    if (type == WorkshopType.Blueprint)
                    {
                        var loopsuccess = false;
                        foreach (var item in items)
                        {
#if SE
                            loopsuccess = MyWorkshop.DownloadBlueprintBlockingUGC(item);
#else
                            loopsuccess = MyWorkshop.DownloadBlueprintBlocking(item, null);
#endif
                            if (!loopsuccess)
                            {
                                MySandboxGame.Log.WriteLineAndConsole(string.Format("Download of {0} FAILED!", item.Id));
                            }
                            else
                            {
                                success = true;
                            }
                        }
                    }
#if SE
                    else if (type == WorkshopType.IngameScript)
                    {
                        var loopsuccess = false;
                        foreach (var item in items)
                        {
                            loopsuccess = MyWorkshop.DownloadScriptBlocking(item);
                            if (!loopsuccess)
                            {
                                MySandboxGame.Log.WriteLineAndConsole(string.Format("Download of {0} FAILED!", item.Id));
                            }
                            else
                            {
                                success = true;
                            }
                        }
                    }
#endif
#if SE
                    else if (type == WorkshopType.World || type == WorkshopType.Scenario)
                    {
                        var    loopsuccess = false;
                        string path;
                        MyWorkshop.MyWorkshopPathInfo pathinfo = type == WorkshopType.World ?
                                                                 MyWorkshop.MyWorkshopPathInfo.CreateWorldInfo() :
                                                                 MyWorkshop.MyWorkshopPathInfo.CreateScenarioInfo();

                        foreach (var item in items)
                        {
                            // This downloads and extracts automatically, no control over it
                            loopsuccess = MyWorkshop.TryCreateWorldInstanceBlocking(item, pathinfo, out path, false);
                            if (!loopsuccess)
                            {
                                MySandboxGame.Log.WriteLineAndConsole(string.Format("Download of {0} FAILED!", item.Id));
                            }
                            else
                            {
                                MySandboxGame.Log.WriteLineAndConsole(string.Format("Downloaded '{0}' to {1}", item.Title, path));
                                success = true;
                            }
                        }
                    }
#endif
                    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("Downloading mod: {0}; {1}", item.Id, item.Title));
                    MySandboxGame.Log.WriteLineAndConsole(string.Format("Visibility: {0}", item.Visibility));
                    MySandboxGame.Log.WriteLineAndConsole(string.Format("Tags: {0}", string.Join(", ", string.Join(", ", item.Tags))));

#if SE
                    MySandboxGame.Log.WriteLineAndConsole(string.Format("DLC requirements: {0}",
                                                                        (item.DLCs.Count > 0 ? string.Join(", ", item.DLCs.Select(i =>
                    {
                        try { return(Sandbox.Game.MyDLCs.DLCs[i].Name); }
                        catch { return($"Unknown({i})"); }
                    })) : "None")));
#endif
                    MySandboxGame.Log.WriteLineAndConsole(string.Format("Dependencies: {0}", (item.Dependencies.Count > 0 ? string.Empty : "None")));

                    if (item.Dependencies.Count > 0)
                    {
                        List <MyWorkshopItem> depItems = new List <MyWorkshopItem>();
#if SE
                        workshopIds.Clear();
                        foreach (var id in item.Dependencies)
                        {
                            workshopIds.Add(new VRage.Game.WorkshopId(id, MyGameService.GetDefaultUGC().ServiceName));
                        }

                        if (MyWorkshop.GetItemsBlockingUGC(workshopIds, depItems))
#else
                        if (MyWorkshop.GetItemsBlocking(item.Dependencies, depItems))
#endif
                        { 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(", ", item.Dependencies)));
                        }
                    }

                    MySandboxGame.Log.WriteLineAndConsole(string.Format("Location: {0}", item.Folder));

                    if (options.Extract)
                    {
                        var mod = new Downloader(downloadPath, item);
                        mod.Extract();
                    }
                    MySandboxGame.Log.WriteLineAndConsole(string.Empty);
                }
            }
            return(true);
        }
Пример #26
0
        static bool ProcessItemsUpload(WorkshopType type, List <string> paths, Options options)
        {
            bool success = true;

            for (int idx = 0; idx < paths.Count; idx++)
            {
                var pathname = Path.GetFullPath(paths[idx]);

                // Check if path is really a modid (this is kind of hacky right now)
                if (!Directory.Exists(pathname) && ulong.TryParse(paths[idx], out var id))
                {
                    if (options.Compile)
                    {
                        MySandboxGame.Log.WriteLineAndConsole(string.Format("'--compile' option not valid with a ModID: {0}", id));
                        continue;
                    }
                    pathname = paths[idx];
                }

                var tags = options.Tags;

                // If user comma-separated the tags, split them
                if (tags != null && tags.Length == 1)
                {
                    tags = tags[0].Split(',', ';');
                }

                if (!string.IsNullOrEmpty(options.Thumbnail) &&
                    !Path.IsPathRooted(options.Thumbnail))
                {
                    options.Thumbnail = Path.GetFullPath(Path.Combine(LaunchDirectory, options.Thumbnail));
                }

                // Read the description filename, if set
                string description = null;
                if (!string.IsNullOrEmpty(options.DescriptionFile))
                {
                    if (!Path.IsPathRooted(options.DescriptionFile))
                    {
                        options.DescriptionFile = Path.GetFullPath(Path.Combine(LaunchDirectory, options.DescriptionFile));
                    }

                    if (File.Exists(options.DescriptionFile))
                    {
                        description = File.ReadAllText(options.DescriptionFile);
                    }
                    else
                    {
                        MySandboxGame.Log.WriteLineAndConsole(string.Format("Unable to set description, file does not exist: {0}", options.DescriptionFile));
                    }
                }

                // Read the changelog from a file, if detected
                var changelog = options.Changelog;
                if (!string.IsNullOrEmpty(options.Changelog))
                {
                    try
                    {
                        if (!Path.IsPathRooted(options.Changelog))
                        {
                            var rootedPath = Path.GetFullPath(Path.Combine(LaunchDirectory, options.Changelog));

                            if (File.Exists(rootedPath))
                            {
                                options.Changelog = rootedPath;
                            }
                        }

                        if (File.Exists(options.Changelog))
                        {
                            MySandboxGame.Log.WriteLineAndConsole(string.Format("Reading changelog from file: {0}", options.Changelog));
                            changelog = File.ReadAllText(options.Changelog);
                        }
                    }
                    catch (Exception ex)
                        when(ex is NotSupportedException || ex is IOException || ex is ArgumentException)
                        {
                            // Assume the string provided isn't a filename
                            // Could contain invalid characters that GetFullPath can't handle.
                        }
                }

                var mod = new Uploader(type, pathname, tags, options.ExcludeExtensions, options.IgnorePaths, options.Compile, options.DryRun, options.Development, options.Visibility, options.Force, options.Thumbnail, options.DLCs, options.Dependencies, description, options.Changelog);
                if (options.UpdateOnly && ((IMod)mod).ModId == 0)
                {
                    MySandboxGame.Log.WriteLineAndConsole(string.Format("--update-only passed, skipping: {0}", mod.Title));
                    continue;
                }
                MySandboxGame.Log.WriteLineAndConsole(string.Format("Processing {0}: {1}", type.ToString(), mod.Title));

                if (mod.Compile())
                {
                    if (!SteamAPI.IsSteamRunning())
                    {
                        MySandboxGame.Log.WriteLineAndConsole("Cannot publish, Steam not detected!");
                        return(false);
                    }

                    if (options.Upload)
                    {
                        if (mod.Publish())
                        {
                            MySandboxGame.Log.WriteLineAndConsole(string.Format("Complete: {0}", mod.Title));
                        }
                        else
                        {
                            success = false;
                            MySandboxGame.Log.WriteLineAndConsole(string.Format("Error occurred: {0}", mod.Title));
                        }
                    }
                    else
                    {
                        if (((IMod)mod).ModId == 0)
                        {
                            MySandboxGame.Log.WriteLineAndConsole(string.Format("Mod not published, skipping: {0}", mod.Title));
                            success = false;
                        }
                        else
                        {
                            MySandboxGame.Log.WriteLineAndConsole(string.Format("Not uploading: {0}", mod.Title));
#if SE
                            foreach (var item in mod.ModId)
                            {
                                mod.UpdatePreviewFileOrTags(item.Id, MyGameService.GetUGC(item.ServiceName).CreateWorkshopPublisher());
                            }
#else
                            mod.UpdatePreviewFileOrTags();
#endif
                            MySandboxGame.Log.WriteLineAndConsole(string.Format("Complete: {0}", mod.Title));
                        }
                    }
                }
                else
                {
                    MySandboxGame.Log.WriteLineAndConsole(string.Format("Skipping {0}: {1}", type.ToString(), mod.Title));
                    success = false;
                }

                MySandboxGame.Log.WriteLineAndConsole(string.Empty);
            }
            return(success);
        }
Пример #27
0
        static bool ProcessItemsUpload(WorkshopType type, List <string> paths, Options options)
        {
            bool success = true;

            for (int idx = 0; idx < paths.Count; idx++)
            {
                var pathname = Path.GetFullPath(paths[idx]);

                // Check if path is really a modid (this is kind of hacky right now)
                if (!Directory.Exists(pathname) && ulong.TryParse(paths[idx], out var id))
                {
                    if (options.Compile)
                    {
                        MySandboxGame.Log.WriteLineAndConsole(string.Format("'--compile' option not valid with a ModID: {0}", id));
                        continue;
                    }
                    pathname = paths[idx];
                }

                var tags = options.Tags;

                // If user comma-separated the tags, split them
                if (tags != null && tags.Length == 1)
                {
                    tags = tags[0].Split(',', ';');
                }

                var mod = new Uploader(type, pathname, tags, options.ExcludeExtensions, options.IgnorePaths, options.Compile, options.DryRun, options.Development, options.Visibility, options.Force, options.Thumbnail, options.DLCs, options.Dependencies);
                if (options.UpdateOnly && mod.ModId == 0)
                {
                    MySandboxGame.Log.WriteLineAndConsole(string.Format("--update-only passed, skipping: {0}", mod.Title));
                    continue;
                }
                MySandboxGame.Log.WriteLineAndConsole(string.Format("Processing {0}: {1}", type.ToString(), mod.Title));

                if (mod.Compile())
                {
                    if (options.Upload)
                    {
                        if (mod.Publish())
                        {
                            MySandboxGame.Log.WriteLineAndConsole(string.Format("Complete: {0}", mod.Title));
                        }
                        else
                        {
                            success = false;
                            MySandboxGame.Log.WriteLineAndConsole(string.Format("Error occurred: {0}", mod.Title));
                        }
                    }
                    else
                    {
                        if (mod.ModId == 0)
                        {
                            MySandboxGame.Log.WriteLineAndConsole(string.Format("Mod not published, skipping: {0}", mod.Title));
                            success = false;
                        }
                        else
                        {
                            MySandboxGame.Log.WriteLineAndConsole(string.Format("Not uploading: {0}", mod.Title));
                            mod.UpdatePreviewFileOrTags();
                            MySandboxGame.Log.WriteLineAndConsole(string.Format("Complete: {0}", mod.Title));
                        }
                    }
                }
                else
                {
                    MySandboxGame.Log.WriteLineAndConsole(string.Format("Skipping {0}: {1}", type.ToString(), mod.Title));
                    success = false;
                }

                MySandboxGame.Log.WriteLineAndConsole(string.Empty);
            }
            return(success);
        }