This commit is contained in:
robin
2026-03-05 02:52:45 +08:00
parent 49776c3d0a
commit a10f3f3740
8 changed files with 171 additions and 351 deletions

View File

@@ -1,17 +1,15 @@
//
// DemoConfigLoader.m
// TrustHttpDNSTestDemo
//
// @author Created by Claude Code on 2025-10-05
// NewHttpDNSTestDemo
//
#import "DemoConfigLoader.h"
@implementation DemoConfigLoader {
NSInteger _accountID;
NSString *_secretKey;
NSString *_aesSecretKey;
BOOL _hasValidAccount;
NSString *_appId;
NSString *_primaryServiceHost;
NSInteger _servicePort;
NSString *_signSecret;
}
+ (instancetype)shared {
@@ -30,56 +28,23 @@
return self;
}
// Bundle > <EFBFBD><EFBFBD>?accountID <EFBFBD><EFBFBD>?
- (void)loadConfig {
_accountID = 0;
_secretKey = @"";
_aesSecretKey = @"";
_hasValidAccount = NO;
NSDictionary *bundleDict = nil;
NSDictionary *dict = nil;
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"DemoConfig" ofType:@"plist"];
if (plistPath.length > 0) {
bundleDict = [NSDictionary dictionaryWithContentsOfFile:plistPath];
dict = [NSDictionary dictionaryWithContentsOfFile:plistPath];
}
NSDictionary *env = [[NSProcessInfo processInfo] environment];
NSNumber *acc = bundleDict[@"accountID"]; // NSNumber preferred in plist
NSString *secret = bundleDict[@"secretKey"] ?: @"";
NSString *aes = bundleDict[@"aesSecretKey"] ?: @"";
NSString *envAcc = env[@"HTTPDNS_ACCOUNT_ID"];
NSString *envSecret = env[@"HTTPDNS_SECRET_KEY"];
NSString *envAes = env[@"HTTPDNS_AES_SECRET_KEY"];
if (envAcc.length > 0) {
acc = @([envAcc integerValue]);
}
if (envSecret.length > 0) {
secret = envSecret;
}
if (envAes.length > 0) {
aes = envAes;
}
if (acc != nil && [acc integerValue] > 0 && secret.length > 0) {
_accountID = [acc integerValue];
_secretKey = secret;
_aesSecretKey = aes ?: @"";
_hasValidAccount = YES;
} else {
_accountID = 0;
_secretKey = @"";
_aesSecretKey = @"";
_hasValidAccount = NO;
}
_appId = dict[@"appId"] ?: @"";
_primaryServiceHost = dict[@"primaryServiceHost"] ?: @"";
_servicePort = [dict[@"servicePort"] integerValue] ?: 443;
NSString *secret = dict[@"signSecret"] ?: @"";
_signSecret = secret.length > 0 ? secret : nil;
}
- (NSInteger)accountID { return _accountID; }
- (NSString *)secretKey { return _secretKey; }
- (NSString *)aesSecretKey { return _aesSecretKey; }
- (BOOL)hasValidAccount { return _hasValidAccount; }
- (NSString *)appId { return _appId; }
- (NSString *)primaryServiceHost { return _primaryServiceHost; }
- (NSInteger)servicePort { return _servicePort; }
- (NSString *)signSecret { return _signSecret; }
@end