5 namespace GameHub
.Data
.Sources
.Humble
7 public class Humble
: GameSource
9 public const string AUTH_COOKIE
= "_simpleauth_sess";
11 public override string name
{ get { return "Humble Bundle"; } }
12 public override string icon
{ get { return "humble"; } }
14 public string? user_token
= null;
16 private Settings
.Auth
.Humble settings
;
20 settings
= Settings
.Auth
.Humble
.get_instance();
21 var access_token
= settings
.access_token
;
22 if(access_token
.length
> 0)
24 user_token
= access_token
;
28 public override bool is_installed(bool refresh
)
33 public override async
bool install()
38 public override async
bool authenticate()
40 settings
.authenticated
= true;
42 return yield
get_token();
45 public override bool is_authenticated()
47 return user_token
!= null;
50 public override bool can_authenticate_automatically()
52 return user_token
!= null && settings
.authenticated
;
55 private async
bool get_token()
57 if(user_token
!= null)
62 var wnd
= new GameHub
.UI
.Windows
.WebAuthWindow(this
.name
, @
"https://www.humblebundle.com/login?goto=home", null, AUTH_COOKIE
);
64 wnd
.finished
.connect(token
=>
67 settings
.access_token
= user_token ??
"";
68 Idle
.add(get_token
.callback);
71 wnd
.canceled
.connect(() => Idle
.add(get_token
.callback));
78 return user_token
!= null;
81 private ArrayList
<Game
> games
= new ArrayList
<Game
>(Game
.is_equal
);
82 public override async ArrayList
<Game
> load_games(FutureResult
<Game
>? game_loaded
= null)
84 if(user_token
== null || games
.size
> 0)
91 var cached
= GamesDB
.get_instance().get_games(this
);
95 if(game_loaded
!= null)
97 foreach(var g
in cached
)
103 games_count
= games
.size
;
105 var headers
= new HashMap
<string, string>();
106 headers
["Cookie"] = @
"$(AUTH_COOKIE)=\"$(user_token)\";";
108 var orders
= (yield Parser
.parse_remote_json_file_async("https://www.humblebundle.com/api/v1/user/order?ajax=true", "GET", null, headers
)).get_array();
110 foreach(var order
in orders
.get_elements())
112 var key
= order
.get_object().get_string_member("gamekey");
114 var root
= (yield Parser
.parse_remote_json_file_async(@
"https://www.humblebundle.com/api/v1/order/$(key)?ajax=true", "GET", null, headers
)).get_object();
115 var products
= root
.get_array_member("subproducts");
117 foreach(var product
in products
.get_elements())
119 var game
= new
HumbleGame(this
, key
, product
.get_object());
120 if(!games
.contains(game
) && yield game
.is_for_linux())
123 if(game_loaded
!= null) game_loaded(game
);
124 GamesDB
.get_instance().add_game(game
);
126 games_count
= games
.size
;