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

@@ -126,6 +126,8 @@
<Compile Include="Methods\ChallengeGenerator\BundleDesign.cs" />
<Compile Include="Methods\ChallengeGenerator\BundleInfos.cs" />
<Compile Include="Methods\ChallengeGenerator\DrawingRewards.cs" />
<Compile Include="Methods\DLLImport.cs" />
<Compile Include="Methods\ImagesMerger\ImagesMerger.cs" />
<Compile Include="Methods\Utilities\FontUtilities.cs" />
<Compile Include="Methods\IconGenerator\ItemIcon.cs" />
<Compile Include="Methods\IconGenerator\Rarity.cs" />

View File

@@ -6,21 +6,17 @@ using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing.Text;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Windows.Forms;
using AutoUpdaterDotNET;
using csharp_wick;
using FModel.Converter;
using FModel.Forms;
using FModel.Parser.Banners;
using FModel.Parser.Challenges;
using FModel.Methods.BackupPAKs.Parser.AESKeyParser;
using FModel.Parser.Items;
using FModel.Parser.Quests;
using FModel.Properties;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
@@ -38,29 +34,12 @@ namespace FModel
public Stopwatch StopWatch;
private static string[] _paksArray;
public static string[] PakAsTxt;
private static Dictionary<string, long> _questStageDict;
private static Dictionary<string, string> _diffToExtract;
private static string _backupFileName;
private static string[] _backupDynamicKeys;
private static List<string> _itemsToDisplay;
public static string ExtractedFilePath;
public static string[] SelectedItemsArray;
public static string[] SelectedChallengesArray;
#endregion
#region DLLIMPORT
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState(out int description, int reservedValue);
public static bool IsInternetAvailable()
{
return InternetGetConnectedState(description: out _, reservedValue: 0);
}
[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);
}
#endregion
public MainWindow()
@@ -190,7 +169,7 @@ namespace FModel
{
AutoUpdater.Start("https://dl.dropbox.com/s/3kv2pukqu6tj1r0/FModel.xml?dl=0");
SetTreeViewTheme(treeView1.Handle);
DLLImport.SetTreeViewTheme(treeView1.Handle);
_backupFileName = "\\FortniteGame_" + DateTime.Now.ToString("MMddyyyy") + ".txt";
// Copy user settings from previous application version if necessary
@@ -613,8 +592,7 @@ namespace FModel
{
_backupDynamicKeys = null;
bool connection = IsInternetAvailable();
if (connection && (!string.IsNullOrWhiteSpace(Settings.Default.eEmail) || !string.IsNullOrWhiteSpace(Settings.Default.ePassword)))
if (DLLImport.IsInternetAvailable() && (!string.IsNullOrWhiteSpace(Settings.Default.eEmail) || !string.IsNullOrWhiteSpace(Settings.Default.ePassword)))
{
string myContent = DynamicPAKs.GetEndpoint("https://fortnite-public-service-prod11.ol.epicgames.com/fortnite/api/storefront/v2/keychain", true);
@@ -715,7 +693,6 @@ namespace FModel
{
CreatePakList(null, false, true, true);
_questStageDict = new Dictionary<string, long>();
Invoke(new Action(() =>
{
ExtractButton.Enabled = false;
@@ -1726,7 +1703,6 @@ namespace FModel
{
scintilla1.Text = "";
pictureBox1.Image = null;
_questStageDict = new Dictionary<string, long>();
ExtractButton.Enabled = false;
OpenImageButton.Enabled = false;
StopButton.Enabled = true;
@@ -1750,104 +1726,6 @@ namespace FModel
#endregion
#region IMAGES SAVE & MERGE
//METHODS
private void AskMergeImages()
{
if (string.IsNullOrEmpty(Settings.Default.mergerFileName))
{
MessageBox.Show(@"Please, set a name to your Merger file before trying to merge images
Steps:
- Load
- Settings", @"Merger File Name Missing", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
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 (*.*)|*.*";
Invoke(new Action(() =>
{
if (theDialog.ShowDialog() == DialogResult.OK)
{
List<Image> selectedImages = new List<Image>();
foreach (var files in theDialog.FileNames)
{
selectedImages.Add(Image.FromFile(files));
}
MergeSelected(selectedImages);
}
}));
}
}
private 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);
}
private 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();
}
}
//EVENTS
private void OpenImageButton_Click(object sender, EventArgs e)
{
@@ -1885,11 +1763,9 @@ Steps:
}
}
}
private async void mergeImagesToolStripMenuItem_Click(object sender, EventArgs e)
private void mergeImagesToolStripMenuItem_Click(object sender, EventArgs e)
{
await Task.Run(() => {
AskMergeImages();
});
ImagesMerger.AskMergeImages();
}
#endregion
}

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;
}

View File

@@ -200,16 +200,6 @@ namespace FModel.Properties {
}
}
/// <summary>
/// Recherche une ressource localisée de type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap Quest {
get {
object obj = ResourceManager.GetObject("Quest", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Recherche une ressource localisée de type System.Drawing.Bitmap.
/// </summary>

View File

@@ -169,9 +169,6 @@
<data name="FModel_Logo" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\FModel_Logo.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="Quest" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Quest.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="T_Icon_Adaptive_64" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\T-Icon-Adaptive-64.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>

View File

@@ -28,7 +28,7 @@
- Asset is a **_Sound_**:
- Try to convert the Asset to OGG and play the sound
- Asset is a **_Bundle Of Challenges_**:
- Try to create an [Icon](https://i.imgur.com/1Uzrlb0.png) with all **Challenges' Description**, **Count** and the **Reward**
- Try to create an [Icon](https://i.imgur.com/pUVxUih.png) with all **Challenges' Description**, **Count** and the **Reward**
- Asset is a **_Font_**:
- Try to convert the Asset to OTF