/[gr2lib]/trunk/gr2lib/core/coretypes/implementation/grnfileinfo.cs
ViewVC logotype

Diff of /trunk/gr2lib/core/coretypes/implementation/grnfileinfo.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/gr2lib/core/coretypes/implementation/grnfileinfo.cs	2010/07/15 23:36:04	82
+++ trunk/gr2lib/core/coretypes/implementation/grnfileinfo.cs	2010/07/16 21:26:08	83
@@ -14,9 +14,9 @@
         private ExporterInfo _ExporterInfo;
         private List<Texture> _Textures;
         private List<Material> _Materials;
+        private List<Skeleton> _Skeletons;
 
 
-        //Skeletons
         //VertexDatas
         //TriTopologies
         //Meshes
@@ -48,7 +48,7 @@
         internal static grnfileinfo ReadFromMemory(IntPtr pointer, string path)
         {
             if (pointer == IntPtr.Zero) return null;
-            native.FileInfo native = Helpers.ReadFromMemory<native.FileInfo>(pointer);
+            native.grnfileinfo native = Helpers.ReadFromMemory<native.grnfileinfo>(pointer);
             grnfileinfo managed = new grnfileinfo(path);
             managed.NativePointer = pointer;
 
@@ -56,28 +56,48 @@
             {
                 managed.ArtToolInfo = ArtToolInfo.ReadFromMemory(native.ArtToolInfo);
             }
+            else
+            {
+                managed.ArtToolInfo = new ArtToolInfo();
+            }
             if (native.ExporterInfo != IntPtr.Zero)
             {
                 managed.ExporterInfo = ExporterInfo.ReadFromMemory(native.ExporterInfo);
             }
+            else
+            {
+                managed.ExporterInfo = new ExporterInfo();
+            }
 
             managed.fromFileName = string.IsNullOrEmpty(native.FromFileName) ? "{null}" : native.FromFileName;
+            managed.ExtendedData = native.ExtendedData;
 
             int length = 0;
             if (native.Textures.Pointer != IntPtr.Zero)
             {
-                IntPtr[] textures = Helpers.ReadArrayFromMemory(native.Textures);
-                length = textures.Length;
-                managed.Textures = new List<Texture>(length);
-                foreach (IntPtr ptr in textures)
+                try
                 {
-                    managed.Textures.Add(new Texture());
+                    IntPtr[] textures = Helpers.ReadArrayFromMemory(native.Textures);
+                    length = textures.Length;
+                    managed.Textures = new List<Texture>(length);
+                    foreach (IntPtr ptr in textures)
+                    {
+                        managed.Textures.Add(new Texture());
+                    }
+                    for (int i = 0; i < length; i++)
+                    {
+                        managed.Textures[i] = Texture.ReadFromMemory(textures[i]);
+                    }
                 }
-                for (int i = 0; i < length; i++)
+                catch (Exception ex)
                 {
-                    managed.Textures[i] = Texture.ReadFromMemory(textures[i]);
+                    Console.WriteLine(ex.ToString());
                 }
             }
+            else
+            {
+                managed.Textures = new List<Texture>();
+            }
 
             if (native.Materials.Pointer != IntPtr.Zero)
             {
@@ -93,6 +113,29 @@
                     managed.Materials[i] = Material.ReadFromMemory(materials[i]);
                 }
             }
+            else
+            {
+                managed.Materials = new List<Material>();
+            }
+
+            if (native.Skeletons.Pointer != IntPtr.Zero)
+            {
+                IntPtr[] skeletons = Helpers.ReadArrayFromMemory(native.Skeletons);
+                length = skeletons.Length;
+                managed.Skeletons = new List<Skeleton>(length);
+                foreach (IntPtr ptr in skeletons)
+                {
+                    managed.Skeletons.Add(new Skeleton());
+                }
+                for (int i = 0; i < length; i++)
+                {
+                    managed.Skeletons[i] = (Skeleton.ReadFromMemory(skeletons[i]));
+                }
+            }
+            else
+            {
+                managed.Skeletons = new List<Skeleton>();
+            }
             return managed;
         }
         public static grnfileinfo ReadFromFile(string fileName)
@@ -103,12 +146,29 @@
             {
                 Console.WriteLine("Error: unable to load {0} as a Granny file.", fileName);
             }
+            grnfileinfo info = null;
 
-            IntPtr pinfo = coreapi.GetFileInfo(file);
-            grnfileinfo info = ReadFromMemory(pinfo, fileName);
-            coreapi.FreeFile(file);
+            try
+            {
+                IntPtr pinfo = coreapi.GetFileInfo(file);
+                info = ReadFromMemory(pinfo, fileName);
+                coreapi.FreeFile(file);
 
-            return info;
+                return info;
+            }
+            catch (Exception ex)
+            {
+                try
+                {
+                    coreapi.FreeFile(file);
+                    return null;
+                }
+                catch (Exception ex1)
+                {
+                    Exception _ex = new Exception(ex.Message, ex1);
+                    throw _ex;
+                }
+            }
         }
 
 
@@ -118,6 +178,7 @@
         public string FromFileName { get { return fromFileName; } set { fromFileName = value; } }
         public List<Texture> Textures { get { return _Textures; } set { _Textures = value; } }
         public List<Material> Materials { get { return _Materials; } set { _Materials = value; } }
+        public List<Skeleton> Skeletons { get { return _Skeletons; } set { _Skeletons = value; } }
         #endregion
 
         #region INativePointer Members

 

  ViewVC Help
Powered by ViewVC 1.1.22