Example #1
0
        private void ReadMeshFile()
        {
            if (mesh == null && meshes == null)
            {
                if (archive != null && !string.IsNullOrEmpty(relativePath) && Resource)
                {
                    archive.Open();
                    List <MTGArchive.ArchiveFile> files = archive.GetAvailableFiles();

                    var m = files.Find(f => f.path.Equals(relativePath));
                    if (m != null)
                    {
                        using (Stream ms = m.GetStream())
                        {
                            RSMI.Importer imp = new Importer();
                            meshes = imp.Parse(ms);
                            archive.Close();
                            return;
                        }
                    }

                    archive.Close();
                }


                if (!string.IsNullOrEmpty(path) && File.Exists(path))
                {
                    RSMI.Importer imp = new Importer();
                    meshes = imp.Parse(path);
                }
                else if (!string.IsNullOrEmpty(relativePath) && ParentGraph != null && !string.IsNullOrEmpty(ParentGraph.CWD) && File.Exists(System.IO.Path.Combine(ParentGraph.CWD, relativePath)))
                {
                    var p = System.IO.Path.Combine(ParentGraph.CWD, relativePath);

                    RSMI.Importer imp = new Importer();
                    meshes = imp.Parse(p);
                }
            }
        }
Example #2
0
        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);
        }
Example #3
0
        private void LoadBitmap()
        {
            try
            {
                if (archive != null && !string.IsNullOrEmpty(relativePath) && Resource)
                {
                    archive.Open();
                    List <MTGArchive.ArchiveFile> files = archive.GetAvailableFiles();

                    var m = files.Find(f => f.path.Equals(relativePath));
                    if (m != null)
                    {
                        using (Stream ms = m.GetStream())
                            using (Bitmap bmp = (Bitmap)Bitmap.FromStream(ms))
                            {
                                if (bmp != null && bmp.Width > 0 && bmp.Height > 0)
                                {
                                    width  = bmp.Width;
                                    height = bmp.Height;
                                    brush  = RawBitmap.FromBitmap(bmp);
                                    archive.Close();
                                    return;
                                }
                            }
                    }

                    archive.Close();
                }

                if (!string.IsNullOrEmpty(path) && File.Exists(path))
                {
                    using (Bitmap bmp = (Bitmap)Bitmap.FromFile(path))
                    {
                        if (bmp != null && bmp.Width > 0 && bmp.Height > 0)
                        {
                            width  = bmp.Width;
                            height = bmp.Height;

                            brush = RawBitmap.FromBitmap(bmp);
                        }
                    }
                }
                else if (!string.IsNullOrEmpty(relativePath) && ParentGraph != null && !string.IsNullOrEmpty(ParentGraph.CWD) && File.Exists(System.IO.Path.Combine(ParentGraph.CWD, relativePath)))
                {
                    using (Bitmap bmp = (Bitmap)Bitmap.FromFile(System.IO.Path.Combine(ParentGraph.CWD, relativePath)))
                    {
                        if (bmp != null && bmp.Width > 0 && bmp.Height > 0)
                        {
                            width  = bmp.Width;
                            height = bmp.Height;

                            brush = RawBitmap.FromBitmap(bmp);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }