|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 using System; |
|
18 using System.Collections.Generic; |
|
19 using System.Collections.ObjectModel; |
|
20 using System.Text; |
|
21 using System.IO; |
|
22 using SymbianUtils; |
|
23 using SymbianUtils.Streams; |
|
24 using SymbianUtils.Tracer; |
|
25 using SymbianStructuresLib.Compression.Common; |
|
26 using SymbianImageLib.Common.Content; |
|
27 using SymbianImageLib.Common.Image; |
|
28 using SymbianImageLib.Common.Header; |
|
29 using SymbianImageLib.Common.Streams; |
|
30 using SymbianImageLib.ROFS.Content; |
|
31 using SymbianImageLib.ROFS.Header; |
|
32 using SymbianImageLib.ROFS.Structures; |
|
33 |
|
34 namespace SymbianImageLib.ROFS.Image |
|
35 { |
|
36 public class SIROFS : SIImage |
|
37 { |
|
38 #region Constructors |
|
39 public SIROFS( ITracer aTracer, Stream aStream, string aName ) |
|
40 : base( aTracer, new SIStream( aStream ), aName ) |
|
41 { |
|
42 base.Trace( "[SymbianImageROFS] Ctor() - START" ); |
|
43 iHeader = SIHeaderROF.New( this, aStream ); |
|
44 |
|
45 ReadFiles(); |
|
46 base.Trace( "[SymbianImageROFS] Ctor() - END" ); |
|
47 } |
|
48 #endregion |
|
49 |
|
50 #region From SIImage |
|
51 public override SIHeader Header |
|
52 { |
|
53 get { return iHeader; } |
|
54 } |
|
55 #endregion |
|
56 |
|
57 #region API |
|
58 public static bool IsROFS( Stream aStream ) |
|
59 { |
|
60 bool ret = false; |
|
61 // |
|
62 try |
|
63 { |
|
64 ret = SIHeaderROF.IsROFS( aStream ); |
|
65 } |
|
66 catch ( Exception ) |
|
67 { |
|
68 } |
|
69 // |
|
70 return ret; |
|
71 } |
|
72 #endregion |
|
73 |
|
74 #region Properties |
|
75 #endregion |
|
76 |
|
77 #region Internal methods |
|
78 private void ReadFiles() |
|
79 { |
|
80 base.Trace( "[SymbianImageROFS] ReadFiles() - reading directory tree..." ); |
|
81 using ( SymbianStreamReaderLE reader = SymbianStreamReaderLE.New( (Stream) base.Stream ) ) |
|
82 { |
|
83 reader.Seek( iHeader.InternalHeader.DirTreeOffset, SeekOrigin.Begin ); |
|
84 TRofsDir rootDirectory = new TRofsDir( string.Empty, (uint) reader.Position, reader, this ); |
|
85 |
|
86 base.Trace( "[SymbianImageROFS] ReadFiles() - converting directory tree to full full paths..." ); |
|
87 MakeFilesForDirectory( rootDirectory, string.Empty ); |
|
88 } |
|
89 } |
|
90 |
|
91 private void MakeFilesForDirectory( TRofsDir aDirectory, string aParentDirectoryName ) |
|
92 { |
|
93 string name = aParentDirectoryName + @"\"; |
|
94 |
|
95 // Create files |
|
96 StringBuilder fullName = new StringBuilder(); |
|
97 foreach ( TRofsEntry entry in aDirectory ) |
|
98 { |
|
99 fullName.Length = 0; |
|
100 fullName.Append( name ); |
|
101 fullName.Append( entry.Name ); |
|
102 // |
|
103 SIContent file = SIContentFactoryROFS.New( this, fullName.ToString(), entry.FileSize, entry.FileAddress, entry.Uids ); |
|
104 base.RegisterFile( file ); |
|
105 } |
|
106 |
|
107 // Create files in any subdirs |
|
108 foreach ( TRofsDir subdir in aDirectory.SubDirectories ) |
|
109 { |
|
110 MakeFilesForDirectory( subdir, name + subdir.Name ); |
|
111 } |
|
112 } |
|
113 #endregion |
|
114 |
|
115 #region Data members |
|
116 private readonly SIHeaderROF iHeader; |
|
117 #endregion |
|
118 } |
|
119 } |