1 using System; 2 using System.Collections.Generic; 3 using System.IO; 4 using System.Linq; 5 using System.Text; 6 using System.Threading.Tasks; 7 8 namespace Mesen.GUI.Forms 9 { 10 public struct ResourcePath : IEquatable<ResourcePath> 11 { 12 public string Path { get; set; } 13 public string InnerFile { get; set; } 14 public int InnerFileIndex { get; set; } 15 16 public bool Exists { get { return File.Exists(Path); } } 17 public bool Compressed { get { return !string.IsNullOrWhiteSpace(InnerFile); } } 18 19 public string FileName { get { return Compressed ? InnerFile : System.IO.Path.GetFileName(Path); } } 20 public string Folder { get { return System.IO.Path.GetDirectoryName(Path); } } 21 22 public string ReadablePath 23 { 24 get 25 { 26 if(Compressed) { 27 return $"{Path} ({InnerFile})"; 28 } else { 29 return Path; 30 } 31 } 32 } 33 ToStringMesen.GUI.Forms.ResourcePath34 public override string ToString() 35 { 36 string resPath = Path; 37 if(Compressed) { 38 resPath += "\x1" + InnerFile; 39 if(InnerFileIndex > 0) { 40 resPath += "\x1" + (InnerFileIndex - 1).ToString(); 41 } 42 } 43 return resPath; 44 } 45 operator ResourcePathMesen.GUI.Forms.ResourcePath46 static public implicit operator ResourcePath(string path) 47 { 48 string[] tokens = path.Split('\x1'); 49 return new ResourcePath() { 50 Path = tokens[0], 51 InnerFile = tokens.Length > 1 ? tokens[1] : "", 52 InnerFileIndex = tokens.Length > 2 ? (int.Parse(tokens[2]) + 1) : 0 53 }; 54 } 55 operator stringMesen.GUI.Forms.ResourcePath56 static public implicit operator string(ResourcePath resourcePath) 57 { 58 return resourcePath.ToString(); 59 } 60 EqualsMesen.GUI.Forms.ResourcePath61 bool IEquatable<ResourcePath>.Equals(ResourcePath other) 62 { 63 return other.ToString() == this.ToString(); 64 } 65 } 66 } 67