public static MyWorkshopPathInfo CreateScenarioInfo() { var info = new MyWorkshopPathInfo(); info.Path = m_workshopScenariosPath; info.Suffix = m_workshopScenariosSuffix; info.NamePrefix = "Scenario"; return info; }
public static MyWorkshopPathInfo CreateWorldInfo() { var info = new MyWorkshopPathInfo(); info.Path = m_workshopWorldsPath; info.Suffix = m_workshopWorldSuffix; info.NamePrefix = "Workshop"; return info; }
/// <summary> /// Do NOT call this method from update thread. /// </summary> public static bool TryCreateWorldInstanceBlocking(SubscribedItem world, MyWorkshopPathInfo pathInfo, out string sessionPath, bool overwrite) { m_stop = false; if (!Directory.Exists(pathInfo.Path)) Directory.CreateDirectory(pathInfo.Path); string safeName = MyUtils.StripInvalidChars(world.Title); sessionPath = null; var localPackedWorldFullPath = Path.Combine(pathInfo.Path, world.PublishedFileId + pathInfo.Suffix); if (!MySteam.IsOnline) return false; if (!IsModUpToDateBlocking(localPackedWorldFullPath, world, true)) { if (!DownloadItemBlocking(localPackedWorldFullPath, world.UGCHandle)) return false; } // Extract packaged world. sessionPath = MyLocalCache.GetSessionSavesPath(safeName, false, false); //overwrite? if (overwrite && Directory.Exists(sessionPath)) Directory.Delete(sessionPath, true); // Find new non existing folder. The game folder name may be different from game name, so we have to // make sure we don't overwrite another save while (Directory.Exists(sessionPath)) sessionPath = MyLocalCache.GetSessionSavesPath(safeName + MyUtils.GetRandomInt(int.MaxValue).ToString("########"), false, false); MyZipArchive.ExtractToDirectory(localPackedWorldFullPath, sessionPath); // Update some meta-data of the new world. ulong checkPointSize; var checkpoint = MyLocalCache.LoadCheckpoint(sessionPath, out checkPointSize); checkpoint.SessionName = string.Format("({0}) {1}", pathInfo.NamePrefix, world.Title); checkpoint.LastSaveTime = DateTime.Now; checkpoint.WorkshopId = null; MyLocalCache.SaveCheckpoint(checkpoint, sessionPath); MyLocalCache.SaveLastLoadedTime(sessionPath, DateTime.Now); return true; }
public CreateWorldResult(SubscribedItem world, MyWorkshopPathInfo pathInfo, Action<bool, string> callback, bool overwrite) { Callback = callback; Task = Parallel.Start(() => { Success = TryCreateWorldInstanceBlocking(world, pathInfo, out m_createdSessionPath, overwrite); }); }
public static void CreateWorldInstanceAsync(SubscribedItem world, MyWorkshopPathInfo pathInfo, bool overwrite, Action<bool, string> callbackOnFinished = null) { MyGuiSandbox.AddScreen(new MyGuiScreenProgressAsync(MyCommonTexts.ProgressTextCreatingWorld, null, () => new CreateWorldResult(world, pathInfo, callbackOnFinished, overwrite), endActionCreateWorldInstance)); }