1 //-----------------------------------------------------------------------------
2 //
3 // Copyright (c) Microsoft. All rights reserved.
4 // This code is licensed under the Microsoft Public License.
5 // THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
6 // ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
7 // IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
8 // PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
9 //
10 //-----------------------------------------------------------------------------
11 using System;
12 
13 namespace Microsoft.Cci.Pdb {
14   internal class MsfDirectory {
MsfDirectory(PdbReader reader, PdbFileHeader head, BitAccess bits)15     internal MsfDirectory(PdbReader reader, PdbFileHeader head, BitAccess bits) {
16       int pages = reader.PagesFromSize(head.directorySize);
17 
18       // 0..n in page of directory pages.
19       bits.MinCapacity(head.directorySize);
20       int directoryRootPages = head.directoryRoot.Length;
21       int pagesPerPage = head.pageSize / 4;
22       int pagesToGo = pages;
23       for (int i = 0; i < directoryRootPages; i++) {
24         int pagesInThisPage = pagesToGo <= pagesPerPage ? pagesToGo : pagesPerPage;
25         reader.Seek(head.directoryRoot[i], 0);
26         bits.Append(reader.reader, pagesInThisPage * 4);
27         pagesToGo -= pagesInThisPage;
28       }
29       bits.Position = 0;
30 
31       DataStream stream = new DataStream(head.directorySize, bits, pages);
32       bits.MinCapacity(head.directorySize);
33       stream.Read(reader, bits);
34 
35       // 0..3 in directory pages
36       int count;
37       bits.ReadInt32(out count);
38 
39       // 4..n
40       int[] sizes = new int[count];
41       bits.ReadInt32(sizes);
42 
43       // n..m
44       streams = new DataStream[count];
45       for (int i = 0; i < count; i++) {
46         if (sizes[i] <= 0) {
47           streams[i] = new DataStream();
48         } else {
49           streams[i] = new DataStream(sizes[i], bits,
50                                       reader.PagesFromSize(sizes[i]));
51         }
52       }
53     }
54 
55     internal DataStream[] streams;
56   }
57 
58 }
59