/[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 71 - (show annotations) (download)
Thu Jul 15 13:07:44 2010 UTC (11 years, 4 months ago) by william
File size: 2149 byte(s)
enable reading of ExporterInfo

1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using gr2lib.core.helpers;
5
6 namespace gr2lib.core.coretypes.implementation
7 {
8 public class grnfileinfo
9 {
10 public ArtToolInfo ArtToolInfo;
11 public ExporterInfo ExporterInfo;
12
13 public IntPtr NativePointer;
14 internal string filePath;
15 internal string fileName;
16
17 public grnfileinfo(string path)
18 {
19 this.filePath = path;
20 this.fileName = FileNameFromPath(path);
21 }
22
23 private static string FileNameFromPath(string path)
24 {
25 int lastSlash = path.LastIndexOf('\\');
26 if (lastSlash > 0) return path.Substring(lastSlash + 1);
27 lastSlash = path.LastIndexOf('/');
28 if (lastSlash > 0) return path.Substring(lastSlash + 1);
29 return path;
30 }
31
32 internal static grnfileinfo ReadFromMemory(IntPtr pointer, string path)
33 {
34 if (pointer == IntPtr.Zero) return null;
35 native.FileInfo native = Helpers.ReadFromMemory<native.FileInfo>(pointer);
36 grnfileinfo managed = new grnfileinfo(path);
37 managed.NativePointer = pointer;
38
39 if (native.ArtToolInfo != IntPtr.Zero)
40 {
41 managed.ArtToolInfo = ArtToolInfo.ReadFromMemory(native.ArtToolInfo);
42 }
43 if (native.ExporterInfo != IntPtr.Zero)
44 {
45 managed.ExporterInfo = ExporterInfo.ReadFromMemory(native.ExporterInfo);
46 }
47 return managed;
48 }
49 public static grnfileinfo ReadFromFile(string fileName)
50 {
51 IntPtr file = coreapi.GrannyReadEntireFile(fileName);
52
53 if (file == null || file == IntPtr.Zero)
54 {
55 Console.WriteLine("Error: unable to load {0} as a Granny file.", fileName);
56 }
57
58 IntPtr pinfo = coreapi.GetFileInfo(file);
59 grnfileinfo info = ReadFromMemory(pinfo, fileName);
60 coreapi.FreeFile(file);
61
62 return info;
63 }
64 }
65 }

  ViewVC Help
Powered by ViewVC 1.1.22