From adccce2db83dc8a29415694014cef22a1c691f93 Mon Sep 17 00:00:00 2001 From: KillzXGaming Date: Wed, 16 Oct 2019 18:38:42 -0400 Subject: [PATCH] Improve texture loader with error icons and messages --- .../FileFormats/Layout/CAFE/BFLYT.cs | 68 +++++++++++------- .../FileFormats/Layout/Rev/BRLYT.cs | 21 ++++-- .../GUI/BFLYT/LayoutTextureList.cs | 4 +- .../Properties/Resources.Designer.cs | 10 +++ File_Format_Library/Properties/Resources.resx | 3 + .../Resources/MissingTexture.png | Bin 0 -> 2015 bytes 6 files changed, 70 insertions(+), 36 deletions(-) create mode 100644 File_Format_Library/Resources/MissingTexture.png diff --git a/File_Format_Library/FileFormats/Layout/CAFE/BFLYT.cs b/File_Format_Library/FileFormats/Layout/CAFE/BFLYT.cs index 8e5136a7..c755ff6e 100644 --- a/File_Format_Library/FileFormats/Layout/CAFE/BFLYT.cs +++ b/File_Format_Library/FileFormats/Layout/CAFE/BFLYT.cs @@ -207,24 +207,31 @@ namespace LayoutBXLYT.Cafe string folder = Path.GetDirectoryName(FilePath); foreach (var file in Directory.GetFiles(folder)) { - if (Utils.GetExtension(file) == ".bflim") + try { - BFLIM bflim = (BFLIM)STFileLoader.OpenFileFormat(file); - if (!textures.ContainsKey(bflim.FileName)) - textures.Add(bflim.FileName, bflim); - } - if (Utils.GetExtension(file) == ".bntx") - { - BNTX bntx = (BNTX)STFileLoader.OpenFileFormat(file); - foreach (var tex in bntx.Textures) + if (Utils.GetExtension(file) == ".bflim") { - if (!textures.ContainsKey(tex.Key)) - textures.Add(tex.Key, tex.Value); + BFLIM bflim = (BFLIM)STFileLoader.OpenFileFormat(file); + if (!textures.ContainsKey(bflim.FileName)) + textures.Add(bflim.FileName, bflim); } + if (Utils.GetExtension(file) == ".bntx") + { + BNTX bntx = (BNTX)STFileLoader.OpenFileFormat(file); + foreach (var tex in bntx.Textures) + { + if (!textures.ContainsKey(tex.Key)) + textures.Add(tex.Key, tex.Value); + } - string fileName = Path.GetFileName(file); - if (!header.TextureManager.BinaryContainers.ContainsKey(fileName)) - header.TextureManager.BinaryContainers.Add(fileName, bntx); + string fileName = Path.GetFileName(file); + if (!header.TextureManager.BinaryContainers.ContainsKey(fileName)) + header.TextureManager.BinaryContainers.Add(fileName, bntx); + } + } + catch (Exception ex) + { + STErrorDialog.Show($"Failed to load texture {file}. ", "Layout Editor", ex.ToString()); } } } @@ -233,23 +240,30 @@ namespace LayoutBXLYT.Cafe { foreach (var file in archive.Files) { - if (Utils.GetExtension(file.FileName) == ".bntx") + try { - BNTX bntx = (BNTX)file.OpenFile(); - file.FileFormat = bntx; - foreach (var tex in bntx.Textures) - if (!textures.ContainsKey(tex.Key)) - textures.Add(tex.Key, tex.Value); + if (Utils.GetExtension(file.FileName) == ".bntx") + { + BNTX bntx = (BNTX)file.OpenFile(); + file.FileFormat = bntx; + foreach (var tex in bntx.Textures) + if (!textures.ContainsKey(tex.Key)) + textures.Add(tex.Key, tex.Value); - if (!header.TextureManager.BinaryContainers.ContainsKey($"{archive.FileName}.bntx")) - header.TextureManager.BinaryContainers.Add($"{archive.FileName}.bntx", bntx); + if (!header.TextureManager.BinaryContainers.ContainsKey($"{archive.FileName}.bntx")) + header.TextureManager.BinaryContainers.Add($"{archive.FileName}.bntx", bntx); + } + if (Utils.GetExtension(file.FileName) == ".bflim") + { + BFLIM bflim = (BFLIM)file.OpenFile(); + file.FileFormat = bflim; + if (!textures.ContainsKey(bflim.FileName)) + textures.Add(bflim.FileName, bflim); + } } - if (Utils.GetExtension(file.FileName) == ".bflim") + catch (Exception ex) { - BFLIM bflim = (BFLIM)file.OpenFile(); - file.FileFormat = bflim; - if (!textures.ContainsKey(bflim.FileName)) - textures.Add(bflim.FileName, bflim); + STErrorDialog.Show($"Failed to load texture {file.FileName}. ", "Layout Editor", ex.ToString()); } } diff --git a/File_Format_Library/FileFormats/Layout/Rev/BRLYT.cs b/File_Format_Library/FileFormats/Layout/Rev/BRLYT.cs index e8499726..398e24a9 100644 --- a/File_Format_Library/FileFormats/Layout/Rev/BRLYT.cs +++ b/File_Format_Library/FileFormats/Layout/Rev/BRLYT.cs @@ -115,17 +115,24 @@ namespace LayoutBXLYT { foreach (var file in IFileInfo.ArchiveParent.Files) { - if (Utils.GetExtension(file.FileName) == ".tpl") + try { - TPL tpl = (TPL)file.OpenFile(); - file.FileFormat = tpl; - foreach (var tex in tpl.IconTextureList) + if (Utils.GetExtension(file.FileName) == ".tpl") { - //Only need the first texture - if (!textures.ContainsKey(tex.Text)) - textures.Add(file.FileName, tex); + TPL tpl = (TPL)file.OpenFile(); + file.FileFormat = tpl; + foreach (var tex in tpl.IconTextureList) + { + //Only need the first texture + if (!textures.ContainsKey(tex.Text)) + textures.Add(file.FileName, tex); + } } } + catch (Exception ex) + { + STErrorDialog.Show($"Failed to load texture {file.FileName}. ", "Layout Editor", ex.ToString()); + } } } diff --git a/File_Format_Library/GUI/BFLYT/LayoutTextureList.cs b/File_Format_Library/GUI/BFLYT/LayoutTextureList.cs index 21b6e31b..2c8d7a49 100644 --- a/File_Format_Library/GUI/BFLYT/LayoutTextureList.cs +++ b/File_Format_Library/GUI/BFLYT/LayoutTextureList.cs @@ -77,9 +77,9 @@ namespace LayoutBXLYT ActiveLayout = header; listViewCustom1.Items.Clear(); imgListSmall.Images.Clear(); - imgListSmall.Images.Add(new Bitmap(30, 30)); + imgListSmall.Images.Add(FirstPlugin.Properties.Resources.MissingTexture); imgListBig.Images.Clear(); - imgListBig.Images.Add(new Bitmap(60, 60)); + imgListBig.Images.Add(FirstPlugin.Properties.Resources.MissingTexture); listViewCustom1.LargeImageList = imgListBig; listViewCustom1.SmallImageList = imgListSmall; diff --git a/File_Format_Library/Properties/Resources.Designer.cs b/File_Format_Library/Properties/Resources.Designer.cs index 2cb42581..8a8a8ea6 100644 --- a/File_Format_Library/Properties/Resources.Designer.cs +++ b/File_Format_Library/Properties/Resources.Designer.cs @@ -200,6 +200,16 @@ namespace FirstPlugin.Properties { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap MissingTexture { + get { + object obj = ResourceManager.GetObject("MissingTexture", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// diff --git a/File_Format_Library/Properties/Resources.resx b/File_Format_Library/Properties/Resources.resx index 44b82642..2c9dade1 100644 --- a/File_Format_Library/Properties/Resources.resx +++ b/File_Format_Library/Properties/Resources.resx @@ -196,4 +196,7 @@ ..\Resources\LayoutAnimation.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\MissingTexture.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + \ No newline at end of file diff --git a/File_Format_Library/Resources/MissingTexture.png b/File_Format_Library/Resources/MissingTexture.png new file mode 100644 index 0000000000000000000000000000000000000000..cb65ba9d23b07e5f4f62aee38a3ce81ce3bc68f6 GIT binary patch literal 2015 zcmZuydpy&7AODTaZ7y3ILZg{z3G2)ma@lGahcy`?_oX72a$T8R%ZNC%M`d#@iB8h# zCU@mhc~H)i%aPV(E+e<_jH$Epbe!jp=lSFF{k%S(_v`(Be?FgozL`{tgOY-#0ssI? zj%3miNv8f8a$w1O1-kT$ByBrMbRhyjU9O@yP)1Vg(#c0$0O0&?07y;;fOSbLc?tkx zO#xsg001nn0f71$&NEjl2_S!l>=g|F%Fq7{P*-HtaY<7n#?CXwE%HQ6d|*^Ca3(M$ zBE~o(I7Sy|j5Rhp?%*kzLKf>tBGMRsb2nUA+V1d+d$Bz9jt)Y)7fDXe@-okfXsU{T z!UHsinev3|WTTQ006Sxiz`m*oVbZuvdqfDSksN*E&{OPsYCQ z6>d;sn`Wk+E6+dU)l@epCXHDSxUcxF!MT)^?NWK2@*?thI`ih)gEnu?cj<(1@^W#M zZU;?+PkK4qmwx^aEKs2sTE5OEN#A1Qo)Oqgi#G!YL-cc8^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