fixed crash when trying to get same header image too fast

This commit is contained in:
Asval
2019-06-01 14:51:24 +02:00
parent 82a9db6839
commit d524e38269
11 changed files with 239 additions and 179 deletions

View File

@@ -17,7 +17,22 @@ namespace FModel
public static ItemsIdParser myItem { get; set; }
/// <summary>
/// draw the pretty header if DisplayStyle exist, else the shitty background
/// get a random color in case DisplayStyle doesn't exist in drawBackground()
/// </summary>
/// <returns></returns>
private static Color getRandomColor()
{
Random rnd = new Random();
int Red = rnd.Next(50, 200);
int Green = rnd.Next(50, 200);
int Blue = rnd.Next(50, 200);
return Color.FromArgb(255, Red, Green, Blue);
}
/// <summary>
/// draw the pretty header if DisplayStyle exist, else the pretty header but with random colors
/// </summary>
/// <param name="myBitmap"></param>
/// <param name="myBundle"></param>
@@ -49,7 +64,11 @@ namespace FModel
//image
string textureFile = Path.GetFileName(myBundle.DisplayStyle.DisplayImage.AssetPathName).Substring(0, Path.GetFileName(myBundle.DisplayStyle.DisplayImage.AssetPathName).LastIndexOf('.'));
Image challengeIcon = new Bitmap(JohnWick.AssetToTexture2D(textureFile));
Image challengeIcon;
using (var bmpTemp = new Bitmap(JohnWick.AssetToTexture2D(textureFile)))
{
challengeIcon = new Bitmap(bmpTemp);
}
toDrawOn.DrawImage(ImageUtilities.ResizeImage(challengeIcon, 282, 282), new Point(40, 0));
//fill the rest
@@ -57,13 +76,27 @@ namespace FModel
}
else
{
toDrawOn.DrawImage(new Bitmap(Resources.Quest), new Point(0, 0));
Color myBaseColor = getRandomColor();
//main header
toDrawOn.FillRectangle(new SolidBrush(myBaseColor), new Rectangle(0, 0, myBitmap.Width, 281));
//gradient at left and right main header
LinearGradientBrush linGrBrush_left = new LinearGradientBrush(new Point(0, 282 / 2), new Point(282, 282 / 2),
ControlPaint.Light(myBaseColor, (float)0.3), myBaseColor);
toDrawOn.FillRectangle(linGrBrush_left, new Rectangle(0, 0, 282, 282));
LinearGradientBrush linGrBrush_right = new LinearGradientBrush(new Point(2500, 282 / 2), new Point(1500, 282 / 2),
ControlPaint.Light(myBaseColor, (float)0.3), myBaseColor);
toDrawOn.FillRectangle(linGrBrush_right, new Rectangle(1500, 0, 1000, 282));
//fill the rest
toDrawOn.FillRectangle(new SolidBrush(ControlPaint.Dark(myBaseColor, (float)0.1)), new Rectangle(0, 271, myBitmap.Width, myBitmap.Height));
//last folder
toDrawOn.DrawString(BundleInfos.getLastFolder(BundlePath), new Font(FontUtilities.pfc.Families[1], 42), new SolidBrush(Color.FromArgb(255, 149, 213, 255)), new Point(340, 40));
toDrawOn.DrawString(BundleInfos.getLastFolder(BundlePath), new Font(FontUtilities.pfc.Families[1], 42), new SolidBrush(ControlPaint.Dark(myBaseColor, (float)0.05)), new Point(40, 40));
//name
toDrawOn.DrawString(BundleInfos.getBundleDisplayName(myItem), new Font(FontUtilities.pfc.Families[1], 115), new SolidBrush(Color.White), new Point(325, 70));
toDrawOn.DrawString(BundleInfos.getBundleDisplayName(myItem), new Font(FontUtilities.pfc.Families[1], 115), new SolidBrush(Color.White), new Point(25, 70));
}
}

View File

