@@ -82,7 +82,8 @@ public int GenerateClientConfig(ProfileItem node, string? fileName, out string m
82
82
//socks-port
83
83
fileContent [ "socks-port" ] = LazyConfig . Instance . GetLocalPort ( EInboundProtocol . socks ) ;
84
84
//log-level
85
- fileContent [ "log-level" ] = _config . coreBasicItem . loglevel ;
85
+ fileContent [ "log-level" ] = GetLogLevel ( _config . coreBasicItem . loglevel ) ;
86
+
86
87
//external-controller
87
88
fileContent [ "external-controller" ] = $ "{ Global . Loopback } :{ LazyConfig . Instance . StatePort2 } ";
88
89
//allow-lan
@@ -97,7 +98,7 @@ public int GenerateClientConfig(ProfileItem node, string? fileName, out string m
97
98
}
98
99
99
100
//ipv6
100
- // fileContent["ipv6"] = _config.EnableIpv6 ;
101
+ fileContent [ "ipv6" ] = _config . clashUIItem . enableIPv6 ;
101
102
102
103
//mode
103
104
if ( ! fileContent . ContainsKey ( "mode" ) )
@@ -112,27 +113,27 @@ public int GenerateClientConfig(ProfileItem node, string? fileName, out string m
112
113
}
113
114
}
114
115
115
- //// enable tun mode
116
- // if (config.EnableTun )
117
- // {
118
- // string tun = Utils.GetEmbedText(Global.SampleTun );
119
- // if (!string.IsNullOrEmpty(tun))
120
- // {
121
- // var tunContent = Utils .FromYaml<Dictionary<string, object>>(tun);
122
- // if (tunContent != null)
123
- // fileContent["tun"] = tunContent["tun"];
124
- // }
125
- // }
116
+ //enable tun mode
117
+ if ( _config . tunModeItem . enableTun )
118
+ {
119
+ string tun = Utils . GetEmbedText ( Global . ClashTunYaml ) ;
120
+ if ( ! string . IsNullOrEmpty ( tun ) )
121
+ {
122
+ var tunContent = YamlUtils . FromYaml < Dictionary < string , object > > ( tun ) ;
123
+ if ( tunContent != null )
124
+ fileContent [ "tun" ] = tunContent [ "tun" ] ;
125
+ }
126
+ }
126
127
127
128
//Mixin
128
- // try
129
- // {
130
- // MixinContent(fileContent, config , node);
131
- // }
132
- // catch (Exception ex)
133
- // {
134
- // Logging.SaveLog("GenerateClientConfigClash-Mixin", ex);
135
- // }
129
+ try
130
+ {
131
+ MixinContent ( fileContent , node ) ;
132
+ }
133
+ catch ( Exception ex )
134
+ {
135
+ Logging . SaveLog ( "GenerateClientConfigClash-Mixin" , ex ) ;
136
+ }
136
137
137
138
var txtFileNew = YamlUtils . ToYaml ( fileContent ) . Replace ( tagYamlStr2 , tagYamlStr3 ) ;
138
139
File . WriteAllText ( fileName , txtFileNew ) ;
@@ -156,49 +157,48 @@ public int GenerateClientConfig(ProfileItem node, string? fileName, out string m
156
157
return 0 ;
157
158
}
158
159
159
- // private static void MixinContent(Dictionary<string, object> fileContent, Config config , ProfileItem node)
160
- // {
161
- // if (!config.EnableMixinContent )
162
- // {
163
- // return;
164
- // }
160
+ private void MixinContent ( Dictionary < string , object > fileContent , ProfileItem node )
161
+ {
162
+ // if (!_config.clashUIItem.enableMixinContent )
163
+ // {
164
+ // return;
165
+ // }
165
166
166
- // var path = Utils.GetConfigPath(Global.mixinConfigFileName );
167
- // if (!File.Exists(path))
168
- // {
169
- // return;
170
- // }
167
+ var path = Utils . GetConfigPath ( Global . ClashMixinConfigFileName ) ;
168
+ if ( ! File . Exists ( path ) )
169
+ {
170
+ return ;
171
+ }
171
172
172
- // var txtFile = File.ReadAllText(Utils.GetConfigPath(Global.mixinConfigFileName));
173
- // //txtFile = txtFile.Replace("!<str>", "");
173
+ var txtFile = File . ReadAllText ( Utils . GetConfigPath ( Global . ClashMixinConfigFileName ) ) ;
174
174
175
- // var mixinContent = YamlUtils.FromYaml<Dictionary<string, object>>(txtFile);
176
- // if (mixinContent == null)
177
- // {
178
- // return;
179
- // }
180
- // foreach (var item in mixinContent)
181
- // {
182
- // if (!config.EnableTun && item.Key == "tun")
183
- // {
184
- // continue;
185
- // }
175
+ var mixinContent = YamlUtils . FromYaml < Dictionary < string , object > > ( txtFile ) ;
176
+ if ( mixinContent == null )
177
+ {
178
+ return ;
179
+ }
180
+ foreach ( var item in mixinContent )
181
+ {
182
+ if ( ! _config . tunModeItem . enableTun && item . Key == "tun" )
183
+ {
184
+ continue ;
185
+ }
186
186
187
- // if (item.Key.StartsWith("prepend-")
188
- // || item.Key.StartsWith("append-")
189
- // || item.Key.StartsWith("removed-"))
190
- // {
191
- // ModifyContentMerge(fileContent, item.Key, item.Value);
192
- // }
193
- // else
194
- // {
195
- // fileContent[item.Key] = item.Value;
196
- // }
197
- // }
198
- // return;
199
- // }
187
+ if ( item . Key . StartsWith ( "prepend-" )
188
+ || item . Key . StartsWith ( "append-" )
189
+ || item . Key . StartsWith ( "removed-" ) )
190
+ {
191
+ ModifyContentMerge ( fileContent , item . Key , item . Value ) ;
192
+ }
193
+ else
194
+ {
195
+ fileContent [ item . Key ] = item . Value ;
196
+ }
197
+ }
198
+ return ;
199
+ }
200
200
201
- private static void ModifyContentMerge ( Dictionary < string , object > fileContent , string key , object value )
201
+ private void ModifyContentMerge ( Dictionary < string , object > fileContent , string key , object value )
202
202
{
203
203
bool blPrepend = false ;
204
204
bool blRemoved = false ;
@@ -255,5 +255,17 @@ private static void ModifyContentMerge(Dictionary<string, object> fileContent, s
255
255
}
256
256
}
257
257
}
258
+
259
+ private string GetLogLevel ( string level )
260
+ {
261
+ if ( level == "none" )
262
+ {
263
+ return "silent" ;
264
+ }
265
+ else
266
+ {
267
+ return level ;
268
+ }
269
+ }
258
270
}
259
271
}
0 commit comments