/[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/16 23:35:21	86
+++ trunk/gr2lib/core/coretypes/implementation/grnfileinfo.cs	2010/07/16 23:37:52	87
@@ -6,7 +6,7 @@
 
 namespace gr2lib.core.coretypes.implementation
 {
-   
+
     public class grnfileinfo : Igrnfileinfo
     {
         private string fromFileName;
@@ -30,11 +30,11 @@
         private string filePath;
         private string fileName;
 
-        public grnfileinfo(string path) 
-         {
-             this.filePath = path;
-             this.fileName = FileNameFromPath(path);
-         }
+        public grnfileinfo(string path)
+        {
+            this.filePath = path;
+            this.fileName = FileNameFromPath(path);
+        }
 
         private static string FileNameFromPath(string path)
         {
@@ -47,36 +47,37 @@
 
         internal static grnfileinfo ReadFromMemory(IntPtr pointer, string path)
         {
-            if (pointer == IntPtr.Zero) return null;
-            native.grnfileinfo native = Helpers.ReadFromMemory<native.grnfileinfo>(pointer);
-            grnfileinfo managed = new grnfileinfo(path);
-            managed.NativePointer = pointer;
-
-            if (native.ArtToolInfo != IntPtr.Zero)
-            {
-                managed.ArtToolInfo = ArtToolInfo.ReadFromMemory(native.ArtToolInfo);
-            }
-            else
-            {
-                managed.ArtToolInfo = new ArtToolInfo();
-            }
-            if (native.ExporterInfo != IntPtr.Zero)
-            {
-                managed.ExporterInfo = ExporterInfo.ReadFromMemory(native.ExporterInfo);
-            }
-            else
+            try
             {
-                managed.ExporterInfo = new ExporterInfo();
-            }
+                if (pointer == IntPtr.Zero) return null;
+                native.grnfileinfo native = Helpers.ReadFromMemory<native.grnfileinfo>(pointer);
+                grnfileinfo managed = new grnfileinfo(path);
+                managed.NativePointer = pointer;
 
-            managed.fromFileName = string.IsNullOrEmpty(native.FromFileName) ? "{null}" : native.FromFileName;
-            managed.ExtendedData = native.ExtendedData;
+                if (native.ArtToolInfo != IntPtr.Zero)
+                {
+                    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();
+                }
 
-            int length = 0;
-            if (native.Textures.Pointer != IntPtr.Zero)
-            {
-                try
+                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);
@@ -91,54 +92,56 @@
                         managed.Textures[i] = Texture.ReadFromMemory(textures[i]);
                     }
                 }
-                catch (Exception ex)
+                else
                 {
-                    Console.WriteLine(ex.ToString());
+                    managed.Textures = new List<Texture>();
                 }
-            }
-            else
-            {
-                managed.Textures = new List<Texture>();
-            }
 
-            if (native.Materials.Pointer != IntPtr.Zero)
-            {
-                IntPtr[] materials = Helpers.ReadArrayFromMemory(native.Materials);
-                length = materials.Length;
-                managed.Materials = new List<Material>(length);
-                foreach (IntPtr ptr in materials)
+                if (native.Materials.Pointer != IntPtr.Zero)
                 {
-                    managed.Materials.Add(new Material());
+                    IntPtr[] materials = Helpers.ReadArrayFromMemory(native.Materials);
+                    length = materials.Length;
+                    managed.Materials = new List<Material>(length);
+                    foreach (IntPtr ptr in materials)
+                    {
+                        managed.Materials.Add(new Material());
+                    }
+                    for (int i = 0; i < length; i++)
+                    {
+                        managed.Materials[i] = Material.ReadFromMemory(materials[i]);
+                    }
                 }
-                for (int i = 0; i < length; i++)
+                else
                 {
-                    managed.Materials[i] = Material.ReadFromMemory(materials[i]);
+                    managed.Materials = new List<Material>();
                 }
-            }
-            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)
+                if (native.Skeletons.Pointer != IntPtr.Zero)
                 {
-                    managed.Skeletons.Add(new Skeleton());
+                    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]));
+                    }
                 }
-                for (int i = 0; i < length; i++)
+                else
                 {
-                    managed.Skeletons[i] = (Skeleton.ReadFromMemory(skeletons[i]));
+                    managed.Skeletons = new List<Skeleton>();
                 }
+
+                return managed;
             }
-            else
+            catch (Exception ex)
             {
-                managed.Skeletons = new List<Skeleton>();
+                Console.WriteLine(ex.ToString());
+                return default(grnfileinfo);
             }
-            return managed;
         }
         public static grnfileinfo ReadFromFile(string fileName)
         {
@@ -161,6 +164,7 @@
             catch (Exception ex)
             {
                 Console.WriteLine(ex.ToString());
+                return default(grnfileinfo);
             }
         }
 

 

  ViewVC Help
Powered by ViewVC 1.1.22