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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 82 - (show annotations) (download)
Thu Jul 15 23:36:04 2010 UTC (10 years, 7 months ago) by william
File size: 4783 byte(s)
move ExtenededData to it's own interface and make the classes, that need it, implement it.

1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using gr2lib.core.helpers;
5 using gr2lib.core.interfaces;
6
7 namespace gr2lib.core.coretypes.implementation
8 {
9
10 public class grnfileinfo : Igrnfileinfo
11 {
12 private string fromFileName;
13 private ArtToolInfo _ArtToolInfo;
14 private ExporterInfo _ExporterInfo;
15 private List<Texture> _Textures;
16 private List<Material> _Materials;
17
18
19 //Skeletons
20 //VertexDatas
21 //TriTopologies
22 //Meshes
23 //Models
24 //TrackGroups
25 //Animations
26 //ExtendedData
27
28
29
30 private string filePath;
31 private string fileName;
32
33 public grnfileinfo(string path)
34 {
35 this.filePath = path;
36 this.fileName = FileNameFromPath(path);
37 }
38
39 private static string FileNameFromPath(string path)
40 {
41 int lastSlash = path.LastIndexOf('\\');
42 if (lastSlash > 0) return path.Substring(lastSlash + 1);
43 lastSlash = path.LastIndexOf('/');
44 if (lastSlash > 0) return path.Substring(lastSlash + 1);
45 return path;
46 }
47
48 internal static grnfileinfo ReadFromMemory(IntPtr pointer, string path)
49 {
50 if (pointer == IntPtr.Zero) return null;
51 native.FileInfo native = Helpers.ReadFromMemory<native.FileInfo>(pointer);
52 grnfileinfo managed = new grnfileinfo(path);
53 managed.NativePointer = pointer;
54
55 if (native.ArtToolInfo != IntPtr.Zero)
56 {
57 managed.ArtToolInfo = ArtToolInfo.ReadFromMemory(native.ArtToolInfo);
58 }
59 if (native.ExporterInfo != IntPtr.Zero)
60 {
61 managed.ExporterInfo = ExporterInfo.ReadFromMemory(native.ExporterInfo);
62 }
63
64 managed.fromFileName = string.IsNullOrEmpty(native.FromFileName) ? "{null}" : native.FromFileName;
65
66 int length = 0;
67 if (native.Textures.Pointer != IntPtr.Zero)
68 {
69 IntPtr[] textures = Helpers.ReadArrayFromMemory(native.Textures);
70 length = textures.Length;
71 managed.Textures = new List<Texture>(length);
72 foreach (IntPtr ptr in textures)
73 {
74 managed.Textures.Add(new Texture());
75 }
76 for (int i = 0; i < length; i++)
77 {
78 managed.Textures[i] = Texture.ReadFromMemory(textures[i]);
79 }
80 }
81
82 if (native.Materials.Pointer != IntPtr.Zero)
83 {
84 IntPtr[] materials = Helpers.ReadArrayFromMemory(native.Materials);
85 length = materials.Length;
86 managed.Materials = new List<Material>(length);
87 foreach (IntPtr ptr in materials)
88 {
89 managed.Materials.Add(new Material());
90 }
91 for (int i = 0; i < length; i++)
92 {
93 managed.Materials[i] = Material.ReadFromMemory(materials[i]);
94 }
95 }
96 return managed;
97 }
98 public static grnfileinfo ReadFromFile(string fileName)
99 {
100 IntPtr file = coreapi.GrannyReadEntireFile(fileName);
101
102 if (file == null || file == IntPtr.Zero)
103 {
104 Console.WriteLine("Error: unable to load {0} as a Granny file.", fileName);
105 }
106
107 IntPtr pinfo = coreapi.GetFileInfo(file);
108 grnfileinfo info = ReadFromMemory(pinfo, fileName);
109 coreapi.FreeFile(file);
110
111 return info;
112 }
113
114
115 #region Igrnfileinfo Members
116 public ArtToolInfo ArtToolInfo { get { return _ArtToolInfo; } set { _ArtToolInfo = value; } }
117 public ExporterInfo ExporterInfo { get { return _ExporterInfo; } set { _ExporterInfo = value; } }
118 public string FromFileName { get { return fromFileName; } set { fromFileName = value; } }
119 public List<Texture> Textures { get { return _Textures; } set { _Textures = value; } }
120 public List<Material> Materials { get { return _Materials; } set { _Materials = value; } }
121 #endregion
122
123 #region INativePointer Members
124 private IntPtr _NativePointer;
125 public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } }
126 #endregion
127
128 #region IExtendedData Members
129 private IntPtr _ExtendedData;
130 public IntPtr ExtendedData { get { return _ExtendedData; } set { _ExtendedData = value; } }
131 #endregion
132 }
133 }

  ViewVC Help
Powered by ViewVC 1.1.22