Skip to content

Commit b691c51

Browse files
committed
Fetch the list of stash tabs directly from GGG
And remove all the logic to use multiple tabs, instead just assume the one selected tab is all that is needed.
1 parent 65df098 commit b691c51

File tree

13 files changed

+444
-666
lines changed

13 files changed

+444
-666
lines changed

EnhancePoE/App.config

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,6 @@
8282
<setting name="ColorAmulet" serializeAs="String">
8383
<value>#FFFF0303</value>
8484
</setting>
85-
<setting name="StashtabMode" serializeAs="String">
86-
<value>0</value>
87-
</setting>
88-
<setting name="StashTabName" serializeAs="String">
89-
<value />
90-
</setting>
91-
<setting name="StashTabIndices" serializeAs="String">
92-
<value />
93-
</setting>
9485
<setting name="TabHeaderWidth" serializeAs="String">
9586
<value>20.4</value>
9687
</setting>
@@ -124,6 +115,9 @@
124115
<setting name="LockOverlayPosition" serializeAs="String">
125116
<value>False</value>
126117
</setting>
118+
<setting name="SelectedStashTabName" serializeAs="String">
119+
<value />
120+
</setting>
127121
</EnhancePoE.Properties.Settings>
128122
</userSettings>
129123
<runtime>

EnhancePoE/App.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Application x:Class="EnhancePoE.App"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4-
StartupUri="View/MainWindow.xaml">
4+
Startup="OnStartup">
55
<Application.Resources>
66
<FontFamily x:Key="PasswordFont">pack://application:,,,/Assets/#password</FontFamily>
77
</Application.Resources>

EnhancePoE/App.xaml.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,7 @@ private void ShowUnhandledException( Exception e, string unhandledExceptionType,
5656
Current.Shutdown();
5757
}
5858
}
59+
60+
private void OnStartup( object sender, StartupEventArgs e ) => EnhancePoE.MainWindow.Instance.Show();
5961
}
6062
}

EnhancePoE/Model/ApiAdapter.cs

Lines changed: 41 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ public static class ApiAdapter
1818
private static StashTabPropsList PropsList { get; set; }
1919
public static bool FetchError { get; set; }
2020
public static bool FetchingDone { get; set; }
21+
22+
public static List<StashTab> StashTabList { get; private set; }
23+
2124
public static async Task<bool> GenerateUri()
2225
{
2326
FetchError = false;
@@ -31,7 +34,7 @@ public static async Task<bool> GenerateUri()
3134

3235
if ( await GetProps( accName, league ) && !FetchError )
3336
{
34-
GenerateStashTabs();
37+
StashTabList = PropsList.tabs.ConvertAll( x => new StashTab( x.n, x.i ) );
3538
GenerateStashtabUris( accName, league );
3639
return true;
3740
}
@@ -44,70 +47,16 @@ public static async Task<bool> GenerateUri()
4447
return false;
4548
}
4649

47-
private static void GenerateStashTabs()
48-
{
49-
var ret = new List<StashTab>();
50-
51-
// mode = ID
52-
if ( Properties.Settings.Default.StashtabMode == 0 )
53-
{
54-
StashTabList.GetStashTabIndices();
55-
if ( PropsList != null )
56-
{
57-
foreach ( var p in PropsList.tabs )
58-
{
59-
for ( int i = StashTabList.StashTabIndices.Count - 1; i > -1; i-- )
60-
{
61-
if ( StashTabList.StashTabIndices[i] == p.i )
62-
{
63-
StashTabList.StashTabIndices.RemoveAt( i );
64-
ret.Add( new StashTab( p.n, p.i ) );
65-
}
66-
}
67-
}
68-
StashTabList.StashTabs = ret;
69-
GetAllTabNames();
70-
}
71-
}
72-
// mode = Name
73-
else
74-
{
75-
if ( PropsList != null )
76-
{
77-
string stashName = Properties.Settings.Default.StashTabName;
78-
foreach ( var p in PropsList.tabs )
79-
{
80-
if ( p.n.StartsWith( stashName ) )
81-
{
82-
ret.Add( new StashTab( p.n, p.i ) );
83-
}
84-
}
85-
StashTabList.StashTabs = ret;
86-
}
87-
}
88-
Trace.WriteLine( StashTabList.StashTabs.Count, "stash tab count" );
89-
}
90-
9150
private static void GenerateStashtabUris( string accName, string league )
9251
{
93-
foreach ( var i in StashTabList.StashTabs )
52+
if ( StashTabList is null )
9453
{
95-
string stashTab = i.TabIndex.ToString();
96-
i.StashTabUri = new Uri( $"https://www.pathofexile.com/character-window/get-stash-items?accountName={accName}&tabIndex={stashTab}&league={league}" );
54+
return;
9755
}
98-
}
9956

