Пример #1
0
        public bool Load(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                return(false);
            }

            if (GraphInst != null)
            {
                GraphInst.OnGraphParameterUpdate -= GraphInst_OnGraphParameterUpdate;
                GraphInst.Dispose();
                GraphInst = null;
            }

            nameMap = new Dictionary <string, GraphParameterValue>();

            if (path.Contains("Materia::Layer::"))
            {
                isLayer = true;
                return(TryAndLoadLayer(path));
            }

            isLayer = false;
            return(TryAndLoadFile(path));
        }
Пример #2
0
        public override void Dispose()
        {
            base.Dispose();

            if (GraphInst != null)
            {
                GraphInst.Dispose();
                GraphInst = null;
            }
        }
Пример #3
0
        public override void Dispose()
        {
            base.Dispose();

            GraphParameterValue.OnGraphParameterUpdate -= GraphParameterValue_OnGraphParameterUpdate;

            if (GraphInst != null)
            {
                GraphInst.Dispose();
                GraphInst = null;
            }
        }
Пример #4
0
        //used for initial loading
        //not used for restoring from .materia
        public bool Load(string path)
        {
            if (GraphInst != null)
            {
                GraphData = null;

                GraphInst.Dispose();
                GraphInst = null;
            }

            if (File.Exists(path) && Path.GetExtension(path).ToLower().Contains("mtg"))
            {
                this.path = path;

                string nm = Path.GetFileNameWithoutExtension(path);

                Name = nm;

                //the width and height here don't matter
                GraphInst = new Graph(nm);

                GraphData = File.ReadAllText(path);

                GraphInst.FromJson(GraphData);
                GraphInst.SetJsonReadyParameters(jsonParameters);
                GraphInst.SetJsonReadyCustomParameters(jsonCustomParameters);
                GraphInst.RandomSeed = randomSeed;

                //now do real initial resize
                GraphInst.ResizeWith(width, height);

                //mark as readonly
                GraphInst.ReadOnly = true;

                //setup inputs and outputs

                Setup();

                return(true);
            }
            else
            {
                this.path = null;
            }

            return(false);
        }
Пример #5
0
        public override void Dispose()
        {
            if (child != null)
            {
                child.Dispose();
                child = null;
            }

            base.Dispose();

            if (GraphInst != null)
            {
                GraphInst.OnGraphParameterUpdate -= GraphParameterValue_OnGraphParameterUpdate;
                GraphInst.Dispose();
                GraphInst = null;
            }
        }
Пример #6
0
        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;
            }
        }
Пример #7
0
        public bool Load(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                return(false);
            }

            isArchive = path.ToLower().EndsWith(".mtga");

            //convert path to a relative resource path
            string relative = Path.Combine("resources", Path.GetFileName(path));

            if (GraphInst != null)
            {
                GraphData = null;
                GraphInst.OnGraphParameterUpdate -= GraphParameterValue_OnGraphParameterUpdate;
                GraphInst.Dispose();
                GraphInst = null;
            }

            nameMap = new Dictionary <string, GraphParameterValue>();

            //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);
                        }
                        else
                        {
                            this.path = null;
                        }
                    }
                    else
                    {
                        this.path = null;
                    }
                }
                else
                {
                    this.path = null;
                }

                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);
                    }
                    else
                    {
                        this.path = null;
                    }
                }
                else
                {
                    this.path = null;
                }
            }
            //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
                    {
                        this.path = null;
                    }
                }
                else
                {
                    this.path = null;
                }
            }
            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);
            }
            else
            {
                this.path = null;
            }

            return(false);
        }