2
2
using System . IO ;
3
3
using System . Text . RegularExpressions ;
4
4
using v2rayN . Enums ;
5
+ using v2rayN . Handler . Fmt ;
5
6
using v2rayN . Models ;
6
7
7
8
namespace v2rayN . Handler
@@ -1070,12 +1071,12 @@ private static int RemoveProfileItem(Config config, string indexId)
1070
1071
/// 批量添加服务器
1071
1072
/// </summary>
1072
1073
/// <param name="config"></param>
1073
- /// <param name="clipboardData "></param>
1074
+ /// <param name="strData "></param>
1074
1075
/// <param name="subid"></param>
1075
1076
/// <returns>成功导入的数量</returns>
1076
- private static int AddBatchServers ( Config config , string clipboardData , string subid , bool isSub , List < ProfileItem > lstOriSub )
1077
+ private static int AddBatchServers ( Config config , string strData , string subid , bool isSub , List < ProfileItem > lstOriSub )
1077
1078
{
1078
- if ( Utils . IsNullOrEmpty ( clipboardData ) )
1079
+ if ( Utils . IsNullOrEmpty ( strData ) )
1079
1080
{
1080
1081
return - 1 ;
1081
1082
}
@@ -1092,7 +1093,7 @@ private static int AddBatchServers(Config config, string clipboardData, string s
1092
1093
//Check for duplicate indexId
1093
1094
List < string > ? lstDbIndexId = null ;
1094
1095
List < ProfileItem > lstAdd = new ( ) ;
1095
- var arrData = clipboardData . Split ( Environment . NewLine . ToCharArray ( ) ) . Where ( t => ! t . IsNullOrEmpty ( ) ) ;
1096
+ var arrData = strData . Split ( Environment . NewLine . ToCharArray ( ) ) . Where ( t => ! t . IsNullOrEmpty ( ) ) ;
1096
1097
if ( isSub )
1097
1098
{
1098
1099
arrData = arrData . Distinct ( ) ;
@@ -1108,7 +1109,7 @@ private static int AddBatchServers(Config config, string clipboardData, string s
1108
1109
}
1109
1110
continue ;
1110
1111
}
1111
- var profileItem = ShareHandler . ImportFromClipboardConfig ( str , out string msg ) ;
1112
+ var profileItem = FmtHandler . ResolveConfig ( str , out string msg ) ;
1112
1113
if ( profileItem is null )
1113
1114
{
1114
1115
continue ;
@@ -1177,9 +1178,9 @@ private static int AddBatchServers(Config config, string clipboardData, string s
1177
1178
return countServers ;
1178
1179
}
1179
1180
1180
- private static int AddBatchServers4Custom ( Config config , string clipboardData , string subid , bool isSub , List < ProfileItem > lstOriSub )
1181
+ private static int AddBatchServers4Custom ( Config config , string strData , string subid , bool isSub , List < ProfileItem > lstOriSub )
1181
1182
{
1182
- if ( Utils . IsNullOrEmpty ( clipboardData ) )
1183
+ if ( Utils . IsNullOrEmpty ( strData ) )
1183
1184
{
1184
1185
return - 1 ;
1185
1186
}
@@ -1195,7 +1196,7 @@ static bool Contains(string str, params string[] s)
1195
1196
}
1196
1197
1197
1198
//Is v2ray array configuration
1198
- var configObjects = JsonUtils . Deserialize < Object [ ] > ( clipboardData ) ;
1199
+ var configObjects = JsonUtils . Deserialize < Object [ ] > ( strData ) ;
1199
1200
if ( configObjects != null && configObjects . Length > 0 )
1200
1201
{
1201
1202
if ( isSub && ! Utils . IsNullOrEmpty ( subid ) )
@@ -1236,42 +1237,42 @@ static bool Contains(string str, params string[] s)
1236
1237
1237
1238
ProfileItem profileItem = new ( ) ;
1238
1239
//Is v2ray configuration
1239
- var v2rayConfig = JsonUtils . Deserialize < V2rayConfig > ( clipboardData ) ;
1240
+ var v2rayConfig = JsonUtils . Deserialize < V2rayConfig > ( strData ) ;
1240
1241
if ( v2rayConfig ? . inbounds ? . Count > 0
1241
1242
&& v2rayConfig . outbounds ? . Count > 0 )
1242
1243
{
1243
1244
var fileName = Utils . GetTempPath ( $ "{ Utils . GetGUID ( false ) } .json") ;
1244
- File . WriteAllText ( fileName , clipboardData ) ;
1245
+ File . WriteAllText ( fileName , strData ) ;
1245
1246
1246
1247
profileItem . coreType = ECoreType . Xray ;
1247
1248
profileItem . address = fileName ;
1248
1249
profileItem . remarks = v2rayConfig . remarks ?? "v2ray_custom" ;
1249
1250
}
1250
1251
//Is Clash configuration
1251
- else if ( Contains ( clipboardData , "port" , "socks-port" , "proxies" ) )
1252
+ else if ( Contains ( strData , "port" , "socks-port" , "proxies" ) )
1252
1253
{
1253
1254
var fileName = Utils . GetTempPath ( $ "{ Utils . GetGUID ( false ) } .yaml") ;
1254
- File . WriteAllText ( fileName , clipboardData ) ;
1255
+ File . WriteAllText ( fileName , strData ) ;
1255
1256
1256
1257
profileItem . coreType = ECoreType . mihomo ;
1257
1258
profileItem . address = fileName ;
1258
1259
profileItem . remarks = "clash_custom" ;
1259
1260
}
1260
1261
//Is hysteria configuration
1261
- else if ( Contains ( clipboardData , "server" , "up" , "down" , "listen" , "<html>" , "<body>" ) )
1262
+ else if ( Contains ( strData , "server" , "up" , "down" , "listen" , "<html>" , "<body>" ) )
1262
1263
{
1263
1264
var fileName = Utils . GetTempPath ( $ "{ Utils . GetGUID ( false ) } .json") ;
1264
- File . WriteAllText ( fileName , clipboardData ) ;
1265
+ File . WriteAllText ( fileName , strData ) ;
1265
1266
1266
1267
profileItem . coreType = ECoreType . hysteria ;
1267
1268
profileItem . address = fileName ;
1268
1269
profileItem . remarks = "hysteria_custom" ;
1269
1270
}
1270
1271
//Is naiveproxy configuration
1271
- else if ( Contains ( clipboardData , "listen" , "proxy" , "<html>" , "<body>" ) )
1272
+ else if ( Contains ( strData , "listen" , "proxy" , "<html>" , "<body>" ) )
1272
1273
{
1273
1274
var fileName = Utils . GetTempPath ( $ "{ Utils . GetGUID ( false ) } .json") ;
1274
- File . WriteAllText ( fileName , clipboardData ) ;
1275
+ File . WriteAllText ( fileName , strData ) ;
1275
1276
1276
1277
profileItem . coreType = ECoreType . naiveproxy ;
1277
1278
profileItem . address = fileName ;
@@ -1282,7 +1283,7 @@ static bool Contains(string str, params string[] s)
1282
1283
{
1283
1284
return - 1 ;
1284
1285
//var fileName = Utile.GetTempPath($"{Utile.GetGUID(false)}.txt");
1285
- //File.WriteAllText(fileName, clipboardData );
1286
+ //File.WriteAllText(fileName, strData );
1286
1287
1287
1288
//profileItem.address = fileName;
1288
1289
//profileItem.remarks = "other_custom";
@@ -1314,9 +1315,9 @@ static bool Contains(string str, params string[] s)
1314
1315
}
1315
1316
}
1316
1317
1317
- private static int AddBatchServers4SsSIP008 ( Config config , string clipboardData , string subid , bool isSub , List < ProfileItem > lstOriSub )
1318
+ private static int AddBatchServers4SsSIP008 ( Config config , string strData , string subid , bool isSub , List < ProfileItem > lstOriSub )
1318
1319
{
1319
- if ( Utils . IsNullOrEmpty ( clipboardData ) )
1320
+ if ( Utils . IsNullOrEmpty ( strData ) )
1320
1321
{
1321
1322
return - 1 ;
1322
1323
}
@@ -1327,10 +1328,10 @@ private static int AddBatchServers4SsSIP008(Config config, string clipboardData,
1327
1328
}
1328
1329
1329
1330
//SsSIP008
1330
- var lstSsServer = JsonUtils . Deserialize < List < SsServer > > ( clipboardData ) ;
1331
+ var lstSsServer = JsonUtils . Deserialize < List < SsServer > > ( strData ) ;
1331
1332
if ( lstSsServer ? . Count <= 0 )
1332
1333
{
1333
- var ssSIP008 = JsonUtils . Deserialize < SsSIP008 > ( clipboardData ) ;
1334
+ var ssSIP008 = JsonUtils . Deserialize < SsSIP008 > ( strData ) ;
1334
1335
if ( ssSIP008 ? . servers ? . Count > 0 )
1335
1336
{
1336
1337
lstSsServer = ssSIP008 . servers ;
@@ -1365,7 +1366,7 @@ private static int AddBatchServers4SsSIP008(Config config, string clipboardData,
1365
1366
return - 1 ;
1366
1367
}
1367
1368
1368
- public static int AddBatchServers ( Config config , string clipboardData , string subid , bool isSub )
1369
+ public static int AddBatchServers ( Config config , string strData , string subid , bool isSub )
1369
1370
{
1370
1371
List < ProfileItem > ? lstOriSub = null ;
1371
1372
if ( isSub && ! Utils . IsNullOrEmpty ( subid ) )
@@ -1374,28 +1375,28 @@ public static int AddBatchServers(Config config, string clipboardData, string su
1374
1375
}
1375
1376
1376
1377
var counter = 0 ;
1377
- if ( Utils . IsBase64String ( clipboardData ) )
1378
+ if ( Utils . IsBase64String ( strData ) )
1378
1379
{
1379
- counter = AddBatchServers ( config , Utils . Base64Decode ( clipboardData ) , subid , isSub , lstOriSub ) ;
1380
+ counter = AddBatchServers ( config , Utils . Base64Decode ( strData ) , subid , isSub , lstOriSub ) ;
1380
1381
}
1381
1382
if ( counter < 1 )
1382
1383
{
1383
- counter = AddBatchServers ( config , clipboardData , subid , isSub , lstOriSub ) ;
1384
+ counter = AddBatchServers ( config , strData , subid , isSub , lstOriSub ) ;
1384
1385
}
1385
1386
if ( counter < 1 )
1386
1387
{
1387
- counter = AddBatchServers ( config , Utils . Base64Decode ( clipboardData ) , subid , isSub , lstOriSub ) ;
1388
+ counter = AddBatchServers ( config , Utils . Base64Decode ( strData ) , subid , isSub , lstOriSub ) ;
1388
1389
}
1389
1390
1390
1391
if ( counter < 1 )
1391
1392
{
1392
- counter = AddBatchServers4SsSIP008 ( config , clipboardData , subid , isSub , lstOriSub ) ;
1393
+ counter = AddBatchServers4SsSIP008 ( config , strData , subid , isSub , lstOriSub ) ;
1393
1394
}
1394
1395
1395
1396
//maybe other sub
1396
1397
if ( counter < 1 )
1397
1398
{
1398
- counter = AddBatchServers4Custom ( config , clipboardData , subid , isSub , lstOriSub ) ;
1399
+ counter = AddBatchServers4Custom ( config , strData , subid , isSub , lstOriSub ) ;
1399
1400
}
1400
1401
1401
1402
return counter ;
@@ -1533,16 +1534,16 @@ public static int SaveRoutingItem(Config config, RoutingItem item)
1533
1534
/// AddBatchRoutingRules
1534
1535
/// </summary>
1535
1536
/// <param name="config"></param>
1536
- /// <param name="clipboardData "></param>
1537
+ /// <param name="strData "></param>
1537
1538
/// <returns></returns>
1538
- public static int AddBatchRoutingRules ( ref RoutingItem routingItem , string clipboardData )
1539
+ public static int AddBatchRoutingRules ( ref RoutingItem routingItem , string strData )
1539
1540
{
1540
- if ( Utils . IsNullOrEmpty ( clipboardData ) )
1541
+ if ( Utils . IsNullOrEmpty ( strData ) )
1541
1542
{
1542
1543
return - 1 ;
1543
1544
}
1544
1545
1545
- var lstRules = JsonUtils . Deserialize < List < RulesItem > > ( clipboardData ) ;
1546
+ var lstRules = JsonUtils . Deserialize < List < RulesItem > > ( strData ) ;
1546
1547
if ( lstRules == null )
1547
1548
{
1548
1549
return - 1 ;
0 commit comments