Skip to content

Commit

Permalink
Merge branch 'patch-1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Triky313 committed Feb 2, 2020
2 parents 8af42e9 + 13e47a3 commit efe6168
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 179 deletions.
4 changes: 2 additions & 2 deletions StatisticsAnalysisTool/StatisticsAnalysisTool/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<fa:ImageAwesome x:Name="FaLoadIcon" Visibility="Hidden" Icon="CircleOutlineNotch" Spin="True" SpinDuration="4" Foreground="{StaticResource SolidColorBrush.Foreground.First}" />
</Grid>
</Grid>
<Grid x:Name="GridNormalMode" Margin="0,80,0,0" Visibility="Hidden">
<Grid x:Name="GridNormalMode" Margin="0,80,0,0" Visibility="Visible">
<TextBox x:Name="TxtSearch" HorizontalAlignment="Left" Height="23" Margin="10,10,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="299" KeyUp="TxtSearch_KeyUp"/>
<Label x:Name="LblItemCounter" Content="0/0" Height="26" Margin="0,6,10,0" VerticalAlignment="Top" Foreground="{StaticResource SolidColorBrush.Foreground.First}" HorizontalContentAlignment="Right" HorizontalAlignment="Right" Width="110" />

Expand Down Expand Up @@ -68,7 +68,7 @@
(<Hyperlink NavigateUri="{Binding Path=DonateUrl}" RequestNavigate="Hyperlink_RequestNavigate"><TextBlock Foreground="{StaticResource SolidColorBrush.Hyperlink.First}" Text="Donate" /></Hyperlink>)</TextBlock>
</Grid>
</Grid>
<Grid x:Name="GridPlayerMode" Margin="0,80,0,0" Visibility="Visible">
<Grid x:Name="GridPlayerMode" Margin="0,80,0,0" Visibility="Hidden">
<TextBox x:Name="TxtBoxPlayerModeUsername" Text="{Binding Path=SavedPlayerInformationName, ElementName=window}" HorizontalAlignment="Left" Height="25" Margin="10,10,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="200" KeyDown="TxtBoxPlayerModeUsername_KeyDown"/>
<Button x:Name="BtnPlayerModeSave" Content="{Binding Path=SaveTranslation}" Style="{StaticResource ButtonStyle}" HorizontalAlignment="Left" Margin="215,10,0,0" VerticalAlignment="Top" Width="110" Height="25" Click="BtnPlayerModeSave_Click"/>
<ScrollViewer Margin="0,40,0,20" HorizontalScrollBarVisibility="Disabled">
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,145 +1,144 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using StatisticsAnalysisTool.Common;
using StatisticsAnalysisTool.Models;
using StatisticsAnalysisTool.Properties;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace StatisticsAnalysisTool
{
public class StatisticsAnalysisManager
{
// Info Link -> https://github.com/broderickhyman/ao-bin-dumps
// Models: https://github.com/broderickhyman/albiondata-models-dotNet

public static List<Item> Items;

private static bool GetItemListSourceUrlIfExist(ref string url)
{
if (string.IsNullOrEmpty(Settings.Default.CurrentItemListSourceUrl))
{
url = Settings.Default.DefaultItemListSourceUrl;
if (string.IsNullOrEmpty(url))
return false;

Settings.Default.CurrentItemListSourceUrl = Settings.Default.DefaultItemListSourceUrl;
MessageBox.Show(LanguageController.Translation("DEFAULT_ITEMLIST_HAS_BEEN_LOADED"), LanguageController.Translation("NOTE"));
}
return true;
}

private static async Task<List<Item>> TryToGetItemListFromWeb(string url)
{
using (var wd = new WebDownload(30000))
{
try
{
var itemsString = await wd.DownloadStringTaskAsync(url);
File.WriteAllText($"{AppDomain.CurrentDomain.BaseDirectory}{Settings.Default.ItemListFileName}", itemsString, Encoding.UTF8);
return JsonConvert.DeserializeObject<List<Item>>(itemsString);
}
catch (Exception)
{
try
{
var itemsString = await wd.DownloadStringTaskAsync(Settings.Default.DefaultItemListSourceUrl);
File.WriteAllText($"{AppDomain.CurrentDomain.BaseDirectory}{Settings.Default.ItemListFileName}", itemsString, Encoding.UTF8);
return JsonConvert.DeserializeObject<List<Item>>(itemsString);
}
catch
{
return null;
}
}
}
}

private static List<Item> GetItemListFromLocal()
{
try
{
var localItemString = File.ReadAllText($"{AppDomain.CurrentDomain.BaseDirectory}{Settings.Default.ItemListFileName}");
return JsonConvert.DeserializeObject<List<Item>>(localItemString);
}
catch
{
return null;
}
}

public static async Task<bool> GetItemListFromJsonAsync()
{
var url = Settings.Default.CurrentItemListSourceUrl;
if (!GetItemListSourceUrlIfExist(ref url))
return false;

if (File.Exists($"{AppDomain.CurrentDomain.BaseDirectory}{Settings.Default.ItemListFileName}"))
{
var fileDateTime = File.GetLastWriteTime($"{AppDomain.CurrentDomain.BaseDirectory}{Settings.Default.ItemListFileName}");

if (fileDateTime.AddDays(7) < DateTime.Now)
{
Items = await TryToGetItemListFromWeb(url);
return (Items != null);
}

Items = GetItemListFromLocal();
return (Items != null);
}

Items = await TryToGetItemListFromWeb(url);
return (Items != null);
}

public static async Task<List<Item>> FindItemsAsync(string searchText)
{
return await Task.Run(() =>
{
try
{
return Items?.FindAll(s => (s.LocalizedName().ToLower().Contains(searchText.ToLower())));
}
catch (Exception ex)
{
Debug.Print(ex.Message);
return null;
}
});
}

public static FrequentlyValues.ItemTier GetItemTier(string uniqueName) => FrequentlyValues.ItemTiers.FirstOrDefault(x => x.Value == uniqueName.Split('_')[0]).Key;

public static FrequentlyValues.ItemLevel GetItemLevel(string uniqueName)
{
if (!uniqueName.Contains("@"))
return FrequentlyValues.ItemLevel.Level0;

if(int.TryParse(uniqueName.Split('@')[1], out int number))
return FrequentlyValues.ItemLevels.First(x => x.Value == number).Key;
return FrequentlyValues.ItemLevel.Level0;
}

public static int GetQuality(FrequentlyValues.ItemQuality value) => FrequentlyValues.ItemQualities.FirstOrDefault(x => x.Key == value).Value;

public static FrequentlyValues.ItemQuality GetQuality(int value) => FrequentlyValues.ItemQualities.FirstOrDefault(x => x.Value == value).Key;

public static void AddLocalizedName(ref ItemData itemData, JObject parsedObject)
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using StatisticsAnalysisTool.Common;
using StatisticsAnalysisTool.Models;
using StatisticsAnalysisTool.Properties;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace StatisticsAnalysisTool
{
public class StatisticsAnalysisManager
{
// Info Link -> https://github.com/broderickhyman/ao-bin-dumps
// Models: https://github.com/broderickhyman/albiondata-models-dotNet

public static List<Item> Items;

private static bool GetItemListSourceUrlIfExist(ref string url)
{
foreach (var language in Enum.GetValues(typeof(FrequentlyValues.GameLanguage)).Cast<FrequentlyValues.GameLanguage>())
{
var cultureCode = FrequentlyValues.GameLanguages.FirstOrDefault(x => x.Key == language).Value;

if (parsedObject["localizedNames"]?[cultureCode] != null)
itemData.LocalizedNames.Add(new ItemData.KeyValueStruct() { Key = cultureCode, Value = parsedObject["localizedNames"][cultureCode].ToString() });
}
}

}
}
if (string.IsNullOrEmpty(Settings.Default.CurrentItemListSourceUrl))
{
url = Settings.Default.DefaultItemListSourceUrl;
if (string.IsNullOrEmpty(url))
return false;

Settings.Default.CurrentItemListSourceUrl = Settings.Default.DefaultItemListSourceUrl;
MessageBox.Show(LanguageController.Translation("DEFAULT_ITEMLIST_HAS_BEEN_LOADED"), LanguageController.Translation("NOTE"));
}
return true;
}

private static async Task<List<Item>> TryToGetItemListFromWeb(string url)
{
using (var wd = new WebDownload(30000))
{
try
{
var itemsString = await wd.DownloadStringTaskAsync(url);
File.WriteAllText($"{AppDomain.CurrentDomain.BaseDirectory}{Settings.Default.ItemListFileName}", itemsString, Encoding.UTF8);
return JsonConvert.DeserializeObject<List<Item>>(itemsString);
}
catch (Exception)
{
try
{
var itemsString = await wd.DownloadStringTaskAsync(Settings.Default.DefaultItemListSourceUrl);
File.WriteAllText($"{AppDomain.CurrentDomain.BaseDirectory}{Settings.Default.ItemListFileName}", itemsString, Encoding.UTF8);
return JsonConvert.DeserializeObject<List<Item>>(itemsString);
}
catch
{
return null;
}
}
}
}

private static List<Item> GetItemListFromLocal()
{
try
{
var localItemString = File.ReadAllText($"{AppDomain.CurrentDomain.BaseDirectory}{Settings.Default.ItemListFileName}");
return JsonConvert.DeserializeObject<List<Item>>(localItemString);
}
catch
{
return null;
}
}

public static async Task<bool> GetItemListFromJsonAsync()
{
var url = Settings.Default.CurrentItemListSourceUrl;
if (!GetItemListSourceUrlIfExist(ref url))
return false;

if (File.Exists($"{AppDomain.CurrentDomain.BaseDirectory}{Settings.Default.ItemListFileName}"))
{
var fileDateTime = File.GetLastWriteTime($"{AppDomain.CurrentDomain.BaseDirectory}{Settings.Default.ItemListFileName}");

if (fileDateTime.AddDays(7) < DateTime.Now)
{
Items = await TryToGetItemListFromWeb(url);
return (Items != null);
}

Items = GetItemListFromLocal();
return (Items != null);
}

Items = await TryToGetItemListFromWeb(url);
return (Items != null);
}

public static async Task<List<Item>> FindItemsAsync(string searchText)
{
return await Task.Run(() =>
{
try
{
return Items?.FindAll(s => (s.LocalizedNameAndEnglish.ToLower().Contains(searchText.ToLower())));
}
catch (Exception ex)
{
Debug.Print(ex.Message);
return null;
}
});
}

public static FrequentlyValues.ItemTier GetItemTier(string uniqueName) => FrequentlyValues.ItemTiers.FirstOrDefault(x => x.Value == uniqueName.Split('_')[0]).Key;

public static FrequentlyValues.ItemLevel GetItemLevel(string uniqueName)
{
if (!uniqueName.Contains("@"))
return FrequentlyValues.ItemLevel.Level0;

if(int.TryParse(uniqueName.Split('@')[1], out int number))
return FrequentlyValues.ItemLevels.First(x => x.Value == number).Key;
return FrequentlyValues.ItemLevel.Level0;
}

public static int GetQuality(FrequentlyValues.ItemQuality value) => FrequentlyValues.ItemQualities.FirstOrDefault(x => x.Key == value).Value;

public static FrequentlyValues.ItemQuality GetQuality(int value) => FrequentlyValues.ItemQualities.FirstOrDefault(x => x.Value == value).Key;

public static void AddLocalizedName(ref ItemData itemData, JObject parsedObject)
{
foreach (var language in Enum.GetValues(typeof(FrequentlyValues.GameLanguage)).Cast<FrequentlyValues.GameLanguage>())
{
var cultureCode = FrequentlyValues.GameLanguages.FirstOrDefault(x => x.Key == language).Value;

if (parsedObject["localizedNames"]?[cultureCode] != null)
itemData.LocalizedNames.Add(new ItemData.KeyValueStruct() { Key = cultureCode, Value = parsedObject["localizedNames"][cultureCode].ToString() });
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@
<Compile Include="Models\Guild.cs" />
<Compile Include="Models\GameInfoPlayers.cs" />
<Compile Include="Models\SearchInfos.cs" />
<Compile Include="Models\ItemWithMarketInformation.cs" />
<Compile Include="Models\MarketOrder.cs" />
<Compile Include="Models\MarketStats.cs" />
<Compile Include="Properties\Resources.Designer.cs">
Expand Down

0 comments on commit efe6168

Please sign in to comment.