static void ReadAllCraftFiles(string editorFacility, string shipDirectory) { foreach (var craftFile in Directory.GetFiles(shipDirectory, "*.craft")) { try { string validFileName = Path.GetFileNameWithoutExtension(craftFile); if (validFileName == "Auto-Saved Ship") { continue; // Skip these, they would lead to duplicates, we only use finished crafts. } var cachedTemplate = new CachedShipTemplate(); switch (editorFacility) { case "VAB": cachedTemplate.templateOrigin = TemplateOrigin.VAB; break; case "SPH": cachedTemplate.templateOrigin = TemplateOrigin.SPH; break; case "Subassemblies": cachedTemplate.templateOrigin = TemplateOrigin.SubAssembly; break; } cachedTemplate.template = ShipConstruction.LoadTemplate(craftFile); if (cachedTemplate.template == null) { continue; } if (cachedTemplate.template.shipPartsExperimental || !cachedTemplate.template.shipPartsUnlocked) { continue; // We won't bother with ships we can't use anyways. } // Try to load the thumbnail for this craft: var thumbFile = KSPUtil.ApplicationRootPath + "thumbs/" + HighLogic.SaveFolder + "_" + editorFacility + "_" + validFileName + ".png"; Texture2D thumbnail; // // Make the thumbnail file if it doesn't exist. // Needed for the subassemblies, will also replace any missing thumbnail files for regular craft // if (!HighLogic.LoadedSceneIsFlight) { if (!File.Exists(thumbFile)) { Log.Info("Missing Thumbfile: " + thumbFile); ShipConstruct ship = ShipConstruction.LoadShip(craftFile); ThumbnailHelper.CaptureThumbnail(ship, 256, "thumbs/", HighLogic.SaveFolder + "_" + editorFacility + "_" + validFileName); } } bool placeholder = false; if (File.Exists(thumbFile)) { thumbnail = new Texture2D(256, 256, TextureFormat.RGBA32, false); thumbnail.LoadImage(File.ReadAllBytes(thumbFile)); } else { thumbnail = placeholderImage; placeholder = true; } // The thumbnails are rather large, so we have to resize them first: cachedTemplate.thumbnail = GUI.ResizeTexture(thumbnail, 64, 64); if (!placeholder) { Destroy(thumbnail); } GUI.shipTemplates.Add(cachedTemplate); } catch (Exception e) { Debug.LogError("UpdateShipTemplateCache() processing '" + craftFile + "': " + e.ToString()); } } }