public static MyObjectBuilder_Definitions LoadWorkshopPrefab(string archive, ulong?publishedItemId) { if (!File.Exists(archive) || publishedItemId == null) { return(null); } var subItem = MyGuiBlueprintScreen.m_subscribedItemsList.Find(item => item.PublishedFileId == publishedItemId); if (subItem == null) { return(null); } var extracted = MyZipArchive.OpenOnFile(archive); var stream = extracted.GetFile("bp.sbc").GetStream(); if (stream == null) { return(null); } MyObjectBuilder_Definitions objectBuilder = null; var success = MyObjectBuilderSerializer.DeserializeXML(stream, out objectBuilder); stream.Close(); extracted.Dispose(); if (success) { objectBuilder.ShipBlueprints[0].Description = subItem.Description; objectBuilder.ShipBlueprints[0].CubeGrids[0].DisplayName = subItem.Title; return(objectBuilder); } return(null); }
private Image TryGetPlanetTexture(string name, MyModContext context, string p, out string fullPath) { bool flag = false; string text1 = name + p; name = text1; fullPath = Path.Combine(context.ModPathData, "PlanetDataFiles", name) + ".png"; if (!context.IsBaseGame) { if (MyFileSystem.FileExists(fullPath)) { flag = true; } else { fullPath = Path.Combine(context.ModPathData, "PlanetDataFiles", name) + ".dds"; if (MyFileSystem.FileExists(fullPath)) { flag = true; } } } if (!flag) { string str = Path.Combine(MyFileSystem.ContentPath, PlanetDataFilesPath); fullPath = Path.Combine(str, name) + ".png"; if (!MyFileSystem.FileExists(fullPath)) { fullPath = Path.Combine(str, name) + ".dds"; if (!MyFileSystem.FileExists(fullPath)) { return(null); } } } if (fullPath.Contains(MyWorkshop.WorkshopModSuffix)) { string path = fullPath.Substring(0, fullPath.IndexOf(MyWorkshop.WorkshopModSuffix) + MyWorkshop.WorkshopModSuffix.Length); string str3 = fullPath.Replace(path + @"\", ""); MyZipArchive archive = MyZipArchive.OpenOnFile(path, FileMode.Open, FileAccess.Read, FileShare.Read, false); try { return(Image.Load(archive.GetFile(str3).GetStream(FileMode.Open, FileAccess.Read))); } catch (Exception) { MyLog.Default.Error("Failed to load existing " + p + " file mod archive. " + fullPath, Array.Empty <object>()); return(null); } finally { if (archive != null) { archive.Dispose(); } } } return(Image.Load(fullPath)); }
bool FileExistsInZip(string zipFile, string subpath) { var arc = MyZipArchive.OpenOnFile(zipFile); try { return(arc.FileExists(subpath)); } finally { arc.Dispose(); } }
public void ExtractSandboxFromZip() { const string filename = @".\TestAssets\Sample World.sbw"; MyObjectBuilder_Checkpoint checkpoint; using (MyZipArchive archive = MyZipArchive.OpenOnFile(filename)) { MyZipFileInfo fileInfo = archive.GetFile(SpaceEngineersConsts.SandBoxCheckpointFilename); checkpoint = SpaceEngineersApi.ReadSpaceEngineersFile <MyObjectBuilder_Checkpoint>(fileInfo.GetStream()); } Assert.AreEqual("Quad Scissor Doors", checkpoint.SessionName, "Checkpoint SessionName must match!"); }
private MyZipArchive TryGetZipArchive(string zipFile, string subpath) { var arc = MyZipArchive.OpenOnFile(zipFile); try { return(arc); } catch { arc.Dispose(); return(null); } }
bool DirectoryExistsInZip(string zipFile, string subpath) { var arc = MyZipArchive.OpenOnFile(zipFile); try { // Root exists when archive can be opened return(subpath == String.Empty ? true : arc.DirectoryExists(subpath + "/")); } finally { arc.Dispose(); } }
private Stream TryOpen(string zipFile, string subpath) { var arc = MyZipArchive.OpenOnFile(zipFile); try { return(arc.FileExists(subpath) ? new MyStreamWrapper(arc.GetFile(subpath).GetStream(), arc) : null); } catch { arc.Dispose(); return(null); } }
void ExtractWorkShopItems() { ProfilerShort.Begin("Blueprint screen - Extracting bluepritns"); if (!Directory.Exists(m_workshopBlueprintFolder)) { Directory.CreateDirectory(m_workshopBlueprintFolder); } var downloadedMods = Directory.GetFiles(m_workshopBlueprintFolder); foreach (var mod in downloadedMods) { var fileName = Path.GetFileNameWithoutExtension(mod); var id = ulong.Parse(fileName); if (!m_subscribedItemsList.Any(item => item.PublishedFileId == id)) { File.Delete(mod); } } var tempPath = Path.Combine(m_workshopBlueprintFolder, "temp"); if (Directory.Exists(tempPath)) { Directory.Delete(tempPath, true); } var tempDir = Directory.CreateDirectory(tempPath); foreach (var subItem in m_subscribedItemsList) { if (downloadedMods.Any(item => item.Contains(subItem.PublishedFileId.ToString()))) { string archive = Array.Find(downloadedMods, item => item.Contains(subItem.PublishedFileId.ToString())); var extractPath = Path.Combine(tempDir.FullName, subItem.PublishedFileId.ToString()); if (!File.Exists(extractPath)) { Directory.CreateDirectory(extractPath); var extracted = MyZipArchive.OpenOnFile(archive); var modInfo = new MyObjectBuilder_ModInfo(); modInfo.SubtypeName = subItem.Title; modInfo.WorkshopId = subItem.PublishedFileId; modInfo.SteamIDOwner = subItem.SteamIDOwner; var infoFile = Path.Combine(m_workshopBlueprintFolder, "temp", subItem.PublishedFileId.ToString(), "info.temp"); if (File.Exists(infoFile)) { File.Delete(infoFile); } var infoSuccess = MyObjectBuilderSerializer.SerializeXML(infoFile, false, modInfo); if (extracted.FileExists("thumb.png")) { var stream = extracted.GetFile("thumb.png").GetStream(); if (stream != null) { using (var file = File.Create(Path.Combine(extractPath, "thumb.png"))) { stream.CopyTo(file); } } stream.Close(); } extracted.Dispose(); var info = new MyBlueprintItemInfo(MyBlueprintTypeEnum.STEAM, subItem.PublishedFileId); var listItem = new MyGuiControlListbox.Item(text: new StringBuilder(subItem.Title), toolTip: subItem.Title, icon: MyGuiConstants.TEXTURE_ICON_MODS_WORKSHOP.Normal, userData: info); var itemIndex = m_blueprintList.Items.FindIndex(item => ((item.UserData as MyBlueprintItemInfo).PublishedItemId == (listItem.UserData as MyBlueprintItemInfo).PublishedItemId) && (item.UserData as MyBlueprintItemInfo).Type == MyBlueprintTypeEnum.STEAM); if (itemIndex == -1) { m_blueprintList.Add(listItem); } } } } ProfilerShort.End(); }