Ejemplo n.º 1
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();
        }
Ejemplo n.º 2
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));
            }
        }