diff options
author | elfmz <fenix1905@tut.by> | 2022-10-29 23:04:59 +0300 |
---|---|---|
committer | elfmz <fenix1905@tut.by> | 2022-10-29 23:04:59 +0300 |
commit | 5f4ea8b9cf7eef926d32da2142eabec48936c2fc (patch) | |
tree | 4af058ec89fe3d627b8df239a9d29116303f7716 /far2l/src/Mounts.cpp | |
parent | 011b24338ab26b8d16b10b17d3f49d407907baaf (diff) |
Location menu mountpoints customizations (touch #1378 #1379)
Diffstat (limited to 'far2l/src/Mounts.cpp')
-rw-r--r-- | far2l/src/Mounts.cpp | 164 |
1 files changed, 108 insertions, 56 deletions
diff --git a/far2l/src/Mounts.cpp b/far2l/src/Mounts.cpp index 2804f915..7e890117 100644 --- a/far2l/src/Mounts.cpp +++ b/far2l/src/Mounts.cpp @@ -1,6 +1,7 @@ #include "headers.hpp" #include <crc64.h> +#include <wordexp.h> #include <fstream> #include "Mounts.hpp" #include "lang.hpp" @@ -64,31 +65,93 @@ namespace Mounts Enum::Enum(FARString &another_curdir) { - MountInfo mi(true); - bool has_rootfs = false; + if (Opt.ChangeDriveMode & DRIVE_SHOW_MOUNTS) + { + AddMounts(has_rootfs); + } + AddFavorites(has_rootfs); + + if (!has_rootfs) { + emplace(begin(), Entry(L"/", Msg::MountsRoot, false, ID_ROOT)); + } + + emplace(begin(), Entry( GetMyHome(), Msg::MountsHome, false, ID_HOME)); + emplace(begin(), Entry( another_curdir, Msg::MountsOther, false, ID_ANOTHER)); + + ConfigReader cfg_reader(HOTKEYS_SECTION); + for (auto &m : *this) { + if (max_path < m.path.GetLength()) + max_path = m.path.GetLength(); + if (max_info < m.info.GetLength()) + max_info = m.info.GetLength(); + if (max_usage < m.usage.GetLength()) + max_usage = m.usage.GetLength(); + wchar_t def_hk[] = {DefaultHotKey(m.id, m.path), 0}; + auto hk = cfg_reader.GetString(SettingsKey(m.id), def_hk); + m.hotkey = hk.IsEmpty() ? 0 : *hk.CPtr(); + } + } + + static void ExpandMountpointInfo(const Mountpoint &mp, FARString &str) + { + FARString val = L" "; + if (mp.bad) { + val = L"?"; + } else if (mp.read_only) { + val = L"!"; + } + ReplaceStrings(str, L"$S", val); + + FileSizeToStr(val, mp.total, -1, COLUMN_ECONOMIC | COLUMN_FLOATSIZE | COLUMN_SHOWBYTESINDEX); + ReplaceStrings(str, L"$T", val); + + FileSizeToStr(val, mp.avail, -1, COLUMN_ECONOMIC | COLUMN_FLOATSIZE | COLUMN_SHOWBYTESINDEX); + ReplaceStrings(str, L"$A", val); + + FileSizeToStr(val, mp.freee, -1, COLUMN_ECONOMIC | COLUMN_FLOATSIZE | COLUMN_SHOWBYTESINDEX); + ReplaceStrings(str, L"$F", val); + + FileSizeToStr(val, mp.total - mp.freee, -1, COLUMN_ECONOMIC | COLUMN_FLOATSIZE | COLUMN_SHOWBYTESINDEX); + ReplaceStrings(str, L"$U", val); + + if (mp.total) + val.Format(L"%d", (mp.avail * 100) / mp.total); + else + val = L"NA"; + ReplaceStrings(str, L"$a", val); + + if (mp.total) + val.Format(L"%d", (mp.freee * 100) / mp.total); + else + val = L"NA"; + ReplaceStrings(str, L"$f", val); + + if (mp.total) + val.Format(L"%d", ((mp.total - mp.freee) * 100) / mp.total); + else + val = L"NA"; + ReplaceStrings(str, L"$u", val); + + val = mp.filesystem; + ReplaceStrings(str, L"$N", val); + + val = mp.device; + ReplaceStrings(str, L"$D", val); + } + + void Enum::AddMounts(bool &has_rootfs) + { + MountInfo mi(true); for (const auto &mp : mi.Enum()) { emplace_back(); auto &e = back(); e.path = mp.path; - e.info = mp.filesystem; - if (mp.bad) { - e.usage = Opt.NoGraphics ? L"X_X" : L"❌_❌"; - - } else { - FileSizeToStr(e.usage, mp.avail, -1, COLUMN_ECONOMIC | COLUMN_FLOATSIZE | COLUMN_SHOWBYTESINDEX); //COLUMN_AUTOSIZE | COLUMN_SHOWBYTESINDEX - while (e.usage.GetLength() < 4) { - e.usage.Insert(0, L' '); - } - FARString tmp; - FileSizeToStr(tmp, mp.total, -1, COLUMN_ECONOMIC | COLUMN_FLOATSIZE | COLUMN_SHOWBYTESINDEX); //COLUMN_AUTOSIZE | COLUMN_SHOWBYTESINDEX - while (e.usage.GetLength() < 4) { - tmp.Insert(0, L' '); - } - e.usage+= L"/"; - e.usage+= tmp; - } - + e.usage = Opt.ChangeDriveColumn2; + e.info = Opt.ChangeDriveColumn3; + ExpandMountpointInfo(mp, e.usage); + ExpandMountpointInfo(mp, e.info); + if (e.path == L"/") { has_rootfs = true; } else { @@ -96,7 +159,10 @@ namespace Mounts } e.id = GenerateIdFromPath(e.path); } + } + void Enum::AddFavorites(bool &has_rootfs) + { std::ifstream favis(InMyConfig("favorites")); if (favis.is_open()) { std::string line; @@ -105,49 +171,35 @@ namespace Mounts if (line.empty() || line.front() == '#') { continue; } - std::vector<std::string> parts; - StrExplode(parts, line, "\t"); - if (!parts.empty()) { - emplace_back(); - auto &e = back(); - e.path = parts.front(); - if (parts.size() > 1) { - e.info = parts.back(); - if (parts.size() > 2) { - e.usage = parts[1]; + Environment::ExpandString(line, true, true); + std::vector<std::string> sublines; + StrExplode(sublines, line, "\n"); + for (const auto &subline : sublines) { + std::vector<std::string> parts; + StrExplode(parts, subline, "\t"); + if (!parts.empty()) { + emplace_back(); + auto &e = back(); + e.path = parts.front(); + if (parts.size() > 1) { + e.info = parts.back(); + if (parts.size() > 2) { + e.usage = parts[1]; + } } - } - e.id = GenerateIdFromPath(e.path); - if (e.path == L"/") { - has_rootfs = true; + e.id = GenerateIdFromPath(e.path); + if (e.path == L"/") { + has_rootfs = true; - } else if (*e.path.CPtr() == L'/') { - e.unmountable = true; + } else if (*e.path.CPtr() == L'/') { + e.unmountable = true; + } } } } } - - if (!has_rootfs) { - emplace(begin(), Entry(L"/", Msg::MountsRoot, false, ID_ROOT)); - } - - emplace(begin(), Entry( GetMyHome(), Msg::MountsHome, false, ID_HOME)); - emplace(begin(), Entry( another_curdir, Msg::MountsOther, false, ID_ANOTHER)); - - ConfigReader cfg_reader(HOTKEYS_SECTION); - for (auto &m : *this) { - if (max_path < m.path.GetLength()) - max_path = m.path.GetLength(); - if (max_info < m.info.GetLength()) - max_info = m.info.GetLength(); - if (max_usage < m.usage.GetLength()) - max_usage = m.usage.GetLength(); - wchar_t def_hk[] = {DefaultHotKey(m.id, m.path), 0}; - auto hk = cfg_reader.GetString(SettingsKey(m.id), def_hk); - m.hotkey = hk.IsEmpty() ? 0 : *hk.CPtr(); - } } + ////// bool Unmount(const FARString &path, bool force) { |