File tree Expand file tree Collapse file tree
HMCLCore/src/main/java/org/jackhuang/hmcl/util/platform/windows
HMCL/src/main/java/org/jackhuang/hmcl/ui/account Expand file tree Collapse file tree Original file line number Diff line number Diff line change 4343import org .jackhuang .hmcl .ui .decorator .DecoratorPage ;
4444import org .jackhuang .hmcl .util .javafx .BindingMapping ;
4545import org .jackhuang .hmcl .util .javafx .MappedObservableList ;
46+ import org .jackhuang .hmcl .util .platform .NativeUtils ;
47+ import org .jackhuang .hmcl .util .platform .OperatingSystem ;
48+ import org .jackhuang .hmcl .util .platform .windows .Kernel32 ;
49+ import org .jackhuang .hmcl .util .platform .windows .WinConstants ;
4650
4751import java .net .URI ;
4852import java .time .ZoneId ;
53+ import java .time .ZonedDateTime ;
4954import java .util .Locale ;
5055
5156import static org .jackhuang .hmcl .setting .ConfigHolder .globalConfig ;
5762public final class AccountListPage extends DecoratorAnimatedPage implements DecoratorPage {
5863 static final BooleanProperty RESTRICTED = new SimpleBooleanProperty (true );
5964
65+ private static boolean isExemptedRegion () {
66+ if ("Asia/Shanghai" .equals (ZoneId .systemDefault ().getId ()))
67+ return true ;
68+
69+ if (OperatingSystem .CURRENT_OS == OperatingSystem .WINDOWS
70+ && NativeUtils .USE_JNA
71+ && ZonedDateTime .now ().getOffset ().getTotalSeconds () == 8 * 3600 ) { // GMT+8
72+ Kernel32 kernel32 = Kernel32 .INSTANCE ;
73+
74+ // https://learn.microsoft.com/windows/win32/intl/table-of-geographical-locations
75+ if (kernel32 != null && kernel32 .GetUserGeoID (WinConstants .GEOCLASS_NATION ) == 45 )
76+ return true ;
77+ }
78+
79+ return false ;
80+ }
81+
6082 static {
6183 String property = System .getProperty ("hmcl.offline.auth.restricted" , "auto" );
6284
6385 if ("false" .equals (property )
64- || "auto" .equals (property ) && "Asia/Shanghai" . equals ( ZoneId . systemDefault (). getId () )
86+ || "auto" .equals (property ) && isExemptedRegion ( )
6587 || globalConfig ().isEnableOfflineAccount ())
6688 RESTRICTED .set (false );
6789 else
Original file line number Diff line number Diff line change @@ -44,4 +44,8 @@ public interface Kernel32 extends StdCallLibrary {
4444 */
4545 int GetACP ();
4646
47+ /**
48+ * @see <a href="https://learn.microsoft.com/windows/win32/api/winnls/nf-winnls-getusergeoid">GetUserGeoID function</a>
49+ */
50+ int GetUserGeoID (int geoClass );
4751}
Original file line number Diff line number Diff line change @@ -36,4 +36,8 @@ public interface WinConstants {
3636 long HKEY_CURRENT_CONFIG = 0x80000005L ;
3737 long HKEY_DYN_DATA = 0x80000006L ;
3838 long HKEY_CURRENT_USER_LOCAL_SETTINGS = 0x80000007L ;
39+
40+ int GEOCLASS_NATION = 16 ;
41+ int GEOCLASS_REGION = 14 ;
42+ int GEOCLASS_ALL = 0 ;
3943}
You can’t perform that action at this time.
0 commit comments