Example #1
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);
        }
Example #2
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);
        }