forked from phiDelPark/PoeTradeSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WinSetting.xaml.cs
141 lines (118 loc) · 5.89 KB
/
WinSetting.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace PoeTradeSearch
{
/// <summary>
/// WinSetting.xaml에 대한 상호 작용 논리
/// </summary>
public partial class WinSetting : Window
{
FilterData mLeagues = null;
public WinSetting()
{
//TODO 페이지로... 근데 언제하냐? 귀찮...
InitializeComponent();
WinMain winMain = (WinMain)Application.Current.MainWindow;
Thread thread = new Thread(() =>
{
string json = winMain.SendHTTP(null, RS.LeaguesApi, 5);
if ((json ?? "") != "")
{
mLeagues = Json.Deserialize<FilterData>(json);
}
});
thread.Start();
thread.Join();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
WinMain winMain = (WinMain)Application.Current.MainWindow;
cbLeague.Items.Clear();
if (mLeagues?.Result.Length > 0)
{
foreach (FilterDict item in mLeagues.Result)
{
cbLeague.Items.Add(item.Id);
}
}
lbDbVersion.Content = "버전: " + Application.Current.Properties["FileVersion"] + "\n" + winMain.mFilter[0].Update;
cbLeague.SelectedItem = winMain.mConfig.Options.League ?? "";
if (cbLeague.SelectedIndex == -1)
{
cbLeague.Items.Add(winMain.mConfig.Options.League ?? "");
cbLeague.SelectedIndex = cbLeague.Items.Count - 1;
}
cbServerType.SelectedIndex = winMain.mConfig.Options.ServerType;
cbSearchAutoDelay.SelectedIndex = Math.Abs(winMain.mConfig.Options.SearchAutoDelay / 30);
cbSearchBeforeDay.SelectedIndex = Math.Abs(winMain.mConfig.Options.SearchBeforeDay / 7);
cbSearchListCount.SelectedIndex = Math.Abs((winMain.mConfig.Options.SearchListCount / 20) - 1);
ckAutoCheckUnique.IsChecked = winMain.mConfig.Options.AutoCheckUnique == true;
ckAutoSelectPseudo.IsChecked = winMain.mConfig.Options.AutoSelectPseudo == true;
ckAutoCheckTotalres.IsChecked = winMain.mConfig.Options.AutoCheckTotalres == true;
ckAutoCheckUpdates.IsChecked = winMain.mConfig.Options.AutoCheckUpdates == true;
ckUseCtrlWheel.IsChecked = winMain.mConfig.Options.UseCtrlWheel == true;
for (int i = 0; i < winMain.mConfig.Shortcuts.Length; i++)
{
if (i == 12) break;
ConfigShortcut shortcut = winMain.mConfig.Shortcuts[i];
HotkeyBox.keyBinding hotkey = new HotkeyBox.keyBinding(
KeyInterop.KeyFromVirtualKey(shortcut.Keycode), (ModifierKeys)shortcut.Modifiers
);
((HotkeyBox)FindName("Hotkey" + (i + 1))).Hotkey = hotkey;
((TextBox)FindName("HotkeyValue" + (i + 1))).Text = shortcut.Value;
}
lbChecked.ItemsSource = winMain.mChecked.Entries;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
WinMain winMain = (WinMain)Application.Current.MainWindow;
winMain.mConfig.Options.League = (string)cbLeague.SelectedItem;
winMain.mConfig.Options.ServerType = cbServerType.SelectedIndex;
winMain.mConfig.Options.SearchAutoDelay = cbSearchAutoDelay.SelectedIndex * 30;
winMain.mConfig.Options.SearchBeforeDay = cbSearchBeforeDay.SelectedIndex * 7;
winMain.mConfig.Options.SearchListCount = (cbSearchListCount.SelectedIndex + 1) * 20;
winMain.mConfig.Options.AutoCheckUnique = ckAutoCheckUnique.IsChecked == true;
winMain.mConfig.Options.AutoSelectPseudo = ckAutoSelectPseudo.IsChecked == true;
winMain.mConfig.Options.AutoCheckTotalres = ckAutoCheckTotalres.IsChecked == true;
winMain.mConfig.Options.AutoCheckUpdates = ckAutoCheckUpdates.IsChecked == true;
winMain.mConfig.Options.UseCtrlWheel = ckUseCtrlWheel.IsChecked == true;
winMain.mConfig.Shortcuts = new ConfigShortcut[12];
for (int i = 0; i < 12; i++)
{
winMain.mConfig.Shortcuts[i] = new ConfigShortcut();
HotkeyBox.keyBinding hotkey = ((HotkeyBox)FindName("Hotkey" + (i + 1))).Hotkey;
string value = ((TextBox)FindName("HotkeyValue" + (i + 1))).Text;
winMain.mConfig.Shortcuts[i].Keycode = (int)KeyInterop.VirtualKeyFromKey(hotkey?.Key ?? 0);
winMain.mConfig.Shortcuts[i].Modifiers = (int)(hotkey?.Modifiers ?? 0);
winMain.mConfig.Shortcuts[i].Value = value;
}
string path = (string)Application.Current.Properties["DataPath"];
using (StreamWriter writer = new StreamWriter(path + "Config.txt", false, Encoding.UTF8))
{
writer.Write(Json.Serialize<ConfigData>(winMain.mConfig, true));
writer.Close();
}
// 설정이 바뀌면 재시작
Process.Start(new ProcessStartInfo(Assembly.GetExecutingAssembly().Location)
{
Arguments = "/wait_shutdown"
});
Application.Current.Shutdown();
}
private void btUpdateDB_Click(object sender, RoutedEventArgs e)
{
string path = (string)Application.Current.Properties["DataPath"];
File.Delete(path + "FiltersKO.txt");
File.Delete(path + "FiltersEN.txt");
lbDbVersion.Content = "버전: " + Application.Current.Properties["FileVersion"] + "\n" + "확인 또는 재실행시 적용됨";
btUpdateDB.IsEnabled = false;
}
}
}