Nice little directory browser :D
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

minor/Utils: cleanups

+6 -52
+6 -52
Utils.cs
··· 33 33 namespace Utatane; 34 34 35 35 public static class Utils { 36 - public static String Root = Environment.GetEnvironmentVariable("nhnd_Utatane_ROOT") ?? throw new NullReferenceException("env nhnd_Utatane_ROOT not set!"); 36 + public static String Root = Environment.GetEnvironmentVariable("nhnd_Utatane_ROOT") 37 + ?? throw new NullReferenceException("env nhnd_Utatane_ROOT not set!"); 37 38 38 39 public static List<String> DoNotServe = ["*cookies.txt"]; 39 40 ··· 97 98 } 98 99 99 100 public static String AbbrIconPlain(String text, String symbol) { 100 - RenderTreeBuilder renderer = new RenderTreeBuilder(); 101 - 102 101 var abbr = new TagBuilder("abbr"); 103 102 abbr.Attributes.Add("title", text); 104 103 abbr.InnerHtml.Append(symbol); 105 104 106 - using var writer = new System.IO.StringWriter(); 105 + using var writer = new StringWriter(); 107 106 abbr.WriteTo(writer, System.Text.Encodings.Web.HtmlEncoder.Default); 108 107 109 108 return writer.ToString(); 110 109 } 111 110 112 - private static readonly Dictionary<String, MarkupString> ExtToAbbr = new Dictionary<String, MarkupString> { 111 + private static readonly Dictionary<String, MarkupString> ExtToAbbr = new() { 113 112 #region Extension <--> Icon mappings 114 113 { ".avc", AbbrIcon("Video file", "🎞️") }, 115 114 { ".flv", AbbrIcon("Video file", "🎞️") }, ··· 269 268 }; 270 269 271 270 public static MarkupString GetIconForFileType(FileSystemInfo fsi) { 272 - if (fsi is DirectoryInfo dir) { 271 + if (fsi is DirectoryInfo) { 273 272 return AbbrIcon("Directory", "📁"); 274 273 } 275 274 ··· 293 292 // DO NOT mark these as `CharSet = CharSet.Unicode`, this will break things!! 294 293 [DllImport("libc.so.6")] 295 294 private static extern int euidaccess(String pathname, int mode); 296 - 297 - [DllImport("libc.so.6", SetLastError=true)] 298 - private static extern String? realpath(String pathname, IntPtr resolved); 299 295 #pragma warning restore CA2101 300 296 301 297 private const int R_OK = 0b0100; ··· 359 355 } 360 356 361 357 // the file at real might not actually exist, but we want to return it anyways 362 - return new FileInfo(real); 358 + return new FileInfo(real ?? ""); 363 359 } 364 360 365 361 // TODO: uhh this might loop if the target doesnt exist ··· 394 390 case RenderTreeFrameType.Text: 395 391 builder.Append(f.TextContent); 396 392 break; 397 - default: 398 - break; 399 393 } 400 394 }); 401 395 ··· 416 410 return Regex.IsMatch(str, regex); 417 411 } 418 412 } 419 - 420 - // extension(OneResult<T1> oneResult) { 421 - // public bool Is<Tx>() where Tx : T1 { 422 - // return typeof(Tx) is typeof(T1) ? oneResult.IsT1 : false; 423 - // } 424 - // 425 - // public Tx As<Tx>() where Tx : T1 { 426 - // return oneResult.IsT1 ? (Tx)oneResult.AsT1() : throw new InvalidOperationException($"Cannot cast value to type {nameof(Tx)}"); 427 - // } 428 - // } 429 - // 430 - // extension(OneResult<T1, T2> oneResult) { 431 - // public bool Is<Tx>() where Tx : T2 { 432 - // return typeof(Tx) is typeof(T2) ? oneResult.IsT2 : false; 433 - // } 434 - // 435 - // public Tx As<Tx>() where Tx : T2 { 436 - // return oneResult.IsT2 ? (Tx)oneResult.AsT2() : throw new InvalidOperationException($"Cannot cast value to type {nameof(Tx)}"); 437 - // } 438 - // } 439 - // 440 - // extension(OneResult<T1, T2, T3> oneResult) { 441 - // public bool Is<Tx>() where Tx : T3 { 442 - // return typeof(Tx) is typeof(T3) ? oneResult.IsT3 : false; 443 - // } 444 - // 445 - // public Tx As<Tx>() where Tx : T3 { 446 - // return oneResult.IsT3 ? (Tx)oneResult.AsT3() : throw new InvalidOperationException($"Cannot cast value to type {nameof(Tx)}"); 447 - // } 448 - // } 449 - // 450 - // extension(OneResult<T1, T2, T3, T4> oneResult) { 451 - // public bool Is(Type tx) where Tx : T4 { 452 - // return typeof(Tx) is typeof(T4) ? oneResult.IsT4 : false; 453 - // } 454 - // 455 - // public Tx As<Tx>() where Tx : T4 { 456 - // return oneResult.IsT4 ? (Tx)oneResult.AsT4() : throw new InvalidOperationException($"Cannot cast value to type {nameof(Tx)}"); 457 - // } 458 - // } 459 413 }