File.vala 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using Invercargill;
  2. namespace Usm {
  3. public class ManifestFile {
  4. public string path { get; set; }
  5. public ManifestFileType file_type { get; set; }
  6. public string? destination { get; set; }
  7. public Vector<RemoveType>? keep_on { get; set; }
  8. public Vector<InstallType>? skip_for { get; set; }
  9. public static PropertyMapper<ManifestFile> get_mapper() {
  10. return new PropertyMapperBuilder<ManifestFile>()
  11. .map<string>("path", o => o.path, (o, v) => o.path = v)
  12. .map<string>("type", o => o.file_type.to_string(), (o, v) => o.file_type = ManifestFileType.from_string(v))
  13. .map<string>("dest", o => o.destination, (o, v) => o.destination = v, false)
  14. .map_many<string>("keepOn", o => o.keep_on.select<string>(i => i.to_string()), (o, v) => o.keep_on = v.convert<RemoveType>(i => RemoveType.from_string(i)).to_vector(), false)
  15. .map_many<string>("skipFor", o => o.skip_for.select<string>(i => i.to_string()), (o, v) => o.skip_for = v.convert<InstallType>(i => InstallType.from_string(i)).to_vector(), false)
  16. .set_constructor(() => new ManifestFile())
  17. .build();
  18. }
  19. public ManifestFile.from_string(string str) {
  20. path = str;
  21. file_type = ManifestFileType.REGULAR;
  22. }
  23. }
  24. public enum ManifestFileType {
  25. REGULAR,
  26. DIRECTORY,
  27. SYMBOLIC_LINK;
  28. public string to_string() {
  29. switch(this) {
  30. case ManifestFileType.REGULAR:
  31. return "reg";
  32. case ManifestFileType.DIRECTORY:
  33. return "dir";
  34. case ManifestFileType.SYMBOLIC_LINK:
  35. return "lnk";
  36. default:
  37. assert_not_reached();
  38. }
  39. }
  40. public static ManifestFileType from_string(string str) throws ManifestError {
  41. switch(str) {
  42. case "reg":
  43. return ManifestFileType.REGULAR;
  44. case "dir":
  45. return ManifestFileType.DIRECTORY;
  46. case "lnk":
  47. return ManifestFileType.SYMBOLIC_LINK;
  48. default:
  49. throw new ManifestError.INVALID_FILE_TYPE(@"Unknown file type \"$str\".");
  50. }
  51. }
  52. }
  53. }