void HandleOpen(string path) { HideStartup(); if (File.Exists(path)) { string originalPath = path; string tempFolder = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "temp", System.IO.Path.GetFileNameWithoutExtension(path)); bool isFromArchive = false; if (System.IO.Path.GetExtension(path).Contains("mtga")) { MTGArchive archive = new MTGArchive(path); if (!Directory.Exists(tempFolder)) { Directory.CreateDirectory(tempFolder); } if (!archive.UnzipTo(tempFolder)) { Log.Error("Failed to uncompress materia archive"); return; } isFromArchive = true; } UIGraph g = NewGraph(); if (g != null) { if (isFromArchive) { g.FromArchive = isFromArchive; g.FromArchivePath = path; path = System.IO.Path.Combine(tempFolder, System.IO.Path.GetFileName(path).Replace(".mtga", ".mtg")); } g.LoadGraph(path); var doc = documents[GraphDocuments.SelectedContentIndex]; doc.Title = g.GraphName; Log.Info("Opened Graph {0}", g.GraphName); recent.Add(originalPath); BuildRecentSubMenu(); } } else { Log.Warn("File does not exist: " + path); } }
public void FromJson(string json, Graph parentGraph, MTGArchive archive = null) { LayerData d = JsonConvert.DeserializeObject <LayerData>(json); if (d == null) { return; } if (d.blendModes != null) { foreach (LayerPasses pass in d.blendModes.Keys) { blendModes[pass] = d.blendModes[pass]; } } if (d.opacityModes != null) { foreach (LayerPasses pass in d.opacityModes.Keys) { opacityModes[pass] = d.opacityModes[pass]; } } Name = d.name; visible = d.visible; width = d.width; height = d.height; Id = d.id; Graph temp = new ImageGraph(Name, width, height, parentGraph); temp.FromJson(d.core, archive); Core = temp; if (!string.IsNullOrEmpty(d.mask)) { Node n = null; if (Core.NodeLookup.TryGetValue(d.mask, out n)) { Mask = n; } } if (parentGraph != null) { parentGraph.LayerLookup[Id] = this; } }
public override void Dispose() { if (child != null) { child.Dispose(); child = null; } base.Dispose(); if (GraphInst != null) { GraphInst.OnGraphParameterUpdate -= GraphParameterValue_OnGraphParameterUpdate; GraphInst.Dispose(); GraphInst = null; } }
public override void Dispose() { if (parentGraph != null) { parentGraph.OnGraphParameterUpdate -= ParentGraph_OnGraphParameterUpdate; } if (child != null) { child.Dispose(); child = null; } base.Dispose(); if (GraphInst != null) { GraphInst.OnGraphParameterUpdate -= GraphInst_OnGraphParameterUpdate; GraphInst.Dispose(); GraphInst = null; } }
public abstract void FromJson(string data, MTGArchive archive = null);
public override void FromJson(string data, MTGArchive arch = null) { archive = arch; FromJson(data); }
protected bool TryAndLoadFile(string path) { isArchive = path.ToLower().EndsWith(".mtga"); //convert path to a relative resource path string relative = Path.Combine("resources", Path.GetFileName(path)); //handle archives within archives if (isArchive && archive != null) { archive.Open(); var files = archive.GetAvailableFiles(); var m = files.Find(f => f.path.Equals(relative)); if (m != null) { loading = true; child = new MTGArchive(relative, m.ExtractBinary()); child.Open(); var childFiles = child.GetAvailableFiles(); if (childFiles != null) { var mtg = childFiles.Find(f => f.path.ToLower().EndsWith(".mtg")); if (mtg != null) { loading = true; this.path = path; string nm = Path.GetFileNameWithoutExtension(path); Name = nm; GraphData = mtg.ExtractText(); child.Close(); PrepareGraph(); archive.Close(); loading = false; return(true); } } } archive.Close(); } //handle absolute path to archive when not in another archive else if (File.Exists(path) && isArchive && archive == null) { loading = true; child = new MTGArchive(path); child.Open(); var childFiles = child.GetAvailableFiles(); if (childFiles != null) { var mtg = childFiles.Find(f => f.path.ToLower().EndsWith(".mtg")); if (mtg != null) { loading = true; this.path = path; string nm = Path.GetFileNameWithoutExtension(path); Name = nm; GraphData = mtg.ExtractText(); child.Close(); PrepareGraph(); loading = false; return(true); } } } //otherwise try relative storage for the archive when not in another archive else if (isArchive && archive == null && ParentGraph != null && !string.IsNullOrEmpty(ParentGraph.CWD) && File.Exists(Path.Combine(ParentGraph.CWD, relative))) { string realPath = Path.Combine(ParentGraph.CWD, relative); child = new MTGArchive(realPath); child.Open(); var childFiles = child.GetAvailableFiles(); if (childFiles != null) { var mtg = childFiles.Find(f => f.path.ToLower().EndsWith(".mtg")); if (mtg != null) { loading = true; this.path = path; string nm = Path.GetFileNameWithoutExtension(path); Name = nm; GraphData = mtg.ExtractText(); child.Close(); PrepareGraph(); loading = false; return(true); } } } else if (!isArchive && File.Exists(path) && Path.GetExtension(path).ToLower().EndsWith("mtg")) { loading = true; this.path = path; string nm = Path.GetFileNameWithoutExtension(path); Name = nm; GraphData = File.ReadAllText(path); PrepareGraph(); loading = false; return(true); } return(false); }