|
2 | 2 | using CollapseLauncher.Helper; |
3 | 3 | using CollapseLauncher.Helper.Metadata; |
4 | 4 | using CollapseLauncher.Plugins; |
| 5 | +using FFmpegInteropX; |
5 | 6 | using Hi3Helper; |
6 | 7 | using Hi3Helper.Data; |
7 | 8 | using Hi3Helper.EncTool; |
|
19 | 20 | using System.Collections; |
20 | 21 | using System.Collections.Generic; |
21 | 22 | using System.IO; |
| 23 | +using System.Linq; |
22 | 24 | using System.Net.Http; |
23 | 25 | using System.Numerics; |
24 | 26 | using System.Threading; |
@@ -1212,4 +1214,112 @@ public object ConvertBack(object value, Type targetType, object parameter, strin |
1212 | 1214 | throw new NotImplementedException(); |
1213 | 1215 | } |
1214 | 1216 | } |
| 1217 | + |
| 1218 | + public partial class ObjectToLocaleKvpConverter : IValueConverter |
| 1219 | + { |
| 1220 | + public object? Convert(object? value, Type targetType, object? parameter, string language) |
| 1221 | + { |
| 1222 | + if (value is not Dictionary<string, string> asKvp) |
| 1223 | + { |
| 1224 | + return parameter; |
| 1225 | + } |
| 1226 | + |
| 1227 | + string? paramStr = parameter?.ToString(); |
| 1228 | + if (paramStr == null || |
| 1229 | + !asKvp.TryGetValue(paramStr, out string? localizedValue)) |
| 1230 | + { |
| 1231 | + return parameter; |
| 1232 | + } |
| 1233 | + |
| 1234 | + return localizedValue; |
| 1235 | + } |
| 1236 | + |
| 1237 | + public object ConvertBack(object value, Type targetType, object parameter, string language) |
| 1238 | + => throw new NotImplementedException(); |
| 1239 | + } |
| 1240 | + |
| 1241 | + public partial class FFmpegVideoDecoderModeToLocalizedConverter : IValueConverter |
| 1242 | + { |
| 1243 | + public object? Convert(object? value, Type targetType, object parameter, string language) |
| 1244 | + { |
| 1245 | + if (value is not VideoDecoderMode asEnum) |
| 1246 | + { |
| 1247 | + return value; |
| 1248 | + } |
| 1249 | + |
| 1250 | + Dictionary<string, string> dict = []; |
| 1251 | + string enumStr = asEnum.ToString(); |
| 1252 | + |
| 1253 | + if (!dict.TryGetValue(enumStr, out string? localedString)) |
| 1254 | + { |
| 1255 | + return enumStr; |
| 1256 | + } |
| 1257 | + |
| 1258 | + return localedString; |
| 1259 | + } |
| 1260 | + |
| 1261 | + public object ConvertBack(object value, Type targetType, object parameter, string language) |
| 1262 | + => throw new NotImplementedException(); |
| 1263 | + } |
| 1264 | + |
| 1265 | + public partial class FFmpegVideoDecoderModeToHelpLocaleConverter : IValueConverter |
| 1266 | + { |
| 1267 | + public object? Convert(object? value, Type targetType, object parameter, string language) |
| 1268 | + { |
| 1269 | + if (value is not VideoDecoderMode asEnum) |
| 1270 | + { |
| 1271 | + return value; |
| 1272 | + } |
| 1273 | + |
| 1274 | + bool isConvertTooltip = parameter is string parameterStr && |
| 1275 | + parameterStr.Equals("Tooltip", StringComparison.OrdinalIgnoreCase); |
| 1276 | + |
| 1277 | + var lang = Locale.Current.Lang; |
| 1278 | + |
| 1279 | + Dictionary<string, string> dict = (isConvertTooltip ? lang?._DictKvpFFmpegDecodingModeTooltip : lang?._DictKvpFFmpegDecodingMode) ?? []; |
| 1280 | + string enumStr = asEnum.ToString(); |
| 1281 | + |
| 1282 | + if (!dict.TryGetValue(enumStr, out string? localedString)) |
| 1283 | + { |
| 1284 | + return lang?._Misc?.DescriptionNotAvailable ?? enumStr; |
| 1285 | + } |
| 1286 | + |
| 1287 | + return localedString; |
| 1288 | + } |
| 1289 | + |
| 1290 | + public object ConvertBack(object value, Type targetType, object parameter, string language) |
| 1291 | + => throw new NotImplementedException(); |
| 1292 | + } |
| 1293 | + |
| 1294 | + public partial class FFmpegVideoDecoderModeToIndexConverter : EnumToIndexConverter<VideoDecoderMode>; |
| 1295 | + |
| 1296 | + public partial class EnumToIndexConverter<TEnum> : IValueConverter |
| 1297 | + where TEnum : struct, Enum |
| 1298 | + { |
| 1299 | + private static List<TEnum> _enums = [.. Enum.GetValues<TEnum>()]; |
| 1300 | + |
| 1301 | + public object? Convert(object? value, Type targetType, object parameter, string language) |
| 1302 | + { |
| 1303 | + if (value is not TEnum asEnum || |
| 1304 | + !Enum.IsDefined<TEnum>(asEnum)) |
| 1305 | + { |
| 1306 | + asEnum = default; |
| 1307 | + } |
| 1308 | + |
| 1309 | + int indexOf = _enums.IndexOf(asEnum); |
| 1310 | + return indexOf < 0 || indexOf > _enums.Count - 1 ? default : indexOf; |
| 1311 | + } |
| 1312 | + |
| 1313 | + public object ConvertBack(object value, Type targetType, object parameter, string language) |
| 1314 | + { |
| 1315 | + if (value is not int asIndex || |
| 1316 | + asIndex < 0 || |
| 1317 | + asIndex > _enums.Count - 1) |
| 1318 | + { |
| 1319 | + return default(TEnum); |
| 1320 | + } |
| 1321 | + |
| 1322 | + return _enums[asIndex]; |
| 1323 | + } |
| 1324 | + } |
1215 | 1325 | } |
0 commit comments