File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -24,7 +24,6 @@ public sealed class Program
2424
2525 public static readonly string GitHubRepoOwner = "hedge-dev" ;
2626 public static readonly string GitHubRepoName = "HedgeModManager" ;
27- public static string UserAgent = $ "Mozilla/5.0 (compatible; { ApplicationName } /{ ApplicationVersion } )";
2827
2928 // Will become the GUID if exists
3029 public static string PipeName = $ "{ ApplicationCompany } \\ { ApplicationName } ";
@@ -38,6 +37,7 @@ public sealed class Program
3837 public const bool IsDebugBuild = false ;
3938#endif
4039
40+ public static string UserAgent = $ "Mozilla/5.0 (compatible; { ApplicationName } /{ ApplicationVersion } )";
4141 public static Mutex ? CurrentMutex = null ;
4242 public static List < ICliCommand > StartupCommands = [ ] ;
4343
@@ -131,8 +131,7 @@ public static void Main(string[] args)
131131 }
132132
133133 Paths . CreateDirectories ( ) ;
134- Network . UserAgent = UserAgent ;
135- Network . Initialize ( ) ;
134+ Network . Initialize ( UserAgent ) ;
136135
137136 if ( Environment . GetEnvironmentVariable ( "FLATPAK_ID" ) is string flatpakID )
138137 FlatpakID = flatpakID ;
Original file line number Diff line number Diff line change 66
77public static class Network
88{
9- public static string UserAgent = $ "Mozilla/5.0 (compatible; HedgeModManager)";
10- public static HttpClient Client = new ( ) ;
9+ public const string DefaultUserAgent = $ "Mozilla/5.0 (compatible; HedgeModManager)";
10+ public static HttpClient Client { get ; set ; } = new ( ) ;
1111
12- public static void Initialize ( )
12+ public static void Initialize ( string ? userAgent = null )
1313 {
1414 Client ? . Dispose ( ) ;
1515 Client = new ( )
1616 {
17- DefaultRequestHeaders = { { "User-Agent" , UserAgent } }
17+ DefaultRequestHeaders = { { "User-Agent" , userAgent ?? DefaultUserAgent } }
1818 } ;
1919 }
2020
21+ /// <summary>
22+ /// Gets the current user agent, if not initialised the default user agent will be returned
23+ /// </summary>
24+ public static string GetUserAgent ( ) => Client ? . DefaultRequestHeaders . UserAgent . ToString ( ) ?? DefaultUserAgent ;
25+
2126 public static Uri ? CreateUri ( string ? uri ) =>
2227 string . IsNullOrEmpty ( uri ) ? null : new Uri ( uri , UriKind . RelativeOrAbsolute ) ;
2328
Original file line number Diff line number Diff line change 11namespace HedgeModManager . Updates ;
2- using System . Net ;
32using System . Text ;
43using Text ;
54
@@ -10,7 +9,7 @@ public class ModUpdateClient : HttpClient
109 public ModUpdateClient ( Uri baseUri )
1110 {
1211 BaseAddress = baseUri ;
13- DefaultRequestHeaders . TryAddWithoutValidation ( "User-Agent" , Network . UserAgent ) ;
12+ DefaultRequestHeaders . TryAddWithoutValidation ( "User-Agent" , Network . GetUserAgent ( ) ) ;
1413 Timeout = TimeSpan . FromMinutes ( 8 ) ;
1514 }
1615
You can’t perform that action at this time.
0 commit comments