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(); }
bool ValidateModInfo(MyObjectBuilder_ModInfo info) { if (info == null) return false; if (info.SubtypeName == null) return false; if (info.WorkshopId == null) return false; if (info.SteamIDOwner == null) return false; return true; }