A new style desktop shell for Windows 11: menu bar, Dock, Finder, Spotlight, Control Center and Liquid Glass, in native C++.
Rust
OneDrive & Cloud Files: index/search cloud folders and discover multi-account OneDrive
Eternity0706289719d4f365ba
diff --git a/src/comum/nuvem.h b/src/comum/nuvem.hnew file mode 100644index 0000000..65a8d7d--- /dev/null+++ b/src/comum/nuvem.h@@ -0,0 +1,123 @@+#pragma once+// Pastas na nuvem no Windows 11 (OneDrive pessoal, OneDrive corporativo / múltiplas contas, iCloud Drive, Dropbox...):+// 1. O filtro de arquivos na nuvem do Windows (cldflt.sys) marca a raiz ativa do OneDrive e cada subpasta sincronizada+// com FILE_ATTRIBUTE_REPARSE_POINT e IO_REPARSE_TAG_CLOUD..CLOUD_F (0x9000001A..0x9000F01A). Diferente de junções e+// symlinks, elas são pastas reais no lugar (sem desvio nem risco de laço) — pular todo reparse point deixava o+// OneDrive ativo inteiro fora do índice do Spotlight, do vigia de mudanças, da busca e do "Obter Informações".+// 2. O FOLDERID_SkyDrive só devolve a pasta do OneDrive pessoal (%USERPROFILE%\OneDrive), ignorando contas corporativas+// e de ensino (HKCU\Software\Microsoft\OneDrive\Accounts\*\UserFolder, OneDriveCommercial e "OneDrive - *").+#include <windows.h>+#include <shlobj.h>+#include <string>+#include <vector>++namespace nuvem {++inline bool TagNuvem(DWORD tag) {+ return (tag & ~0x0000F000u) == 0x9000001Au /* IO_REPARSE_TAG_CLOUD..CLOUD_F */ ||+ tag == 0x80000021u /* IO_REPARSE_TAG_ONEDRIVE */;+}++// Reparse point que redireciona para outro caminho (junção, symlink, ponto de montagem): evita voltas ao varrer pastas.+// Pastas do filtro de nuvem (TagNuvem) devolvem false para entrarem normalmente na varredura.+inline bool ReparseDeDesvio(const WIN32_FIND_DATAW& fd) {+ if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)) return false;+ return !TagNuvem(fd.dwReserved0);+}++// Arquivo desidratado ("só na nuvem", Files On-Demand): não ocupa blocos no disco local e abri-lo sem+// FILE_FLAG_OPEN_REPARSE_POINT dispara o download completo pelo cldflt.sys.+inline bool SoNaNuvem(DWORD attr) {+ return (attr & (FILE_ATTRIBUTE_OFFLINE | 0x00400000u /*FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS*/ |+ 0x00040000u /*FILE_ATTRIBUTE_RECALL_ON_OPEN*/)) != 0;+}++struct Conta {+ std::wstring rotulo;+ std::wstring caminho;+};++inline std::vector<Conta> PastasOneDrive() {+ std::vector<Conta> out;+ auto limpar = [](std::wstring p) {+ while (p.size() > 3 && (p.back() == L'\\' || p.back() == L'/')) p.pop_back();+ return p;+ };+ auto nomeFolha = [](const std::wstring& p) {+ size_t b = p.find_last_of(L"\\/");+ return b == std::wstring::npos ? p : p.substr(b + 1);+ };+ auto adicionar = [&](std::wstring p, std::wstring rotulo) {+ p = limpar(std::move(p));+ if (p.empty()) return;+ DWORD a = GetFileAttributesW(p.c_str());+ if (a == INVALID_FILE_ATTRIBUTES || !(a & FILE_ATTRIBUTE_DIRECTORY)) return;+ for (auto& e : out) if (!_wcsicmp(e.caminho.c_str(), p.c_str())) return;+ if (rotulo.empty()) {+ std::wstring folha = nomeFolha(p);+ rotulo = !_wcsnicmp(folha.c_str(), L"OneDrive", 8) ? folha : L"OneDrive";+ }+ out.push_back({ std::move(rotulo), std::move(p) });+ };++ // 1. Contas configuradas no cliente do OneDrive (Personal, Business1, Business2...)+ HKEY hk = nullptr;+ if (RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\Microsoft\\OneDrive\\Accounts", 0, KEY_READ, &hk) == ERROR_SUCCESS) {+ wchar_t sub[128];+ for (DWORD idx = 0;; idx++) {+ DWORD subLen = 128;+ if (RegEnumKeyExW(hk, idx, sub, &subLen, nullptr, nullptr, nullptr, nullptr) != ERROR_SUCCESS) break;+ HKEY ak = nullptr;+ if (RegOpenKeyExW(hk, sub, 0, KEY_READ, &ak) != ERROR_SUCCESS) continue;+ wchar_t pasta[MAX_PATH] = {}, disp[256] = {};+ DWORD cbPasta = sizeof(pasta), cbDisp = sizeof(disp), tp = 0, bus = 0, cbBus = sizeof(bus);+ bool temPasta = RegQueryValueExW(ak, L"UserFolder", nullptr, &tp, (BYTE*)pasta, &cbPasta) == ERROR_SUCCESS &&+ (tp == REG_SZ || tp == REG_EXPAND_SZ) && pasta[0];+ if (temPasta) {+ RegQueryValueExW(ak, L"DisplayName", nullptr, &tp, (BYTE*)disp, &cbDisp);+ RegQueryValueExW(ak, L"Business", nullptr, &tp, (BYTE*)&bus, &cbBus);+ std::wstring rot;+ if (bus && disp[0]) rot = std::wstring(L"OneDrive - ") + disp;+ adicionar(pasta, std::move(rot));+ }+ RegCloseKey(ak);+ }+ RegCloseKey(hk);+ }++ // 2. Variáveis de ambiente (OneDriveCommercial, OneDriveConsumer, OneDrive)+ for (const wchar_t* ev : { L"OneDriveCommercial", L"OneDriveConsumer", L"OneDrive" }) {+ wchar_t buf[MAX_PATH] = {};+ DWORD n = GetEnvironmentVariableW(ev, buf, MAX_PATH);+ if (n > 0 && n < MAX_PATH) adicionar(buf, L"");+ }++ // 3. Pastas "OneDrive" e "OneDrive - *" na pasta do usuário (inclui pastas corporativas mantidas localmente após logout)+ PWSTR prof = nullptr;+ if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_Profile, 0, nullptr, &prof)) && prof) {+ std::wstring base = limpar(prof);+ CoTaskMemFree(prof);+ WIN32_FIND_DATAW fd{};+ HANDLE f = FindFirstFileExW((base + L"\\OneDrive*").c_str(), FindExInfoBasic, &fd, FindExSearchNameMatch, nullptr, 0);+ if (f != INVALID_HANDLE_VALUE) {+ do {+ if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) || (fd.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM)) continue;+ const wchar_t* nm = fd.cFileName;+ if (!_wcsicmp(nm, L"OneDrive") || !_wcsnicmp(nm, L"OneDrive - ", 11) || !_wcsnicmp(nm, L"OneDrive ", 9))+ adicionar(base + L"\\" + nm, nm);+ } while (FindNextFileW(f, &fd));+ FindClose(f);+ }+ }++ // 4. FOLDERID_SkyDrive (caso o OneDrive pessoal tenha sido movido para outro disco/caminho)+ PWSTR sky = nullptr;+ if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_SkyDrive, 0, nullptr, &sky)) && sky) {+ adicionar(sky, L"");+ CoTaskMemFree(sky);+ }++ return out;+}++} // namespace nuvemdiff --git a/src/finder/info.cpp b/src/finder/info.cppindex 914bb5a..eaf2e00 100644--- a/src/finder/info.cpp+++ b/src/finder/info.cpp@@ -23,6 +23,7 @@#include <thread>#include "../comum/idioma.h"#include "../comum/semaforo.h"+#include "../comum/nuvem.h"namespace {@@ -156,9 +157,12 @@ void Walk(const std::wstring& dir, Calc& c, unsigned long long cl) {{std::lock_guard<std::mutex> g(c.m);c.items++;- if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { c.bytes += sz; c.disk += OnDisk(sz, cl); }+ if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {+ c.bytes += sz;+ if (!nuvem::SoNaNuvem(fd.dwFileAttributes)) c.disk += OnDisk(sz, cl);+ }}- if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && !(fd.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT))+ if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && !nuvem::ReparseDeDesvio(fd))Walk(dir + L"\\" + fd.cFileName, c, cl);} while (FindNextFileW(h, &fd));FindClose(h);@@ -340,16 +344,18 @@ void Gather(Info& in) {in.sizeText = Tr(L"Calculando…");} else {unsigned long long sz = ((unsigned long long)fa.nFileSizeHigh << 32) | fa.nFileSizeLow;+ unsigned long long noDisco = nuvem::SoNaNuvem(fa.dwFileAttributes) ? 0 : OnDisk(sz, Cluster(p));in.headerSize = Human(sz);- in.sizeText = Thousands(sz) + Tr(L" bytes (") + Human(OnDisk(sz, Cluster(p))) + Tr(L" no disco)");+ in.sizeText = Thousands(sz) + Tr(L" bytes (") + Human(noDisco) + Tr(L" no disco)");wchar_t app[260] = {}; DWORD n = 260;const wchar_t* ext = PathFindExtensionW(p.c_str());if (*ext && SUCCEEDED(AssocQueryStringW(ASSOCF_INIT_IGNOREUNKNOWN, ASSOCSTR_FRIENDLYAPPNAME, ext, L"open", app, &n))) in.openWith = app;else in.openWith = Tr(L"Nenhum aplicativo");}- // permissões: tenta abrir para escrita sem mexer em nada+ // permissões: tenta abrir para escrita sem mexer em nada (em arquivo só na nuvem, sem hidratá-lo)DWORD acc = in.dir ? FILE_ADD_FILE : FILE_WRITE_DATA;- HANDLE hf = CreateFileW(p.c_str(), acc, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr, OPEN_EXISTING, in.dir ? FILE_FLAG_BACKUP_SEMANTICS : 0, nullptr);+ DWORD flags = in.dir ? FILE_FLAG_BACKUP_SEMANTICS : (nuvem::SoNaNuvem(fa.dwFileAttributes) ? FILE_FLAG_OPEN_REPARSE_POINT : 0);+ HANDLE hf = CreateFileW(p.c_str(), acc, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr, OPEN_EXISTING, flags, nullptr);in.canWrite = hf != INVALID_HANDLE_VALUE;if (hf != INVALID_HANDLE_VALUE) CloseHandle(hf);GatherPerms(in);diff --git a/src/finder/main.cpp b/src/finder/main.cppindex e011c2e..65e1a6c 100644--- a/src/finder/main.cpp+++ b/src/finder/main.cpp@@ -6,6 +6,7 @@#include "finder.h"#include "../comum/fonte_cjk.h" // a reserva para coreano, japonês e chinês+#include "../comum/nuvem.h"#include <d2d1effects.h> // Leopard: a perspectiva 3D do Cover Flow#pragma comment(lib, "dxguid.lib")#include <windowsx.h>@@ -7138,6 +7139,8 @@ 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();+ for (auto& c : clouds) g_emblems.push_back({ c.caminho, 0xE753 });const bool leoSide = !g_tahoe && tahoe::Leopard();auto devices = [&](const std::wstring& title) {@@ -7164,10 +7167,9 @@ static void BuildSidebar() {g_side.push_back(e);}devices(Tr(L"Dispositivos"));- std::wstring cl = KnownFolder(FOLDERID_SkyDrive);- if (!cl.empty() && GetFileAttributesW(cl.c_str()) != INVALID_FILE_ATTRIBUTES) {+ if (!clouds.empty()) {g_side.push_back({ Tr(L"Compartilhado"), L"", 0, true });- g_side.push_back({ L"OneDrive", cl, 0xE753, false });+ for (auto& c : clouds) g_side.push_back({ c.rotulo, c.caminho, 0xE753, false });}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@@ -7180,11 +7182,10 @@ static void BuildSidebar() {g_side.push_back(e);}- // OneDrive faz o papel do iCloud Drive- std::wstring cloud = g_sideCloud ? KnownFolder(FOLDERID_SkyDrive) : L"";- if (!cloud.empty() && GetFileAttributesW(cloud.c_str()) != INVALID_FILE_ATTRIBUTES) {+ // OneDrive faz o papel do iCloud Drive (pessoal, corporativo e múltiplas contas)+ if (g_sideCloud && !clouds.empty()) {g_side.push_back({ L"OneDrive", L"", 0, true });- g_side.push_back({ L"OneDrive", cloud, 0xE753, false });+ for (auto& c : clouds) g_side.push_back({ c.rotulo, c.caminho, 0xE753, false });}if (g_sideDrives) {@@ -7285,8 +7286,7 @@ static void FinderSettings() {}ctxmenu::Item sep; sep.separator = true;items.push_back(sep);- std::wstring cl = KnownFolder(FOLDERID_SkyDrive);- if (!cl.empty() && GetFileAttributesW(cl.c_str()) != INVALID_FILE_ATTRIBUTES) { ctxmenu::Item c; c.label = L"OneDrive"; c.id = 40; c.checked = g_sideCloud; c.icon = 0xE753; items.push_back(c); }+ 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); }{ 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);diff --git a/src/finder/search.cpp b/src/finder/search.cppindex 3f6af3a..c9fa032 100644--- a/src/finder/search.cpp+++ b/src/finder/search.cpp@@ -1,6 +1,7 @@// Busca no índice do Windows Search (o "Spotlight" do Windows), via OLE DB/ADO.// Pastas fora do índice caem numa varredura simples pelo nome.#include "finder.h"+#include "../comum/nuvem.h"#include <shlwapi.h>#include <shlobj.h>#import "C:\\Program Files\\Common Files\\System\\ado\\msado15.dll" no_namespace rename("EOF", "AdoEOF")@@ -147,7 +148,7 @@ int Walk(const std::wstring& q, const std::wstring& folder, int max, const std::if (fd.cFileName[0] == L'.') continue;std::wstring p = dir + (dir.back() == L'\\' ? L"" : L"\\") + fd.cFileName;if (StrStrIW(fd.cFileName, q.c_str())) { n++; if (!onPath(p) || n >= max) { stop = true; break; } }- if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && !(fd.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)) stack.push_back(p);+ if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && !nuvem::ReparseDeDesvio(fd)) stack.push_back(p);} while (FindNextFileW(f, &fd));FindClose(f);}diff --git a/src/shell/indice.cpp b/src/shell/indice.cppindex a7e201e..db82d02 100644--- a/src/shell/indice.cpp+++ b/src/shell/indice.cpp@@ -4,6 +4,7 @@// varredura nova roda em segundo plano; depois, mudanças nas pastas refazem o índice (no máximo a// cada 2 minutos). A busca é uma passada na memória: milissegundos mesmo com centenas de milhares de itens.#include "shell.h"+#include "../comum/nuvem.h"#include <shlobj.h>#include <algorithm>#include <atomic>@@ -100,7 +101,7 @@ template <class F> void List(const std::wstring& path, bool top, bool profile, Fif ((n[0] == L'.' && !n[1]) || (n[0] == L'.' && n[1] == L'.' && !n[2])) continue;bool dir = (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;if (fd.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM && dir) continue;- if (dir && (fd.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)) continue; // junções (evita voltas)+ if (dir && nuvem::ReparseDeDesvio(fd)) continue; // junções e links (evita voltas; pastas da nuvem entram)if (dir && SkipDir(n, top, profile)) continue;size_t len = wcslen(n);if (len > 0xFFFF) continue;@@ -375,7 +376,7 @@ std::vector<Watch*> MakeWatches() {HANDLE f = FindFirstFileExW((root + L"\\*").c_str(), FindExInfoBasic, &fd, FindExSearchNameMatch, nullptr, 0);if (f == INVALID_HANDLE_VALUE) continue;do {- if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) || (fd.dwFileAttributes & (FILE_ATTRIBUTE_REPARSE_POINT | FILE_ATTRIBUTE_SYSTEM))) continue;+ if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) || (fd.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) || nuvem::ReparseDeDesvio(fd)) continue;if ((fd.cFileName[0] == L'.' && (!fd.cFileName[1] || fd.cFileName[1] == L'.')) || SkipDir(fd.cFileName, true, profile)) continue;add(root + L"\\" + fd.cFileName, root, profile, true);} while (FindNextFileW(f, &fd));diff --git a/src/shell/main.cpp b/src/shell/main.cppindex 5668ddf..ae6afd6 100644--- a/src/shell/main.cpp+++ b/src/shell/main.cpp@@ -5,6 +5,7 @@#include "../comum/simbolos.h"#include "../comum/ajustes_arquivo.h"#include "../comum/idioma.h"+#include "../comum/nuvem.h"#include "../menu/context_menu.h"#include <shlobj.h>#include <propkey.h>@@ -523,6 +524,7 @@ bool shell::PastaProtegida(const std::wstring& path0) {if (igual) return true;}}+ for (auto& c : nuvem::PastasOneDrive()) if (!_wcsicmp(c.caminho.c_str(), p.c_str())) return true;return false;}