//this ctor is used when reading files.xml FileNode(XmlReader x, FileNode parent, FilesModel model) { _model = model; if (parent == null) //the root node { if (x.Name != "files") { throw new ArgumentException("XML root element name must be 'files'"); } x["max-i"].ToInt(out uint u); _model.MaxId = u; } else { _type = x.Name switch { "d" => EFileType.Folder, "s" => EFileType.Script, "c" => EFileType.Class, "n" => EFileType.NotCodeFile, _ => throw new ArgumentException("XML element name must be 'd', 's', 'c' or 'n'"), }; uint id = 0, testScriptId = 0; string linkTarget = null, icon = null; while (x.MoveToNextAttribute()) { var v = x.Value; switch (x.Name) { case "n": _name = v; break; case "i": v.ToInt(out id); break; case "f": _flags = (_Flags)v.ToInt(); break; case "path": linkTarget = v; break; case "icon": icon = v; break; case "run": v.ToInt(out testScriptId); break; } } if (_name.NE()) { throw new ArgumentException("no 'n' attribute in XML"); } _id = _model.AddGetId(this, id); _CtorMisc(linkTarget); if (icon != null && linkTarget == null) { _iconOrLinkTarget = icon; } if (testScriptId != 0) { _testScriptId = testScriptId; } } }
//this ctor is used when copying or importing a workspace. //Deep-copies fields from f, except _model, _name, _id (generates new) and _testScriptId. FileNode(FilesModel model, FileNode f, string name) { _model = model; _name = name; _type = f._type; _state = f._state; _flags = f._flags; _iconOrLinkTarget = f._iconOrLinkTarget; _id = _model.AddGetId(this); }
//this ctor is used when copying or importing a workspace. //Deep-copies fields from f, except _model, _name, _id (generates new) and _testScriptId. FileNode(FilesModel model, FileNode f, string name) { _model = model; _SetName(name); _type = f._type; _state = f._state; _flags = f._flags; _linkTarget = f._linkTarget; _icon = f.CustomIconName; _id = _model.AddGetId(this); }
//this ctor is used when reading files.xml FileNode(XmlReader x, FileNode parent, FilesModel model) { _model = model; if (parent == null) //the root node { if (x.Name != "files") { throw new ArgumentException("XML root element name must be 'files'"); } x["max-i"].ToInt(out uint u); _model.MaxId = u; } else { _type = XmlTagToFileType(x.Name, canThrow: true); uint id = 0; while (x.MoveToNextAttribute()) { var v = x.Value; if (v.NE()) { continue; } switch (x.Name) { case "n": _SetName(v); break; case "i": v.ToInt(out id); break; case "f": _flags = (_Flags)v.ToInt(); break; case "path": if (!IsFolder) { _linkTarget = v; } break; case "icon": _icon = v; break; case "run": v.ToInt(out _testScriptId); break; } } if (_name == null) { throw new ArgumentException("no 'n' attribute in XML"); } _id = _model.AddGetId(this, id); } }