public WorldGeneratorDialog(InstanceManager instanceManager) { _instanceManager = instanceManager; InitializeComponent(); _loadLocalization(); var scenarios = MyLocalCache.GetAvailableWorldInfos(Path.Combine(MyFileSystem.ContentPath, "CustomWorlds")); foreach (var tup in scenarios) { string directory = tup.Item1; MyWorldInfo info = tup.Item2; string localizedName = MyTexts.GetString(MyStringId.GetOrCompute(info.SessionName)); var checkpoint = MyLocalCache.LoadCheckpoint(directory, out _); checkpoint.OnlineMode = MyOnlineModeEnum.PUBLIC; _checkpoints.Add(new PremadeCheckpointItem { Name = localizedName, Icon = Path.Combine(directory, "thumb.jpg"), Path = directory, Checkpoint = checkpoint }); } /* * var premadeCheckpoints = Directory.EnumerateDirectories(Path.Combine("Content", "CustomWorlds")); * foreach (var path in premadeCheckpoints) * { * var thumbPath = Path.GetFullPath(Directory.EnumerateFiles(path).First(x => x.Contains("thumb"))); * * _checkpoints.Add(new PremadeCheckpointItem * { * Path = path, * Icon = thumbPath, * Name = Path.GetFileName(path) * }); * }*/ PremadeCheckpoints.ItemsSource = _checkpoints; }
private void endWorkshop(IMyAsyncResult result, MyGuiScreenProgressAsync screen) { var loadResult = (LoadWorkshopResult)result; m_subscribedScenarios = loadResult.SubscribedScenarios; foreach (var item in loadResult.SubscribedScenarios) { MyWorldInfo wi = new MyWorldInfo(); wi.SessionName = item.Title; wi.Briefing = item.Description; wi.WorkshopId = item.PublishedFileId; m_availableSavesWorkshop.Add(new Tuple <string, MyWorldInfo>(WORKSHOP_PATH_TAG, wi)); } m_availableSavesWorkshop.Sort((x, y) => x.Item2.SessionName.CompareTo(y.Item2.SessionName)); AfterPartLoaded(); screen.CloseScreen(); }
public static void GetWorldInfoFromDirectory(string path, List <Tuple <string, MyWorldInfo> > result) { bool flag = Directory.Exists(path); MySandboxGame.Log.WriteLine($"GetWorldInfoFromDirectory (Exists: {flag}) '{path}'"); if (flag) { foreach (string str in Directory.GetDirectories(path, "*", SearchOption.TopDirectoryOnly)) { MyWorldInfo info = LoadWorldInfo(str); if ((info != null) && string.IsNullOrEmpty(info.SessionName)) { info.SessionName = Path.GetFileName(str); } result.Add(Tuple.Create <string, MyWorldInfo>(str, info)); } } }
public MyGuiScreenSaveAs(MyWorldInfo copyFrom, string sessionPath, List <string> existingSessionNames) : base(new Vector2(0.5f, 0.5f), MyGuiConstants.SCREEN_BACKGROUND_COLOR, new Vector2(0.5f, 0.35f)) { EnabledBackgroundFade = true; AddCaption(MyCommonTexts.ScreenCaptionSaveAs); float textboxPositionY = -0.02f; m_nameTextbox = new MyGuiControlTextbox( position: new Vector2(0, textboxPositionY), defaultText: copyFrom.SessionName, maxLength: 75); m_okButton = new MyGuiControlButton( text: MyTexts.Get(MyCommonTexts.Ok), onButtonClick: OnOkButtonClick, originAlign: MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM); m_cancelButton = new MyGuiControlButton( text: MyTexts.Get(MyCommonTexts.Cancel), onButtonClick: OnCancelButtonClick, originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM); Vector2 buttonOrigin = new Vector2(0f, Size.Value.Y * 0.4f); Vector2 buttonOffset = new Vector2(0.01f, 0f); m_okButton.Position = buttonOrigin - buttonOffset; m_cancelButton.Position = buttonOrigin + buttonOffset; Controls.Add(m_nameTextbox); Controls.Add(m_okButton); Controls.Add(m_cancelButton); m_nameTextbox.MoveCarriageToEnd(); m_copyFrom = copyFrom; m_sessionPath = sessionPath; m_existingSessionNames = existingSessionNames; CloseButtonEnabled = true; CloseButtonOffset = new Vector2(-0.005f, 0.0035f); OnEnterCallback = OnEnterPressed; }
void SaveAsync(string newSaveName, string sessionPath, MyWorldInfo copyFrom) { // Try a simple path, then a random if it already exists var newSessionPath = MyLocalCache.GetSessionSavesPath(newSaveName, false, false); while (Directory.Exists(newSessionPath)) { newSessionPath = MyLocalCache.GetSessionSavesPath(newSaveName + MyUtils.GetRandomInt(int.MaxValue).ToString("########"), false, false); } Directory.CreateDirectory(newSessionPath); MyUtils.CopyDirectory(sessionPath, newSessionPath); ulong sizeInBytes; var checkpoint = MyLocalCache.LoadCheckpoint(newSessionPath, out sizeInBytes); Debug.Assert(checkpoint != null); checkpoint.SessionName = copyFrom.SessionName; checkpoint.WorkshopId = null; MyLocalCache.SaveCheckpoint(checkpoint, newSessionPath); MyLocalCache.SaveLastLoadedTime(newSessionPath, DateTime.Now); }
private static void GetWorldInfoFromDirectory(string path, List <Tuple <string, MyWorldInfo> > result) { bool dirExists = Directory.Exists(path); MySandboxGame.Log.WriteLine(string.Format("GetWorldInfoFromDirectory (Exists: {0}) '{1}'", dirExists, path)); if (!dirExists) { return; } foreach (var saveDir in Directory.GetDirectories(path, "*", SearchOption.TopDirectoryOnly)) { MyWorldInfo worldInfo = MyLocalCache.LoadWorldInfo(saveDir); if (worldInfo != null) { if (string.IsNullOrEmpty(worldInfo.SessionName)) { worldInfo.SessionName = Path.GetFileName(saveDir); } } result.Add(Tuple.Create(saveDir, worldInfo)); } }
void OnPublishButtonClick(MyGuiControlButton sender) { var row = m_scenarioTable.SelectedRow; if (row == null) { return; } if (row.UserData == null) { return; } string fullPath = (string)(((Tuple <string, MyWorldInfo>)row.UserData).Item1); MyWorldInfo worldInfo = FindSave(m_scenarioTable.SelectedRow).Item2; //var mod = (MyObjectBuilder_Checkpoint.ModItem)row.UserData; //var nameSB = m_selectedRow.GetCell(1).Text; //var name = nameSB.ToString(); MyStringId textQuestion, captionQuestion; if (worldInfo.WorkshopId != null) { textQuestion = MySpaceTexts.MessageBoxTextDoYouWishToUpdateScenario; captionQuestion = MySpaceTexts.MessageBoxCaptionDoYouWishToUpdateScenario; } else { textQuestion = MySpaceTexts.MessageBoxTextDoYouWishToPublishScenario; captionQuestion = MySpaceTexts.MessageBoxCaptionDoYouWishToPublishScenario; } MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox( styleEnum : MyMessageBoxStyleEnum.Info, buttonType : MyMessageBoxButtonsType.YES_NO, messageText : MyTexts.Get(textQuestion), messageCaption : MyTexts.Get(captionQuestion), callback : delegate(MyGuiScreenMessageBox.ResultEnum val) { if (val == MyGuiScreenMessageBox.ResultEnum.YES) { string[] inTags = null; var subscribedItem = GetSubscribedItem(worldInfo.WorkshopId); if (subscribedItem != null) { inTags = subscribedItem.Tags; if (subscribedItem.SteamIDOwner != MySteam.UserId) { MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox( messageText: MyTexts.Get(MySpaceTexts.MessageBoxTextPublishFailed_OwnerMismatchMod),//TODO rename messageCaption: MyTexts.Get(MySpaceTexts.MessageBoxCaptionModPublishFailed))); return; } } /*MyGuiSandbox.AddScreen(new MyGuiScreenWorkshopTags(MySteamWorkshop.WORKSHOP_SCENARIO_TAG, MySteamWorkshop.ScenarioCategories, inTags, delegate(MyGuiScreenMessageBox.ResultEnum tagsResult, string[] outTags) * { * if (tagsResult == MyGuiScreenMessageBox.ResultEnum.YES) * {*/ MySteamWorkshop.PublishScenarioAsync(fullPath, worldInfo.SessionName, worldInfo.Description, worldInfo.WorkshopId, /*outTags,*/ SteamSDK.PublishedFileVisibility.Public, callbackOnFinished : delegate(bool success, Result result, ulong publishedFileId) //TODO public visibility!! { if (success) { ulong dummy; var checkpoint = MyLocalCache.LoadCheckpoint(fullPath, out dummy); worldInfo.WorkshopId = publishedFileId; checkpoint.WorkshopId = publishedFileId; MyLocalCache.SaveCheckpoint(checkpoint, fullPath); MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox( styleEnum: MyMessageBoxStyleEnum.Info, messageText: MyTexts.Get(MySpaceTexts.MessageBoxTextScenarioPublished), messageCaption: MyTexts.Get(MySpaceTexts.MessageBoxCaptionScenarioPublished), callback: (a) => { MySteam.API.OpenOverlayUrl(string.Format("http://steamcommunity.com/sharedfiles/filedetails/?id={0}", publishedFileId)); FillList(); })); } else { MyStringId error; switch (result) { case Result.AccessDenied: error = MySpaceTexts.MessageBoxTextPublishFailed_AccessDenied; break; default: error = MySpaceTexts.MessageBoxTextScenarioPublishFailed; break; } MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox( messageText: MyTexts.Get(error), messageCaption: MyTexts.Get(MySpaceTexts.MessageBoxCaptionModPublishFailed))); } }); /* * } * }));*/ } })); }
private static MyWorldInfo LoadWorldInfo(string sessionPath) { MyWorldInfo worldInfo = null; try { System.Xml.Linq.XDocument doc = null; string checkpointFile = Path.Combine(sessionPath, CHECKPOINT_FILE); if (!File.Exists(checkpointFile)) { return(null); } using (var stream = MyFileSystem.OpenRead(checkpointFile).UnwrapGZip()) { doc = XDocument.Load(stream); } Debug.Assert(doc != null); var root = doc.Root; Debug.Assert(root != null); var session = root.Element("SessionName"); var description = root.Element("Description"); var lastSaveTime = root.Element("LastSaveTime"); var lastLoadTime = root.Element("LastLoadTime"); var worldId = root.Element("WorldID"); var workshopId = root.Element("WorkshopId"); var briefing = root.Element("Briefing"); worldInfo = new MyWorldInfo(); if (session != null) { worldInfo.SessionName = session.Value; } if (description != null) { worldInfo.Description = description.Value; } if (lastSaveTime != null) { DateTime.TryParse(lastSaveTime.Value, out worldInfo.LastSaveTime); } if (lastLoadTime != null) { DateTime.TryParse(lastLoadTime.Value, out worldInfo.LastLoadTime); } if (workshopId != null) { ulong tmp; if (ulong.TryParse(workshopId.Value, out tmp)) { worldInfo.WorkshopId = tmp; } } if (briefing != null) { worldInfo.Briefing = briefing.Value; } } catch (Exception ex) { MySandboxGame.Log.WriteLine(ex); } return(worldInfo); }
public SaveResult(string saveDir, string sessionPath, MyWorldInfo copyFrom) { Task = Parallel.Start(() => SaveAsync(saveDir, sessionPath, copyFrom)); }
public static void Publish(string sessionPath, MyWorldInfo worlInfo) { if (MyFakes.XBOX_PREVIEW) { MyGuiSandbox.Show(MyCommonTexts.MessageBoxTextErrorFeatureNotAvailableYet, MyCommonTexts.MessageBoxCaptionError); return; } MyStringId textQuestion, captionQuestion; if (worlInfo.WorkshopId.HasValue) { textQuestion = MyCommonTexts.MessageBoxTextDoYouWishToUpdateWorld; captionQuestion = MyCommonTexts.MessageBoxCaptionDoYouWishToUpdateWorld; } else { textQuestion = MyCommonTexts.MessageBoxTextDoYouWishToPublishWorld; captionQuestion = MyCommonTexts.MessageBoxCaptionDoYouWishToPublishWorld; } MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox( styleEnum : MyMessageBoxStyleEnum.Info, buttonType : MyMessageBoxButtonsType.YES_NO, messageText : MyTexts.Get(textQuestion), messageCaption : MyTexts.Get(captionQuestion), callback : delegate(MyGuiScreenMessageBox.ResultEnum val) { if (val == MyGuiScreenMessageBox.ResultEnum.YES) { Action <MyGuiScreenMessageBox.ResultEnum, string[]> onTagsChosen = delegate(MyGuiScreenMessageBox.ResultEnum tagsResult, string[] outTags) { if (tagsResult == MyGuiScreenMessageBox.ResultEnum.YES) { MySteamWorkshop.PublishWorldAsync(sessionPath, worlInfo.SessionName, worlInfo.Description, worlInfo.WorkshopId, outTags, SteamSDK.PublishedFileVisibility.Public, callbackOnFinished : delegate(bool success, Result result, ulong publishedFileId) { if (success) { ulong dummy; var checkpoint = MyLocalCache.LoadCheckpoint(sessionPath, out dummy); worlInfo.WorkshopId = publishedFileId; checkpoint.WorkshopId = publishedFileId; MyLocalCache.SaveCheckpoint(checkpoint, sessionPath); MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox( styleEnum: MyMessageBoxStyleEnum.Info, messageText: MyTexts.Get(MyCommonTexts.MessageBoxTextWorldPublished), messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionWorldPublished), callback: (a) => { MySteam.API.OpenOverlayUrl(string.Format("http://steamcommunity.com/sharedfiles/filedetails/?id={0}", publishedFileId)); })); } else { MyStringId error; switch (result) { case Result.AccessDenied: error = MyCommonTexts.MessageBoxTextPublishFailed_AccessDenied; break; default: error = MyCommonTexts.MessageBoxTextWorldPublishFailed; break; } MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox( messageText: MyTexts.Get(error), messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionWorldPublishFailed))); } }); } }; if (MySteamWorkshop.WorldCategories.Length > 0) { MyGuiSandbox.AddScreen(new MyGuiScreenWorkshopTags(MySteamWorkshop.WORKSHOP_WORLD_TAG, MySteamWorkshop.WorldCategories, null, onTagsChosen)); } else { onTagsChosen(MyGuiScreenMessageBox.ResultEnum.YES, new string[] { MySteamWorkshop.WORKSHOP_WORLD_TAG }); } } })); }
private static MyWorldInfo LoadWorldInfo(string sessionPath) { MyWorldInfo info = null; try { XDocument document = null; string path = Path.Combine(sessionPath, "Sandbox.sbc"); if (File.Exists(path)) { ulong num; info = new MyWorldInfo(); using (Stream stream = MyFileSystem.OpenRead(path).UnwrapGZip()) { document = XDocument.Load(stream); } XElement root = document.Root; XElement element2 = root.Element("SessionName"); XElement element3 = root.Element("Description"); XElement element4 = root.Element("LastSaveTime"); root.Element("WorldID"); XElement element5 = root.Element("WorkshopId"); XElement element6 = root.Element("Briefing"); XElement element1 = root.Element("Settings"); XElement element7 = (element1 != null) ? root.Element("Settings").Element("ScenarioEditMode") : null; XElement element8 = (element1 != null) ? root.Element("Settings").Element("ExperimentalMode") : null; if (element8 != null) { bool.TryParse(element8.Value, out info.IsExperimental); } if (element2 != null) { info.SessionName = MyStatControlText.SubstituteTexts(element2.Value, null); } if (element3 != null) { info.Description = element3.Value; } if (element4 != null) { DateTime.TryParse(element4.Value, out info.LastSaveTime); } if ((element5 != null) && ulong.TryParse(element5.Value, out num)) { info.WorkshopId = new ulong?(num); } if (element6 != null) { info.Briefing = element6.Value; } if (element7 != null) { bool.TryParse(element7.Value, out info.ScenarioEditMode); } } else { return(null); } } catch (Exception exception) { MySandboxGame.Log.WriteLine(exception); info.IsCorrupted = true; } return(info); }