Platform_Win32_FileSystem.cpp
Go to the documentation of this file.00001 //*** Platform_Win32_FileSystem.cpp *** 00002 00003 #include "Platform_Win32_FileSystem.h" 00004 #include "Platform_Win32_FileSystem_Device.h" 00005 #include "Platform_Win32_FileSystem_Directory.h" 00006 #include "Platform_OS.h" 00007 00008 #define WIN32_LEAN_AND_MEAN 00009 #define VC_EXTRALEAN 00010 #include <windows.h> 00011 00012 #include "Platform_Win32_FileSystem_File.h" 00013 00014 00015 //*** Constructor *** 00016 00017 Platform_Win32_FileSystem::Platform_Win32_FileSystem(): 00018 deviceCount_(0), 00019 logging_(false) 00020 { 00021 RescanDevices(); 00022 } 00023 00024 00025 //*** Destructor *** 00026 00027 Platform_Win32_FileSystem::~Platform_Win32_FileSystem() 00028 { 00029 EmptyDeviceList(); 00030 } 00031 00032 00033 //*** SetLogging *** 00034 00035 void Platform_Win32_FileSystem::SetLogging(bool enabled) 00036 { 00037 logging_=enabled; 00038 } 00039 00040 00041 //*** GetDirectory *** 00042 00043 Platform_FileSystem_Directory* Platform_Win32_FileSystem::CreateDirectoryObject(const char* path) 00044 { 00045 if (logging_ && path) 00046 { 00047 Platform::GetPlatform_OS()->OutputDebugText(" >> \n"); 00048 Platform::GetPlatform_OS()->OutputDebugText(" >> FileSystem - CreateDirectoryObject: %s\n",path); 00049 Platform::GetPlatform_OS()->OutputDebugText(" >> \n"); 00050 } 00051 return new Platform_Win32_FileSystem_Directory(path); 00052 } 00053 00054 00055 //*** GetFile *** 00056 00057 Platform_FileSystem_File* Platform_Win32_FileSystem::CreateFileObject(const char* path) 00058 { 00059 if (logging_ && path) 00060 { 00061 Platform::GetPlatform_OS()->OutputDebugText(" >> \n"); 00062 Platform::GetPlatform_OS()->OutputDebugText(" >> FileSystem - CreateFileObject: %s\n",path); 00063 Platform::GetPlatform_OS()->OutputDebugText(" >> \n"); 00064 } 00065 return new Platform_Win32_FileSystem_File(path); 00066 } 00067 00068 00069 //*** RescanDevices *** 00070 00071 void Platform_Win32_FileSystem::RescanDevices() 00072 { 00073 if (logging_) 00074 { 00075 Platform::GetPlatform_OS()->OutputDebugText(" >> \n"); 00076 Platform::GetPlatform_OS()->OutputDebugText(" >> FileSystem - RescanDevices\n"); 00077 Platform::GetPlatform_OS()->OutputDebugText(" >> \n"); 00078 } 00079 00080 // Get rid of any existing devices 00081 EmptyDeviceList(); 00082 00083 // Get the list of logical drives from windows 00084 char logicalDrives[256]; 00085 int len=GetLogicalDriveStrings(255, logicalDrives); 00086 00087 // Parse through the list 00088 char deviceName[10]; 00089 int pos=0; // current position in deviceName 00090 00091 for (int i=0; i<len; i++) 00092 { 00093 // Add next character to the current device name 00094 deviceName[pos]=logicalDrives[i]; 00095 00096 // If we reached the end of the current device name 00097 if (logicalDrives[i]==0) 00098 { 00099 // Remove trailing "\" 00100 //Assert(deviceName[pos-1]=='\\',"Invalid device name"); 00101 deviceName[pos-1]=0; 00102 00103 // Create new device object 00104 Platform_FileSystem_Device* device=new Platform_Win32_FileSystem_Device(deviceName); 00105 00106 // Add the device to the internal list 00107 devices_[deviceCount_]=device; 00108 deviceCount_++; 00109 00110 // Reset device name position, as we're now starting to parse a new device name 00111 pos=0; 00112 } 00113 else // We have NOT yet reached the end of the current device name 00114 { 00115 // Increase the position 00116 if (pos<10) // But make sure it don't increase too much (should only ever be 3 characters anyway, like "C:\") 00117 { 00118 pos++; 00119 } 00120 } 00121 } 00122 00123 } 00124 00125 00126 //*** EmptyDeviceList *** 00127 00128 void Platform_Win32_FileSystem::EmptyDeviceList() 00129 { 00130 for (int i=0; i<deviceCount_; i++) 00131 { 00132 Platform_FileSystem_Device* device=devices_[i]; 00133 delete device; 00134 } 00135 deviceCount_=0; 00136 } 00137 00138 00139 //*** GetDeviceCount *** 00140 00141 int Platform_Win32_FileSystem::GetDeviceCount() 00142 { 00143 return deviceCount_; 00144 } 00145 00146 00147 //*** GetDevice *** 00148 00149 const Platform_FileSystem_Device* Platform_Win32_FileSystem::GetDevice(int index) 00150 { 00151 if (index<0 || index>=deviceCount_) 00152 { 00153 return 0; 00154 } 00155 00156 return devices_[index]; 00157 }
Reproduction/republishing of any material on this site without permission is strictly prohibited.
