From 18feaceddc0d616ea6c8bc120c9bad602b92bb35 Mon Sep 17 00:00:00 2001 From: Martin Fuchs Date: Sat, 31 Jan 2004 23:02:21 +0000 Subject: [PATCH] display types of files, NT objects and registry key/entries svn path=/trunk/; revision=7946 --- reactos/subsys/system/explorer/explorer.cpp | 62 ++++++++++++++++++- reactos/subsys/system/explorer/globals.h | 5 ++ .../subsys/system/explorer/shell/entries.cpp | 6 ++ .../subsys/system/explorer/shell/entries.h | 7 +++ .../subsys/system/explorer/shell/ntobjfs.cpp | 10 ++- .../subsys/system/explorer/shell/ntobjfs.h | 6 -- reactos/subsys/system/explorer/shell/pane.cpp | 54 ++++------------ reactos/subsys/system/explorer/shell/pane.h | 2 +- .../subsys/system/explorer/shell/regfs.cpp | 20 +++++- .../subsys/system/explorer/shell/shellfs.cpp | 13 ++-- .../subsys/system/explorer/shell/winfs.cpp | 4 ++ 11 files changed, 126 insertions(+), 63 deletions(-) diff --git a/reactos/subsys/system/explorer/explorer.cpp b/reactos/subsys/system/explorer/explorer.cpp index 167fce91fda..8cce5a40ad9 100644 --- a/reactos/subsys/system/explorer/explorer.cpp +++ b/reactos/subsys/system/explorer/explorer.cpp @@ -92,6 +92,35 @@ void _log_(LPCTSTR txt) } +bool FileTypeManager::is_exe_file(LPCTSTR ext) +{ + static const LPCTSTR s_executable_extensions[] = { + TEXT("COM"), + TEXT("EXE"), + TEXT("BAT"), + TEXT("CMD"), + TEXT("CMM"), + TEXT("BTM"), + TEXT("AWK"), + 0 + }; + + TCHAR ext_buffer[_MAX_EXT]; + const LPCTSTR* p; + LPCTSTR s; + LPTSTR d; + + for(s=ext+1,d=ext_buffer; (*d=toupper(*s)); s++) + ++d; + + for(p=s_executable_extensions; *p; p++) + if (!lstrcmp(ext_buffer, *p)) + return true; + + return false; +} + + const FileTypeInfo& FileTypeManager::operator[](String ext) { #ifndef __WINE__ ///@todo @@ -107,12 +136,16 @@ const FileTypeInfo& FileTypeManager::operator[](String ext) ftype._neverShowExt = false; HKEY hkey; - TCHAR value[MAX_PATH]; - LONG valuelen = MAX_PATH; + TCHAR value[MAX_PATH], display_name[MAX_PATH];; + LONG valuelen = sizeof(value); if (!RegQueryValue(HKEY_CLASSES_ROOT, ext, value, &valuelen)) { ftype._classname = value; + valuelen = sizeof(display_name); + if (!RegQueryValue(HKEY_CLASSES_ROOT, ftype._classname, display_name, &valuelen)) + ftype._displayname = display_name; + if (!RegOpenKey(HKEY_CLASSES_ROOT, ftype._classname, &hkey)) { if (!RegQueryValueEx(hkey, TEXT("NeverShowExt"), 0, NULL, NULL, NULL)) ftype._neverShowExt = true; @@ -124,6 +157,31 @@ const FileTypeInfo& FileTypeManager::operator[](String ext) return ftype; } +LPCTSTR FileTypeManager::set_type(Entry* entry, bool dont_hide_ext) +{ + LPCTSTR ext = _tcsrchr(entry->_data.cFileName, TEXT('.')); + + if (ext) { + const FileTypeInfo& type = (*this)[ext]; + + if (!type._displayname.empty()) + entry->_type_name = _tcsdup(type._displayname); + + // hide some file extensions + if (type._neverShowExt && !dont_hide_ext) { + int len = ext - entry->_data.cFileName; + entry->_display_name = (LPTSTR) malloc((len+1)*sizeof(TCHAR)); + _tcsncpy(entry->_display_name, entry->_data.cFileName, len); + entry->_display_name[len] = TEXT('\0'); + } + + if (is_exe_file(ext)) + entry->_data.dwFileAttributes |= ATTRIBUTE_EXECUTABLE; + } + + return ext; +} + Icon::Icon() : _id(ICID_UNKNOWN), diff --git a/reactos/subsys/system/explorer/globals.h b/reactos/subsys/system/explorer/globals.h index 6c76a5ddab3..1443dde1076 100644 --- a/reactos/subsys/system/explorer/globals.h +++ b/reactos/subsys/system/explorer/globals.h @@ -29,6 +29,7 @@ /// management of file types struct FileTypeInfo { String _classname; + String _displayname; bool _neverShowExt; }; @@ -37,6 +38,10 @@ struct FileTypeManager : public map typedef map super; const FileTypeInfo& operator[](String ext); + + static bool is_exe_file(LPCTSTR ext); + + LPCTSTR set_type(struct Entry* entry, bool dont_hide_ext=false); }; diff --git a/reactos/subsys/system/explorer/shell/entries.cpp b/reactos/subsys/system/explorer/shell/entries.cpp index 5540eb677a4..d481914b4d2 100644 --- a/reactos/subsys/system/explorer/shell/entries.cpp +++ b/reactos/subsys/system/explorer/shell/entries.cpp @@ -46,6 +46,7 @@ Entry::Entry(ENTRY_TYPE etype) _level = 0; _icon_id = ICID_UNKNOWN; _display_name = _data.cFileName; + _type_name = NULL; } Entry::Entry(Entry* parent, ENTRY_TYPE etype) @@ -60,6 +61,7 @@ Entry::Entry(Entry* parent, ENTRY_TYPE etype) _level = 0; _icon_id = ICID_UNKNOWN; _display_name = _data.cFileName; + _type_name = NULL; } Entry::Entry(const Entry& other) @@ -80,6 +82,7 @@ Entry::Entry(const Entry& other) _shell_attribs = other._shell_attribs; _display_name = other._display_name==other._data.cFileName? _data.cFileName: _tcsdup(other._display_name); + _type_name = other._type_name? _tcsdup(other._type_name): NULL; _etype = other._etype; _icon_id = other._icon_id; @@ -96,6 +99,9 @@ Entry::~Entry() if (_display_name != _data.cFileName) free(_display_name); + + if (_type_name) + free(_type_name); } diff --git a/reactos/subsys/system/explorer/shell/entries.h b/reactos/subsys/system/explorer/shell/entries.h index 4f5564f1f42..b875f21ff87 100644 --- a/reactos/subsys/system/explorer/shell/entries.h +++ b/reactos/subsys/system/explorer/shell/entries.h @@ -53,6 +53,12 @@ enum SCAN_FLAGS { SCAN_FILESYSTEM = 4 }; +#ifndef ATTRIBUTE_SYMBOLIC_LINK +#define ATTRIBUTE_SYMBOLIC_LINK 0x40000000 +#define ATTRIBUTE_EXECUTABLE 0x80000000 +#endif + + /// base of all file and directory entries struct Entry { @@ -76,6 +82,7 @@ public: SFGAOF _shell_attribs; LPTSTR _display_name; + LPTSTR _type_name; ENTRY_TYPE _etype; int /*ICON_ID*/ _icon_id; diff --git a/reactos/subsys/system/explorer/shell/ntobjfs.cpp b/reactos/subsys/system/explorer/shell/ntobjfs.cpp index e51bb729e3b..5edea5fc49f 100644 --- a/reactos/subsys/system/explorer/shell/ntobjfs.cpp +++ b/reactos/subsys/system/explorer/shell/ntobjfs.cpp @@ -230,10 +230,8 @@ void NtObjDirectory::read_directory(int scan_flags) #ifdef UNICODE wcscpyn(p, info->name.string_ptr, _MAX_PATH); - //@@wcscpyn(_class, info->type.string_ptr, 32); #else WideCharToMultiByte(CP_ACP, 0, info->name.string_ptr, info->name.string_len, p, MAX_PATH, 0, 0); - //@@U2T(info->type.string_ptr, _class, 32); #endif lstrcpy(w32fd.cFileName, p); @@ -301,6 +299,14 @@ void NtObjDirectory::read_directory(int scan_flags) memcpy(&entry->_data, &w32fd, sizeof(WIN32_FIND_DATA)); +#ifdef UNICODE + entry->_type_name = _wcsdup(info->type.string_ptr); +#else + char type_name[32]; + WideCharToMultiByte(CP_ACP, 0, info->type.string_ptr, info->type.string_len, type_name, 32, 0, 0); + entry->_type_name = strdup(type_name); +#endif + if (!first_entry) first_entry = entry; diff --git a/reactos/subsys/system/explorer/shell/ntobjfs.h b/reactos/subsys/system/explorer/shell/ntobjfs.h index 2738d2b504c..833516980ad 100644 --- a/reactos/subsys/system/explorer/shell/ntobjfs.h +++ b/reactos/subsys/system/explorer/shell/ntobjfs.h @@ -81,12 +81,6 @@ struct NtObject { }; -#ifndef ATTRIBUTE_SYMBOLIC_LINK -#define ATTRIBUTE_SYMBOLIC_LINK 0x40000000 -#define ATTRIBUTE_EXECUTABLE 0x80000000 -#endif - - /// NtObj file system file-entry struct NtObjEntry : public Entry { diff --git a/reactos/subsys/system/explorer/shell/pane.cpp b/reactos/subsys/system/explorer/shell/pane.cpp index 3ba2a16d952..b9b97b19a6b 100644 --- a/reactos/subsys/system/explorer/shell/pane.cpp +++ b/reactos/subsys/system/explorer/shell/pane.cpp @@ -45,45 +45,10 @@ enum IMAGE { #define IMAGE_HEIGHT 13 -static int is_exe_file(LPCTSTR ext) -{ - static const LPCTSTR executable_extensions[] = { - TEXT("COM"), - TEXT("EXE"), - TEXT("BAT"), - TEXT("CMD"), - TEXT("CMM"), - TEXT("BTM"), - TEXT("AWK"), - 0 - }; - - TCHAR ext_buffer[_MAX_EXT]; - const LPCTSTR* p; - LPCTSTR s; - LPTSTR d; - - for(s=ext+1,d=ext_buffer; (*d=tolower(*s)); s++) - ++d; - - for(p=executable_extensions; *p; p++) - if (!lstrcmp(ext_buffer, *p)) - return 1; - - return 0; -} - -static int is_registered_type(LPCTSTR ext) -{ - // TODO - - return 1; -} - - static const LPTSTR g_pos_names[COLUMNS] = { TEXT(""), /* symbol */ TEXT("Name"), + TEXT("Type"), TEXT("Size"), TEXT("CDate"), TEXT("ADate"), @@ -97,6 +62,7 @@ static const LPTSTR g_pos_names[COLUMNS] = { static const int g_pos_align[] = { 0, HDF_LEFT, /* Name */ + HDF_LEFT, /* Type */ HDF_RIGHT, /* Size */ HDF_LEFT, /* CDate */ HDF_LEFT, /* ADate */ @@ -353,13 +319,9 @@ void Pane::draw_item(LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol) else img = IMG_FOLDER; } else { - LPCTSTR ext = _tcsrchr(entry->_data.cFileName, TEXT('.')); - if (!ext) - ext = TEXT(""); - - if (is_exe_file(ext)) + if (attrs & ATTRIBUTE_EXECUTABLE) img = IMG_EXECUTABLE; - else if (is_registered_type(ext)) + else if (entry->_type_name) img = IMG_DOCUMENT; else img = IMG_FILE; @@ -521,6 +483,14 @@ void Pane::draw_item(LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol) else if (calcWidthCol==col || calcWidthCol==COLUMNS) calc_width(dis, col, entry->_display_name); + ++col; + + // ouput type/class name + if (calcWidthCol == -1) + _out_wrkr.output_text(dis, _positions, col, entry->_type_name, 0); + else if (calcWidthCol==col || calcWidthCol==COLUMNS) + calc_width(dis, col, entry->_type_name); + ++col; // display file size diff --git a/reactos/subsys/system/explorer/shell/pane.h b/reactos/subsys/system/explorer/shell/pane.h index 67f3c9dcd4e..fdc3fa452e5 100644 --- a/reactos/subsys/system/explorer/shell/pane.h +++ b/reactos/subsys/system/explorer/shell/pane.h @@ -67,7 +67,7 @@ struct Pane : public SubclassedWindow Pane(HWND hparent, int id, int id_header, Entry* rool, bool treePane, int visible_cols); -#define COLUMNS 10 +#define COLUMNS 11 int _widths[COLUMNS]; int _positions[COLUMNS+1]; diff --git a/reactos/subsys/system/explorer/shell/regfs.cpp b/reactos/subsys/system/explorer/shell/regfs.cpp index 79c2ac93aeb..3bfcb1ee0cf 100644 --- a/reactos/subsys/system/explorer/shell/regfs.cpp +++ b/reactos/subsys/system/explorer/shell/regfs.cpp @@ -68,7 +68,6 @@ void RegDirectory::read_directory(int scan_flags) w32fd.dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY; _tcscpy(p, name); - ///@todo class_name -> _entry->_class_name lstrcpy(w32fd.cFileName, p); @@ -76,6 +75,9 @@ void RegDirectory::read_directory(int scan_flags) memcpy(&entry->_data, &w32fd, sizeof(WIN32_FIND_DATA)); + if (*class_name) + entry->_type_name = _tcsdup(class_name); + if (!first_entry) first_entry = entry; @@ -100,7 +102,6 @@ void RegDirectory::read_directory(int scan_flags) memset(&w32fd, 0, sizeof(WIN32_FIND_DATA)); _tcscpy(p, name); - ///@todo type -> _entry->_class_name lstrcpy(w32fd.cFileName, p); @@ -108,6 +109,21 @@ void RegDirectory::read_directory(int scan_flags) memcpy(&entry->_data, &w32fd, sizeof(WIN32_FIND_DATA)); + switch(type) { + case REG_NONE: entry->_type_name = _tcsdup(TEXT("REG_NONE")); break; + case REG_SZ: entry->_type_name = _tcsdup(TEXT("REG_SZ")); break; + case REG_EXPAND_SZ: entry->_type_name = _tcsdup(TEXT("REG_EXPAND_SZ")); break; + case REG_BINARY: entry->_type_name = _tcsdup(TEXT("REG_BINARY")); break; + case REG_DWORD: entry->_type_name = _tcsdup(TEXT("REG_DWORD")); break; + case REG_DWORD_BIG_ENDIAN: entry->_type_name = _tcsdup(TEXT("REG_DWORD_BIG_ENDIAN")); break; + case REG_LINK: entry->_type_name = _tcsdup(TEXT("REG_LINK")); break; + case REG_MULTI_SZ: entry->_type_name = _tcsdup(TEXT("REG_MULTI_SZ")); break; + case REG_RESOURCE_LIST: entry->_type_name = _tcsdup(TEXT("REG_RESOURCE_LIST")); break; + case REG_FULL_RESOURCE_DESCRIPTOR: entry->_type_name = _tcsdup(TEXT("REG_FULL_RESOURCE_DESCRIPTOR")); break; + case REG_RESOURCE_REQUIREMENTS_LIST: entry->_type_name = _tcsdup(TEXT("REG_RESOURCE_REQUIREMENTS_LIST"));break; + case REG_QWORD: entry->_type_name = _tcsdup(TEXT("REG_QWORD")); break; + } + if (!first_entry) first_entry = entry; diff --git a/reactos/subsys/system/explorer/shell/shellfs.cpp b/reactos/subsys/system/explorer/shell/shellfs.cpp index 77fe42c53e6..593bf5bfab3 100644 --- a/reactos/subsys/system/explorer/shell/shellfs.cpp +++ b/reactos/subsys/system/explorer/shell/shellfs.cpp @@ -282,14 +282,8 @@ void ShellDirectory::read_directory(int scan_flags) } } - LPCTSTR ext = _tcsrchr(entry->_data.cFileName, TEXT('.')); - - if (ext && g_Globals._ftype_mgr[ext]._neverShowExt) { - int len = ext - entry->_data.cFileName; - entry->_display_name = (LPTSTR) malloc((len+1)*sizeof(TCHAR)); - _tcsncpy(entry->_display_name, entry->_data.cFileName, len); - entry->_display_name[len] = TEXT('\0'); - } + // set file type name + LPCTSTR ext = g_Globals._ftype_mgr.set_type(entry); DWORD attribs = SFGAO_FILESYSTEM; @@ -408,6 +402,9 @@ void ShellDirectory::read_directory(int scan_flags) entry->_shell_attribs = attribs; entry->_bhfi_valid = bhfi_valid; + // set file type name + g_Globals._ftype_mgr.set_type(entry); + // get icons for files and virtual objects if (!(entry->_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) || !(attribs & SFGAO_FILESYSTEM)) { diff --git a/reactos/subsys/system/explorer/shell/winfs.cpp b/reactos/subsys/system/explorer/shell/winfs.cpp index 0a5bcb413d0..4737fccb614 100644 --- a/reactos/subsys/system/explorer/shell/winfs.cpp +++ b/reactos/subsys/system/explorer/shell/winfs.cpp @@ -28,6 +28,7 @@ #include "../utility/utility.h" #include "../utility/shellclasses.h" +#include "../globals.h" #include "entries.h" #include "winfs.h" @@ -159,6 +160,9 @@ void WinDirectory::read_directory(int scan_flags) entry->_scanned = false; entry->_level = level; + // display file type names, but don't hide file extensions + g_Globals._ftype_mgr.set_type(entry, true); + if (scan_flags & SCAN_DO_ACCESS) { HANDLE hFile = CreateFile(buffer, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);