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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 70 - (hide annotations) (download)
Thu Jul 15 12:55:21 2010 UTC (11 years, 6 months ago) by william
File size: 1998 byte(s)
initial commit of support to read ArtToolInfo

1 william 70 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    
12     public IntPtr NativePointer;
13     internal string filePath;
14     internal string fileName;
15    
16     public grnfileinfo(string path)
17     {
18     this.filePath = path;
19     this.fileName = FileNameFromPath(path);
20     }
21    
22     private static string FileNameFromPath(string path)
23     {
24     int lastSlash = path.LastIndexOf('\\');
25     if (lastSlash > 0) return path.Substring(lastSlash + 1);
26     lastSlash = path.LastIndexOf('/');
27     if (lastSlash > 0) return path.Substring(lastSlash + 1);
28     return path;
29     }
30    
31     internal static grnfileinfo ReadFromMemory(IntPtr pointer, string path)
32     {
33     if (pointer == IntPtr.Zero) return null;
34     native.FileInfo native = Helpers.ReadFromMemory<native.FileInfo>(pointer);
35     grnfileinfo managed = new grnfileinfo(path);
36     managed.NativePointer = pointer;
37    
38     if (native.ArtToolInfo != IntPtr.Zero)
39     {
40     managed.ArtToolInfo = ArtToolInfo.ReadFromMemory(native.ArtToolInfo);
41     //managed.Nodes.Insert(1, managed.ArtToolInfo);
42     }
43     return managed;
44     }
45     public static grnfileinfo ReadFromFile(string fileName)
46     {
47     IntPtr file = coreapi.GrannyReadEntireFile(fileName);
48    
49     if (file == null || file == IntPtr.Zero)
50     {
51     Console.WriteLine("Error: unable to load {0} as a Granny file.", fileName);
52     }
53    
54     IntPtr pinfo = coreapi.GetFileInfo(file);
55     grnfileinfo info = ReadFromMemory(pinfo, fileName);
56     coreapi.FreeFile(file);
57    
58     return info;
59     }
60     }
61     }

  ViewVC Help
Powered by ViewVC 1.1.22