@@ -63,24 +63,14 @@ namespace FModel
{
ItemIcon.SearchAthIteDefIcon(itemId[i]);
if (File.Exists(ItemIcon.ItemIconPath))
{
Image itemIcon;
using (var bmpTemp = new Bitmap(ItemIcon.ItemIconPath))
{
itemIcon = new Bitmap(bmpTemp);
}
BundleDesign.toDrawOn.DrawImage(ImageUtilities.ResizeImage(itemIcon, 110, 110), new Point(2300, BundleDesign.theY + 6));
}
else
{
Image itemIcon = Resources.unknown512;
BundleDesign.toDrawOn.DrawImage(ImageUtilities.ResizeImage(itemIcon, 110, 110), new Point(2300, BundleDesign.theY + 6));
}
drawIcon();
}
}
}
catch (JsonSerializationException) { }
catch (JsonSerializationException)
{
//do not crash when JsonSerialization does weird stuff
}
}
}
}
@@ -121,28 +111,35 @@ namespace FModel
ItemIcon.ItemIconPath = JohnWick.AssetToTexture2D(textureFile);
}
if (File.Exists(ItemIcon.ItemIconPath))
{
Image itemIcon;
using (var bmpTemp = new Bitmap(ItemIcon.ItemIconPath))
{
itemIcon = new Bitmap(bmpTemp);
}
BundleDesign.toDrawOn.DrawImage(ImageUtilities.ResizeImage(itemIcon, 110, 110), new Point(2300, BundleDesign.theY + 6));
}
else
{
Image itemIcon = Resources.unknown512;
BundleDesign.toDrawOn.DrawImage(ImageUtilities.ResizeImage(itemIcon, 110, 110), new Point(2300, BundleDesign.theY + 6));
}
drawIcon();
}
}
}
catch (JsonSerializationException) { }
catch (JsonSerializationException)
{
//do not crash when JsonSerialization does weird stuff
}
}
}
}
private static void drawIcon()
{
if (File.Exists(ItemIcon.ItemIconPath))
{
Image itemIcon;
using (var bmpTemp = new Bitmap(ItemIcon.ItemIconPath))
{
itemIcon = new Bitmap(bmpTemp);
}
BundleDesign.toDrawOn.DrawImage(ImageUtilities.ResizeImage(itemIcon, 110, 110), new Point(2300, BundleDesign.theY + 6));
}
else
{
Image itemIcon = Resources.unknown512;
BundleDesign.toDrawOn.DrawImage(ImageUtilities.ResizeImage(itemIcon, 110, 110), new Point(2300, BundleDesign.theY + 6));
}
}
private static void drawBattleStar(string quantity)
{
Image rewardIcon = Resources.T_FNBR_BattlePoints_L;

View File

@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace FModel
{
class DLLImport
{
/// <summary>
/// used to check if internet is turned on or off
/// </summary>
/// <param name="description"></param>
/// <param name="reservedValue"></param>
/// <returns> boolean about the internet </returns>
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState(out int description, int reservedValue);
public static bool IsInternetAvailable()
{
return InternetGetConnectedState(description: out _, reservedValue: 0);
}
/// <summary>
/// used to set the theme on the TreeView
/// </summary>
/// <param name="hwnd"></param>
/// <param name="pszSubAppName"></param>
/// <param name="pszSubIdList"></param>
[DllImport("uxtheme.dll", ExactSpelling = true, CharSet = CharSet.Unicode)]
private static extern int SetWindowTheme(IntPtr hwnd, string pszSubAppName, string pszSubIdList);
public static void SetTreeViewTheme(IntPtr treeHandle)
{
SetWindowTheme(treeHandle, "explorer", null);
}
}
}

View File

@@ -264,9 +264,13 @@ namespace FModel
{
string ammoFilePath;
if (ThePak.CurrentUsedPakGuid != null && ThePak.CurrentUsedPakGuid != "0-0-0-0")
{
ammoFilePath = JohnWick.ExtractAsset(ThePak.CurrentUsedPak, ammoFile.Substring(ammoFile.LastIndexOf('.') + 1));
}
else
{
ammoFilePath = JohnWick.ExtractAsset(ThePak.AllpaksDictionary[ammoFile.Substring(ammoFile.LastIndexOf('.') + 1)], ammoFile.Substring(ammoFile.LastIndexOf('.') + 1));
}
if (ammoFilePath != null)
{
@@ -300,7 +304,10 @@ namespace FModel
}
}
}
catch (JsonSerializationException) { }
catch (JsonSerializationException)
{
//do not crash when JsonSerialization does weird stuff
}
}
}
}

