|
From: Emilien K. <cur...@us...> - 2005-01-26 16:11:54
|
Update of /cvsroot/wxdevcenter/wxDevCenter/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7874/src Modified Files: FileSystemStandard.cpp Log Message: Séparation des classes spécifiques aux plateformes. Index: FileSystemStandard.cpp =================================================================== RCS file: /cvsroot/wxdevcenter/wxDevCenter/src/FileSystemStandard.cpp,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** FileSystemStandard.cpp 15 Jan 2005 14:53:47 -0000 1.10 --- FileSystemStandard.cpp 26 Jan 2005 16:11:43 -0000 1.11 *************** *** 3,7 **** * @author Cursor * ! * @brief Implémentation des classes du système de fichiers virtuel standard. */ // --- 3,8 ---- * @author Cursor * ! * @brief Implémentation de la classes du système de fichiers virtuel standard de base et de la classe de l'archive de fichiers. ! * */ // *************** *** 53,458 **** - #ifdef __WINDOWS__ - ////////////////////////////////////////////////////////////////////// - // Implémentation spécifique WINDOWS - ////////////////////////////////////////////////////////////////////// - - - #define WXDC_WSFS_ERROR -1 // une erreur (ou la fin de l'énumération) s'est produite - #define WXDC_WSFS_OK 0x00000000 // tout va bien - #define WXDC_WSFS_DESKTOP1 0x00000001 // viens de retourner le "My computer" - #define WXDC_WSFS_DESKTOP2 0x00000002 // viens de retourner le "My docs" - #define WXDC_WSFS_COMPUTER 0x00000100 // flag pour l'énumération des disques - - - // Convertit un chemin logique en chemin physique. - wxString FileSystemStandardWindows::LogicalToPhysical(FilePath strPath) - { - wxString str; - - // On retire le file: - strPath.RemoveProtocol(); - - if(strPath.StartsWith(m_strNameDesktop, &str)) // "Bureau" - return m_strPathDesktop + str; - else if(strPath.StartsWith(m_strNameMyDocs, &str)) // "Mes documents" - return m_strPathDocuments + str; - else if(strPath.StartsWith(m_strNameComputer, &str)) // "Poste de travail" - { - str.Remove(0, 1); - return str; - } - else - return strPath; - } - - - Archive* FileSystemStandardWindows::GetFileArchive(FilePath strPath, unsigned int nMode) - { - return new ArchiveFile(LogicalToPhysical(strPath), (Archive::ARCHIVE_OPEN_MODE)nMode); - } - - wxString FileSystemStandardWindows::FindFirst(FilePath strPath, int iFlags) - { - m_strFindPath = strPath; - m_iFindFlags = iFlags; - - wxString str; - - strPath.RemoveProtocol(); - m_strCurrentFile = GetProtocoleName() + wxT(":"); - - if(strPath.IsEmpty()) // Racine - { - if(m_iFindFlags&wxDIR_DIRS) - { - m_strCurrentFile += m_strNameDesktop; - return m_strNameDesktop; - } - } - else if(strPath == m_strNameDesktop) // Bureau - { - m_Dir.Open(LogicalToPhysical(m_strNameDesktop)); - if(m_Dir.GetFirst(&str, wxEmptyString, m_iFindFlags)) - { - m_strCurrentFile.Append(m_strNameDesktop).Append(wxT("/")).Append(str); - return str; - } - } - else if(strPath == m_strNameMyDocs) // Mes Documents - { - m_Dir.Open(LogicalToPhysical(m_strNameMyDocs)); - if(m_Dir.GetFirst(&str, wxEmptyString, m_iFindFlags)) - { - m_strCurrentFile.Append(m_strNameMyDocs).Append(wxT("/")).Append(str); - return str; - } - - } - else if(strPath == m_strNameComputer) // Poste de travail - { - if(m_iFindFlags&wxDIR_DIRS) - { - PopulateDrives(); - if(m_arDrives.GetCount()>0) - { - m_strCurrentFile.Append(m_strNameComputer).Append(wxT("/")).Append(m_arDrives[0]).Append(wxT(":")); - return m_arDrives[0] + wxT(":"); - } - } - } - else // Listage standard - { - wxString strPhysical = LogicalToPhysical(m_strFindPath); - if(!wxDirExists(strPhysical)) - { - m_strCurrentFile = wxT(""); - return wxT(""); - } - m_Dir.Open(strPhysical); - if(!m_Dir.IsOpened()) - { - m_strCurrentFile = wxT(""); - return wxT(""); - } - if(m_Dir.GetFirst(&str, wxEmptyString, m_iFindFlags)) - { - m_strCurrentFile.Append(strPath).Append(wxT("/")).Append(str); - return str; - } - } - m_strCurrentFile = wxT(""); - return wxT(""); - } - - - wxString FileSystemStandardWindows::FindNext() - { - wxString str; - - if(m_strCurrentFile.IsEmpty()) - { - return wxT(""); - } - else if(m_strCurrentFile == (GetProtocoleName() + wxT(":") + m_strNameDesktop)) - { - m_strCurrentFile = GetProtocoleName() + wxT(":") + m_strNameMyDocs; - return m_strNameMyDocs; - } - else if(m_strCurrentFile == (GetProtocoleName() + wxT(":") + m_strNameMyDocs)) - { - m_strCurrentFile = GetProtocoleName() + wxT(":") + m_strNameComputer; - return m_strNameComputer; - } - else if(m_strCurrentFile == (GetProtocoleName() + wxT(":") + m_strNameComputer)) - { - m_strCurrentFile.Empty(); - return wxT(""); - } - else if(m_strFindPath == (GetProtocoleName() + wxT(":") + m_strNameComputer)) - { - wxChar c = m_strCurrentFile[m_strCurrentFile.Length()-2]; - for(unsigned int n=0; n<m_arDrives.GetCount(); n++) - { - if(m_arDrives[n]==c && (n+1)<m_arDrives.GetCount()) - { - m_strCurrentFile.Empty(); - m_strCurrentFile << GetProtocoleName() << wxT(":") - << m_strNameComputer << wxT("/") - << m_arDrives[n+1] << wxT(":"); - return m_arDrives[n+1] + wxT(":"); - } - } - m_strCurrentFile.Empty(); - return wxT(""); - } - else - { - if(m_Dir.GetNext(&str)) - { - m_strCurrentFile.Empty(); - m_strCurrentFile.Append(m_strFindPath).Append(wxT("/")).Append(str); - return str; - } - else - { - m_strCurrentFile.Empty(); - return wxT(""); - } - } - - } - - // Retorune le chemin logique vers le dernier fichier trouvé - // nom et extension de fichier compris - FilePath FileSystemStandardWindows::GetCurrentFilePath() - { - return m_strCurrentFile; - } - - - bool FileSystemStandardWindows::IsDirectory(FilePath strPath) - { - if(strPath.Last()=='\\' || strPath.Last()=='/') - strPath.RemoveLast(); - - if(strPath.IsEmpty()) - return true; - else if(strPath==(GetProtocoleName() + wxT(":"))) - return true; - else if(strPath==(GetProtocoleName() + wxT(":") + m_strNameDesktop)) - return true; - else if(strPath==(GetProtocoleName() + wxT(":") + m_strNameMyDocs)) - return true; - else if(strPath==(GetProtocoleName() + wxT(":") + m_strNameComputer)) - return true; - else if(strPath.Matches(GetProtocoleName() + wxT(":") + m_strNameComputer + wxT("??:"))) - return true; - else - return wxDir::Exists(LogicalToPhysical(strPath)); - } - - int FileSystemStandardWindows::GetDirectorySystemType(FilePath strPath) - { - if(strPath.IsEmpty()) - return WXDC_FS_DIRTYPE_MOUNT; - else if(strPath==(GetProtocoleName() + wxT(":"))) - return WXDC_FS_DIRTYPE_MOUNT; - else if(strPath==(GetProtocoleName() + wxT(":") + m_strNameDesktop)) - return WXDC_FS_DIRTYPE_DESKTOP; - else if(strPath==(GetProtocoleName() + wxT(":") + m_strNameMyDocs)) - return WXDC_FS_DIRTYPE_DOC; - else if(strPath==(GetProtocoleName() + wxT(":") + m_strNameComputer)) - return WXDC_FS_DIRTYPE_MOUNT; - else if(strPath.Matches(GetProtocoleName() + wxT(":") + m_strNameComputer + wxT("??:"))) - { - wxChar c = strPath[strPath.Length()-2]; - wxString strDrive = c; - strDrive << wxT(":\\"); - switch(GetDriveType(strDrive.GetData())) - { - case DRIVE_REMOVABLE: - return WXDC_FS_DIRTYPE_FLOPPY; - case DRIVE_FIXED: - return WXDC_FS_DIRTYPE_HARDDRIVE; - case DRIVE_REMOTE: - return WXDC_FS_DIRTYPE_REMOTE; - case DRIVE_CDROM: - return WXDC_FS_DIRTYPE_CDROM; - case DRIVE_RAMDISK: - return WXDC_FS_DIRTYPE_RAMDISK; - default: - return WXDC_DOCMANAGER_TYPE_UNKNOW; - } - } - else - return wxDir::Exists(LogicalToPhysical(strPath))?WXDC_FS_DIRTYPE_NORMAL:-1; - } - - - FilePath FileSystemStandardWindows::GetParentDirectory(FilePath strPath) - { - if(strPath.IsEmpty()) - return wxT(""); - else if(strPath==(GetProtocoleName() + wxT(":"))) - return GetProtocoleName() + wxT(":"); - else if(strPath==(GetProtocoleName() + wxT(":") + m_strNameDesktop)) - return GetProtocoleName() + wxT(":"); - else if(strPath==(GetProtocoleName() + wxT(":") + m_strNameMyDocs)) - return GetProtocoleName() + wxT(":"); - else if(strPath==(GetProtocoleName() + wxT(":") + m_strNameComputer)) - return GetProtocoleName() + wxT(":"); - else - { - int i, j; - i = strPath.Last(wxT('/')); - j = strPath.Last(wxT('\\')); - if(i==-1) - i = j; - if(i==-1) - return GetProtocoleName() + wxT(":"); - if(i<j) - i = j; - return strPath.Left(i); - } - } - - /** Teste si un lecteur est présent.*/ - bool FileSystemStandardWindows::HasDrive(wxChar cLetter) - { - for(unsigned int n=0; n<m_arDrives.GetCount(); n++) - if(m_arDrives[n] == cLetter) - return true; - return false; - } - - - // Peuple le Drapeau des disques. - #include <direct.h> - void FileSystemStandardWindows::PopulateDrives() - { - RAZDrives(); - unsigned long ulDrives = GetLogicalDrives(); - for(int i=0, l=65; i<26; i++, l++) - { - unsigned long n = 1 << i; - if(ulDrives&n) - { - m_arDrives.Add(wxChar(l)); - } - } - } - - - // N'inclure <Windows.h> qu'à la fin car il à la sale manie de renommer - // CreateDirectory et RemoveDirectory. - #include <Windows.h> - FileSystemStandardWindows::FileSystemStandardWindows(): - FileSystemStandardBase(), - m_strNameDesktop(WXDC_WINDOWS_DESKTOP), - m_strNameMyDocs(WXDC_WINDOWS_MYDOCS), - m_strNameComputer(WXDC_WINDOWS_COMPUTER) - { - HKEY key; - char buffer[MAX_PATH]; - unsigned long size; - - - if(RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", 0, KEY_READ, &key)==ERROR_SUCCESS) - { - size=MAX_PATH; - RegQueryValueEx(key, "Desktop", NULL, NULL, (unsigned char*)buffer, &size); - m_strPathDesktop = FilePath(buffer); - - size=MAX_PATH; - RegQueryValueEx(key, "Personal", NULL, NULL, (unsigned char*)buffer, &size); - m_strPathDocuments = FilePath(buffer); - } - else - m_strFindPath = "Error"; - - - m_strComputerName = wxGetHostName(); - } - - - - #elif defined __UNIX_LIKE__ - ////////////////////////////////////////////////////////////////////// - // Implémentation spécifique UNIX - ////////////////////////////////////////////////////////////////////// - - FileSystemStandardUnix::FileSystemStandardUnix(): - FileSystemStandardBase() - { - } - - Archive* FileSystemStandardUnix::GetFileArchive(FilePath strPath, unsigned int nMode) - { - return new ArchiveFile(strPath.GetFilePath(), (Archive::ARCHIVE_OPEN_MODE)nMode); - } - - wxString FileSystemStandardUnix::FindFirst(FilePath strPath, int iFlags) - { - wxString str; - m_strFindPath = strPath; - m_iFindFlags = iFlags; - - strPath.RemoveProtocol(); - str = strPath; - if(str.IsEmpty()) - str = wxT("/"); - - if(!m_Dir.Open(str)) - return ""; - m_Dir.GetFirst(&str, wxEmptyString, m_iFindFlags); - m_strCurrentFile = m_strFindPath + "/" + str; - return str; - } - - wxString FileSystemStandardUnix::FindNext() - { - wxString str; - m_Dir.GetNext(&str); - m_strCurrentFile = m_strFindPath + "/" + str; - return str; - } - - FilePath FileSystemStandardUnix::GetCurrentFilePath() - { - return m_strCurrentFile; - } - - - bool FileSystemStandardUnix::IsDirectory(FilePath strPath) - { - strPath.RemoveProtocol(); - if(strPath.IsEmpty()) - return true; - else - return wxDir::Exists(strPath); - } - - int FileSystemStandardUnix::GetDirectorySystemType(FilePath strPath) - { - if(strPath.IsEmpty()) - return WXDC_FS_DIRTYPE_MOUNT; - else if(strPath=="file:/mnt") - return WXDC_FS_DIRTYPE_MOUNT; - else if(strPath=="file:/home") - return WXDC_FS_DIRTYPE_HOME; - else if(strPath.GetFileDir()=="file:/home") - return WXDC_FS_DIRTYPE_DOC; - else - return WXDC_FS_DIRTYPE_NORMAL; - } - - #endif // Fin des implémentations spécifiques - - - - - - ////////////////////////////////////////////////////////////////////// // Archive de fichiers --- 54,57 ---- |