示例#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);
 }
示例#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);
        }