View File

@@ -0,0 +1,117 @@
using FModel.Properties;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Globalization;
using System.Windows.Forms;
namespace FModel
{
class ImagesMerger
{
/// <summary>
/// open a FileDialog to choose our images to merge, add them to the list of images
/// use this list to merge, with MergeSelected()
/// </summary>
public static void AskMergeImages()
{
if (string.IsNullOrEmpty(Settings.Default.mergerFileName))
{
Settings.Default.mergerFileName = "Merger";
Settings.Default.Save();
}
OpenFileDialog theDialog = new OpenFileDialog();
theDialog.Multiselect = true;
theDialog.InitialDirectory = App.DefaultOutputPath + "\\Icons\\";
theDialog.Title = @"Choose your images";
theDialog.Filter = @"PNG Files (*.png)|*.png|JPEG Files (*.jpg)|*.jpg|BMP Files (*.bmp)|*.bmp|All Files (*.*)|*.*";
if (theDialog.ShowDialog() == DialogResult.OK)
{
List<Image> selectedImages = new List<Image>();
foreach (var files in theDialog.FileNames)
{
selectedImages.Add(Image.FromFile(files));
}
MergeSelected(selectedImages);
}
}
/// <summary>
/// take all the selected images and draw them one after the other depending on mergerImagesRow
/// at the end, save and open the generated image with OpenMerged()
/// </summary>
/// <param name="mySelectedImages"></param>
private static void MergeSelected(List<Image> mySelectedImages)
{
if (Settings.Default.mergerImagesRow == 0)
{
Settings.Default.mergerImagesRow = 7;
Settings.Default.Save();
}
int numperrow = Settings.Default.mergerImagesRow;
var w = 530 * numperrow;
if (mySelectedImages.Count * 530 < 530 * numperrow)
{
w = mySelectedImages.Count * 530;
}
int h = int.Parse(Math.Ceiling(double.Parse(mySelectedImages.Count.ToString()) / numperrow).ToString(CultureInfo.InvariantCulture)) * 530;
Bitmap bmp = new Bitmap(w - 8, h - 8);
var num = 1;
var curW = 0;
var curH = 0;
for (int i = 0; i < mySelectedImages.Count; i++)
{
using (Graphics g = Graphics.FromImage(bmp))
{
g.DrawImage(ImageUtilities.ResizeImage(mySelectedImages[i], 522, 522), new PointF(curW, curH));
if (num % numperrow == 0)
{
curW = 0;
curH += 530;
num += 1;
}
else
{
curW += 530;
num += 1;
}
}
}
bmp.Save(App.DefaultOutputPath + "\\" + Settings.Default.mergerFileName + ".png", ImageFormat.Png);
OpenMerged(bmp);
}
/// <summary>
/// if bitmap exist, open a new form in fullscreen and display the bitmap in a picturebox
/// </summary>
/// <param name="mergedImage"></param>
private static void OpenMerged(Bitmap mergedImage)
{
if (mergedImage != null)
{
var newForm = new Form();
PictureBox pb = new PictureBox();
pb.Dock = DockStyle.Fill;
pb.Image = mergedImage;
pb.SizeMode = PictureBoxSizeMode.Zoom;
newForm.WindowState = FormWindowState.Maximized;
newForm.Size = mergedImage.Size;
newForm.Icon = Resources.FModel;
newForm.Text = App.DefaultOutputPath + @"\" + Settings.Default.mergerFileName + @".png";
newForm.StartPosition = FormStartPosition.CenterScreen;
newForm.Controls.Add(pb);
newForm.Show();
}
}
}
}

View File

@@ -161,7 +161,10 @@ namespace FModel
}
}
}
catch (JsonSerializationException) { }
catch (JsonSerializationException)
{
//do not crash when JsonSerialization does weird stuff
}
}
return TexturePath;
}