2 * Copyright 2003, 2004, 2005, 2006 Martin Fuchs
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 // Martin Fuchs, 23.07.2003
27 // Credits: Thanks to Leon Finker for his explorer cabinet window example
31 #include <precomp.h> // <precomp.h> instead of "precomp.h" because the ROS build system needs this to find the precompiled header file (*.gch) in the output directory tree
34 #include <locale.h> // for setlocale()
37 #include <io.h> // for dup2()
38 #include <fcntl.h> // for _O_RDONLY
41 //#include "dialogs/settings.h" // for MdiSdiDlg
43 #include "services/shellservices.h"
46 extern "C" int initialize_gdb_stub(); // start up GDB stub
49 DynamicLoadLibFct
<void(__stdcall
*)(BOOL
)> g_SHDOCVW_ShellDDEInit(TEXT("SHDOCVW"), 118);
52 ExplorerGlobals g_Globals
;
53 boolean SelectOpt
=FALSE
;
56 ExplorerGlobals::ExplorerGlobals()
64 _desktop_mode
= false;
65 _prescan_nodes
= false;
76 void ExplorerGlobals::init(HINSTANCE hInstance
)
78 _hInstance
= hInstance
;
79 _SHRestricted
= (DWORD(STDAPICALLTYPE
*)(RESTRICTIONS
)) GetProcAddress(GetModuleHandle(TEXT("SHELL32")), "SHRestricted");
84 void ExplorerGlobals::read_persistent()
86 // read configuration file
87 _cfg_dir
.printf(TEXT("%s\\ReactOS"), (LPCTSTR
)SpecialFolderFSPath(CSIDL_APPDATA
,0));
88 _cfg_path
.printf(TEXT("%s\\ros-explorer-cfg.xml"), _cfg_dir
.c_str());
90 if (!_cfg
.read_file(_cfg_path
)) {
91 if (!_cfg
._errors
.empty()) {
92 MessageBox(_hwndDesktop
,
94 TEXT("ROS Explorer - reading user settings"),
97 _cfg
.read_file(TEXT("explorer-cfg-template.xml"));
101 _favorites_path
.printf(TEXT("%s\\ros-explorer-bookmarks.xml"), _cfg_dir
.c_str());
103 if (!_favorites
.read(_favorites_path
)) {
104 _favorites
.import_IE_favorites(0);
105 _favorites
.write(_favorites_path
);
109 void ExplorerGlobals::write_persistent()
111 // write configuration file
112 RecursiveCreateDirectory(_cfg_dir
);
114 _cfg
.write_file(_cfg_path
);
115 _favorites
.write(_favorites_path
);
119 XMLPos
ExplorerGlobals::get_cfg()
121 XMLPos
cfg_pos(&_cfg
);
123 cfg_pos
.smart_create("explorer-cfg");
128 XMLPos
ExplorerGlobals::get_cfg(const char* path
)
130 XMLPos
cfg_pos(&_cfg
);
132 cfg_pos
.smart_create("explorer-cfg");
133 cfg_pos
.create_relative(path
);
139 void _log_(LPCTSTR txt
)
141 FmtString
msg(TEXT("%s\n"), txt
);
144 _fputts(msg
, g_Globals
._log
);
146 OutputDebugString(msg
);
150 bool FileTypeManager::is_exe_file(LPCTSTR ext
)
152 static const LPCTSTR s_executable_extensions
[] = {
163 TCHAR ext_buffer
[_MAX_EXT
];
168 for(s
=ext
+1,d
=ext_buffer
; (*d
=toupper(*s
)); s
++)
171 for(p
=s_executable_extensions
; *p
; p
++)
172 if (!lstrcmp(ext_buffer
, *p
))
179 const FileTypeInfo
& FileTypeManager::operator[](String ext
)
183 iterator found
= find(ext
);
185 return found
->second
;
187 FileTypeInfo
& ftype
= super::operator[](ext
);
189 ftype
._neverShowExt
= false;
192 TCHAR value
[MAX_PATH
], display_name
[MAX_PATH
];
193 LONG valuelen
= sizeof(value
);
195 if (!RegQueryValue(HKEY_CLASSES_ROOT
, ext
, value
, &valuelen
)) {
196 ftype
._classname
= value
;
198 valuelen
= sizeof(display_name
);
199 if (!RegQueryValue(HKEY_CLASSES_ROOT
, ftype
._classname
, display_name
, &valuelen
))
200 ftype
._displayname
= display_name
;
202 if (!RegOpenKey(HKEY_CLASSES_ROOT
, ftype
._classname
, &hkey
)) {
203 if (!RegQueryValueEx(hkey
, TEXT("NeverShowExt"), 0, NULL
, NULL
, NULL
))
204 ftype
._neverShowExt
= true;
213 LPCTSTR
FileTypeManager::set_type(Entry
* entry
, bool dont_hide_ext
)
215 LPCTSTR ext
= _tcsrchr(entry
->_data
.cFileName
, TEXT('.'));
218 const FileTypeInfo
& type
= (*this)[ext
];
220 if (!type
._displayname
.empty())
221 entry
->_type_name
= _tcsdup(type
._displayname
);
223 // hide some file extensions
224 if (type
._neverShowExt
&& !dont_hide_ext
) {
225 int len
= ext
- entry
->_data
.cFileName
;
227 if (entry
->_display_name
!= entry
->_data
.cFileName
)
228 free(entry
->_display_name
);
230 entry
->_display_name
= (LPTSTR
) malloc((len
+1)*sizeof(TCHAR
));
231 lstrcpyn(entry
->_display_name
, entry
->_data
.cFileName
, len
+ 1);
234 if (is_exe_file(ext
))
235 entry
->_data
.dwFileAttributes
|= ATTRIBUTE_EXECUTABLE
;
249 Icon::Icon(ICON_ID id
, UINT nid
) //, int cx, int cy
252 _hicon(ResIcon(nid
)) // ResIconEx(nid, cx, cy)
256 Icon::Icon(ICON_ID id
, UINT nid
, int icon_size
)
259 _hicon(ResIconEx(nid
, icon_size
, icon_size
))
263 Icon::Icon(ICON_TYPE itype
, int id
, HICON hIcon
)
270 Icon::Icon(ICON_TYPE itype
, int id
, int sys_idx
)
277 void Icon::draw(HDC hdc
, int x
, int y
, int cx
, int cy
, COLORREF bk_color
, HBRUSH bk_brush
) const
279 if (_itype
== IT_SYSCACHE
)
280 ImageList_DrawEx(g_Globals
._icon_cache
.get_sys_imagelist(), _sys_idx
, hdc
, x
, y
, cx
, cy
, bk_color
, CLR_DEFAULT
, ILD_NORMAL
);
282 DrawIconEx(hdc
, x
, y
, _hicon
, cx
, cy
, 0, bk_brush
, DI_NORMAL
);
285 HBITMAP
Icon::create_bitmap(COLORREF bk_color
, HBRUSH hbrBkgnd
, HDC hdc_wnd
) const
287 if (_itype
== IT_SYSCACHE
) {
288 HIMAGELIST himl
= g_Globals
._icon_cache
.get_sys_imagelist();
291 ImageList_GetIconSize(himl
, &cx
, &cy
);
293 HBITMAP hbmp
= CreateCompatibleBitmap(hdc_wnd
, cx
, cy
);
294 HDC hdc
= CreateCompatibleDC(hdc_wnd
);
295 HBITMAP hbmp_old
= SelectBitmap(hdc
, hbmp
);
296 ImageList_DrawEx(himl
, _sys_idx
, hdc
, 0, 0, cx
, cy
, bk_color
, CLR_DEFAULT
, ILD_NORMAL
);
297 SelectBitmap(hdc
, hbmp_old
);
302 return create_bitmap_from_icon(_hicon
, hbrBkgnd
, hdc_wnd
);
306 int Icon::add_to_imagelist(HIMAGELIST himl
, HDC hdc_wnd
, COLORREF bk_color
, HBRUSH bk_brush
) const
310 if (_itype
== IT_SYSCACHE
) {
311 HIMAGELIST himl
= g_Globals
._icon_cache
.get_sys_imagelist();
314 ImageList_GetIconSize(himl
, &cx
, &cy
);
316 HBITMAP hbmp
= CreateCompatibleBitmap(hdc_wnd
, cx
, cy
);
317 HDC hdc
= CreateCompatibleDC(hdc_wnd
);
318 HBITMAP hbmp_old
= SelectBitmap(hdc
, hbmp
);
319 ImageList_DrawEx(himl
, _sys_idx
, hdc
, 0, 0, cx
, cy
, bk_color
, CLR_DEFAULT
, ILD_NORMAL
);
320 SelectBitmap(hdc
, hbmp_old
);
323 ret
= ImageList_Add(himl
, hbmp
, 0);
327 ret
= ImageList_AddAlphaIcon(himl
, _hicon
, bk_brush
, hdc_wnd
);
332 HBITMAP
create_bitmap_from_icon(HICON hIcon
, HBRUSH hbrush_bkgnd
, HDC hdc_wnd
/*, int icon_size*/)
334 int cx
= ICON_SIZE_SMALL
;
335 int cy
= ICON_SIZE_SMALL
;
336 HBITMAP hbmp
= CreateCompatibleBitmap(hdc_wnd
, cx
, cy
);
339 BitmapSelection
sel(canvas
, hbmp
);
341 RECT rect
= {0, 0, cx
, cy
};
342 FillRect(canvas
, &rect
, hbrush_bkgnd
);
344 DrawIconEx(canvas
, 0, 0, hIcon
, cx
, cy
, 0, hbrush_bkgnd
, DI_NORMAL
);
349 HBITMAP
create_small_bitmap_from_icon(HICON hIcon
, HBRUSH hbrush_bkgnd
, HDC hdc_wnd
)
351 int cx
= GetSystemMetrics(SM_CXSMICON
);
352 int cy
= GetSystemMetrics(SM_CYSMICON
);
353 HBITMAP hbmp
= CreateCompatibleBitmap(hdc_wnd
, cx
, cy
);
356 BitmapSelection
sel(canvas
, hbmp
);
358 RECT rect
= {0, 0, cx
, cy
};
359 FillRect(canvas
, &rect
, hbrush_bkgnd
);
361 DrawIconEx(canvas
, 0, 0, hIcon
, cx
, cy
, 0, hbrush_bkgnd
, DI_NORMAL
);
366 int ImageList_AddAlphaIcon(HIMAGELIST himl
, HICON hIcon
, HBRUSH hbrush_bkgnd
, HDC hdc_wnd
)
368 HBITMAP hbmp
= create_bitmap_from_icon(hIcon
, hbrush_bkgnd
, hdc_wnd
);
370 int ret
= ImageList_Add(himl
, hbmp
, 0);
378 int IconCache::s_next_id
= ICID_DYNAMIC
;
381 void IconCache::init()
383 int icon_size
= STARTMENUROOT_ICON_SIZE
;
385 _icons
[ICID_NONE
] = Icon(IT_STATIC
, ICID_NONE
, (HICON
)0);
387 _icons
[ICID_FOLDER
] = Icon(ICID_FOLDER
, IDI_FOLDER
);
388 //_icons[ICID_DOCUMENT] = Icon(ICID_DOCUMENT, IDI_DOCUMENT);
389 _icons
[ICID_EXPLORER
] = Icon(ICID_EXPLORER
, IDI_EXPLORER
);
390 //_icons[ICID_APP] = Icon(ICID_APP, IDI_APPICON);
392 _icons
[ICID_CONFIG
] = Icon(ICID_CONFIG
, IDI_CONFIG
, icon_size
);
393 _icons
[ICID_DOCUMENTS
] = Icon(ICID_DOCUMENTS
, IDI_DOCUMENTS
, icon_size
);
394 _icons
[ICID_FAVORITES
] = Icon(ICID_FAVORITES
, IDI_FAVORITES
, icon_size
);
395 _icons
[ICID_INFO
] = Icon(ICID_INFO
, IDI_INFO
, icon_size
);
396 _icons
[ICID_APPS
] = Icon(ICID_APPS
, IDI_APPS
, icon_size
);
397 _icons
[ICID_SEARCH
] = Icon(ICID_SEARCH
, IDI_SEARCH
, icon_size
);
398 _icons
[ICID_ACTION
] = Icon(ICID_ACTION
, IDI_ACTION
, icon_size
);
399 _icons
[ICID_SEARCH_DOC
] = Icon(ICID_SEARCH_DOC
, IDI_SEARCH_DOC
, icon_size
);
400 _icons
[ICID_PRINTER
] = Icon(ICID_PRINTER
, IDI_PRINTER
, icon_size
);
401 _icons
[ICID_NETWORK
] = Icon(ICID_NETWORK
, IDI_NETWORK
, icon_size
);
402 _icons
[ICID_COMPUTER
] = Icon(ICID_COMPUTER
, IDI_COMPUTER
, icon_size
);
403 _icons
[ICID_LOGOFF
] = Icon(ICID_LOGOFF
, IDI_LOGOFF
, icon_size
);
404 _icons
[ICID_SHUTDOWN
] = Icon(ICID_SHUTDOWN
, IDI_SHUTDOWN
, icon_size
);
405 _icons
[ICID_RESTART
] = Icon(ICID_RESTART
, IDI_RESTART
, icon_size
);
406 _icons
[ICID_BOOKMARK
] = Icon(ICID_BOOKMARK
, IDI_DOT_TRANS
, icon_size
);
407 _icons
[ICID_MINIMIZE
] = Icon(ICID_MINIMIZE
, IDI_MINIMIZE
, icon_size
);
408 _icons
[ICID_CONTROLPAN
] = Icon(ICID_CONTROLPAN
, IDI_CONTROLPAN
, icon_size
);
409 _icons
[ICID_DESKSETTING
]= Icon(ICID_DESKSETTING
,IDI_DESKSETTING
,icon_size
);
410 _icons
[ICID_NETCONNS
] = Icon(ICID_NETCONNS
, IDI_NETCONNS
, icon_size
);
411 _icons
[ICID_ADMIN
] = Icon(ICID_ADMIN
, IDI_ADMIN
, icon_size
);
412 _icons
[ICID_RECENT
] = Icon(ICID_RECENT
, IDI_RECENT
, icon_size
);
416 const Icon
& IconCache::extract(LPCTSTR path
, ICONCACHE_FLAGS flags
)
418 // search for matching icon with unchanged flags in the cache
419 CacheKey
mapkey(path
, flags
);
420 PathCacheMap::iterator found
= _pathCache
.find(mapkey
);
422 if (found
!= _pathCache
.end())
423 return _icons
[found
->second
];
425 // search for matching icon with handle
426 CacheKey
mapkey_hicon(path
, flags
|ICF_HICON
);
427 if (flags
!= mapkey_hicon
.second
) {
428 found
= _pathCache
.find(mapkey_hicon
);
430 if (found
!= _pathCache
.end())
431 return _icons
[found
->second
];
434 // search for matching icon in the system image list cache
435 CacheKey
mapkey_syscache(path
, flags
|ICF_SYSCACHE
);
436 if (flags
!= mapkey_syscache
.second
) {
437 found
= _pathCache
.find(mapkey_syscache
);
439 if (found
!= _pathCache
.end())
440 return _icons
[found
->second
];
447 if (flags
& ICF_OPEN
)
448 shgfi_flags
|= SHGFI_OPENICON
;
450 if ((flags
&(ICF_LARGE
|ICF_MIDDLE
|ICF_OVERLAYS
|ICF_HICON
)) && !(flags
&ICF_SYSCACHE
)) {
451 shgfi_flags
|= SHGFI_ICON
;
453 if (!(flags
& (ICF_LARGE
|ICF_MIDDLE
)))
454 shgfi_flags
|= SHGFI_SMALLICON
;
456 if (flags
& ICF_OVERLAYS
)
457 shgfi_flags
|= SHGFI_ADDOVERLAYS
;
459 // get small/big icons with/without overlays
460 if (SHGetFileInfo(path
, 0, &sfi
, sizeof(sfi
), shgfi_flags
)) {
461 const Icon
& icon
= add(sfi
.hIcon
, IT_CACHED
);
463 ///@todo limit cache size
464 _pathCache
[mapkey_hicon
] = icon
;
469 assert(!(flags
&ICF_OVERLAYS
));
471 shgfi_flags
|= SHGFI_SYSICONINDEX
|SHGFI_SMALLICON
;
473 // use system image list - the "search program dialog" needs it
474 HIMAGELIST himlSys_small
= (HIMAGELIST
) SHGetFileInfo(path
, 0, &sfi
, sizeof(sfi
), shgfi_flags
);
477 _himlSys_small
= himlSys_small
;
479 const Icon
& icon
= add(sfi
.iIcon
/*, IT_SYSCACHE*/);
481 ///@todo limit cache size
482 _pathCache
[mapkey_syscache
] = icon
;
488 return _icons
[ICID_NONE
];
491 const Icon
& IconCache::extract(LPCTSTR path
, int icon_idx
, ICONCACHE_FLAGS flags
)
493 IdxCacheKey
key(path
, make_pair(icon_idx
, (flags
|ICF_HICON
)&~ICF_SYSCACHE
));
497 IdxCacheMap::iterator found
= _idxCache
.find(key
);
499 if (found
!= _idxCache
.end())
500 return _icons
[found
->second
];
504 if ((int)ExtractIconEx(path
, icon_idx
, NULL
, &hIcon
, 1) > 0) {
505 const Icon
& icon
= add(hIcon
, IT_CACHED
);
507 _idxCache
[key
] = icon
;
512 ///@todo retreive "http://.../favicon.ico" format icons
514 return _icons
[ICID_NONE
];
518 const Icon
& IconCache::extract(IExtractIcon
* pExtract
, LPCTSTR path
, int icon_idx
, ICONCACHE_FLAGS flags
)
520 HICON hIconLarge
= 0;
523 int icon_size
= ICON_SIZE_FROM_ICF(flags
);
524 HRESULT hr
= pExtract
->Extract(path
, icon_idx
, &hIconLarge
, &hIcon
, MAKELONG(GetSystemMetrics(SM_CXICON
), icon_size
));
526 if (hr
== NOERROR
) { //@@ oder SUCCEEDED(hr) ?
527 if (icon_size
> ICON_SIZE_SMALL
) { //@@ OK?
534 DestroyIcon(hIconLarge
);
538 return add(hIcon
); //@@ When do we want not to free this icons?
541 return _icons
[ICID_NONE
];
544 const Icon
& IconCache::extract(LPCITEMIDLIST pidl
, ICONCACHE_FLAGS flags
)
546 // search for matching icon with unchanged flags in the cache
547 PidlCacheKey
mapkey(pidl
, flags
);
548 PidlCacheMap::iterator found
= _pidlcache
.find(mapkey
);
550 if (found
!= _pidlcache
.end())
551 return _icons
[found
->second
];
553 // search for matching icon with handle
554 PidlCacheKey
mapkey_hicon(pidl
, flags
|ICF_HICON
);
555 if (flags
!= mapkey_hicon
.second
) {
556 found
= _pidlcache
.find(mapkey_hicon
);
558 if (found
!= _pidlcache
.end())
559 return _icons
[found
->second
];
562 // search for matching icon in the system image list cache
563 PidlCacheKey
mapkey_syscache(pidl
, flags
|ICF_SYSCACHE
);
564 if (flags
!= mapkey_syscache
.second
) {
565 found
= _pidlcache
.find(mapkey_syscache
);
567 if (found
!= _pidlcache
.end())
568 return _icons
[found
->second
];
573 int shgfi_flags
= SHGFI_PIDL
;
575 if (!(flags
& (ICF_LARGE
|ICF_MIDDLE
)))
576 shgfi_flags
|= SHGFI_SMALLICON
;
578 if (flags
& ICF_OPEN
)
579 shgfi_flags
|= SHGFI_OPENICON
;
581 if (flags
& ICF_SYSCACHE
) {
582 assert(!(flags
&ICF_OVERLAYS
));
584 HIMAGELIST himlSys
= (HIMAGELIST
) SHGetFileInfo((LPCTSTR
)pidl
, 0, &sfi
, sizeof(sfi
), SHGFI_SYSICONINDEX
|shgfi_flags
);
586 const Icon
& icon
= add(sfi
.iIcon
/*, IT_SYSCACHE*/);
588 ///@todo limit cache size
589 _pidlcache
[mapkey_syscache
] = icon
;
594 if (flags
& ICF_OVERLAYS
)
595 shgfi_flags
|= SHGFI_ADDOVERLAYS
;
597 if (SHGetFileInfo((LPCTSTR
)pidl
, 0, &sfi
, sizeof(sfi
), SHGFI_ICON
|shgfi_flags
)) {
598 const Icon
& icon
= add(sfi
.hIcon
, IT_CACHED
);
600 ///@todo limit cache size
601 _pidlcache
[mapkey_hicon
] = icon
;
607 return _icons
[ICID_NONE
];
611 const Icon
& IconCache::add(HICON hIcon
, ICON_TYPE type
)
613 int id
= ++s_next_id
;
615 return _icons
[id
] = Icon(type
, id
, hIcon
);
618 const Icon
& IconCache::add(int sys_idx
/*, ICON_TYPE type=IT_SYSCACHE*/)
620 int id
= ++s_next_id
;
622 return _icons
[id
] = SysCacheIcon(id
, sys_idx
);
625 const Icon
& IconCache::get_icon(int id
)
630 IconCache::~IconCache()
632 /* We don't need to free cached resources - they are automatically freed at process termination
633 for (int index = s_next_id; index >= 0; index--) {
634 IconMap::iterator found = _icons.find(index);
636 if (found != _icons.end()) {
637 Icon& icon = found->second;
639 if ((icon.get_icontype() == IT_DYNAMIC) ||
640 (icon.get_icontype() == IT_CACHED))
642 DestroyIcon(icon.get_hicon());
650 void IconCache::free_icon(int icon_id
)
652 IconMap::iterator found
= _icons
.find(icon_id
);
654 if (found
!= _icons
.end()) {
655 Icon
& icon
= found
->second
;
663 ResString::ResString(UINT nid
)
665 TCHAR buffer
[BUFFER_LEN
];
667 int len
= LoadString(g_Globals
._hInstance
, nid
, buffer
, sizeof(buffer
)/sizeof(TCHAR
));
669 super::assign(buffer
, len
);
673 ResIcon::ResIcon(UINT nid
)
675 _hicon
= LoadIcon(g_Globals
._hInstance
, MAKEINTRESOURCE(nid
));
678 SmallIcon::SmallIcon(UINT nid
)
680 _hicon
= (HICON
)LoadImage(g_Globals
._hInstance
, MAKEINTRESOURCE(nid
), IMAGE_ICON
, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), LR_SHARED
);
683 ResIconEx::ResIconEx(UINT nid
, int w
, int h
)
685 _hicon
= (HICON
)LoadImage(g_Globals
._hInstance
, MAKEINTRESOURCE(nid
), IMAGE_ICON
, w
, h
, LR_SHARED
);
689 void SetWindowIcon(HWND hwnd
, UINT nid
)
691 HICON hIcon
= ResIcon(nid
);
692 (void)Window_SetIcon(hwnd
, ICON_BIG
, hIcon
);
694 HICON hIconSmall
= SmallIcon(nid
);
695 (void)Window_SetIcon(hwnd
, ICON_SMALL
, hIconSmall
);
699 ResBitmap::ResBitmap(UINT nid
)
701 _hBmp
= LoadBitmap(g_Globals
._hInstance
, MAKEINTRESOURCE(nid
));
707 void explorer_show_frame(int cmdShow
, LPTSTR lpCmdLine
)
711 if (g_Globals
._hMainWnd
) {
712 if (IsIconic(g_Globals
._hMainWnd
))
713 ShowWindow(g_Globals
._hMainWnd
, SW_RESTORE
);
715 SetForegroundWindow(g_Globals
._hMainWnd
);
720 g_Globals
._prescan_nodes
= false;
723 cmd
._cmdShow
= cmdShow
;
725 // parse command line options, which may overwrite the MDI flag
727 cmd
.ParseCmdLine(lpCmdLine
);
729 // create main window
730 MainFrameBase::Create(cmd
);
733 bool ExplorerCmd::ParseCmdLine(LPCTSTR lpCmdLine
)
737 LPCTSTR b
= lpCmdLine
;
741 // remove leading space
742 while(_istspace((unsigned)*b
))
749 // options are separated by ','
751 if (*p
== '"') // Quote characters may appear at any position in the command line.
753 else if (*p
==',' && !quote
)
760 // remove trailing space
761 while(l
>0 && _istspace((unsigned)b
[l
-1]))
764 if (!EvaluateOption(String(b
, l
)))
777 bool ExplorerCmd::EvaluateOption(LPCTSTR option
)
781 // Remove quote characters, as they are evaluated at this point.
782 for(; *option
; ++option
)
788 if (option
[0] == '/') {
791 // option /e for windows in explorer mode
792 if (!_tcsicmp(option
, TEXT("e")))
793 _flags
|= OWM_EXPLORE
;
794 // option /root for rooted explorer windows
795 else if (!_tcsicmp(option
, TEXT("root")))
796 _flags
|= OWM_ROOTED
;
797 // non-standard options: /mdi, /sdi
798 else if (!_tcsicmp(option
, TEXT("mdi")))
800 else if (!_tcsicmp(option
, TEXT("sdi")))
802 else if (!_tcsicmp(option
, TEXT("n")))
806 else if (!_tcsicmp(option
, TEXT("select")))
817 if((SelectOpt
== TRUE
) && (PathFileExists(option
)))
819 WCHAR szDir
[MAX_PATH
];
821 _wsplitpath(option
, szPath
, szDir
, NULL
, NULL
);
822 wcscat(szPath
, szDir
);
823 PathRemoveBackslash(szPath
);
834 bool ExplorerCmd::IsValidPath() const
836 if (!_path
.empty()) {
837 DWORD attribs
= GetFileAttributes(_path
);
839 if (attribs
!=INVALID_FILE_ATTRIBUTES
&& (attribs
&FILE_ATTRIBUTE_DIRECTORY
))
840 return true; // file system path
841 else if (*_path
==':' && _path
.at(1)==':')
842 return true; // text encoded IDL
850 void explorer_show_frame(int cmdShow
, LPTSTR lpCmdLine
)
853 lpCmdLine
= TEXT("explorer.exe");
855 launch_file(GetDesktopWindow(), lpCmdLine
, cmdShow
);
861 PopupMenu::PopupMenu(UINT nid
)
863 HMENU hMenu
= LoadMenu(g_Globals
._hInstance
, MAKEINTRESOURCE(nid
));
864 _hmenu
= GetSubMenu(hMenu
, 0);
865 RemoveMenu(hMenu
, 0, MF_BYPOSITION
);
870 /// "About Explorer" Dialog
871 struct ExplorerAboutDlg
: public
873 OwnerDrawParent
<Dialog
>
876 typedef CtlColorParent
<
877 OwnerDrawParent
<Dialog
>
880 ExplorerAboutDlg(HWND hwnd
)
883 SetWindowIcon(hwnd
, IDI_REACTOS
);
885 new FlatButton(hwnd
, IDOK
);
887 _hfont
= CreateFont(20, 0, 0, 0, FW_BOLD
, TRUE
, 0, 0, 0, 0, 0, 0, 0, TEXT("Sans Serif"));
888 new ColorStatic(hwnd
, IDC_ROS_EXPLORER
, RGB(32,32,128), 0, _hfont
);
890 new HyperlinkCtrl(hwnd
, IDC_WWW
);
892 FmtString
ver_txt(ResString(IDS_EXPLORER_VERSION_STR
), (LPCTSTR
)ResString(IDS_VERSION_STR
));
893 SetWindowText(GetDlgItem(hwnd
, IDC_VERSION_TXT
), ver_txt
);
895 HWND hwnd_winver
= GetDlgItem(hwnd
, IDC_WIN_VERSION
);
896 SetWindowText(hwnd_winver
, get_windows_version_str());
897 SetWindowFont(hwnd_winver
, GetStockFont(DEFAULT_GUI_FONT
), FALSE
);
904 DeleteObject(_hfont
);
907 LRESULT
WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
915 return super::WndProc(nmsg
, wparam
, lparam
);
923 PaintCanvas
canvas(_hwnd
);
925 HICON hicon
= (HICON
) LoadImage(g_Globals
._hInstance
, MAKEINTRESOURCE(IDI_REACTOS_BIG
), IMAGE_ICON
, 0, 0, LR_SHARED
);
927 DrawIconEx(canvas
, 20, 10, hicon
, 0, 0, 0, 0, DI_NORMAL
);
934 void explorer_about(HWND hwndParent
)
936 Dialog::DoModal(IDD_ABOUT_EXPLORER
, WINDOW_CREATOR(ExplorerAboutDlg
), hwndParent
);
940 static void InitInstance(HINSTANCE hInstance
)
942 CONTEXT("InitInstance");
944 setlocale(LC_COLLATE
, ""); // set collating rules to local settings for compareName
947 // register frame window class
948 g_Globals
._hframeClass
= IconWindowClass(CLASSNAME_FRAME
,IDI_EXPLORER
);
950 // register child window class
951 WindowClass(CLASSNAME_CHILDWND
, CS_CLASSDC
|CS_DBLCLKS
).Register();
953 // register tree window class
954 WindowClass(CLASSNAME_WINEFILETREE
, CS_CLASSDC
|CS_DBLCLKS
).Register();
957 g_Globals
._cfStrFName
= RegisterClipboardFormat(CFSTR_FILENAME
);
961 int explorer_main(HINSTANCE hInstance
, LPTSTR lpCmdLine
, int cmdShow
)
963 CONTEXT("explorer_main");
965 // initialize Common Controls library
966 CommonControlInit usingCmnCtrl
;
969 InitInstance(hInstance
);
970 } catch(COMException
& e
) {
971 HandleException(e
, GetDesktopWindow());
976 if (cmdShow
!= SW_HIDE
) {
977 /* // don't maximize if being called from the ROS desktop
978 if (cmdShow == SW_SHOWNORMAL)
979 ///@todo read window placement from registry
980 cmdShow = SW_MAXIMIZE;
983 explorer_show_frame(cmdShow
, lpCmdLine
);
987 Window::MessageLoop();
993 static bool SetShellReadyEvent(LPCTSTR evtName
)
995 HANDLE hEvent
= OpenEvent(EVENT_MODIFY_STATE
, FALSE
, evtName
);
1000 CloseHandle(hEvent
);
1006 int WINAPI
_tWinMain(HINSTANCE hInstance
, HINSTANCE hPrevInstance
, LPTSTR lpCmdLine
, int nShowCmd
)
1008 CONTEXT("WinMain()");
1010 BOOL any_desktop_running
= IsAnyDesktopRunning();
1012 BOOL startup_desktop
;
1014 // strip extended options from the front of the command line
1017 while(*lpCmdLine
== '-') {
1018 while(*lpCmdLine
&& !_istspace((unsigned)*lpCmdLine
))
1019 ext_options
+= *lpCmdLine
++;
1021 while(_istspace((unsigned)*lpCmdLine
))
1025 // command line option "-install" to replace previous shell application with ROS Explorer
1026 if (_tcsstr(ext_options
,TEXT("-install"))) {
1027 // install ROS Explorer into the registry
1028 TCHAR path
[MAX_PATH
];
1030 int l
= GetModuleFileName(0, path
, COUNTOF(path
));
1034 if (!RegOpenKey(HKEY_LOCAL_MACHINE
, TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon"), &hkey
)) {
1036 ///@todo save previous shell application in config file
1038 RegSetValueEx(hkey
, TEXT("Shell"), 0, REG_SZ
, (LPBYTE
)path
, l
*sizeof(TCHAR
));
1042 if (!RegOpenKey(HKEY_CURRENT_USER
, TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon"), &hkey
)) {
1044 ///@todo save previous shell application in config file
1046 RegSetValueEx(hkey
, TEXT("Shell"), 0, REG_SZ
, (LPBYTE
)TEXT(""), l
*sizeof(TCHAR
));
1051 HWND shellWindow
= GetShellWindow();
1056 // terminate shell process for NT like systems
1057 GetWindowThreadProcessId(shellWindow
, &pid
);
1058 HANDLE hProcess
= OpenProcess(PROCESS_ALL_ACCESS
, FALSE
, pid
);
1060 // On Win 9x it's sufficient to destroy the shell window.
1061 DestroyWindow(shellWindow
);
1063 if (TerminateProcess(hProcess
, 0))
1064 WaitForSingleObject(hProcess
, INFINITE
);
1066 CloseHandle(hProcess
);
1069 startup_desktop
= TRUE
;
1071 // create desktop window and task bar only, if there is no other shell and we are
1072 // the first explorer instance
1073 // MS Explorer looks additionally into the registry entry HKCU\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\shell,
1074 // to decide wether it is currently configured as shell application.
1075 startup_desktop
= !any_desktop_running
;
1079 bool autostart
= !any_desktop_running
;
1081 // disable autostart if the SHIFT key is pressed
1082 if (GetAsyncKeyState(VK_SHIFT
) < 0)
1085 #ifdef _DEBUG //MF: disabled for debugging
1089 // If there is given the command line option "-desktop", create desktop window anyways
1090 if (_tcsstr(ext_options
,TEXT("-desktop")))
1091 startup_desktop
= TRUE
;
1093 else if (_tcsstr(ext_options
,TEXT("-nodesktop")))
1094 startup_desktop
= FALSE
;
1096 // Don't display cabinet window in desktop mode
1097 if (startup_desktop
&& !_tcsstr(ext_options
,TEXT("-explorer")))
1101 if (_tcsstr(ext_options
,TEXT("-noautostart")))
1103 else if (_tcsstr(ext_options
,TEXT("-autostart")))
1107 if (_tcsstr(ext_options
,TEXT("-console"))) {
1110 _dup2(_open_osfhandle((long)GetStdHandle(STD_INPUT_HANDLE
), _O_RDONLY
), 0);
1111 _dup2(_open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE
), 0), 1);
1112 _dup2(_open_osfhandle((long)GetStdHandle(STD_ERROR_HANDLE
), 0), 2);
1114 g_Globals
._log
= _fdopen(1, "w");
1115 setvbuf(g_Globals
._log
, 0, _IONBF
, 0);
1117 LOG(TEXT("starting explorer debug log\n"));
1122 if (startup_desktop
) {
1123 // hide the XP login screen (Credit to Nicolas Escuder)
1124 // another undocumented event: "Global\\msgina: ReturnToWelcome"
1125 if (!SetShellReadyEvent(TEXT("msgina: ShellReadyEvent")))
1126 SetShellReadyEvent(TEXT("Global\\msgina: ShellReadyEvent"));
1130 return 0; // no shell to launch, so exit immediatelly
1134 if (!any_desktop_running
) {
1135 // launch the shell DDE server
1136 if (g_SHDOCVW_ShellDDEInit
)
1137 (*g_SHDOCVW_ShellDDEInit
)(TRUE
);
1141 bool use_gdb_stub
= false; // !IsDebuggerPresent();
1143 if (_tcsstr(ext_options
,TEXT("-debug")))
1144 use_gdb_stub
= true;
1146 if (_tcsstr(ext_options
,TEXT("-break"))) {
1147 LOG(TEXT("debugger breakpoint"));
1152 // activate GDB remote debugging stub if no other debugger is running
1154 LOG(TEXT("waiting for debugger connection...\n"));
1156 initialize_gdb_stub();
1160 g_Globals
.init(hInstance
);
1162 // initialize COM and OLE before creating the desktop window
1165 // init common controls library
1166 CommonControlInit usingCmnCtrl
;
1168 g_Globals
.read_persistent();
1170 if (startup_desktop
) {
1173 g_Globals
._desktops
.init();
1175 g_Globals
._hwndDesktop
= DesktopWindow::Create();
1177 g_Globals
._desktops
.get_current_Desktop()->_hwndDesktop
= g_Globals
._hwndDesktop
;
1181 if (_tcsstr(ext_options
,TEXT("-?"))) {
1182 MessageBoxA(g_Globals
._hwndDesktop
,
1183 "/e open cabinet window in explorer mode\r\n"
1184 "/root open cabinet window in rooted mode\r\n"
1185 "/mdi open cabinet window in MDI mode\r\n"
1186 "/sdi open cabinet window in SDI mode\r\n"
1188 "-? display command line options\r\n"
1190 "-desktop start in desktop mode regardless of an already running shell\r\n"
1191 "-nodesktop disable desktop mode\r\n"
1192 "-explorer display cabinet window regardless of enabled desktop mode\r\n"
1194 "-install replace previous shell application with ROS Explorer\r\n"
1196 "-noautostart disable autostarts\r\n"
1197 "-autostart enable autostarts regardless of debug build\r\n"
1199 "-console open debug console\r\n"
1201 "-debug activate GDB remote debugging stub\r\n"
1202 "-break activate debugger breakpoint\r\n",
1203 "ROS Explorer - command line options", MB_OK
);
1207 * Set our shutdown parameters: we want to shutdown the very last,
1208 * but before any TaskMgr instance (which has a shutdown level of 1).
1210 SetProcessShutdownParameters(2, 0);
1212 Thread
* pSSOThread
= NULL
;
1214 if (startup_desktop
) {
1215 // launch SSO thread to allow message processing independent from the explorer main thread
1216 pSSOThread
= new SSOThread
;
1217 pSSOThread
->Start();
1220 /**TODO launching autostart programs can be moved into a background thread. */
1222 const char* argv
[] = {"", "s"}; // call startup routine in SESSION_START mode
1227 if (g_Globals
._hwndDesktop
)
1228 g_Globals
._desktop_mode
= true;
1232 int ret
= explorer_main(hInstance
, lpCmdLine
, nShowCmd
);
1235 // write configuration file
1236 g_Globals
.write_persistent();
1243 if (!any_desktop_running
) {
1244 // shutdown the shell DDE server
1245 if (g_SHDOCVW_ShellDDEInit
)
1246 (*g_SHDOCVW_ShellDDEInit
)(FALSE
);