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
43 extern "C" int initialize_gdb_stub(); // start up GDB stub
46 ExplorerGlobals g_Globals
;
49 ExplorerGlobals::ExplorerGlobals()
55 _prescan_nodes
= false;
56 _desktop_mode
= false;
58 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
67 void ExplorerGlobals::init(HINSTANCE hInstance
)
69 _hInstance
= hInstance
;
71 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
72 _SHRestricted
= (DWORD(STDAPICALLTYPE
*)(RESTRICTIONS
)) GetProcAddress(GetModuleHandle(TEXT("SHELL32")), "SHRestricted");
79 void ExplorerGlobals::read_persistent()
81 // read configuration file
82 _cfg_dir
.printf(TEXT("%s\\ReactOS"), (LPCTSTR
)SpecialFolderFSPath(CSIDL_APPDATA
,0));
83 _cfg_path
.printf(TEXT("%s\\ros-explorer-cfg.xml"), _cfg_dir
.c_str());
85 if (!_cfg
.read(_cfg_path
)) {
86 if (_cfg
._last_error
!= XML_ERROR_NO_ELEMENTS
)
87 MessageBox(g_Globals
._hwndDesktop
, String(_cfg
._last_error_msg
.c_str()),
88 TEXT("ROS Explorer - reading user settings"), MB_OK
);
90 _cfg
.read(TEXT("explorer-cfg-template.xml"));
94 _favorites_path
.printf(TEXT("%s\\ros-explorer-bookmarks.xml"), _cfg_dir
.c_str());
96 if (!_favorites
.read(_favorites_path
)) {
97 _favorites
.import_IE_favorites(0);
98 _favorites
.write(_favorites_path
);
102 void ExplorerGlobals::write_persistent()
104 // write configuration file
105 RecursiveCreateDirectory(_cfg_dir
);
107 _cfg
.write(_cfg_path
);
108 _favorites
.write(_favorites_path
);
112 XMLPos
ExplorerGlobals::get_cfg()
116 pos
.smart_create("explorer-cfg");
121 XMLPos
ExplorerGlobals::get_cfg(const String
& name
)
125 pos
.smart_create("explorer-cfg");
126 pos
.smart_create(name
);
132 void _log_(LPCTSTR txt
)
134 FmtString
msg(TEXT("%s\n"), txt
);
137 _fputts(msg
, g_Globals
._log
);
139 OutputDebugString(msg
);
143 bool FileTypeManager::is_exe_file(LPCTSTR ext
)
145 static const LPCTSTR s_executable_extensions
[] = {
156 TCHAR ext_buffer
[_MAX_EXT
];
161 for(s
=ext
+1,d
=ext_buffer
; (*d
=toupper(*s
)); s
++)
164 for(p
=s_executable_extensions
; *p
; p
++)
165 if (!lstrcmp(ext_buffer
, *p
))
172 const FileTypeInfo
& FileTypeManager::operator[](String ext
)
174 #ifndef __WINE__ ///@todo _tcslwr() for Wine
175 _tcslwr((LPTSTR
)ext
.c_str());
178 iterator found
= find(ext
);
180 return found
->second
;
182 FileTypeInfo
& ftype
= super::operator[](ext
);
184 ftype
._neverShowExt
= false;
187 TCHAR value
[MAX_PATH
], display_name
[MAX_PATH
];
188 LONG valuelen
= sizeof(value
);
190 if (!RegQueryValue(HKEY_CLASSES_ROOT
, ext
, value
, &valuelen
)) {
191 ftype
._classname
= value
;
193 valuelen
= sizeof(display_name
);
194 if (!RegQueryValue(HKEY_CLASSES_ROOT
, ftype
._classname
, display_name
, &valuelen
))
195 ftype
._displayname
= display_name
;
197 if (!RegOpenKey(HKEY_CLASSES_ROOT
, ftype
._classname
, &hkey
)) {
198 if (!RegQueryValueEx(hkey
, TEXT("NeverShowExt"), 0, NULL
, NULL
, NULL
))
199 ftype
._neverShowExt
= true;
208 LPCTSTR
FileTypeManager::set_type(Entry
* entry
, bool dont_hide_ext
)
210 LPCTSTR ext
= _tcsrchr(entry
->_data
.cFileName
, TEXT('.'));
213 const FileTypeInfo
& type
= (*this)[ext
];
215 if (!type
._displayname
.empty())
216 entry
->_type_name
= _tcsdup(type
._displayname
);
218 // hide some file extensions
219 if (type
._neverShowExt
&& !dont_hide_ext
) {
220 int len
= ext
- entry
->_data
.cFileName
;
221 entry
->_display_name
= (LPTSTR
) malloc((len
+1)*sizeof(TCHAR
));
222 _tcsncpy(entry
->_display_name
, entry
->_data
.cFileName
, len
);
223 entry
->_display_name
[len
] = TEXT('\0');
226 if (is_exe_file(ext
))
227 entry
->_data
.dwFileAttributes
|= ATTRIBUTE_EXECUTABLE
;
241 Icon::Icon(ICON_ID id
, UINT nid
)
244 _hicon(SmallIcon(nid
))
248 Icon::Icon(ICON_TYPE itype
, int id
, HICON hIcon
)
255 Icon::Icon(ICON_TYPE itype
, int id
, int sys_idx
)
262 void Icon::draw(HDC hdc
, int x
, int y
, int cx
, int cy
, COLORREF bk_color
, HBRUSH bk_brush
) const
264 if (_itype
== IT_SYSCACHE
)
265 ImageList_DrawEx(g_Globals
._icon_cache
.get_sys_imagelist(), _sys_idx
, hdc
, x
, y
, cx
, cy
, bk_color
, CLR_DEFAULT
, ILD_NORMAL
);
267 DrawIconEx(hdc
, x
, y
, _hicon
, cx
, cy
, 0, bk_brush
, DI_NORMAL
);
270 HBITMAP
Icon::create_bitmap(COLORREF bk_color
, HBRUSH hbrBkgnd
, HDC hdc_wnd
) const
272 if (_itype
== IT_SYSCACHE
) {
273 HIMAGELIST himl
= g_Globals
._icon_cache
.get_sys_imagelist();
276 ImageList_GetIconSize(himl
, &cx
, &cy
);
278 HBITMAP hbmp
= CreateCompatibleBitmap(hdc_wnd
, cx
, cy
);
279 HDC hdc
= CreateCompatibleDC(hdc_wnd
);
280 HBITMAP hbmp_old
= SelectBitmap(hdc
, hbmp
);
281 ImageList_DrawEx(himl
, _sys_idx
, hdc
, 0, 0, cx
, cy
, bk_color
, CLR_DEFAULT
, ILD_NORMAL
);
282 SelectBitmap(hdc
, hbmp_old
);
287 return create_bitmap_from_icon(_hicon
, hbrBkgnd
, hdc_wnd
);
291 int Icon::add_to_imagelist(HIMAGELIST himl
, HDC hdc_wnd
, COLORREF bk_color
, HBRUSH bk_brush
) const
295 if (_itype
== IT_SYSCACHE
) {
296 HIMAGELIST himl
= g_Globals
._icon_cache
.get_sys_imagelist();
299 ImageList_GetIconSize(himl
, &cx
, &cy
);
301 HBITMAP hbmp
= CreateCompatibleBitmap(hdc_wnd
, cx
, cy
);
302 HDC hdc
= CreateCompatibleDC(hdc_wnd
);
303 HBITMAP hbmp_old
= SelectBitmap(hdc
, hbmp
);
304 ImageList_DrawEx(himl
, _sys_idx
, hdc
, 0, 0, cx
, cy
, bk_color
, CLR_DEFAULT
, ILD_NORMAL
);
305 SelectBitmap(hdc
, hbmp_old
);
308 ret
= ImageList_Add(himl
, hbmp
, 0);
312 ret
= ImageList_AddAlphaIcon(himl
, _hicon
, bk_brush
, hdc_wnd
);
317 HBITMAP
create_bitmap_from_icon(HICON hIcon
, HBRUSH hbrush_bkgnd
, HDC hdc_wnd
)
319 int cx
= GetSystemMetrics(SM_CXSMICON
);
320 int cy
= GetSystemMetrics(SM_CYSMICON
);
321 HBITMAP hbmp
= CreateCompatibleBitmap(hdc_wnd
, cx
, cy
);
324 BitmapSelection
sel(canvas
, hbmp
);
326 RECT rect
= {0, 0, cx
, cy
};
327 FillRect(canvas
, &rect
, hbrush_bkgnd
);
329 DrawIconEx(canvas
, 0, 0, hIcon
, cx
, cy
, 0, hbrush_bkgnd
, DI_NORMAL
);
334 int ImageList_AddAlphaIcon(HIMAGELIST himl
, HICON hIcon
, HBRUSH hbrush_bkgnd
, HDC hdc_wnd
)
336 HBITMAP hbmp
= create_bitmap_from_icon(hIcon
, hbrush_bkgnd
, hdc_wnd
);
338 int ret
= ImageList_Add(himl
, hbmp
, 0);
346 int IconCache::s_next_id
= ICID_DYNAMIC
;
349 void IconCache::init()
351 _icons
[ICID_NONE
] = Icon(IT_STATIC
, ICID_NONE
, (HICON
)0);
353 _icons
[ICID_FOLDER
] = Icon(ICID_FOLDER
, IDI_FOLDER
);
354 //_icons[ICID_DOCUMENT] = Icon(ICID_DOCUMENT, IDI_DOCUMENT);
355 _icons
[ICID_EXPLORER
] = Icon(ICID_EXPLORER
, IDI_EXPLORER
);
356 _icons
[ICID_APP
] = Icon(ICID_APP
, IDI_APPICON
);
358 _icons
[ICID_CONFIG
] = Icon(ICID_CONFIG
, IDI_CONFIG
);
359 _icons
[ICID_DOCUMENTS
] = Icon(ICID_DOCUMENTS
, IDI_DOCUMENTS
);
360 _icons
[ICID_FAVORITES
] = Icon(ICID_FAVORITES
, IDI_FAVORITES
);
361 _icons
[ICID_INFO
] = Icon(ICID_INFO
, IDI_INFO
);
362 _icons
[ICID_APPS
] = Icon(ICID_APPS
, IDI_APPS
);
363 _icons
[ICID_SEARCH
] = Icon(ICID_SEARCH
, IDI_SEARCH
);
364 _icons
[ICID_ACTION
] = Icon(ICID_ACTION
, IDI_ACTION
);
365 _icons
[ICID_SEARCH_DOC
] = Icon(ICID_SEARCH_DOC
, IDI_SEARCH_DOC
);
366 _icons
[ICID_PRINTER
] = Icon(ICID_PRINTER
, IDI_PRINTER
);
367 _icons
[ICID_NETWORK
] = Icon(ICID_NETWORK
, IDI_NETWORK
);
368 _icons
[ICID_COMPUTER
] = Icon(ICID_COMPUTER
, IDI_COMPUTER
);
369 _icons
[ICID_LOGOFF
] = Icon(ICID_LOGOFF
, IDI_LOGOFF
);
370 _icons
[ICID_BOOKMARK
] = Icon(ICID_BOOKMARK
, IDI_DOT_TRANS
);
374 const Icon
& IconCache::extract(const String
& path
)
376 PathMap::iterator found
= _pathMap
.find(path
);
378 if (found
!= _pathMap
.end())
379 return _icons
[found
->second
];
383 #if 1 // use system image list
384 HIMAGELIST himlSys
= (HIMAGELIST
) SHGetFileInfo(path
, 0, &sfi
, sizeof(sfi
), SHGFI_SYSICONINDEX
|SHGFI_SMALLICON
);
389 const Icon
& icon
= add(sfi
.iIcon
/*, IT_SYSCACHE*/);
391 if (SHGetFileInfo(path
, 0, &sfi
, sizeof(sfi
), SHGFI_ICON
|SHGFI_SMALLICON
)) {
392 const Icon
& icon
= add(sfi
.hIcon
, IT_CACHED
);
395 ///@todo limit cache size
396 _pathMap
[path
] = icon
;
400 return _icons
[ICID_NONE
];
403 const Icon
& IconCache::extract(LPCTSTR path
, int idx
)
405 CachePair
key(path
, idx
);
407 #ifndef __WINE__ ///@todo _tcslwr() for Wine
408 _tcslwr((LPTSTR
)key
.first
.c_str());
411 PathIdxMap::iterator found
= _pathIdxMap
.find(key
);
413 if (found
!= _pathIdxMap
.end())
414 return _icons
[found
->second
];
418 if ((int)ExtractIconEx(path
, idx
, NULL
, &hIcon
, 1) > 0) {
419 const Icon
& icon
= add(hIcon
, IT_CACHED
);
421 _pathIdxMap
[key
] = icon
;
426 ///@todo retreive "http://.../favicon.ico" format icons
428 return _icons
[ICID_NONE
];
432 const Icon
& IconCache::extract(IExtractIcon
* pExtract
, LPCTSTR path
, int idx
)
434 HICON hIconLarge
= 0;
437 HRESULT hr
= pExtract
->Extract(path
, idx
, &hIconLarge
, &hIcon
, MAKELONG(0/*GetSystemMetrics(SM_CXICON)*/,GetSystemMetrics(SM_CXSMICON
)));
441 DestroyIcon(hIconLarge
);
447 return _icons
[ICID_NONE
];
450 const Icon
& IconCache::add(HICON hIcon
, ICON_TYPE type
)
452 int id
= ++s_next_id
;
454 return _icons
[id
] = Icon(type
, id
, hIcon
);
457 const Icon
& IconCache::add(int sys_idx
/*, ICON_TYPE type=IT_SYSCACHE*/)
459 int id
= ++s_next_id
;
461 return _icons
[id
] = SysCacheIcon(id
, sys_idx
);
464 const Icon
& IconCache::get_icon(int id
)
469 void IconCache::free_icon(int icon_id
)
471 IconMap::iterator found
= _icons
.find(icon_id
);
473 if (found
!= _icons
.end()) {
474 Icon
& icon
= found
->second
;
482 ResString::ResString(UINT nid
)
484 TCHAR buffer
[BUFFER_LEN
];
486 int len
= LoadString(g_Globals
._hInstance
, nid
, buffer
, sizeof(buffer
)/sizeof(TCHAR
));
488 super::assign(buffer
, len
);
492 ResIcon::ResIcon(UINT nid
)
494 _hicon
= LoadIcon(g_Globals
._hInstance
, MAKEINTRESOURCE(nid
));
497 SmallIcon::SmallIcon(UINT nid
)
499 _hicon
= (HICON
)LoadImage(g_Globals
._hInstance
, MAKEINTRESOURCE(nid
), IMAGE_ICON
, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), LR_SHARED
);
502 ResIconEx::ResIconEx(UINT nid
, int w
, int h
)
504 _hicon
= (HICON
)LoadImage(g_Globals
._hInstance
, MAKEINTRESOURCE(nid
), IMAGE_ICON
, w
, h
, LR_SHARED
);
508 void SetWindowIcon(HWND hwnd
, UINT nid
)
510 HICON hIcon
= ResIcon(nid
);
511 Window_SetIcon(hwnd
, ICON_BIG
, hIcon
);
513 HICON hIconSmall
= SmallIcon(nid
);
514 Window_SetIcon(hwnd
, ICON_SMALL
, hIconSmall
);
518 ResBitmap::ResBitmap(UINT nid
)
520 _hBmp
= LoadBitmap(g_Globals
._hInstance
, MAKEINTRESOURCE(nid
));
524 void explorer_show_frame(int cmdshow
, LPTSTR lpCmdLine
)
526 if (g_Globals
._hMainWnd
) {
527 if (IsIconic(g_Globals
._hMainWnd
))
528 ShowWindow(g_Globals
._hMainWnd
, SW_RESTORE
);
530 SetForegroundWindow(g_Globals
._hMainWnd
);
535 g_Globals
._prescan_nodes
= false;
537 // create main window
538 MainFrameBase::Create(lpCmdLine
, true, cmdshow
);
542 PopupMenu::PopupMenu(UINT nid
)
544 HMENU hMenu
= LoadMenu(g_Globals
._hInstance
, MAKEINTRESOURCE(nid
));
545 _hmenu
= GetSubMenu(hMenu
, 0);
549 /// "About Explorer" Dialog
550 struct ExplorerAboutDlg
: public
552 OwnerDrawParent
<Dialog
>
555 typedef CtlColorParent
<
556 OwnerDrawParent
<Dialog
>
559 ExplorerAboutDlg(HWND hwnd
)
562 SetWindowIcon(hwnd
, IDI_REACTOS
);
564 new FlatButton(hwnd
, IDOK
);
566 _hfont
= CreateFont(20, 0, 0, 0, FW_BOLD
, TRUE
, 0, 0, 0, 0, 0, 0, 0, TEXT("Sans Serif"));
567 new ColorStatic(hwnd
, IDC_ROS_EXPLORER
, RGB(32,32,128), 0, _hfont
);
569 new HyperlinkCtrl(hwnd
, IDC_WWW
);
571 FmtString
ver_txt(ResString(IDS_EXPLORER_VERSION_STR
), (LPCTSTR
)ResString(IDS_VERSION_STR
));
572 SetWindowText(GetDlgItem(hwnd
, IDC_VERSION_TXT
), ver_txt
);
574 HWND hwnd_winver
= GetDlgItem(hwnd
, IDC_WIN_VERSION
);
575 SetWindowText(hwnd_winver
, get_windows_version_str());
576 SetWindowFont(hwnd_winver
, GetStockFont(DEFAULT_GUI_FONT
), FALSE
);
583 DeleteObject(_hfont
);
586 LRESULT
WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
594 return super::WndProc(nmsg
, wparam
, lparam
);
602 PaintCanvas
canvas(_hwnd
);
604 HICON hicon
= (HICON
) LoadImage(g_Globals
._hInstance
, MAKEINTRESOURCE(IDI_REACTOS_BIG
), IMAGE_ICON
, 0, 0, LR_SHARED
);
606 DrawIconEx(canvas
, 20, 10, hicon
, 0, 0, 0, 0, DI_NORMAL
);
613 void explorer_about(HWND hwndParent
)
615 Dialog::DoModal(IDD_ABOUT_EXPLORER
, WINDOW_CREATOR(ExplorerAboutDlg
), hwndParent
);
619 static void InitInstance(HINSTANCE hInstance
)
621 CONTEXT("InitInstance");
623 setlocale(LC_COLLATE
, ""); // set collating rules to local settings for compareName
625 // register frame window class
626 g_Globals
._hframeClass
= IconWindowClass(CLASSNAME_FRAME
,IDI_EXPLORER
);
628 // register child windows class
629 WindowClass(CLASSNAME_CHILDWND
, CS_CLASSDC
|CS_DBLCLKS
|CS_VREDRAW
).Register();
631 // register tree windows class
632 WindowClass(CLASSNAME_WINEFILETREE
, CS_CLASSDC
|CS_DBLCLKS
|CS_VREDRAW
).Register();
634 g_Globals
._cfStrFName
= RegisterClipboardFormat(CFSTR_FILENAME
);
638 int explorer_main(HINSTANCE hInstance
, LPTSTR lpCmdLine
, int cmdshow
)
640 CONTEXT("explorer_main");
642 // initialize Common Controls library
643 CommonControlInit usingCmnCtrl
;
646 InitInstance(hInstance
);
647 } catch(COMException
& e
) {
648 HandleException(e
, GetDesktopWindow());
652 if (cmdshow
!= SW_HIDE
) {
653 /* // don't maximize if being called from the ROS desktop
654 if (cmdshow == SW_SHOWNORMAL)
655 ///@todo read window placement from registry
656 cmdshow = SW_MAXIMIZE;
659 explorer_show_frame(cmdshow
, lpCmdLine
);
662 return Window::MessageLoop();
666 // MinGW does not provide a Unicode startup routine, so we have to implement an own.
667 #if defined(__MINGW32__) && defined(UNICODE)
669 #define _tWinMain wWinMain
670 int WINAPI
wWinMain(HINSTANCE
, HINSTANCE
, LPWSTR
, int);
672 int main(int argc
, char* argv
[])
676 STARTUPINFO startupinfo
;
677 int nShowCmd
= SW_SHOWNORMAL
;
679 GetStartupInfo(&startupinfo
);
681 if (startupinfo
.dwFlags
& STARTF_USESHOWWINDOW
)
682 nShowCmd
= startupinfo
.wShowWindow
;
684 LPWSTR cmdline
= GetCommandLineW();
686 while(*cmdline
&& !_istspace(*cmdline
))
689 return wWinMain(GetModuleHandle(NULL
), 0, cmdline
, nShowCmd
);
692 #endif // __MINGW && UNICODE
695 int WINAPI
_tWinMain(HINSTANCE hInstance
, HINSTANCE hPrevInstance
, LPTSTR lpCmdLine
, int nShowCmd
)
697 CONTEXT("WinMain()");
699 BOOL any_desktop_running
= IsAnyDesktopRunning();
701 BOOL startup_desktop
;
703 // command line option "-install" to replace previous shell application with ROS Explorer
704 if (_tcsstr(lpCmdLine
,TEXT("-install"))) {
705 // install ROS Explorer into the registry
706 TCHAR path
[MAX_PATH
];
708 int l
= GetModuleFileName(0, path
, MAX_PATH
);
712 if (!RegOpenKey(HKEY_LOCAL_MACHINE
, TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon"), &hkey
)) {
714 ///@todo save previous shell application in config file
716 RegSetValueEx(hkey
, TEXT("Shell"), 0, REG_SZ
, (LPBYTE
)path
, l
*sizeof(TCHAR
));
721 HWND shellWindow
= GetShellWindow();
726 // terminate shell process for NT like systems
727 GetWindowThreadProcessId(shellWindow
, &pid
);
728 HANDLE hProcess
= OpenProcess(PROCESS_ALL_ACCESS
, FALSE
, pid
);
730 // On Win 9x it's sufficient to destroy the shell window.
731 DestroyWindow(shellWindow
);
733 if (TerminateProcess(hProcess
, 0))
734 WaitForSingleObject(hProcess
, INFINITE
);
736 CloseHandle(hProcess
);
739 startup_desktop
= TRUE
;
741 // create desktop window and task bar only, if there is no other shell and we are
742 // the first explorer instance
743 startup_desktop
= !any_desktop_running
;
745 bool autostart
= !any_desktop_running
;
747 // disable autostart if the SHIFT key is pressed
748 if (GetAsyncKeyState(VK_SHIFT
) < 0)
751 #ifdef _DEBUG //MF: disabled for debugging
755 // If there is given the command line option "-desktop", create desktop window anyways
756 if (_tcsstr(lpCmdLine
,TEXT("-desktop")))
757 startup_desktop
= TRUE
;
758 else if (_tcsstr(lpCmdLine
,TEXT("-nodesktop")))
759 startup_desktop
= FALSE
;
761 // Don't display cabinet window in desktop mode
762 if (startup_desktop
&& !_tcsstr(lpCmdLine
,TEXT("-explorer")))
765 if (_tcsstr(lpCmdLine
,TEXT("-noautostart")))
767 else if (_tcsstr(lpCmdLine
,TEXT("-autostart")))
771 if (_tcsstr(lpCmdLine
,TEXT("-console"))) {
774 _dup2(_open_osfhandle((long)GetStdHandle(STD_INPUT_HANDLE
), _O_RDONLY
), 0);
775 _dup2(_open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE
), 0), 1);
776 _dup2(_open_osfhandle((long)GetStdHandle(STD_ERROR_HANDLE
), 0), 2);
778 g_Globals
._log
= fdopen(1, "w");
779 setvbuf(g_Globals
._log
, 0, _IONBF
, 0);
781 LOG(TEXT("starting explorer debug log\n"));
785 bool use_gdb_stub
= false; // !IsDebuggerPresent();
787 if (_tcsstr(lpCmdLine
,TEXT("-debug")))
790 if (_tcsstr(lpCmdLine
,TEXT("-break"))) {
791 LOG(TEXT("debugger breakpoint"));
799 // activate GDB remote debugging stub if no other debugger is running
801 LOG(TEXT("waiting for debugger connection...\n"));
803 initialize_gdb_stub();
806 g_Globals
.init(hInstance
);
808 // initialize COM and OLE before creating the desktop window
811 // init common controls library
812 CommonControlInit usingCmnCtrl
;
814 g_Globals
.read_persistent();
816 if (startup_desktop
) {
817 g_Globals
._desktops
.init();
819 g_Globals
._hwndDesktop
= DesktopWindow::Create();
821 g_Globals
._desktops
.get_current_Desktop()->_hwndDesktop
= g_Globals
._hwndDesktop
;
825 char* argv
[] = {"", "s"}; // call startup routine in SESSION_START mode
830 /**TODO fix command line handling */
831 if (*lpCmdLine
=='"' && lpCmdLine
[_tcslen(lpCmdLine
)-1]=='"') {
833 lpCmdLine
[_tcslen(lpCmdLine
)-1] = '\0';
836 if (g_Globals
._hwndDesktop
)
837 g_Globals
._desktop_mode
= true;
839 int ret
= explorer_main(hInstance
, lpCmdLine
, nShowCmd
);
841 // write configuration file
842 g_Globals
.write_persistent();