Bool RecursiveCreateDirectory( const Char * dir ) { if ( ! CreateDirectory( dir, NULL ) ) { DWORD err = GetLastError(); if ( err == ERROR_ALREADY_EXISTS ) { return true; } if ( err == ERROR_PATH_NOT_FOUND ) { Char * fileStart; Char parentDir[ 256 ]; if ( GetFullPathName( dir, 256, parentDir, &fileStart ) == 0 ) { return false; } *(fileStart - 1 ) = 0; if ( RecursiveCreateDirectory( parentDir ) ) { return ( CreateDirectory( dir, NULL ) != 0 ); } return false; } return false; } return true; }
void ExplorerGlobals::write_persistent() { // write configuration file RecursiveCreateDirectory(_cfg_dir); _cfg.write_file(_cfg_path); _favorites.write(_favorites_path); }
Bool FileSystem::Save( const PathString& fileName, const void * buffer, SizeT size ) { Char dir[ 256 ]; Char * fileStart; if ( GetFullPathName( fileName.ConstPtr(), 256, dir, &fileStart ) == 0 ) { return false; } *( fileStart - 1 ) = 0; if ( ! RecursiveCreateDirectory( dir ) ) { return false; } FILE * pFile; if ( fopen_s( &pFile, fileName.ConstPtr(), "wb" ) ) { return false; } if ( size == 0 ) { fclose( pFile ); return true; } if ( fwrite( buffer, 1, size, pFile ) != size ) { fclose( pFile ); return false; } fclose(pFile); return true; }
void QuickLaunchBar::AddShortcuts() { CONTEXT("QuickLaunchBar::AddShortcuts()"); WaitCursor wait; try { TCHAR path[MAX_PATH]; SpecialFolderFSPath app_data(CSIDL_APPDATA, _hwnd); ///@todo perhaps also look into CSIDL_COMMON_APPDATA ? _stprintf(path, TEXT("%s\\")QUICKLAUNCH_FOLDER, (LPCTSTR)app_data); RecursiveCreateDirectory(path); _dir = new ShellDirectory(GetDesktopFolder(), path, _hwnd); _dir->smart_scan(SORT_NAME); // immediatelly extract the shortcut icons for(Entry*entry=_dir->_down; entry; entry=entry->_next) entry->_icon_id = entry->safe_extract_icon(ICF_NORMAL); } catch(COMException&) { return; } ShellFolder desktop_folder; WindowCanvas canvas(_hwnd); COLORREF bk_color = GetSysColor(COLOR_BTNFACE); HBRUSH bk_brush = GetSysColorBrush(COLOR_BTNFACE); AddButton(ID_MINIMIZE_ALL, g_Globals._icon_cache.get_icon(ICID_MINIMIZE).create_bitmap(bk_color, bk_brush, canvas), ResString(IDS_MINIMIZE_ALL), NULL); AddButton(ID_EXPLORE, g_Globals._icon_cache.get_icon(ICID_EXPLORER).create_bitmap(bk_color, bk_brush, canvas), ResString(IDS_TITLE), NULL); TBBUTTON sep = {0, -1, TBSTATE_ENABLED, BTNS_SEP, {0, 0}, 0, 0}; SendMessage(_hwnd, TB_INSERTBUTTON, INT_MAX, (LPARAM)&sep); int cur_desktop = g_Globals._desktops._current_desktop; ResString desktop_fmt(IDS_DESKTOP_NUM); HDC hdc = CreateCompatibleDC(canvas); DWORD size = SendMessage(_hwnd, TB_GETBUTTONSIZE, 0, 0); int cx = LOWORD(size); int cy = HIWORD(size); RECT rect = {0, 0, cx, cy}; RECT textRect = {0, 0, cx-7, cy-7}; for(int i=0; i<DESKTOP_COUNT; ++i) { HBITMAP hbmp = CreateCompatibleBitmap(canvas, cx, cy); HBITMAP hbmp_old = SelectBitmap(hdc, hbmp); FontSelection font(hdc, GetStockFont(ANSI_VAR_FONT)); FmtString num_txt(TEXT("%d"), i+1); TextColor color(hdc, RGB(64,64,64)); BkMode mode(hdc, TRANSPARENT); FillRect(hdc, &rect, GetSysColorBrush(COLOR_BTNFACE)); DrawText(hdc, num_txt, num_txt.length(), &textRect, DT_CENTER|DT_VCENTER|DT_SINGLELINE); SelectBitmap(hdc, hbmp_old); AddButton(ID_SWITCH_DESKTOP_1+i, hbmp, FmtString(desktop_fmt, i+1), NULL, cur_desktop==i?TBSTATE_ENABLED|TBSTATE_PRESSED:TBSTATE_ENABLED); } DeleteDC(hdc); for(Entry*entry=_dir->_down; entry; entry=entry->_next) { // hide files like "desktop.ini" if (entry->_data.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) continue; // hide subfolders if (!(entry->_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { HBITMAP hbmp = g_Globals._icon_cache.get_icon(entry->_icon_id).create_bitmap(bk_color, bk_brush, canvas); AddButton(_next_id++, hbmp, entry->_display_name, entry); //entry->_etype==ET_SHELL? desktop_folder.get_name(static_cast<ShellEntry*>(entry)->_pidl): entry->_display_name); } } _btn_dist = LOWORD(SendMessage(_hwnd, TB_GETBUTTONSIZE, 0, 0)); _size = _entries.size() * _btn_dist; SendMessage(GetParent(_hwnd), PM_RESIZE_CHILDREN, 0, 0); }