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

Contents of /trunk/gr2lib_UnitTest/Program.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 100 - (show annotations) (download)
Sat Jul 17 13:53:22 2010 UTC (9 years, 6 months ago) by william
File size: 18081 byte(s)
enable copying of granny2_X.X.X.X.dll -> granny2.dll at run-time, based on compiler directive

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

  ViewVC Help
Powered by ViewVC 1.1.22