2 * Copyright 2003, 2004 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 // Martin Fuchs, 23.07.2003
27 // Credits: Thanks to Leon Finker for his explorer cabinet window example
33 #include "explorer_intres.h"
35 #include <locale.h> // for setlocale()
38 #include <io.h> // for dup2()
39 #include <fcntl.h> // for _O_RDONLY
42 #include "dialogs/settings.h" // for MdiSdiDlg
45 extern "C" int initialize_gdb_stub(); // start up GDB stub
48 ExplorerGlobals g_Globals
;
51 ExplorerGlobals::ExplorerGlobals()
57 _prescan_nodes
= false;
58 _desktop_mode
= false;
60 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
69 void ExplorerGlobals::init(HINSTANCE hInstance
)
71 _hInstance
= hInstance
;
73 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
74 _SHRestricted
= (DWORD(STDAPICALLTYPE
*)(RESTRICTIONS
)) GetProcAddress(GetModuleHandle(TEXT("SHELL32")), "SHRestricted");
81 void ExplorerGlobals::read_persistent()
83 // read configuration file
84 _cfg_dir
.printf(TEXT("%s\\ReactOS"), (LPCTSTR
)SpecialFolderFSPath(CSIDL_APPDATA
,0));
85 _cfg_path
.printf(TEXT("%s\\ros-explorer-cfg.xml"), _cfg_dir
.c_str());
87 if (!_cfg
.read(_cfg_path
)) {
88 if (_cfg
._last_error
!= XML_ERROR_NO_ELEMENTS
)
89 MessageBox(g_Globals
._hwndDesktop
, String(_cfg
._last_error_msg
.c_str()),
90 TEXT("ROS Explorer - reading user settings"), MB_OK
);
92 _cfg
.read(TEXT("explorer-cfg-template.xml"));
96 _favorites_path
.printf(TEXT("%s\\ros-explorer-bookmarks.xml"), _cfg_dir
.c_str());
98 if (!_favorites
.read(_favorites_path
)) {
99 _favorites
.import_IE_favorites(0);
100 _favorites
.write(_favorites_path
);
104 void ExplorerGlobals::write_persistent()
106 // write configuration file
107 RecursiveCreateDirectory(_cfg_dir
);
109 _cfg
.write(_cfg_path
);
110 _favorites
.write(_favorites_path
);
114 XMLPos
ExplorerGlobals::get_cfg()
116 XMLPos
cfg_pos(&_cfg
);
118 cfg_pos
.smart_create("explorer-cfg");
123 XMLPos
ExplorerGlobals::get_cfg(const char* path
)
125 XMLPos
cfg_pos(&_cfg
);
127 cfg_pos
.smart_create("explorer-cfg");
128 cfg_pos
.create_relative(path
);
134 void _log_(LPCTSTR txt
)
136 FmtString
msg(TEXT("%s\n"), txt
);
139 _fputts(msg
, g_Globals
._log
);
141 OutputDebugString(msg
);
145 bool FileTypeManager::is_exe_file(LPCTSTR ext
)
147 static const LPCTSTR s_executable_extensions
[] = {
158 TCHAR ext_buffer
[_MAX_EXT
];
163 for(s
=ext
+1,d
=ext_buffer
; (*d
=toupper(*s
)); s
++)
166 for(p
=s_executable_extensions
; *p
; p
++)
167 if (!lstrcmp(ext_buffer
, *p
))
174 const FileTypeInfo
& FileTypeManager::operator[](String ext
)
176 #ifndef __WINE__ ///@todo _tcslwr() for Wine
177 _tcslwr((LPTSTR
)ext
.c_str());
180 iterator found
= find(ext
);
182 return found
->second
;
184 FileTypeInfo
& ftype
= super::operator[](ext
);
186 ftype
._neverShowExt
= false;
189 TCHAR value
[MAX_PATH
], display_name
[MAX_PATH
];
190 LONG valuelen
= sizeof(value
);
192 if (!RegQueryValue(HKEY_CLASSES_ROOT
, ext
, value
, &valuelen
)) {
193 ftype
._classname
= value
;
195 valuelen
= sizeof(display_name
);
196 if (!RegQueryValue(HKEY_CLASSES_ROOT
, ftype
._classname
, display_name
, &valuelen
))
197 ftype
._displayname
= display_name
;
199 if (!RegOpenKey(HKEY_CLASSES_ROOT
, ftype
._classname
, &hkey
)) {
200 if (!RegQueryValueEx(hkey
, TEXT("NeverShowExt"), 0, NULL
, NULL
, NULL
))
201 ftype
._neverShowExt
= true;
210 LPCTSTR
FileTypeManager::set_type(Entry
* entry
, bool dont_hide_ext
)
212 LPCTSTR ext
= _tcsrchr(entry
->_data
.cFileName
, TEXT('.'));
215 const FileTypeInfo
& type
= (*this)[ext
];
217 if (!type
._displayname
.empty())
218 entry
->_type_name
= _tcsdup(type
._displayname
);
220 // hide some file extensions
221 if (type
._neverShowExt
&& !dont_hide_ext
) {
222 int len
= ext
- entry
->_data
.cFileName
;
223 entry
->_display_name
= (LPTSTR
) malloc((len
+1)*sizeof(TCHAR
));
224 _tcsncpy(entry
->_display_name
, entry
->_data
.cFileName
, len
);
225 entry
->_display_name
[len
] = TEXT('\0');
228 if (is_exe_file(ext
))
229 entry
->_data
.dwFileAttributes
|= ATTRIBUTE_EXECUTABLE
;
243 Icon::Icon(ICON_ID id
, UINT nid
)
246 _hicon(SmallIcon(nid
))
250 Icon::Icon(ICON_TYPE itype
, int id
, HICON hIcon
)
257 Icon::Icon(ICON_TYPE itype
, int id
, int sys_idx
)
264 void Icon::draw(HDC hdc
, int x
, int y
, int cx
, int cy
, COLORREF bk_color
, HBRUSH bk_brush
) const
266 if (_itype
== IT_SYSCACHE
)
267 ImageList_DrawEx(g_Globals
._icon_cache
.get_sys_imagelist(), _sys_idx
, hdc
, x
, y
, cx
, cy
, bk_color
, CLR_DEFAULT
, ILD_NORMAL
);
269 DrawIconEx(hdc
, x
, y
, _hicon
, cx
, cy
, 0, bk_brush
, DI_NORMAL
);
272 HBITMAP
Icon::create_bitmap(COLORREF bk_color
, HBRUSH hbrBkgnd
, HDC hdc_wnd
) const
274 if (_itype
== IT_SYSCACHE
) {
275 HIMAGELIST himl
= g_Globals
._icon_cache
.get_sys_imagelist();
278 ImageList_GetIconSize(himl
, &cx
, &cy
);
280 HBITMAP hbmp
= CreateCompatibleBitmap(hdc_wnd
, cx
, cy
);
281 HDC hdc
= CreateCompatibleDC(hdc_wnd
);
282 HBITMAP hbmp_old
= SelectBitmap(hdc
, hbmp
);
283 ImageList_DrawEx(himl
, _sys_idx
, hdc
, 0, 0, cx
, cy
, bk_color
, CLR_DEFAULT
, ILD_NORMAL
);
284 SelectBitmap(hdc
, hbmp_old
);
289 return create_bitmap_from_icon(_hicon
, hbrBkgnd
, hdc_wnd
);
293 int Icon::add_to_imagelist(HIMAGELIST himl
, HDC hdc_wnd
, COLORREF bk_color
, HBRUSH bk_brush
) const
297 if (_itype
== IT_SYSCACHE
) {
298 HIMAGELIST himl
= g_Globals
._icon_cache
.get_sys_imagelist();
301 ImageList_GetIconSize(himl
, &cx
, &cy
);
303 HBITMAP hbmp
= CreateCompatibleBitmap(hdc_wnd
, cx
, cy
);
304 HDC hdc
= CreateCompatibleDC(hdc_wnd
);
305 HBITMAP hbmp_old
= SelectBitmap(hdc
, hbmp
);
306 ImageList_DrawEx(himl
, _sys_idx
, hdc
, 0, 0, cx
, cy
, bk_color
, CLR_DEFAULT
, ILD_NORMAL
);
307 SelectBitmap(hdc
, hbmp_old
);
310 ret
= ImageList_Add(himl
, hbmp
, 0);
314 ret
= ImageList_AddAlphaIcon(himl
, _hicon
, bk_brush
, hdc_wnd
);
319 HBITMAP
create_bitmap_from_icon(HICON hIcon
, HBRUSH hbrush_bkgnd
, HDC hdc_wnd
)
321 int cx
= GetSystemMetrics(SM_CXSMICON
);
322 int cy
= GetSystemMetrics(SM_CYSMICON
);
323 HBITMAP hbmp
= CreateCompatibleBitmap(hdc_wnd
, cx
, cy
);
326 BitmapSelection
sel(canvas
, hbmp
);
328 RECT rect
= {0, 0, cx
, cy
};
329 FillRect(canvas
, &rect
, hbrush_bkgnd
);
331 DrawIconEx(canvas
, 0, 0, hIcon
, cx
, cy
, 0, hbrush_bkgnd
, DI_NORMAL
);
336 int ImageList_AddAlphaIcon(HIMAGELIST himl
, HICON hIcon
, HBRUSH hbrush_bkgnd
, HDC hdc_wnd
)
338 HBITMAP hbmp
= create_bitmap_from_icon(hIcon
, hbrush_bkgnd
, hdc_wnd
);
340 int ret
= ImageList_Add(himl
, hbmp
, 0);
348 int IconCache::s_next_id
= ICID_DYNAMIC
;
351 void IconCache::init()
353 _icons
[ICID_NONE
] = Icon(IT_STATIC
, ICID_NONE
, (HICON
)0);
355 _icons
[ICID_FOLDER
] = Icon(ICID_FOLDER
, IDI_FOLDER
);
356 //_icons[ICID_DOCUMENT] = Icon(ICID_DOCUMENT, IDI_DOCUMENT);
357 _icons
[ICID_EXPLORER
] = Icon(ICID_EXPLORER
, IDI_EXPLORER
);
358 _icons
[ICID_APP
] = Icon(ICID_APP
, IDI_APPICON
);
360 _icons
[ICID_CONFIG
] = Icon(ICID_CONFIG
, IDI_CONFIG
);
361 _icons
[ICID_DOCUMENTS
] = Icon(ICID_DOCUMENTS
, IDI_DOCUMENTS
);
362 _icons
[ICID_FAVORITES
] = Icon(ICID_FAVORITES
, IDI_FAVORITES
);
363 _icons
[ICID_INFO
] = Icon(ICID_INFO
, IDI_INFO
);
364 _icons
[ICID_APPS
] = Icon(ICID_APPS
, IDI_APPS
);
365 _icons
[ICID_SEARCH
] = Icon(ICID_SEARCH
, IDI_SEARCH
);
366 _icons
[ICID_ACTION
] = Icon(ICID_ACTION
, IDI_ACTION
);
367 _icons
[ICID_SEARCH_DOC
] = Icon(ICID_SEARCH_DOC
, IDI_SEARCH_DOC
);
368 _icons
[ICID_PRINTER
] = Icon(ICID_PRINTER
, IDI_PRINTER
);
369 _icons
[ICID_NETWORK
] = Icon(ICID_NETWORK
, IDI_NETWORK
);
370 _icons
[ICID_COMPUTER
] = Icon(ICID_COMPUTER
, IDI_COMPUTER
);
371 _icons
[ICID_LOGOFF
] = Icon(ICID_LOGOFF
, IDI_LOGOFF
);
372 _icons
[ICID_BOOKMARK
] = Icon(ICID_BOOKMARK
, IDI_DOT_TRANS
);
376 const Icon
& IconCache::extract(const String
& path
)
378 PathMap::iterator found
= _pathMap
.find(path
);
380 if (found
!= _pathMap
.end())
381 return _icons
[found
->second
];
385 #if 1 // use system image list
386 HIMAGELIST himlSys
= (HIMAGELIST
) SHGetFileInfo(path
, 0, &sfi
, sizeof(sfi
), SHGFI_SYSICONINDEX
|SHGFI_SMALLICON
);
391 const Icon
& icon
= add(sfi
.iIcon
/*, IT_SYSCACHE*/);
393 if (SHGetFileInfo(path
, 0, &sfi
, sizeof(sfi
), SHGFI_ICON
|SHGFI_SMALLICON
)) {
394 const Icon
& icon
= add(sfi
.hIcon
, IT_CACHED
);
397 ///@todo limit cache size
398 _pathMap
[path
] = icon
;
402 return _icons
[ICID_NONE
];
405 const Icon
& IconCache::extract(LPCTSTR path
, int idx
)
407 CachePair
key(path
, idx
);
409 #ifndef __WINE__ ///@todo _tcslwr() for Wine
410 _tcslwr((LPTSTR
)key
.first
.c_str());
413 PathIdxMap::iterator found
= _pathIdxMap
.find(key
);
415 if (found
!= _pathIdxMap
.end())
416 return _icons
[found
->second
];
420 if ((int)ExtractIconEx(path
, idx
, NULL
, &hIcon
, 1) > 0) {
421 const Icon
& icon
= add(hIcon
, IT_CACHED
);
423 _pathIdxMap
[key
] = icon
;
428 ///@todo retreive "http://.../favicon.ico" format icons
430 return _icons
[ICID_NONE
];
434 const Icon
& IconCache::extract(IExtractIcon
* pExtract
, LPCTSTR path
, int idx
)
436 HICON hIconLarge
= 0;
439 HRESULT hr
= pExtract
->Extract(path
, idx
, &hIconLarge
, &hIcon
, MAKELONG(0/*GetSystemMetrics(SM_CXICON)*/,GetSystemMetrics(SM_CXSMICON
)));
441 if (hr
== NOERROR
) { //@@ oder SUCCEEDED(hr) ?
443 DestroyIcon(hIconLarge
);
449 return _icons
[ICID_NONE
];
452 const Icon
& IconCache::add(HICON hIcon
, ICON_TYPE type
)
454 int id
= ++s_next_id
;
456 return _icons
[id
] = Icon(type
, id
, hIcon
);
459 const Icon
& IconCache::add(int sys_idx
/*, ICON_TYPE type=IT_SYSCACHE*/)
461 int id
= ++s_next_id
;
463 return _icons
[id
] = SysCacheIcon(id
, sys_idx
);
466 const Icon
& IconCache::get_icon(int id
)
471 void IconCache::free_icon(int icon_id
)
473 IconMap::iterator found
= _icons
.find(icon_id
);
475 if (found
!= _icons
.end()) {
476 Icon
& icon
= found
->second
;
484 ResString::ResString(UINT nid
)
486 TCHAR buffer
[BUFFER_LEN
];
488 int len
= LoadString(g_Globals
._hInstance
, nid
, buffer
, sizeof(buffer
)/sizeof(TCHAR
));
490 super::assign(buffer
, len
);
494 ResIcon::ResIcon(UINT nid
)
496 _hicon
= LoadIcon(g_Globals
._hInstance
, MAKEINTRESOURCE(nid
));
499 SmallIcon::SmallIcon(UINT nid
)
501 _hicon
= (HICON
)LoadImage(g_Globals
._hInstance
, MAKEINTRESOURCE(nid
), IMAGE_ICON
, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), LR_SHARED
);
504 ResIconEx::ResIconEx(UINT nid
, int w
, int h
)
506 _hicon
= (HICON
)LoadImage(g_Globals
._hInstance
, MAKEINTRESOURCE(nid
), IMAGE_ICON
, w
, h
, LR_SHARED
);
510 void SetWindowIcon(HWND hwnd
, UINT nid
)
512 HICON hIcon
= ResIcon(nid
);
513 Window_SetIcon(hwnd
, ICON_BIG
, hIcon
);
515 HICON hIconSmall
= SmallIcon(nid
);
516 Window_SetIcon(hwnd
, ICON_SMALL
, hIconSmall
);
520 ResBitmap::ResBitmap(UINT nid
)
522 _hBmp
= LoadBitmap(g_Globals
._hInstance
, MAKEINTRESOURCE(nid
));
526 void explorer_show_frame(int cmdshow
, LPTSTR lpCmdLine
)
528 if (g_Globals
._hMainWnd
) {
529 if (IsIconic(g_Globals
._hMainWnd
))
530 ShowWindow(g_Globals
._hMainWnd
, SW_RESTORE
);
532 SetForegroundWindow(g_Globals
._hMainWnd
);
537 g_Globals
._prescan_nodes
= false;
539 XMLPos explorer_options
= g_Globals
.get_cfg("general/explorer");
540 XS_String mdiStr
= XMLString(explorer_options
, "mdi");
543 Dialog::DoModal(IDD_MDI_SDI
, WINDOW_CREATOR(MdiSdiDlg
), g_Globals
._hwndDesktop
);
545 bool mdi
= XMLBool(explorer_options
, "mdi", true);
547 // create main window
548 MainFrameBase::Create(lpCmdLine
, mdi
, cmdshow
);
552 PopupMenu::PopupMenu(UINT nid
)
554 HMENU hMenu
= LoadMenu(g_Globals
._hInstance
, MAKEINTRESOURCE(nid
));
555 _hmenu
= GetSubMenu(hMenu
, 0);
559 /// "About Explorer" Dialog
560 struct ExplorerAboutDlg
: public
562 OwnerDrawParent
<Dialog
>
565 typedef CtlColorParent
<
566 OwnerDrawParent
<Dialog
>
569 ExplorerAboutDlg(HWND hwnd
)
572 SetWindowIcon(hwnd
, IDI_REACTOS
);
574 new FlatButton(hwnd
, IDOK
);
576 _hfont
= CreateFont(20, 0, 0, 0, FW_BOLD
, TRUE
, 0, 0, 0, 0, 0, 0, 0, TEXT("Sans Serif"));
577 new ColorStatic(hwnd
, IDC_ROS_EXPLORER
, RGB(32,32,128), 0, _hfont
);
579 new HyperlinkCtrl(hwnd
, IDC_WWW
);
581 FmtString
ver_txt(ResString(IDS_EXPLORER_VERSION_STR
), (LPCTSTR
)ResString(IDS_VERSION_STR
));
582 SetWindowText(GetDlgItem(hwnd
, IDC_VERSION_TXT
), ver_txt
);
584 HWND hwnd_winver
= GetDlgItem(hwnd
, IDC_WIN_VERSION
);
585 SetWindowText(hwnd_winver
, get_windows_version_str());
586 SetWindowFont(hwnd_winver
, GetStockFont(DEFAULT_GUI_FONT
), FALSE
);
593 DeleteObject(_hfont
);
596 LRESULT
WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
604 return super::WndProc(nmsg
, wparam
, lparam
);
612 PaintCanvas
canvas(_hwnd
);
614 HICON hicon
= (HICON
) LoadImage(g_Globals
._hInstance
, MAKEINTRESOURCE(IDI_REACTOS_BIG
), IMAGE_ICON
, 0, 0, LR_SHARED
);
616 DrawIconEx(canvas
, 20, 10, hicon
, 0, 0, 0, 0, DI_NORMAL
);
623 void explorer_about(HWND hwndParent
)
625 Dialog::DoModal(IDD_ABOUT_EXPLORER
, WINDOW_CREATOR(ExplorerAboutDlg
), hwndParent
);
629 static void InitInstance(HINSTANCE hInstance
)
631 CONTEXT("InitInstance");
633 setlocale(LC_COLLATE
, ""); // set collating rules to local settings for compareName
635 // register frame window class
636 g_Globals
._hframeClass
= IconWindowClass(CLASSNAME_FRAME
,IDI_EXPLORER
);
638 // register child window class
639 WindowClass(CLASSNAME_CHILDWND
, CS_CLASSDC
|CS_DBLCLKS
|CS_VREDRAW
).Register();
641 // register tree window class
642 WindowClass(CLASSNAME_WINEFILETREE
, CS_CLASSDC
|CS_DBLCLKS
|CS_VREDRAW
).Register();
644 g_Globals
._cfStrFName
= RegisterClipboardFormat(CFSTR_FILENAME
);
648 int explorer_main(HINSTANCE hInstance
, LPTSTR lpCmdLine
, int cmdshow
)
650 CONTEXT("explorer_main");
652 // initialize Common Controls library
653 CommonControlInit usingCmnCtrl
;
656 InitInstance(hInstance
);
657 } catch(COMException
& e
) {
658 HandleException(e
, GetDesktopWindow());
662 if (cmdshow
!= SW_HIDE
) {
663 /* // don't maximize if being called from the ROS desktop
664 if (cmdshow == SW_SHOWNORMAL)
665 ///@todo read window placement from registry
666 cmdshow = SW_MAXIMIZE;
669 explorer_show_frame(cmdshow
, lpCmdLine
);
672 return Window::MessageLoop();
676 // MinGW does not provide a Unicode startup routine, so we have to implement an own.
677 #if defined(__MINGW32__) && defined(UNICODE)
679 #define _tWinMain wWinMain
680 int WINAPI
wWinMain(HINSTANCE
, HINSTANCE
, LPWSTR
, int);
682 int main(int argc
, char* argv
[])
686 STARTUPINFO startupinfo
;
687 int nShowCmd
= SW_SHOWNORMAL
;
689 GetStartupInfo(&startupinfo
);
691 if (startupinfo
.dwFlags
& STARTF_USESHOWWINDOW
)
692 nShowCmd
= startupinfo
.wShowWindow
;
694 LPWSTR cmdline
= GetCommandLineW();
696 while(*cmdline
&& !_istspace(*cmdline
))
699 while(_istspace(*cmdline
))
702 return wWinMain(GetModuleHandle(NULL
), 0, cmdline
, nShowCmd
);
705 #endif // __MINGW && UNICODE
708 int WINAPI
_tWinMain(HINSTANCE hInstance
, HINSTANCE hPrevInstance
, LPTSTR lpCmdLine
, int nShowCmd
)
710 CONTEXT("WinMain()");
712 BOOL any_desktop_running
= IsAnyDesktopRunning();
714 BOOL startup_desktop
;
716 // command line option "-install" to replace previous shell application with ROS Explorer
717 if (_tcsstr(lpCmdLine
,TEXT("-install"))) {
718 // install ROS Explorer into the registry
719 TCHAR path
[MAX_PATH
];
721 int l
= GetModuleFileName(0, path
, MAX_PATH
);
725 if (!RegOpenKey(HKEY_LOCAL_MACHINE
, TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon"), &hkey
)) {
727 ///@todo save previous shell application in config file
729 RegSetValueEx(hkey
, TEXT("Shell"), 0, REG_SZ
, (LPBYTE
)path
, l
*sizeof(TCHAR
));
734 HWND shellWindow
= GetShellWindow();
739 // terminate shell process for NT like systems
740 GetWindowThreadProcessId(shellWindow
, &pid
);
741 HANDLE hProcess
= OpenProcess(PROCESS_ALL_ACCESS
, FALSE
, pid
);
743 // On Win 9x it's sufficient to destroy the shell window.
744 DestroyWindow(shellWindow
);
746 if (TerminateProcess(hProcess
, 0))
747 WaitForSingleObject(hProcess
, INFINITE
);
749 CloseHandle(hProcess
);
752 startup_desktop
= TRUE
;
754 // create desktop window and task bar only, if there is no other shell and we are
755 // the first explorer instance
756 startup_desktop
= !any_desktop_running
;
758 bool autostart
= !any_desktop_running
;
760 // disable autostart if the SHIFT key is pressed
761 if (GetAsyncKeyState(VK_SHIFT
) < 0)
764 #ifdef _DEBUG //MF: disabled for debugging
768 // If there is given the command line option "-desktop", create desktop window anyways
769 if (_tcsstr(lpCmdLine
,TEXT("-desktop")))
770 startup_desktop
= TRUE
;
771 else if (_tcsstr(lpCmdLine
,TEXT("-nodesktop")))
772 startup_desktop
= FALSE
;
774 // Don't display cabinet window in desktop mode
775 if (startup_desktop
&& !_tcsstr(lpCmdLine
,TEXT("-explorer")))
778 if (_tcsstr(lpCmdLine
,TEXT("-noautostart")))
780 else if (_tcsstr(lpCmdLine
,TEXT("-autostart")))
784 if (_tcsstr(lpCmdLine
,TEXT("-console"))) {
787 _dup2(_open_osfhandle((long)GetStdHandle(STD_INPUT_HANDLE
), _O_RDONLY
), 0);
788 _dup2(_open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE
), 0), 1);
789 _dup2(_open_osfhandle((long)GetStdHandle(STD_ERROR_HANDLE
), 0), 2);
791 g_Globals
._log
= fdopen(1, "w");
792 setvbuf(g_Globals
._log
, 0, _IONBF
, 0);
794 LOG(TEXT("starting explorer debug log\n"));
798 bool use_gdb_stub
= false; // !IsDebuggerPresent();
800 if (_tcsstr(lpCmdLine
,TEXT("-debug")))
803 if (_tcsstr(lpCmdLine
,TEXT("-break"))) {
804 LOG(TEXT("debugger breakpoint"));
812 // activate GDB remote debugging stub if no other debugger is running
814 LOG(TEXT("waiting for debugger connection...\n"));
816 initialize_gdb_stub();
819 g_Globals
.init(hInstance
);
821 // initialize COM and OLE before creating the desktop window
824 // init common controls library
825 CommonControlInit usingCmnCtrl
;
827 g_Globals
.read_persistent();
829 if (startup_desktop
) {
830 g_Globals
._desktops
.init();
832 g_Globals
._hwndDesktop
= DesktopWindow::Create();
834 g_Globals
._desktops
.get_current_Desktop()->_hwndDesktop
= g_Globals
._hwndDesktop
;
838 char* argv
[] = {"", "s"}; // call startup routine in SESSION_START mode
843 /**TODO fix command line handling */
844 if (*lpCmdLine
=='"' && lpCmdLine
[_tcslen(lpCmdLine
)-1]=='"') {
846 lpCmdLine
[_tcslen(lpCmdLine
)-1] = '\0';
849 if (g_Globals
._hwndDesktop
)
850 g_Globals
._desktop_mode
= true;
852 int ret
= explorer_main(hInstance
, lpCmdLine
, nShowCmd
);
854 // write configuration file
855 g_Globals
.write_persistent();