100-
private static void GetAllTabNames()
101-
{
102-
foreach ( var s in StashTabList.StashTabs )
57+
for ( int i = 0; i < StashTabList.Count; i++ )
10358
{
104-
foreach ( var p in PropsList.tabs )
105-
{
106-
if ( s.TabIndex == p.i )
107-
{
108-
s.TabName = p.n;
109-
}
110-
}
59+
StashTabList[i].StashTabUri = new Uri( $"https://www.pathofexile.com/character-window/get-stash-items?accountName={accName}&tabIndex={i}&league={league}" );
11160
}
11261
}
11362

@@ -193,7 +142,7 @@ public static async Task<bool> GetItems()
193142
return false;
194143
}
195144
// check rate limit
196-
if ( RateLimit.RateLimitState[0] >= RateLimit.MaximumRequests - StashTabList.StashTabs.Count - 4 )
145+
if ( RateLimit.RateLimitState[0] >= RateLimit.MaximumRequests - 5 )
197146
{
198147
RateLimit.RateLimitExceeded = true;
199148
return false;
@@ -209,42 +158,42 @@ public static async Task<bool> GetItems()
209158
{
210159
// add user agent
211160
client.DefaultRequestHeaders.Add( "User-Agent", $"EnhancePoEApp/v{Assembly.GetExecutingAssembly().GetName().Version}" );
212-
foreach ( var i in StashTabList.StashTabs )
161+
162+
// check rate limit ban
163+
if ( RateLimit.CheckForBan() )
213164
{
214-
// check rate limit ban
215-
if ( RateLimit.CheckForBan() )
165+
return false;
166+
}
167+
168+
var stashTab = MainWindow.Instance.SelectedStashTab;
169+
if ( !usedUris.Contains( stashTab.StashTabUri ) )
170+
{
171+
cookieContainer.Add( stashTab.StashTabUri, new Cookie( "POESESSID", sessionId ) );
172+
using var res = await client.GetAsync( stashTab.StashTabUri );
173+
usedUris.Add( stashTab.StashTabUri );
174+
if ( res.IsSuccessStatusCode )
216175
{
217-
return false;
176+
using var content = res.Content;
177+
// get new rate limit values
178+
string rateLimit = res.Headers.GetValues( "X-Rate-Limit-Account" ).FirstOrDefault();
179+
string rateLimitState = res.Headers.GetValues( "X-Rate-Limit-Account-State" ).FirstOrDefault();
180+
string responseTime = res.Headers.GetValues( "Date" ).FirstOrDefault();
181+
RateLimit.DeserializeRateLimits( rateLimit, rateLimitState );
182+
RateLimit.DeserializeResponseSeconds( responseTime );
183+
184+
// deserialize response
185+
string resContent = await content.ReadAsStringAsync();
186+
var deserializedContent = JsonSerializer.Deserialize<ItemList>( resContent );
187+
stashTab.ItemList = deserializedContent.items;
188+
stashTab.Quad = deserializedContent.quadLayout;
189+
190+
stashTab.CleanItemList();
218191
}
219-
if ( !usedUris.Contains( i.StashTabUri ) )
192+
else
220193
{
221-
cookieContainer.Add( i.StashTabUri, new Cookie( "POESESSID", sessionId ) );
222-
using var res = await client.GetAsync( i.StashTabUri );
223-
usedUris.Add( i.StashTabUri );
224-
if ( res.IsSuccessStatusCode )
225-
{
226-
using var content = res.Content;
227-
// get new rate limit values
228-
string rateLimit = res.Headers.GetValues( "X-Rate-Limit-Account" ).FirstOrDefault();
229-
string rateLimitState = res.Headers.GetValues( "X-Rate-Limit-Account-State" ).FirstOrDefault();
230-
string responseTime = res.Headers.GetValues( "Date" ).FirstOrDefault();
231-
RateLimit.DeserializeRateLimits( rateLimit, rateLimitState );
232-
RateLimit.DeserializeResponseSeconds( responseTime );
233-
234-
// deserialize response
235-
string resContent = await content.ReadAsStringAsync();
236-
var deserializedContent = JsonSerializer.Deserialize<ItemList>( resContent );
237-
i.ItemList = deserializedContent.items;
238-
i.Quad = deserializedContent.quadLayout;
239-
240-
i.CleanItemList();
241-
}
242-
else
243-
{
244-
FetchError = true;
245-
_ = MessageBox.Show( res.ReasonPhrase, "Error fetching data", MessageBoxButton.OK, MessageBoxImage.Error );
246-
return false;
247-
}
194+
FetchError = true;
195+
_ = MessageBox.Show( res.ReasonPhrase, "Error fetching data", MessageBoxButton.OK, MessageBoxImage.Error );
196+
return false;
248197
}
249198
}
250199
}

EnhancePoE/Model/Coordinates.cs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ private static System.Windows.Point GetEditButtonCoordinates( System.Windows.Con
7676
return button != null ? button.PointToScreen( new System.Windows.Point( 0, 0 ) ) : new System.Windows.Point( 0, 0 );
7777
}
7878

79-
private static List<Cell> GetAllActiveCells( int index )
79+
private static List<Cell> GetAllActiveCells()
8080
{
8181
var activeCells = new List<Cell>();
82-
foreach ( var cell in StashTabList.StashTabs[index].OverlayCellsList )
82+
foreach ( var cell in MainWindow.Instance.SelectedStashTab.OverlayCellsList )
8383
{
8484
if ( cell.Active )
8585
{
@@ -96,11 +96,10 @@ private static void OverlayClickEvent()
9696
{
9797
if ( MainWindow.StashTabOverlay.IsOpen )
9898
{
99-
int selectedIndex = MainWindow.StashTabOverlay.StashTabOverlayTabControl.SelectedIndex;
10099
bool isHit = false;
101100
int hitIndex = -1;
102101

103-
var activeCells = GetAllActiveCells( selectedIndex );
102+
var activeCells = GetAllActiveCells();
104103

105104
var buttonList = new List<ButtonAndCell>();
106105

@@ -109,7 +108,7 @@ private static void OverlayClickEvent()
109108
MainWindow.StashTabOverlay.HandleEditButton();
110109
}
111110

112-
if ( StashTabList.StashTabs[selectedIndex].Quad )
111+
if ( MainWindow.Instance.SelectedStashTab.Quad )
113112
{
114113
var ctrl = MainWindow.StashTabOverlay.StashTabOverlayTabControl.SelectedContent as UserControls.DynamicGridControlQuad;
115114
foreach ( var cell in activeCells )
@@ -134,12 +133,9 @@ private static void OverlayClickEvent()
134133
Data.ActivateNextCell( true, buttonList[hitIndex].Cell );
135134
}
136135

137-
for ( int stash = 0; stash < StashTabList.StashTabs.Count; stash++ )
136+
if ( CheckForHeaderHit( MainWindow.Instance.SelectedStashTab ) )
138137
{
139-
if ( CheckForHeaderHit( StashTabList.StashTabs[stash] ) )
140-
{
141-
MainWindow.StashTabOverlay.StashTabOverlayTabControl.SelectedIndex = stash;
142-
}
138+
MainWindow.StashTabOverlay.StashTabOverlayTabControl.SelectedIndex = 0;
143139
}
144140
}
145141
else
@@ -166,12 +162,9 @@ private static void OverlayClickEvent()
166162
{
167163
Data.ActivateNextCell( true, buttonList[hitIndex].Cell );
168164
}
169-
for ( int stash = 0; stash < StashTabList.StashTabs.Count; stash++ )
165+
if ( CheckForHeaderHit( MainWindow.Instance.SelectedStashTab ) )
170166
{
171-
if ( CheckForHeaderHit( StashTabList.StashTabs[stash] ) )
172-
{
173-
MainWindow.StashTabOverlay.StashTabOverlayTabControl.SelectedIndex = stash;
174-
}
167+
MainWindow.StashTabOverlay.StashTabOverlayTabControl.SelectedIndex = 0;
175168
}
176169
}
177170
}

0 commit comments

Comments
 (0)