forked from MontagueM/Phonon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
APIView.xaml.cs
110 lines (104 loc) · 3.62 KB
/
APIView.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
using Newtonsoft.Json;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Phonon
{
/// <summary>
/// Interaction logic for APIView.xaml
/// </summary>
public partial class APIView : UserControl
{
Dictionary<string, Item> ItemsDict = new Dictionary<string, Item>();
private MainWindow mainWindow = null;
public APIView()
{
InitializeComponent();
CacheAllItems();
RefreshItemList();
}
private void OnControlLoaded(object sender, RoutedEventArgs e)
{
mainWindow = Window.GetWindow(this) as MainWindow;
}
private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
{
RefreshItemList();
}
private void RefreshItemList()
{
List<Item> items = new List<Item>();
string SearchStr = textBox.Text.ToLower();
if (SearchStr != "")
{
// Select and sort by relevance to selected string
Parallel.ForEach(ItemsDict.Keys, Name =>
{
if (items.Count > 30) return;
if (Name.Contains(SearchStr))
{
items.Add(ItemsDict[Name]);
}
});
}
ListViewAPI.ItemsSource = items;
}
private void ExtractGearBtn_Click(object sender, RoutedEventArgs e)
{
using (var dialog = new System.Windows.Forms.FolderBrowserDialog())
{
System.Windows.Forms.DialogResult result = dialog.ShowDialog();
if (dialog.SelectedPath == "")
{
return;
}
mainWindow.ExportSettings.Path = dialog.SelectedPath;
}
mainWindow.ExportSettings.SaveName = ((sender as Button).DataContext as Item).Name.Split("|")[0].Trim();
List<string> Models = ((sender as Button).DataContext as Item).Models;
//Parallel.ForEach(Models, ModelHash =>
foreach (string ModelHash in Models)
{
mainWindow.ExportSettings.Hash = ModelHash;
mainWindow.ExportSettings.Export(GetPackagesPath());
}//);
System.Windows.MessageBox.Show("Export success");
var a = 0;
}
public string GetPackagesPath()
{
Configuration config = ConfigurationManager.OpenExeConfiguration(System.Windows.Forms.Application.ExecutablePath);
if (config.AppSettings.Settings["PackagesPathD1"] == null)
{
System.Windows.MessageBox.Show($"No package path found for Destiny 1.");
return "";
}
return config.AppSettings.Settings["PackagesPathD1"].Value.ToString();
}
private void CacheAllItems()
{
ItemsDict = JsonConvert.DeserializeObject<Dictionary<string, Item>>(File.ReadAllText("APIGear.json"));
}
}
public class Item
{
public uint Hash { get; set; }
public int Index { get; set; }
public List<string> Models { get; set; }
public string Name { get; set; }
}
}