Skip to content

Commit 0bb9420

Browse files
committed
Fix an issue where widgets wouldn't load with "UNAUTHORIZED" or "Missing UniGetUI" messages (fix marticliment/UniGetUI#3440, fix marticliment/UniGetUI#3379)
1 parent b89aad7 commit 0bb9420

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

src/Package/Package.appxmanifest

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<Identity
1414
Name="9932MartCliment.WingetUIWidgets"
1515
Publisher="CN=7054F010-7BE3-4163-B64E-D51DF58CF867"
16-
Version="0.9.0.0" />
16+
Version="0.9.1.0" />
1717

1818
<Properties>
1919
<DisplayName>Widgets for UniGetUI</DisplayName>

src/Widgets/WingetUIConnector.cs

+23-12
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,32 @@ async public void GetAvailableUpdates(GenericWidget Widget, bool DeepCheck = fal
7979

8080
new Template_LoadingPage(Widget).UpdateWidget();
8181

82-
string old_path = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".wingetui", "CurrentSessionToken");
83-
string new_path = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "UniGetUI", "CurrentSessionToken");
82+
string path_1 = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".wingetui", "CurrentSessionToken");
83+
string path_2 = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "UniGetUI", "CurrentSessionToken");
84+
string path_3 = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "UniGetUI", "Configuration", "CurrentSessionToken");
85+
86+
DateTime date_1 = DateTime.MinValue;
87+
DateTime date_2 = DateTime.MinValue;
88+
DateTime date_3 = DateTime.MinValue;
8489

8590
string SessionTokenFile;
86-
if (!File.Exists(new_path))
87-
SessionTokenFile = old_path;
88-
else if (!File.Exists(old_path))
89-
SessionTokenFile = new_path;
90-
else
91+
92+
if (File.Exists(path_1)) date_1 = new FileInfo(path_1).LastWriteTimeUtc;
93+
if (File.Exists(path_2)) date_2 = new FileInfo(path_2).LastWriteTimeUtc;
94+
if (File.Exists(path_3)) date_3 = new FileInfo(path_3).LastWriteTimeUtc;
95+
96+
if (date_1 > date_2 && date_1 > date_3) SessionTokenFile = path_1;
97+
else if (date_2 > date_1 && date_2 > date_3) SessionTokenFile = path_2;
98+
else if (date_3 > date_1 && date_3 > date_2) SessionTokenFile = path_3;
99+
else SessionTokenFile = path_3; // If none of the files exist
100+
101+
if(!File.Exists(SessionTokenFile))
91102
{
92-
FileInfo old_path_data = new(old_path);
93-
DateTime old_created = old_path_data.LastWriteTimeUtc; //File Creation
94-
FileInfo new_path_data = new(new_path);
95-
DateTime new_created = new_path_data.LastWriteTimeUtc; //File Creation
96-
SessionTokenFile = old_created > new_created ? old_path : new_path;
103+
Logger.Log("GetAvailableUpdates: ABORTED connection to UniGetUI due to NO_AUTH_TOKEN");
104+
result.Succeeded = is_connected_to_host = false;
105+
result.ErrorReason = "NO_AUTH_TOKEN";
106+
if (UpdateCheckFinished != null) UpdateCheckFinished(this, result);
107+
return;
97108
}
98109

99110
StreamReader reader = new(SessionTokenFile);

0 commit comments

Comments
 (0)