Changeset 1220


Ignore:
Timestamp:
09/29/09 14:15:24 (5 years ago)
Author:
lowjoel
Message:

Implemented parent handling in the FatDirectoryEntry? structure to allow traversing the volume.

Location:
trunk/eraser6/Eraser.Util.FileSystem
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/eraser6/Eraser.Util.FileSystem/Fat32Api.cpp

    r1219 r1220  
    5858    } 
    5959 
    60     FatDirectory^ Fat32Api::LoadDirectory(unsigned cluster, String^ name) 
     60    FatDirectory^ Fat32Api::LoadDirectory(unsigned cluster, String^ name, FatDirectory^ parent) 
    6161    { 
    62         return gcnew Directory(name, cluster, this); 
     62        return gcnew Directory(name, parent, cluster, this); 
    6363    } 
    6464 
     
    126126        //Traverse the directories until we get the cluster we want. 
    127127        unsigned cluster = BootSector->Fat32ParameterBlock.RootDirectoryCluster; 
    128         String^ parentDir = nullptr; 
     128        FatDirectory^ parentDir = nullptr; 
    129129        for each (String^ component in components) 
    130130        { 
     
    132132                break; 
    133133 
    134             FatDirectory^ currentDirectory = LoadDirectory(cluster, parentDir); 
    135             cluster = currentDirectory->Items[component]->Cluster; 
    136             parentDir = component; 
     134            parentDir = LoadDirectory(cluster, parentDir == nullptr ? nullptr : parentDir->Name, 
     135                parentDir); 
     136            cluster = parentDir->Items[component]->Cluster; 
    137137        } 
    138138 
     
    140140    } 
    141141 
    142     Fat32Api::Directory::Directory(String^ name, unsigned cluster, Fat32Api^ api) 
    143         : FatDirectory(name, cluster, api) 
     142    Fat32Api::Directory::Directory(String^ name, FatDirectory^ parent, unsigned cluster, Fat32Api^ api) 
     143        : FatDirectory(name, parent, cluster, api) 
    144144    { 
    145145    } 
  • trunk/eraser6/Eraser.Util.FileSystem/FatApi.cpp

    r1219 r1220  
    8080    FatDirectory^ FatApi::LoadDirectory(String^ directory) 
    8181    { 
    82         String^ directory2 = Path::GetDirectoryName(directory); 
    83         return LoadDirectory(DirectoryToCluster(directory), directory2); 
     82        array<wchar_t>^ pathSeparators = { Path::DirectorySeparatorChar, Path::AltDirectorySeparatorChar }; 
     83        DirectoryInfo^ info = gcnew DirectoryInfo(directory); 
     84        return LoadDirectory(DirectoryToCluster(directory), directory->Substring( 
     85                directory->IndexOfAny(pathSeparators)), 
     86            info->Parent == nullptr ? nullptr : LoadDirectory(info->Parent->FullName)); 
    8487    } 
    8588 
     
    146149    } 
    147150 
    148     FatDirectoryEntry::FatDirectoryEntry(String^ name, FatDirectoryEntryTypes type, unsigned cluster) 
     151    FatDirectoryEntry::FatDirectoryEntry(String^ name, FatDirectory^ parent, 
     152        FatDirectoryEntryTypes type, unsigned cluster) 
    149153    { 
    150154        Name = name; 
     155        Parent = parent; 
    151156        Type = type; 
    152157        Cluster = cluster; 
     
    161166        { 
    162167            currentEntry = currentEntry->Parent; 
    163             result = currentEntry->Name + Path::PathSeparator + result; 
     168            result = currentEntry->Name + Path::DirectorySeparatorChar + result; 
    164169        } 
    165170 
     
    167172    } 
    168173 
    169     FatDirectory::FatDirectory(String^ name, unsigned cluster, FatApi^ api) 
    170         : FatDirectoryEntry(name, FatDirectoryEntryTypes::Directory, cluster) 
    171     { 
     174    FatDirectory::FatDirectory(String^ name, FatDirectory^ parent, unsigned cluster, FatApi^ api) 
     175        : FatDirectoryEntry(name, parent, FatDirectoryEntryTypes::Directory, cluster) 
     176    { 
     177        System::Diagnostics::Debug::Print(FullName); 
    172178        Entries = gcnew Dictionary<String^, FatDirectoryEntry^>(); 
    173179        Api = api; 
     
    227233                    //invalid characters. 
    228234                    String^ fileName = gcnew String(longFileName.c_str()); 
    229                     Entries->Add(fileName, gcnew FatDirectoryEntry(fileName, 
     235                    Entries->Add(fileName, gcnew FatDirectoryEntry(fileName, this, 
    230236                        (i->Short.Attributes & FILE_ATTRIBUTE_DIRECTORY) ? 
    231237                            FatDirectoryEntryTypes::Directory : FatDirectoryEntryTypes::File, 
     
    259265 
    260266            String^ fileName = gcnew String(shortFileName); 
    261             Entries->Add(fileName, gcnew FatDirectoryEntry(fileName, 
     267            Entries->Add(fileName, gcnew FatDirectoryEntry(fileName, this, 
    262268                (i->Short.Attributes & FILE_ATTRIBUTE_DIRECTORY) ? 
    263269                    FatDirectoryEntryTypes::Directory : FatDirectoryEntryTypes::File, 
  • trunk/eraser6/Eraser.Util.FileSystem/FatApi.h

    r1219 r1220  
    5454 
    5555        /// Loads the directory structure at the given cluster. 
    56         virtual FatDirectory^ LoadDirectory(unsigned cluster, String^ name) = 0; 
     56        virtual FatDirectory^ LoadDirectory(unsigned cluster, String^ name, FatDirectory^ parent) = 0; 
    5757 
    5858    internal: 
     
    128128    { 
    129129    public: 
     130        /// Gets the name of the file or directory. 
     131        property String^ Name 
     132        { 
     133            String^ get() { return name; } 
     134        private: 
     135            void set(String^ value) { name = value; } 
     136        } 
     137 
     138        /// Gets the full path to the file or directory. 
     139        property String^ FullName 
     140        { 
     141            String^ get(); 
     142        } 
     143 
     144        /// Gets the parent directory of this entry. 
     145        property FatDirectory^ Parent 
     146        { 
     147            FatDirectory^ get() { return parent; } 
     148        private: 
     149            void set(FatDirectory^ value) { parent = value; } 
     150        } 
     151 
     152        /// Gets the type of this entry. 
     153        property FatDirectoryEntryTypes Type 
     154        { 
     155            FatDirectoryEntryTypes get() { return type; } 
     156        private: 
     157            void set(FatDirectoryEntryTypes value) { type = value; } 
     158        } 
     159 
     160        /// Gets the first cluster of this entry. 
     161        property unsigned Cluster 
     162        { 
     163            unsigned get() { return cluster; } 
     164        private: 
     165            void set(unsigned value) { cluster = value; } 
     166        } 
     167 
     168    internal: 
    130169        /// Constructor. 
    131170        ///  
    132171        /// \param[in] name    The name of the entry. 
     172        /// \param[in] parent  The parent directory containing this file. 
    133173        /// \param[in] type    The type of this entry. 
    134174        /// \param[in] cluster The first cluster of the file. 
    135         FatDirectoryEntry(String^ name, FatDirectoryEntryTypes type, unsigned cluster); 
    136  
    137         /// Gets the name of the file or directory. 
    138         property String^ Name 
    139         { 
    140             String^ get() { return name; } 
    141         private: 
    142             void set(String^ value) { name = value; } 
    143         } 
    144  
    145         /// Gets the full path to the file or directory. 
    146         property String^ FullName 
    147         { 
    148             String^ get(); 
    149         } 
    150  
    151         /// Gets the parent directory of this entry. 
    152         property FatDirectory^ Parent 
    153         { 
    154             FatDirectory^ get() { return parent; } 
    155         private: 
    156             void set(FatDirectory^ value) { parent = value; } 
    157         } 
    158  
    159         /// Gets the type of this entry. 
    160         property FatDirectoryEntryTypes Type 
    161         { 
    162             FatDirectoryEntryTypes get() { return type; } 
    163         private: 
    164             void set(FatDirectoryEntryTypes value) { type = value; } 
    165         } 
    166  
    167         /// Gets the first cluster of this entry. 
    168         property unsigned Cluster 
    169         { 
    170             unsigned get() { return cluster; } 
    171         private: 
    172             void set(unsigned value) { cluster = value; } 
    173         } 
     175        FatDirectoryEntry(String^ name, FatDirectory^ parent, FatDirectoryEntryTypes type, 
     176            unsigned cluster); 
    174177 
    175178    private: 
     
    187190        ///  
    188191        /// \param[in] name    The name of the current directory. 
     192        /// \param[in] parent  The parent directory containing this directory. 
    189193        /// \param[in] cluster The cluster at which the directory list starts. 
    190194        /// \param[in] api     The FAT API object which is creating this object. 
    191         FatDirectory(String^ name, unsigned cluster, FatApi^ api); 
     195        FatDirectory(String^ name, FatDirectory^ parent, unsigned cluster, FatApi^ api); 
    192196 
    193197        /// Compacts the directory structure. 
     
    222226    public: 
    223227        virtual void LoadFat() override; 
    224         virtual FatDirectory^ LoadDirectory(unsigned cluster, String^ name) override; 
     228        virtual FatDirectory^ LoadDirectory(unsigned cluster, String^ name, FatDirectory^ parent) override; 
    225229 
    226230    internal: 
     
    235239        { 
    236240        public: 
    237             Directory(String^ name, unsigned cluster, Fat32Api^ api); 
     241            Directory(String^ name, FatDirectory^ parent, unsigned cluster, Fat32Api^ api); 
    238242 
    239243        protected: 
Note: See TracChangeset for help on using the changeset viewer.