@@ -60,6 +60,7 @@ namespace TIGER_API {
6060 utility::string_t socket_ca_certs;
6161 unsigned int send_interval = 10 * 1000 ;
6262 unsigned int receive_interval = 10 * 1000 ;
63+ utility::string_t license;
6364 utility::string_t token;
6465 utility::string_t props_path;
6566
@@ -109,6 +110,8 @@ namespace TIGER_API {
109110 return this ->socket_port ;
110111 }
111112
113+
114+
112115 private:
113116 bool sandbox_debug = false ;
114117 utility::string_t server_url = TIGER_SERVER_URL;
@@ -117,14 +120,15 @@ namespace TIGER_API {
117120 utility::string_t socket_port = TIGER_SOCKET_PORT;
118121
119122 void load_props () {
120- if (props_path.empty ()) {
123+ utility::string_t full_path = get_props_path (DEFAULT_PROPS_FILE);
124+ if (full_path.empty ()) {
121125 return ;
122126 }
123127
124128 try {
125- std::ifstream file (props_path );
129+ std::ifstream file (Utils::str16to8 (full_path) );
126130 if (!file.is_open ()) {
127- LOG (ERROR) << U (" Failed to open properties file: " ) << props_path << endl;
131+ LOG (ERROR) << U (" Failed to open properties file: " ) << full_path << endl;
128132 return ;
129133 }
130134
@@ -141,21 +145,82 @@ namespace TIGER_API {
141145 if (account.empty ()) {
142146 account = props.get_property (U (" account" ));
143147 }
148+ if (license.empty ()) {
149+ license = props.get_property (U (" license" ));
150+ }
144151
145- // 检查是否为沙箱环境
146- if (!sandbox_debug) {
147- utility::string_t env = props.get_property (U (" env" ));
148- std::transform (env.begin (), env.end (), env.begin (), ::toupper);
149- if (env == U (" SANDBOX" )) {
150- sandbox_debug = true ;
151- server_url = SANDBOX_TIGER_SERVER_URL;
152- server_public_key = SANDBOX_TIGER_PUBLIC_KEY;
153- socket_url = SANDBOX_TIGER_SOCKET_HOST;
154- socket_port = SANDBOX_TIGER_SOCKET_PORT;
155- }
152+ utility::string_t env = props.get_property (U (" env" ));
153+ std::transform (env.begin (), env.end (), env.begin (), ::toupper);
154+ if (env == U (" SANDBOX" )) {
155+ sandbox_debug = true ;
156+ server_url = SANDBOX_TIGER_SERVER_URL;
157+ server_public_key = SANDBOX_TIGER_PUBLIC_KEY;
158+ socket_url = SANDBOX_TIGER_SOCKET_HOST;
159+ socket_port = SANDBOX_TIGER_SOCKET_PORT;
156160 }
161+
157162 } catch (const std::exception& e) {
158- LOG (ERROR) << U (" Failed to load properties file: " ) << e.what () << endl;
163+ LOG (ERROR) << U (" Failed to load properties file: " ) << Utils::str8to16 (e.what ()) << endl;
164+ }
165+ }
166+
167+ utility::string_t get_props_path (const utility::string_t & filename) const {
168+ if (!props_path.empty ()) {
169+ if (Utils::is_directory (props_path)) {
170+ return Utils::path_join (props_path, filename);
171+ } else {
172+ utility::string_t dirname = Utils::path_dirname (props_path);
173+ return Utils::path_join (dirname, filename);
174+ }
175+ }
176+ return utility::string_t ();
177+ }
178+
179+ utility::string_t get_token_path () const {
180+ return get_props_path (DEFAULT_TOKEN_FILE);
181+ }
182+
183+ void load_token () {
184+ utility::string_t full_path = get_token_path ();
185+ if (!full_path.empty ()) {
186+ try {
187+ std::ifstream file (Utils::str16to8 (full_path));
188+ if (!file.is_open ()) {
189+ LOG (ERROR) << U (" Failed to open token file: " ) << full_path << endl;
190+ return ;
191+ }
192+
193+ Properties props;
194+ props.load (file);
195+
196+ // 获取token值
197+ token = props.get_property (U (" token" ));
198+
199+ } catch (const std::exception& e) {
200+ LOG (ERROR) << U (" Failed to load token file: " ) << Utils::str8to16 (e.what ()) << endl;
201+ }
202+ }
203+ }
204+
205+ void save_token (const utility::string_t & new_token) {
206+ utility::string_t full_path = get_token_path ();
207+ if (!full_path.empty ()) {
208+ try {
209+ Properties props;
210+ props.set_property (U (" token" ), new_token);
211+
212+ std::ofstream file (Utils::str16to8 (full_path));
213+ if (!file.is_open ()) {
214+ LOG (ERROR) << U (" Failed to open token file for writing: " ) << full_path << endl;
215+ return ;
216+ }
217+
218+ props.store (file);
219+ token = new_token;
220+
221+ } catch (const std::exception& e) {
222+ LOG (ERROR) << U (" Failed to save token file: " ) << Utils::str8to16 (e.what ()) << endl;
223+ }
159224 }
160225 }
161226 };
0 commit comments