A new style desktop shell for Windows 11: menu bar, Dock, Finder, Spotlight, Control Center and Liquid Glass, in native C++.
Rust
Organize cloud and network locations in the Finder sidebar
Eternity070628e9288b3ce35f
diff --git a/src/comum/nuvem.h b/src/comum/nuvem.hindex 65a8d7d..43a993d 100644--- a/src/comum/nuvem.h+++ b/src/comum/nuvem.h@@ -8,6 +8,7 @@// e de ensino (HKCU\Software\Microsoft\OneDrive\Accounts\*\UserFolder, OneDriveCommercial e "OneDrive - *").#include <windows.h>#include <shlobj.h>+#include <appmodel.h>#include <string>#include <vector>@@ -32,9 +33,12 @@ inline bool SoNaNuvem(DWORD attr) {0x00040000u /*FILE_ATTRIBUTE_RECALL_ON_OPEN*/)) != 0;}+enum class Provider { None, OneDrive, ICloud, GoogleDrive };+struct Conta {std::wstring rotulo;std::wstring caminho;+ Provider provider = Provider::OneDrive;};inline std::vector<Conta> PastasOneDrive() {@@ -120,4 +124,65 @@ inline std::vector<Conta> PastasOneDrive() {return out;}+inline bool PastaExiste(const std::wstring& path) {+ DWORD attr = GetFileAttributesW(path.c_str());+ return attr != INVALID_FILE_ATTRIBUTES && (attr & FILE_ATTRIBUTE_DIRECTORY);+}++inline std::wstring Perfil() {+ PWSTR path = nullptr;+ if (FAILED(SHGetKnownFolderPath(FOLDERID_Profile, 0, nullptr, &path)) || !path) return {};+ std::wstring result(path);+ CoTaskMemFree(path);+ return result;+}++inline std::vector<Conta> PastasICloud() {+ const std::wstring profile = Perfil();+ if (profile.empty()) return {};+ const std::wstring root = profile + L"\\iCloudDrive";+ if (!PastaExiste(root)) return {};++ // A versão da Microsoft Store não instala iCloudDrive.exe no caminho do cliente clássico.+ UINT32 count = 0, bufferLength = 0;+ LONG packageResult = GetPackagesByPackageFamily(L"AppleInc.iCloud_nzyj5cx40ttqa", &count, nullptr,+ &bufferLength, nullptr);+ bool installed = packageResult == ERROR_INSUFFICIENT_BUFFER && count > 0;+ if (!installed) {+ for (const wchar_t* base : { L"C:\\Program Files\\Common Files\\Apple\\Internet Services\\iCloudDrive.exe",+ L"C:\\Program Files (x86)\\Common Files\\Apple\\Internet Services\\iCloudDrive.exe" }) {+ if (GetFileAttributesW(base) != INVALID_FILE_ATTRIBUTES) { installed = true; break; }+ }+ }+ return installed ? std::vector<Conta>{ { L"iCloud Drive", root, Provider::ICloud } } : std::vector<Conta>{};+}++inline std::vector<Conta> PastasGoogleDrive() {+ // Drive for desktop oferece o modo streaming como unidade e o modo espelho como pasta.+ HKEY key = nullptr;+ bool installed = RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\Google\\DriveFS", 0, KEY_READ, &key) == ERROR_SUCCESS;+ if (installed) RegCloseKey(key);+ if (!installed) return {};+ std::vector<Conta> out;+ DWORD drives = GetLogicalDrives();+ for (int d = 0; d < 26; ++d) {+ if (!(drives & (1u << d))) continue;+ std::wstring root = std::wstring(1, wchar_t(L'A' + d)) + L":\\";+ if (GetDriveTypeW(root.c_str()) != DRIVE_FIXED) continue;+ wchar_t label[MAX_PATH] = {};+ if (GetVolumeInformationW(root.c_str(), label, MAX_PATH, nullptr, nullptr, nullptr, nullptr, 0) &&+ !_wcsicmp(label, L"Google Drive")) out.push_back({ L"Google Drive", root, Provider::GoogleDrive });+ }+ return out;+}++inline std::vector<Conta> PastasNuvem() {+ std::vector<Conta> result = PastasICloud();+ auto google = PastasGoogleDrive();+ result.insert(result.end(), google.begin(), google.end());+ auto oneDrive = PastasOneDrive();+ result.insert(result.end(), oneDrive.begin(), oneDrive.end());+ return result;+}+} // namespace nuvemdiff --git a/src/finder/main.cpp b/src/finder/main.cppindex afd26c7..0e471ee 100644--- a/src/finder/main.cpp+++ b/src/finder/main.cpp@@ -1,4 +1,4 @@-// Arquivos — gerenciador de arquivos no estilo do Finder (shell próprio, fase 4).+// Arquivos — gerenciador de arquivos no estilo do Finder (shell próprio, fase 4).// Primeira entrega: visão de ícones, barra lateral translúcida, menu de contexto próprio,// arrastar e soltar, renomear no lugar. Roda ao lado do Explorer; não registra nada.//@@ -7,6 +7,8 @@#include "finder.h"#include "../comum/fonte_cjk.h" // a reserva para coreano, japonês e chinês#include "../comum/nuvem.h"+#include <d2d1_3.h>+#include <wrl/client.h>#include <d2d1effects.h> // Leopard: a perspectiva 3D do Cover Flow#pragma comment(lib, "dxguid.lib")#include <windowsx.h>@@ -125,6 +127,7 @@ struct SideEntry {UINT32 tagColor = 0; // etiqueta: bolinha colorida (0xRRGGBB) no lugar do íconeint tag = -1; // etiqueta: índice da corint fav = -1; // favorito: posição em g_favs (editável)+ nuvem::Provider cloud = nuvem::Provider::None;};static HWND g_hwnd;@@ -1955,6 +1958,57 @@ static void DrawGlyph(ID2D1DeviceContext* dc, wchar_t g, D2D1_RECT_F r, ID2D1Brudc->DrawTextW(&g, 1, tf ? tf : g_tfGlyph, r, b, D2D1_DRAW_TEXT_OPTIONS_CLIP);}+static bool DrawCloudBrand(ID2D1DeviceContext* dc, nuvem::Provider provider, float cx, float cy) {+ if (provider != nuvem::Provider::GoogleDrive && provider != nuvem::Provider::OneDrive) return false;+ static constexpr char googleDrive[] = R"svg(<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#3897FF" stroke-width="1.35" stroke-linecap="round" stroke-linejoin="round">+ <path d="M 8.28,5.03 Q 8.90,3.95 10.15,3.95 L 13.85,3.95 Q 15.10,3.95 15.72,5.03 L 20.68,13.61 Q 21.30,14.69 20.68,15.77 L 18.82,18.98 Q 18.20,20.06 16.95,20.06 L 7.05,20.06 Q 5.80,20.06 5.18,18.98 L 3.32,15.77 Q 2.70,14.69 3.32,13.61 Z"/>+ <path d="M 9.06,4.22 L 15.10,14.69"/>+ <path d="M 5.96,19.79 L 12.00,9.32"/>+ <path d="M 20.99,14.69 L 8.90,14.69"/>+</svg>)svg";+ static constexpr char oneDrive[] = R"svg(<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#3897FF" stroke-width="1.35" stroke-linecap="round" stroke-linejoin="round">+ <path d="M 6.45,18.40 A 4.45,4.45 0 1,1 6.69,9.51 A 5.75,5.75 0 0,1 17.83,11.02 A 3.70,3.70 0 1,1 18.25,18.40 Z"/>+ <path d="M 6.69,9.51 Q 8.19,9.59 21.32,16.77"/>+ <path d="M 2.94,16.69 Q 16.34,11.19 17.83,11.02"/>+</svg>)svg";++ using Microsoft::WRL::ComPtr;+ struct SvgCache {+ ComPtr<ID2D1Device> device;+ ComPtr<ID2D1SvgDocument> google, one;+ };+ static thread_local SvgCache cache;++ ComPtr<ID2D1DeviceContext5> svgContext;+ if (FAILED(dc->QueryInterface(IID_PPV_ARGS(&svgContext)))) return false;+ ComPtr<ID2D1Device> device;+ dc->GetDevice(&device);+ if (cache.device.Get() != device.Get()) {+ cache = {};+ cache.device = device;+ }++ const bool google = provider == nuvem::Provider::GoogleDrive;+ auto& document = google ? cache.google : cache.one;+ if (!document) {+ auto bytes = reinterpret_cast<const BYTE*>(google ? googleDrive : oneDrive);+ ComPtr<IStream> stream;+ stream.Attach(SHCreateMemStream(bytes, static_cast<UINT>(google ? sizeof(googleDrive) - 1 : sizeof(oneDrive) - 1)));+ if (!stream || FAILED(svgContext->CreateSvgDocument(stream.Get(), D2D1::SizeF(24, 24), &document))) return false;+ }++ D2D1_MATRIX_3X2_F old;+ dc->GetTransform(&old);+ // Ajusta a largura visível dos dois SVGs à dos demais glifos da barra lateral.+ const float scale = google ? 0.72f : 0.67f;+ const float half = 12 * scale;+ dc->SetTransform(D2D1::Matrix3x2F::Scale(scale, scale) *+ D2D1::Matrix3x2F::Translation(cx - half, cy - half) * old);+ svgContext->DrawSvgDocument(document.Get());+ dc->SetTransform(old);+ return true;+}+// Ícones da barra de ferramentas: traço fino e pontas arredondadas, desenhados aqui mesmo.// Leopard: os glifos pretos cheios da barra do Finder do 10.5 (captura real: ◀ ▶, quadradinhos, linhas, colunas, as// capas do Cover Flow, o olho do Quick Look e a engrenagem ▾)@@ -2591,7 +2645,8 @@ static void DrawSidebar(ID2D1DeviceContext* dc, const Palette& pal, ID2D1SolidCodefault: leoIcon = L"side pasta"; break;}}- if (leoIcon && DrawLeoPng(dc, leoIcon, D2D1::RectF(16.7f + dx, cy - 8, 32.7f + dx, cy + 8))) {}+ if (DrawCloudBrand(dc, s.cloud, 24.7f + dx, cy)) {}+ else if (leoIcon && DrawLeoPng(dc, leoIcon, D2D1::RectF(16.7f + dx, cy - 8, 32.7f + dx, cy + 8))) {}else if (leoSide && pasta) DrawFolder(dc, D2D1::RectF(16.7f + dx, cy - 8, 32.7f + dx, cy + 8), s.glyph == 0xE8B7 ? 0 : s.glyph, br);else {if (leoSide) br->SetColor(cur ? D2D1::ColorF(1, 1, 1, 1) : D2D1::ColorF(96 / 255.f, 110 / 255.f, 128 / 255.f, 1));@@ -7184,7 +7239,7 @@ static void BuildSidebar() {{ &FOLDERID_Documents, 0xE8A5 }, { &FOLDERID_Downloads, 0xE896 }, { &FOLDERID_Pictures, 0xE91B },{ &FOLDERID_Music, 0xE8D6 }, { &FOLDERID_Videos, 0xE714 }, { &FOLDERID_Profile, 0xE80F }, { &FOLDERID_SkyDrive, 0xE753 } };for (auto& k : special) { std::wstring p = KnownFolder(*k.id); if (!p.empty()) g_emblems.push_back({ p, k.glyph }); }- auto clouds = nuvem::PastasOneDrive();+ auto clouds = nuvem::PastasNuvem();for (auto& c : clouds) g_emblems.push_back({ c.caminho, 0xE753 });const bool leoSide = !g_tahoe && tahoe::Leopard();@@ -7197,6 +7252,7 @@ static void BuildSidebar() {std::wstring root = std::wstring(1, (wchar_t)(L'A' + d)) + L":\\";UINT type = GetDriveTypeW(root.c_str());if (type != DRIVE_FIXED && type != DRIVE_REMOVABLE && type != DRIVE_REMOTE) continue;+ if (g_sideCloud && std::any_of(clouds.begin(), clouds.end(), [&](const nuvem::Conta& c) { return SamePath(c.caminho, root); })) continue;SHFILEINFOW sfi{};std::wstring label = SHGetFileInfoW(root.c_str(), 0, &sfi, sizeof(sfi), SHGFI_DISPLAYNAME) ? sfi.szDisplayName : root;g_side.push_back({ label, root, (wchar_t)(type == DRIVE_REMOVABLE ? 0xE88E : 0xEDA2), false });@@ -7214,7 +7270,7 @@ static void BuildSidebar() {devices(Tr(L"Dispositivos"));if (!clouds.empty()) {g_side.push_back({ Tr(L"Compartilhado"), L"", 0, true });- for (auto& c : clouds) g_side.push_back({ c.rotulo, c.caminho, 0xE753, false });+ for (auto& c : clouds) { SideEntry e{ c.rotulo, c.caminho, 0xE753, false }; e.cloud = c.provider; g_side.push_back(std::move(e)); }}g_side.push_back({ Tr(L"Buscar Por"), L"", 0, true });const wchar_t smartGlyph[6] = { 0xE823, 0xE823, 0xE823, 0xE91B, 0xE714, 0xE8A5 }; // relógio ×3, imagem, filme, documento@@ -7227,24 +7283,53 @@ static void BuildSidebar() {g_side.push_back(e);}- // OneDrive faz o papel do iCloud Drive (pessoal, corporativo e múltiplas contas)+ // Serviços de nuvem instalados aparecem juntos sob um título comum.if (g_sideCloud && !clouds.empty()) {- g_side.push_back({ L"OneDrive", L"", 0, true });- for (auto& c : clouds) g_side.push_back({ c.rotulo, c.caminho, 0xE753, false });+ g_side.push_back({ L"Cloud Storage", L"", 0, true });+ for (auto& c : clouds) { SideEntry e{ c.rotulo, c.caminho, 0xE753, false }; e.cloud = c.provider; g_side.push_back(std::move(e)); }}if (g_sideDrives) {- g_side.push_back({ Tr(L"Locais"), L"", 0, true });- { SideEntry pc{ Tr(L"Este Computador"), L"", 0xE7F4, false }; pc.tag = VIEW_COMPUTER; g_side.push_back(pc); }+ std::vector<SideEntry> localDrives, remoteDrives;DWORD drives = GetLogicalDrives();for (int d = 0; d < 26; d++) {if (!(drives & (1u << d))) continue;std::wstring root = std::wstring(1, (wchar_t)(L'A' + d)) + L":\\";UINT type = GetDriveTypeW(root.c_str());if (type != DRIVE_FIXED && type != DRIVE_REMOVABLE && type != DRIVE_REMOTE) continue;+ if (g_sideCloud && std::any_of(clouds.begin(), clouds.end(), [&](const nuvem::Conta& c) { return SamePath(c.caminho, root); })) continue;SHFILEINFOW sfi{};std::wstring label = SHGetFileInfoW(root.c_str(), 0, &sfi, sizeof(sfi), SHGFI_DISPLAYNAME) ? sfi.szDisplayName : root;- g_side.push_back({ label, root, (wchar_t)(type == DRIVE_REMOVABLE ? 0xE88E : 0xEDA2), false });+ SideEntry entry{ label, root, (wchar_t)(type == DRIVE_REMOTE ? 0xE968 : type == DRIVE_REMOVABLE ? 0xE88E : 0xEDA2), false };+ (type == DRIVE_REMOTE ? remoteDrives : localDrives).push_back(std::move(entry));+ }+ // Locais de rede salvos no Explorer (atalhos .lnk, inclusive dentro das pastas do NetHood).+ wchar_t netHood[MAX_PATH] = {};+ if (SUCCEEDED(SHGetFolderPathW(nullptr, CSIDL_NETHOOD, nullptr, SHGFP_TYPE_CURRENT, netHood))) {+ auto addShortcut = [&](const std::wstring& shortcut, const std::wstring& label) {+ std::wstring target = LinkTarget(shortcut);+ if (target.rfind(L"\\\\", 0) != 0) return;+ if (std::any_of(remoteDrives.begin(), remoteDrives.end(), [&](const SideEntry& e) { return SamePath(e.path, target); })) return;+ remoteDrives.push_back({ label, target, 0xE968, false });+ };+ WIN32_FIND_DATAW fd{};+ HANDLE find = FindFirstFileW((std::wstring(netHood) + L"\\*").c_str(), &fd);+ if (find != INVALID_HANDLE_VALUE) {+ do {+ const std::wstring name = fd.cFileName;+ if (name == L"." || name == L"..") continue;+ std::wstring path = std::wstring(netHood) + L"\\" + name;+ if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) addShortcut(path + L"\\target.lnk", name);+ else if (!_wcsicmp(PathFindExtensionW(name.c_str()), L".lnk")) addShortcut(path, name.substr(0, name.size() - 4));+ } while (FindNextFileW(find, &fd));+ FindClose(find);+ }+ }+ g_side.push_back({ Tr(L"Este Computador"), L"", 0, true });+ g_side.insert(g_side.end(), localDrives.begin(), localDrives.end());+ if (!remoteDrives.empty()) {+ g_side.push_back({ L"Remote Locations", L"", 0, true });+ g_side.insert(g_side.end(), remoteDrives.begin(), remoteDrives.end());}}@@ -7331,7 +7416,7 @@ static void FinderSettings() {}ctxmenu::Item sep; sep.separator = true;items.push_back(sep);- if (!nuvem::PastasOneDrive().empty()) { ctxmenu::Item c; c.label = L"OneDrive"; c.id = 40; c.checked = g_sideCloud; c.icon = 0xE753; items.push_back(c); }+ if (!nuvem::PastasNuvem().empty()) { ctxmenu::Item c; c.label = L"Cloud Storage"; c.id = 40; c.checked = g_sideCloud; c.icon = 0xE753; items.push_back(c); }{ ctxmenu::Item c; c.label = Tr(L"Locais"); c.id = 41; c.checked = g_sideDrives; c.icon = 0xEDA2; items.push_back(c); }{ ctxmenu::Item c; c.label = Tr(L"Etiquetas"); c.id = 42; c.checked = g_sideTags; c.icon = 0xE8EC; items.push_back(c); }items.push_back(sep);