/[gr2lib]/trunk/gr2lib_UnitTest/Program.cs
ViewVC logotype

Contents of /trunk/gr2lib_UnitTest/Program.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 96 - (show annotations) (download)
Sat Jul 17 05:11:13 2010 UTC (9 years, 4 months ago) by william
File size: 15453 byte(s)
bulk commit:

*Update structs to use simple datatypes
*Add new Classes, etc, etc

1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4
5 using gr2lib.core;
6 //using gr2lib.core.coretypes;
7 using gr2lib.core.apiversion;
8 using gr2lib.core.exceptions;
9 using gr2lib.core.helpers;
10 using gr2lib.core.coretypes.implementation;
11 using System.Runtime.CompilerServices;
12 using gr2lib.core.header;
13
14 namespace gr2lib_UnitTest
15 {
16
17 class Program
18 {
19 static void Main(string[] args)
20 {
21 string GrannyFilename = shared.GRANNY_TEST_FILE;
22 try
23 {
24 #region Check Granny2 API Version
25 // Setup access to check loaded Granny2 API Version
26 granny2apiversion apiversion = new granny2apiversion(shared.EXPECTED_API_VERSION);
27
28 // Check if the Loaded API Version Matches
29 if (!apiversion.apiversionsmatch)
30 {
31 // the loaded version does not match
32 Console.WriteLine("Warning:\n" +
33 "\t Loaded Granny2 DLL Version: " + apiversion.apiversion.version + "\n" +
34 "\t Expected Version: " + apiversion.expectedapiversion.version);
35 // return from void to exit application
36 return;
37 }
38 else
39 {
40 // the loaded version matches
41 Console.WriteLine("Loaded granny2.dll: " + apiversion.apiversion.version);
42 }
43 #endregion
44
45 #region Parse Commandline
46 if (args.Length == 1)
47 {
48 GrannyFilename = args[0];
49 }
50 else if (args.Length > 1)
51 {
52 throw new InvalidOperationException("ERROR: Recieved Invalid Commandline: " + new arraytostring<string, string[]>(args));
53 }
54
55 if (System.IO.File.Exists(GrannyFilename))
56 {
57 Console.WriteLine("Using Granny2 File: " + GrannyFilename);
58 }
59 else
60 {
61 throw new System.IO.FileNotFoundException("Unable to find: " + GrannyFilename);
62 }
63 #endregion
64
65 #region Read Granny2 Data
66
67 granny_file grn_file = granny_file.ReadFromFile(GrannyFilename);
68 //grnfileinfo info = grnfileinfo.GetFileInfo(grn_file);
69 grnfileinfo info = grn_file.GrannyFileInfo;
70
71
72 #region granny_file data
73 Console.WriteLine();
74 Console.WriteLine("grann_file data:");
75 Console.WriteLine("\tIs Byte Reversed: {0}", grn_file.IsByteReversed.ToString());
76 Console.WriteLine("\tHeader: ");
77 Console.WriteLine("\t\tHeader Version: 0x{0}", grn_file.Header.Version.ToString("X2"));
78 Console.WriteLine("\t\tHeader TotalSize: 0x{0}",grn_file.Header.TotalSize.ToString("X8"));
79 Console.WriteLine("\t\tHeader CRC: 0x{0}", grn_file.Header.CRC.ToString("X8"));
80 Console.WriteLine("\t\tHeader SectionArrayOffset: 0x{0}",grn_file.Header.SectionArrayOffset.ToString("X4"));
81 Console.WriteLine("\t\tHeader SectionArrayCount: 0x{0}", grn_file.Header.SectionArrayCount.ToString("X4"));
82
83 //Console.WriteLine("\t\tHeader RootObjectTypeDefinition:");
84 //Console.WriteLine("\t\t\tSectionIndex: " + grn_file.Header.RootObjectTypeDefinition.SectionIndex);
85 //Console.WriteLine("\t\t\tOffset: " + grn_file.Header.RootObjectTypeDefinition.Offset);
86
87 //Console.WriteLine("\t\tHeader RootObject:");
88 //Console.WriteLine("\t\t\tSectionIndex: " + grn_file.Header.RootObject.SectionIndex);
89 //Console.WriteLine("\t\t\tOffset: " + grn_file.Header.RootObject.Offset);
90
91 Console.WriteLine("\t\tHeader TypeTag: 0x{0}",grn_file.Header.TypeTag.ToString("X8"));
92 Console.WriteLine("\t\tHeader ExtraTags: {0}", new arraytostring<int, int[]>(grn_file.Header.ExtraTags));
93 Console.WriteLine("\t\tHeader StringDatabaseCRC: 0x{0}", grn_file.Header.StringDatabaseCRC.ToString("X8"));
94 Console.WriteLine("\t\tHeader ReservedUnused: {0}",new arraytostring<int, int[]>(grn_file.Header.ReservedUnused));
95 Console.WriteLine("Press {ENTER} to Continue."); Console.ReadLine();
96 #endregion
97
98 #region Read FromFileName
99 Console.WriteLine();
100 if (info.HaveFromFileName)
101 {
102 Console.WriteLine("From File Name: " + info.FromFileName);
103 Console.WriteLine("ExtendedData: " + info.ExtendedData);
104 }
105 else { Console.WriteLine("From File Name: " + "No From File Name Available"); }
106 Console.WriteLine("Press {ENTER} to Continue."); Console.ReadLine();
107 #endregion
108
109 #region Read ArtToolInfo
110 Console.WriteLine();
111 if (info.HaveArtToolInfo)
112 {
113 Console.WriteLine("Art Tool Data:");
114 Console.WriteLine("\tTool Name: " + info.ArtToolInfo.FromArtToolName);
115 Console.WriteLine("\tTool Version: " + string.Format("{0}.{1}", info.ArtToolInfo.ArtToolMajorRevision, info.ArtToolInfo.ArtToolMinorRevision));
116 Console.WriteLine("\tTool Units Per Meter: " + info.ArtToolInfo.UnitsPerMeter);
117
118 Console.WriteLine("\tTool Origin: " + string.Format("[{0},{1},{2}]", info.ArtToolInfo.Origin.x, info.ArtToolInfo.Origin.y, info.ArtToolInfo.Origin.z));
119 Console.WriteLine("\tTool Right: " + string.Format("[{0},{1},{2}]", info.ArtToolInfo.Right.x, info.ArtToolInfo.Right.y, info.ArtToolInfo.Right.z));
120 Console.WriteLine("\tTool Up: " + string.Format("[{0},{1},{2}]", info.ArtToolInfo.Up.x, info.ArtToolInfo.Up.y, info.ArtToolInfo.Up.z));
121 Console.WriteLine("\tTool Back: " + string.Format("[{0},{1},{2}]", info.ArtToolInfo.Back.x, info.ArtToolInfo.Back.y, info.ArtToolInfo.Back.z));
122
123 Console.WriteLine("\tTool ExtendedData: " + info.ArtToolInfo.ExtendedData);
124 }
125 else { Console.WriteLine("Art Tool Data: " + "No Art Tool Info Available"); }
126 Console.WriteLine("Press {ENTER} to Continue."); Console.ReadLine();
127 #endregion
128
129 #region Read ExporterInfo
130 Console.WriteLine();
131 if (info.HaveExporterInfo)
132 {
133 Console.WriteLine("Exporter Info:");
134 Console.WriteLine("\tExporter Name: " + info.ExporterInfo.ExporterName);
135
136 Console.WriteLine("\tExporter Version: " +
137 string.Format("{0}.{1}.{2}.{3}",
138 info.ExporterInfo.ExporterMajorRevision,
139 info.ExporterInfo.ExporterMinorRevision,
140 info.ExporterInfo.ExporterCustomization,
141 info.ExporterInfo.ExporterBuildNumber));
142
143 Console.WriteLine("\tExporter ExtendedData: " + info.ExporterInfo.ExtendedData);
144 }
145 else { Console.WriteLine("Exporter Info: " + "No Exporter Info Available"); }
146 Console.WriteLine("Press {ENTER} to Continue."); Console.ReadLine();
147 #endregion
148
149 #region Read Textures
150 Console.WriteLine();
151 if (info.HaveTextures)
152 {
153 Console.WriteLine("Texture List:");
154 foreach (Texture t in info.Textures)
155 {
156 Console.WriteLine("\tName: " + t.FromFileName);
157 Console.WriteLine("\tType: " + t.TextureType);
158 Console.WriteLine("\tWidth: " + t.Width);
159 Console.WriteLine("\tHeight: " + t.Height);
160 Console.WriteLine("\tEncoding: " + t.Encoding);
161 Console.WriteLine("\tSubFormat: " + t.SubFormat);
162 // layout
163 Console.WriteLine("\tBytes Per Pixel: " + t.Layout.BytesPerPixel);
164 Console.WriteLine("\tShiftForComponent: " + new arraytostring<int, int[]>(t.Layout.ShiftForComponent));
165 Console.WriteLine("\tBitsForComponent: " + new arraytostring<int, int[]>(t.Layout.BitsForComponent));
166 // images
167 Console.WriteLine("\tImage List:");
168 foreach (Image img in t.Images)
169 {
170 foreach (MIPLevel mip in img.MIPLevels)
171 {
172 Console.WriteLine("\t\tMipLevel Stride: " + mip.Stride);
173 if (mip.Pixels.Count > 0)
174 {
175 Console.WriteLine("\t\tMipLevel Pixel: " + "{Pixel Data " + "[" + mip.Pixels.Count + "]}");
176 //// export image
177 //mip.Pixels.Export(@"exported_images\" + t.FromFileName.Name, t.Width, t.Height, mip.Stride);
178 }
179 }
180 }
181 Console.WriteLine("\tExtendedData: " + t.ExtendedData);
182 Console.WriteLine();
183 }
184 }
185 else { Console.WriteLine("Texture List: " + "No Textures Available"); }
186 Console.WriteLine("Press {ENTER} to Continue."); Console.ReadLine();
187 #endregion
188
189 #region Read Materials
190 Console.WriteLine();
191 if (info.HaveMaterials)
192 {
193 Console.WriteLine("Material List:");
194 foreach (Material m in info.Materials)
195 {
196 Console.WriteLine("\tMaterial Name: " + m.Name);
197 Console.WriteLine("\t\tMaterial IsTexture: " + m.IsTexture.ToString());
198 if (m.IsTexture)
199 {
200 Texture t = m.Texture;
201 Console.WriteLine("\t\tTexture:");
202 Console.WriteLine("\t\t\tName: " + t.FromFileName);
203 Console.WriteLine("\t\t\tType: " + t.TextureType);
204 Console.WriteLine("\t\t\tWidth: " + t.Width);
205 Console.WriteLine("\t\t\tHeight: " + t.Height);
206 Console.WriteLine("\t\t\tEncoding: " + t.Encoding);
207 Console.WriteLine("\t\t\tSubFormat: " + t.SubFormat);
208 // layout
209 Console.WriteLine("\t\t\tBytes Per Pixel: " + t.Layout.BytesPerPixel);
210 Console.WriteLine("\t\t\tShiftForComponent: " + new arraytostring<int, int[]>(t.Layout.ShiftForComponent));
211 Console.WriteLine("\t\t\tBitsForComponent: " + new arraytostring<int, int[]>(t.Layout.BitsForComponent));
212
213
214 Console.WriteLine("\t\t\tImage List:");
215 foreach (Image img in t.Images)
216 {
217 foreach (MIPLevel mip in img.MIPLevels)
218 {
219 Console.WriteLine("\t\t\t\tMipLevel Stride: " + mip.Stride);
220 if (mip.Pixels.Count > 0)
221 {
222 Console.WriteLine("\t\t\t\tMipLevel Pixel: " + "{Pixel Data " + "[" + mip.Pixels.Count + "]}");
223 //// export image
224 //mip.Pixels.Export(@"exported_images\" + t.FromFileName.Name, t.Width, t.Height, mip.Stride);
225 }
226 }
227 }
228
229 Console.WriteLine("\t\t\tExtendedData: " + t.ExtendedData);
230 Console.WriteLine();
231 }
232 Console.WriteLine("\t\tExtendedData: " + m.ExtendedData);
233 Console.WriteLine();
234 }
235 }
236 else { Console.WriteLine("Material List: " + "No Materials Available"); }
237 Console.WriteLine("Press {ENTER} to Continue."); Console.ReadLine();
238 #endregion
239
240
241 #region Read Skeletons
242 Console.WriteLine();
243 if (info.HaveSkeletons)
244 {
245 Console.WriteLine("Skeleton List:");
246 foreach (Skeleton s in info.Skeletons)
247 {
248 Console.WriteLine("\tSkeleton Name: " + s.SkeletonName);
249 Console.WriteLine("\tSkeleton LodType: " + s.LodType);
250 Console.WriteLine("\tBones:");
251 foreach (Bone b in s.Bones)
252 {
253 Console.WriteLine("\t\tName: " + b.BoneName);
254 Console.WriteLine("\t\tParent Index: " + b.ParentIndex);
255 Console.WriteLine("\t\tLod Error: " + b.LodError);
256 Console.WriteLine("\t\tTransform: " + b.Transform.ToString());
257 if (b.HasLightInfo) { Console.WriteLine("\t\tLightInfo ExtendedData: " + b.LightInfo.ExtendedData); }
258 else { Console.WriteLine("\t\tLightInfo ExtendedData: " + "No LightInfo"); }
259 if (b.HasCameraInfo) { Console.WriteLine("\t\tCameraInfo ExtendedData: " + b.CameraInfo.ExtendedData); }
260 else { Console.WriteLine("\t\tCameraInfo ExtendedData: " + "No CameraInfo"); }
261 Console.WriteLine();
262 }
263 Console.WriteLine("\t\tExtendedData: " + s.ExtendedData);
264 Console.WriteLine();
265 }
266
267 }
268 else { Console.WriteLine("Skeleton List: " + "No Skeletons Available"); }
269 Console.WriteLine("Press {ENTER} to Continue."); Console.ReadLine();
270 #endregion
271 }
272 #endregion
273
274
275 catch (granny2apiloadexception ex)
276 {
277 Console.WriteLine(ex.Message);
278 }
279 catch (Exception ex)
280 {
281 RuntimeWrappedException rwe = ex as RuntimeWrappedException;
282 if (rwe != null)
283 {
284 Console.WriteLine(rwe.ToString());
285 }
286 else
287 {
288 Console.WriteLine(ex.Message);
289 }
290 }
291 }
292 }
293 }
294
295

  ViewVC Help
Powered by ViewVC 1.1.22