123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- using Invercargill;
- namespace Usm {
- public class ManifestFile {
- public ManifestFilePathBase path_base { get; set; }
- public string path { get; set; }
- public ManifestFileType file_type { get; set; }
- public string? destination { get; set; }
- public Vector<RemoveType>? keep_on { get; set; }
- public Vector<InstallType>? skip_for { get; set; }
- public static PropertyMapper<ManifestFile> get_mapper() {
- return PropertyMapper.build_for<ManifestFile>(cfg => {
- cfg.map<string>("path", o => o.path, (o, v) => o.path = v);
- cfg.map<string>("pathBase", o => o.path_base.to_string(), (o, v) => o.path_base = ManifestFilePathBase.from_string(v));
- cfg.map<string>("type", o => o.file_type.to_string(), (o, v) => o.file_type = ManifestFileType.from_string(v));
- cfg.map<string>("dest", o => o.destination, (o, v) => o.destination = v, false);
- cfg.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);
- cfg.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);
- cfg.set_constructor(() => new ManifestFile());
- });
- }
- public ManifestFile.from_string(string str) throws ManifestError {
- var parts = str.split(":", 2);
- path_base = ManifestFilePathBase.from_string(parts[0]);
- file_type = ManifestFileType.REGULAR;
- if(path_base == ManifestFilePathBase.AS_EXPECTED) {
- path = "";
- return;
- }
- if(parts.length != 2) {
- throw new ManifestError.INVALID_FILE_PATH("No file path provided");
- }
- path = parts[1];
- }
-
- }
- public enum ManifestFileType {
- REGULAR,
- DIRECTORY,
- SYMBOLIC_LINK;
- public string to_string() {
- switch(this) {
- case ManifestFileType.REGULAR:
- return "reg";
- case ManifestFileType.DIRECTORY:
- return "dir";
- case ManifestFileType.SYMBOLIC_LINK:
- return "lnk";
- default:
- assert_not_reached();
- }
- }
- public static ManifestFileType from_string(string str) throws ManifestError {
- switch(str) {
- case "reg":
- return ManifestFileType.REGULAR;
- case "dir":
- return ManifestFileType.DIRECTORY;
- case "lnk":
- return ManifestFileType.SYMBOLIC_LINK;
- default:
- throw new ManifestError.INVALID_FILE_TYPE(@"Unknown file type \"$str\".");
- }
- }
- }
- public enum ManifestFilePathBase {
- SOURCE,
- BUILD,
- INSTALL,
- AS_EXPECTED;
- public string to_string() {
- switch(this) {
- case ManifestFilePathBase.SOURCE:
- return "source";
- case ManifestFilePathBase.BUILD:
- return "build";
- case ManifestFilePathBase.INSTALL:
- return "install";
- case ManifestFilePathBase.AS_EXPECTED:
- return "as-expected";
- default:
- assert_not_reached();
- }
- }
- public static ManifestFilePathBase from_string(string str) throws ManifestError {
- switch(str) {
- case "source":
- return ManifestFilePathBase.SOURCE;
- case "build":
- return ManifestFilePathBase.BUILD;
- case "install":
- return ManifestFilePathBase.INSTALL;
- case "as-expected":
- return ManifestFilePathBase.AS_EXPECTED;
- default:
- throw new ManifestError.INVALID_PATH_BASE(@"Unknown path base \"$str\".");
- }
- }
- }
- }
|