@@ -21,7 +21,7 @@ use sodiumoxide::crypto::sign;
21
21
22
22
use crate :: {
23
23
compress:: { compress, decompress} ,
24
- log,
24
+ is_client , is_host , is_sos , is_standard , log,
25
25
password_security:: {
26
26
decrypt_str_or_original, decrypt_vec_or_original, encrypt_str_or_original,
27
27
encrypt_vec_or_original, symmetric_crypt,
@@ -70,6 +70,8 @@ lazy_static::lazy_static! {
70
70
pub static ref OVERWRITE_LOCAL_SETTINGS : RwLock <HashMap <String , String >> = Default :: default ( ) ;
71
71
pub static ref HARD_SETTINGS : RwLock <HashMap <String , String >> = Default :: default ( ) ;
72
72
pub static ref BUILTIN_SETTINGS : RwLock <HashMap <String , String >> = Default :: default ( ) ;
73
+ pub static ref STRATEGY_OVERRIDE_SETTINGS : RwLock <HashMap <String , String >> = Default :: default ( ) ;
74
+ pub static ref STRATEGY_HARD_SETTINGS : RwLock <HashMap <String , String >> = Default :: default ( ) ;
73
75
}
74
76
75
77
lazy_static:: lazy_static! {
@@ -986,13 +988,22 @@ impl Config {
986
988
pub fn get_options ( ) -> HashMap < String , String > {
987
989
let mut res = DEFAULT_SETTINGS . read ( ) . unwrap ( ) . clone ( ) ;
988
990
res. extend ( CONFIG2 . read ( ) . unwrap ( ) . options . clone ( ) ) ;
991
+ res. extend ( STRATEGY_OVERRIDE_SETTINGS . read ( ) . unwrap ( ) . clone ( ) ) ;
989
992
res. extend ( OVERWRITE_SETTINGS . read ( ) . unwrap ( ) . clone ( ) ) ;
990
993
res
991
994
}
992
995
993
996
#[ inline]
994
997
fn purify_options ( v : & mut HashMap < String , String > ) {
995
- v. retain ( |k, v| is_option_can_save ( & OVERWRITE_SETTINGS , k, & DEFAULT_SETTINGS , v) ) ;
998
+ v. retain ( |k, v| {
999
+ is_option_can_save (
1000
+ & OVERWRITE_SETTINGS ,
1001
+ & STRATEGY_OVERRIDE_SETTINGS ,
1002
+ k,
1003
+ & DEFAULT_SETTINGS ,
1004
+ v,
1005
+ )
1006
+ } ) ;
996
1007
}
997
1008
998
1009
pub fn set_options ( mut v : HashMap < String , String > ) {
@@ -1008,6 +1019,7 @@ impl Config {
1008
1019
pub fn get_option ( k : & str ) -> String {
1009
1020
get_or (
1010
1021
& OVERWRITE_SETTINGS ,
1022
+ & STRATEGY_OVERRIDE_SETTINGS ,
1011
1023
& CONFIG2 . read ( ) . unwrap ( ) . options ,
1012
1024
& DEFAULT_SETTINGS ,
1013
1025
k,
@@ -1020,7 +1032,13 @@ impl Config {
1020
1032
}
1021
1033
1022
1034
pub fn set_option ( k : String , v : String ) {
1023
- if !is_option_can_save ( & OVERWRITE_SETTINGS , & k, & DEFAULT_SETTINGS , & v) {
1035
+ if !is_option_can_save (
1036
+ & OVERWRITE_SETTINGS ,
1037
+ & STRATEGY_OVERRIDE_SETTINGS ,
1038
+ & k,
1039
+ & DEFAULT_SETTINGS ,
1040
+ & v,
1041
+ ) {
1024
1042
return ;
1025
1043
}
1026
1044
let mut config = CONFIG2 . write ( ) . unwrap ( ) ;
@@ -1098,6 +1116,13 @@ impl Config {
1098
1116
{
1099
1117
return ;
1100
1118
}
1119
+ if STRATEGY_OVERRIDE_SETTINGS
1120
+ . read ( )
1121
+ . unwrap ( )
1122
+ . contains_key ( keys:: OPTION_PROXY_URL )
1123
+ {
1124
+ return ;
1125
+ }
1101
1126
1102
1127
let mut config = CONFIG2 . write ( ) . unwrap ( ) ;
1103
1128
if config. socks == socks {
@@ -1156,6 +1181,9 @@ impl Config {
1156
1181
1157
1182
pub fn get_socks ( ) -> Option < Socks5Server > {
1158
1183
Self :: get_socks_from_custom_client_advanced_settings ( & OVERWRITE_SETTINGS . read ( ) . unwrap ( ) )
1184
+ . or ( Self :: get_socks_from_custom_client_advanced_settings (
1185
+ & STRATEGY_OVERRIDE_SETTINGS . read ( ) . unwrap ( ) ,
1186
+ ) )
1159
1187
. or ( CONFIG2 . read ( ) . unwrap ( ) . socks . clone ( ) )
1160
1188
. or ( Self :: get_socks_from_custom_client_advanced_settings (
1161
1189
& DEFAULT_SETTINGS . read ( ) . unwrap ( ) ,
@@ -1176,6 +1204,14 @@ impl Config {
1176
1204
{
1177
1205
return NetworkType :: ProxySocks ;
1178
1206
}
1207
+ if STRATEGY_OVERRIDE_SETTINGS
1208
+ . read ( )
1209
+ . unwrap ( )
1210
+ . get ( keys:: OPTION_PROXY_URL )
1211
+ . is_some ( )
1212
+ {
1213
+ return NetworkType :: ProxySocks ;
1214
+ }
1179
1215
if CONFIG2 . read ( ) . unwrap ( ) . socks . is_some ( ) {
1180
1216
return NetworkType :: ProxySocks ;
1181
1217
}
@@ -1766,6 +1802,7 @@ impl LocalConfig {
1766
1802
pub fn get_option ( k : & str ) -> String {
1767
1803
get_or (
1768
1804
& OVERWRITE_LOCAL_SETTINGS ,
1805
+ & STRATEGY_OVERRIDE_SETTINGS ,
1769
1806
& LOCAL_CONFIG . read ( ) . unwrap ( ) . options ,
1770
1807
& DEFAULT_LOCAL_SETTINGS ,
1771
1808
k,
@@ -1777,6 +1814,7 @@ impl LocalConfig {
1777
1814
pub fn get_option_from_file ( k : & str ) -> String {
1778
1815
get_or (
1779
1816
& OVERWRITE_LOCAL_SETTINGS ,
1817
+ & STRATEGY_OVERRIDE_SETTINGS ,
1780
1818
& Self :: load ( ) . options ,
1781
1819
& DEFAULT_LOCAL_SETTINGS ,
1782
1820
k,
@@ -1789,7 +1827,13 @@ impl LocalConfig {
1789
1827
}
1790
1828
1791
1829
pub fn set_option ( k : String , v : String ) {
1792
- if !is_option_can_save ( & OVERWRITE_LOCAL_SETTINGS , & k, & DEFAULT_LOCAL_SETTINGS , & v) {
1830
+ if !is_option_can_save (
1831
+ & OVERWRITE_LOCAL_SETTINGS ,
1832
+ & STRATEGY_OVERRIDE_SETTINGS ,
1833
+ & k,
1834
+ & DEFAULT_LOCAL_SETTINGS ,
1835
+ & v,
1836
+ ) {
1793
1837
return ;
1794
1838
}
1795
1839
let mut config = LOCAL_CONFIG . write ( ) . unwrap ( ) ;
@@ -1814,6 +1858,7 @@ impl LocalConfig {
1814
1858
pub fn get_flutter_option ( k : & str ) -> String {
1815
1859
get_or (
1816
1860
& OVERWRITE_LOCAL_SETTINGS ,
1861
+ & STRATEGY_OVERRIDE_SETTINGS ,
1817
1862
& LOCAL_CONFIG . read ( ) . unwrap ( ) . ui_flutter ,
1818
1863
& DEFAULT_LOCAL_SETTINGS ,
1819
1864
k,
@@ -1946,6 +1991,7 @@ impl UserDefaultConfig {
1946
1991
pub fn set ( & mut self , key : String , value : String ) {
1947
1992
if !is_option_can_save (
1948
1993
& OVERWRITE_DISPLAY_SETTINGS ,
1994
+ & STRATEGY_OVERRIDE_SETTINGS ,
1949
1995
& key,
1950
1996
& DEFAULT_DISPLAY_SETTINGS ,
1951
1997
& value,
@@ -1995,6 +2041,7 @@ impl UserDefaultConfig {
1995
2041
fn get_after ( & self , k : & str ) -> Option < String > {
1996
2042
get_or (
1997
2043
& OVERWRITE_DISPLAY_SETTINGS ,
2044
+ & STRATEGY_OVERRIDE_SETTINGS ,
1998
2045
& self . options ,
1999
2046
& DEFAULT_DISPLAY_SETTINGS ,
2000
2047
k,
@@ -2174,6 +2221,12 @@ pub struct GroupPeer {
2174
2221
skip_serializing_if = "String::is_empty"
2175
2222
) ]
2176
2223
pub login_name : String ,
2224
+ #[ serde(
2225
+ default ,
2226
+ deserialize_with = "deserialize_string" ,
2227
+ skip_serializing_if = "String::is_empty"
2228
+ ) ]
2229
+ pub user : String ,
2177
2230
}
2178
2231
2179
2232
#[ derive( Debug , Default , Serialize , Deserialize , Clone ) ]
@@ -2184,6 +2237,12 @@ pub struct GroupUser {
2184
2237
skip_serializing_if = "String::is_empty"
2185
2238
) ]
2186
2239
pub name : String ,
2240
+ #[ serde(
2241
+ default ,
2242
+ deserialize_with = "deserialize_string" ,
2243
+ skip_serializing_if = "String::is_empty"
2244
+ ) ]
2245
+ pub user : String ,
2187
2246
}
2188
2247
2189
2248
#[ derive( Debug , Default , Serialize , Deserialize , Clone ) ]
@@ -2291,26 +2350,30 @@ deserialize_default!(deserialize_hashmap_resolutions, HashMap<String, Resolution
2291
2350
#[ inline]
2292
2351
fn get_or (
2293
2352
a : & RwLock < HashMap < String , String > > ,
2294
- b : & HashMap < String , String > ,
2295
- c : & RwLock < HashMap < String , String > > ,
2353
+ b : & RwLock < HashMap < String , String > > ,
2354
+ c : & HashMap < String , String > ,
2355
+ d : & RwLock < HashMap < String , String > > ,
2296
2356
k : & str ,
2297
2357
) -> Option < String > {
2298
2358
a. read ( )
2299
2359
. unwrap ( )
2300
2360
. get ( k)
2301
- . or ( b. get ( k) )
2302
- . or ( c. read ( ) . unwrap ( ) . get ( k) )
2361
+ . or ( b. read ( ) . unwrap ( ) . get ( k) )
2362
+ . or ( c. get ( k) )
2363
+ . or ( d. read ( ) . unwrap ( ) . get ( k) )
2303
2364
. cloned ( )
2304
2365
}
2305
2366
2306
2367
#[ inline]
2307
2368
fn is_option_can_save (
2308
2369
overwrite : & RwLock < HashMap < String , String > > ,
2370
+ strategy_override : & RwLock < HashMap < String , String > > ,
2309
2371
k : & str ,
2310
2372
defaults : & RwLock < HashMap < String , String > > ,
2311
2373
v : & str ,
2312
2374
) -> bool {
2313
2375
if overwrite. read ( ) . unwrap ( ) . contains_key ( k)
2376
+ || strategy_override. read ( ) . unwrap ( ) . contains_key ( k)
2314
2377
|| defaults. read ( ) . unwrap ( ) . get ( k) . map_or ( false , |x| x == v)
2315
2378
{
2316
2379
return false ;
@@ -2320,29 +2383,36 @@ fn is_option_can_save(
2320
2383
2321
2384
#[ inline]
2322
2385
pub fn is_incoming_only ( ) -> bool {
2323
- HARD_SETTINGS
2324
- . read ( )
2325
- . unwrap ( )
2326
- . get ( "conn-type" )
2327
- . map_or ( false , |x| x == ( "incoming" ) )
2386
+ is_host ( )
2387
+ || is_sos ( )
2388
+ || ( is_standard ( )
2389
+ && HARD_SETTINGS
2390
+ . read ( )
2391
+ . unwrap ( )
2392
+ . get ( "conn-type" )
2393
+ . map_or ( false , |x| x == ( "incoming" ) ) )
2328
2394
}
2329
2395
2330
2396
#[ inline]
2331
2397
pub fn is_outgoing_only ( ) -> bool {
2332
- HARD_SETTINGS
2333
- . read ( )
2334
- . unwrap ( )
2335
- . get ( "conn-type" )
2336
- . map_or ( false , |x| x == ( "outgoing" ) )
2398
+ is_client ( )
2399
+ || ( is_standard ( )
2400
+ && HARD_SETTINGS
2401
+ . read ( )
2402
+ . unwrap ( )
2403
+ . get ( "conn-type" )
2404
+ . map_or ( false , |x| x == ( "outgoing" ) ) )
2337
2405
}
2338
2406
2339
2407
#[ inline]
2340
2408
fn is_some_hard_opton ( name : & str ) -> bool {
2341
- HARD_SETTINGS
2342
- . read ( )
2343
- . unwrap ( )
2344
- . get ( name)
2345
- . map_or ( false , |x| x == ( "Y" ) )
2409
+ if let Some ( value) = HARD_SETTINGS . read ( ) . unwrap ( ) . get ( name) {
2410
+ return value == "Y" ;
2411
+ }
2412
+ if let Some ( value) = STRATEGY_HARD_SETTINGS . read ( ) . unwrap ( ) . get ( name) {
2413
+ return value == "Y" ;
2414
+ }
2415
+ false
2346
2416
}
2347
2417
2348
2418
#[ inline]
@@ -2362,12 +2432,12 @@ pub fn is_disable_ab() -> bool {
2362
2432
2363
2433
#[ inline]
2364
2434
pub fn is_disable_account ( ) -> bool {
2365
- is_some_hard_opton ( "disable-account" )
2435
+ is_sos ( ) || is_host ( ) || ( is_standard ( ) && is_some_hard_opton ( "disable-account" ) )
2366
2436
}
2367
2437
2368
2438
#[ inline]
2369
2439
pub fn is_disable_installation ( ) -> bool {
2370
- is_some_hard_opton ( "disable-installation" )
2440
+ is_sos ( ) || is_some_hard_opton ( "disable-installation" )
2371
2441
}
2372
2442
2373
2443
// This function must be kept the same as the one in flutter and sciter code.
@@ -2610,6 +2680,7 @@ pub mod keys {
2610
2680
OPTION_VIDEO_SAVE_DIRECTORY ,
2611
2681
OPTION_ENABLE_UDP_PUNCH ,
2612
2682
OPTION_ENABLE_IPV6_PUNCH ,
2683
+ OPTION_ENABLE_CHECK_UPDATE ,
2613
2684
] ;
2614
2685
// DEFAULT_SETTINGS, OVERWRITE_SETTINGS
2615
2686
pub const KEYS_SETTINGS : & [ & str ] = & [
@@ -2655,6 +2726,7 @@ pub mod keys {
2655
2726
OPTION_ENABLE_DIRECTX_CAPTURE ,
2656
2727
OPTION_ENABLE_ANDROID_SOFTWARE_ENCODING_HALF_SCALE ,
2657
2728
OPTION_ENABLE_TRUSTED_DEVICES ,
2729
+ OPTION_ALLOW_AUTO_UPDATE ,
2658
2730
] ;
2659
2731
2660
2732
// BUILDIN_SETTINGS
0 commit comments