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

Contents of /trunk/gr2lib_UnitTest/Program.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 107 - (show annotations) (download)
Sat Jul 17 14:52:47 2010 UTC (10 years, 7 months ago) by william
File size: 18261 byte(s)
commit bulk

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

  ViewVC Help
Powered by ViewVC 1.1.22