std::filesystem i pliki lnk - czyli jak wyciągnąć ścieżki do plików ze skrótów
Ostatnio zmodyfikowano 2025-09-29 05:40
tBane Temat założony przez niniejszego użytkownika |
std::filesystem i pliki lnk - czyli jak wyciągnąć ścieżki do plików ze skrótów » 2025-09-28 07:44:25 Witam. Potrzebuję wyciągnąć z plików skrótów lnk ścieżki plików na które wskazują. Jak to zrobić ? std::filesystem::path getPathFromlnk( std::filesystem::directory_entry entry ) { return std::filesystem::absolute( entry ); }
LocationRect::LocationRect( std::wstring path ) : ElementGUI() { _rect = sf::RectangleShape(); _rect.setFillColor( sf::Color( 95, 47, 47 ) ); _rect.setOutlineThickness( 1.0f ); _rect.setOutlineColor( sf::Color( 63, 47, 47 ) ); std::filesystem::directory_entry entry( path ); _path = getPathFromlnk( entry ); _ico = sf::Sprite(); if( entry.is_block_file() ) _ico.setTexture( * getTexture( L"tex\\dialog\\harddrive.png" )->_texture ); else if( entry.is_directory() ) _ico.setTexture( * getTexture( L"tex\\dialog\\dictionary.png" )->_texture ); else _ico.setTexture( * getTexture( L"tex\\dialog\\empty.png" )->_texture ); _text = sf::Text(); _text.setFont( basicFont ); _text.setCharacterSize( dialog_content_font_size ); _text.setFillColor( normal_text_color ); _text.setString( _path.filename().wstring() ); }
Jeżeli potrzebujesz zbudować program do testów to zamieszczam poniżej link do repozytorium https://github.com/tBane1995/Anim-Paint.gitLokalizacja kodu: Anim-Paint\Source Files\Dialogs\Dialog_Save_As.cpp |
|
pekfos |
» 2025-09-29 00:52:35 |
|
tBane Temat założony przez niniejszego użytkownika |
» 2025-09-29 05:32:58 Działa :-) #include <shobjidl.h> #include <objbase.h> inline bool is_lnk( const std::filesystem::path & p ) { std::wstring ext = p.extension().wstring(); std::transform( ext.begin(), ext.end(), ext.begin(),::towlower ); return ext == L".lnk"; }
inline std::filesystem::path resolve_lnk( const std::filesystem::path & lnkPath ) { std::filesystem::path result; HRESULT hrCo = CoInitializeEx( nullptr, COINIT_APARTMENTTHREADED ); bool comInit = SUCCEEDED( hrCo ); IShellLinkW * psl = nullptr; if( SUCCEEDED( CoCreateInstance( CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS( & psl ) ) ) ) { IPersistFile * ppf = nullptr; if( SUCCEEDED( psl->QueryInterface( IID_PPV_ARGS( & ppf ) ) ) ) { if( SUCCEEDED( ppf->Load( lnkPath.c_str(), STGM_READ ) ) ) { WCHAR szTarget[ MAX_PATH ] = { }; WIN32_FIND_DATAW wfd { }; if( SUCCEEDED( psl->GetPath( szTarget, MAX_PATH, & wfd, SLGP_UNCPRIORITY ) ) ) { result = szTarget; } } ppf->Release(); } psl->Release(); } if( comInit ) CoUninitialize(); return result; }
std::filesystem::path getPath( std::filesystem::directory_entry entry ) { if( is_lnk( entry.path() ) ) { std::filesystem::path path = resolve_lnk( entry.path() ); std::wcout << L"is lnk: " << path.wstring() << std::endl; return path; } else { std::wcout << L"is other: " << entry.path().wstring() << std::endl; return entry.path(); } }
|
|
« 1 » |