# HG changeset patch # User Paper # Date 1700075657 18000 # Node ID d43d68408d3caf8b04aa0af3ba0049391305bbb3 # Parent bd439dd6ffc5929ac40bfa136715d63217b57ea0 dep/animia: fix XnuFdTools also we use anitomy directly now. HG Enter commit message. Lines beginning with 'HG:' are removed. diff -r bd439dd6ffc5 -r d43d68408d3c dep/animia/CMakeLists.txt --- a/dep/animia/CMakeLists.txt Wed Nov 15 13:28:18 2023 -0500 +++ b/dep/animia/CMakeLists.txt Wed Nov 15 14:14:17 2023 -0500 @@ -10,12 +10,13 @@ src/win.cc ) +# FD if(LINUX) list(APPEND SRC_FILES # linux src/fd/linux.cc ) -elseif(MACOSX) # this won't run on Linux +elseif(APPLE) # this won't run on Linux list(APPEND SRC_FILES # xnu stuff src/fd/xnu.cc @@ -27,6 +28,7 @@ ) endif() +# Windows if(WIN32) list(APPEND SRC_FILES src/win/win32.cc diff -r bd439dd6ffc5 -r d43d68408d3c dep/animia/include/animia/fd.h --- a/dep/animia/include/animia/fd.h Wed Nov 15 13:28:18 2023 -0500 +++ b/dep/animia/include/animia/fd.h Wed Nov 15 14:14:17 2023 -0500 @@ -24,6 +24,7 @@ class BaseFdTools { public: + virtual ~BaseFdTools() {} virtual bool EnumerateOpenProcesses(process_proc_t process_proc) { return false; } virtual bool EnumerateOpenFiles(const std::set& pids, open_file_proc_t open_file_proc) { return false; } }; diff -r bd439dd6ffc5 -r d43d68408d3c dep/animia/src/fd/linux.cc --- a/dep/animia/src/fd/linux.cc Wed Nov 15 13:28:18 2023 -0500 +++ b/dep/animia/src/fd/linux.cc Wed Nov 15 14:14:17 2023 -0500 @@ -99,14 +99,17 @@ return ret.c_str(); } -static bool GetProcessName(pid_t pid, std::string& result) { +static std::string GetProcessName(pid_t pid) { const std::string path = PROC_LOCATION "/" + std::to_string(pid) + "/comm"; + std::string result; + if (!util::ReadFile(path, result)) - return false; + return ""; result.erase(std::remove(result.begin(), result.end(), '\n'), result.end()); - return true; + + return result; } bool LinuxFdTools::EnumerateOpenProcesses(process_proc_t process_proc) { diff -r bd439dd6ffc5 -r d43d68408d3c dep/animia/src/fd/xnu.cc --- a/dep/animia/src/fd/xnu.cc Wed Nov 15 13:28:18 2023 -0500 +++ b/dep/animia/src/fd/xnu.cc Wed Nov 15 14:14:17 2023 -0500 @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -17,17 +18,16 @@ namespace animia::internal::xnu { -static bool GetProcessName(pid_t pid, std::string& result) { +static std::string GetProcessName(pid_t pid) { struct proc_bsdinfo proc; int st = proc_pidinfo(pid, PROC_PIDTBSDINFO, 0, &proc, PROC_PIDTBSDINFO_SIZE); if (st != PROC_PIDTBSDINFO_SIZE) - return false; + return ""; /* fixme: is this right? pbi_comm is an alternative, but it reduces the string size to 16 chars. does pbi_name do the same, or is it different? */ - result = proc.pbi_name; - return true; + return proc.pbi_name; } /* this is a cleaned up version of a function from... Apple? @@ -60,6 +60,8 @@ if (!process_proc({pid, GetProcessName(pid)})) return false; } + + return true; } bool XnuFdTools::EnumerateOpenFiles(const std::set& pids, open_file_proc_t open_file_proc) { @@ -95,6 +97,7 @@ } } } + return true; } diff -r bd439dd6ffc5 -r d43d68408d3c dep/animia/src/win.cc --- a/dep/animia/src/win.cc Wed Nov 15 13:28:18 2023 -0500 +++ b/dep/animia/src/win.cc Wed Nov 15 14:14:17 2023 -0500 @@ -1,4 +1,4 @@ -#include "animia/fd.h" +#include "animia/win.h" #ifdef WIN32 # include "animia/win/win32.h" diff -r bd439dd6ffc5 -r d43d68408d3c include/gui/pages/now_playing.h --- a/include/gui/pages/now_playing.h Wed Nov 15 13:28:18 2023 -0500 +++ b/include/gui/pages/now_playing.h Wed Nov 15 14:14:17 2023 -0500 @@ -10,13 +10,17 @@ class Anime; } +namespace anitomy { +class Elements; +} + class NowPlayingPage final : public QFrame { Q_OBJECT public: NowPlayingPage(QWidget* parent = nullptr); void SetDefault(); - void SetPlaying(const Anime::Anime& anime, const std::unordered_map& episodes); + void SetPlaying(const Anime::Anime& anime, const anitomy::Elements& episodes); int GetPlayingId(); private: diff -r bd439dd6ffc5 -r d43d68408d3c include/track/media.h --- a/include/track/media.h Wed Nov 15 13:28:18 2023 -0500 +++ b/include/track/media.h Wed Nov 15 14:14:17 2023 -0500 @@ -1,6 +1,5 @@ #ifndef __track__media_h #define __track__media_h -#include "core/filesystem.h" #include #include #include @@ -9,8 +8,6 @@ namespace Media { bool GetCurrentlyPlaying(std::vector& vec); -std::unordered_map GetFileElements(const std::string& basename); -//std::unordered_map GetFileElements(const std::filesystem::path& path); } // namespace Media } // namespace Track diff -r bd439dd6ffc5 -r d43d68408d3c src/gui/pages/now_playing.cc --- a/src/gui/pages/now_playing.cc Wed Nov 15 13:28:18 2023 -0500 +++ b/src/gui/pages/now_playing.cc Wed Nov 15 14:14:17 2023 -0500 @@ -10,11 +10,8 @@ #include #include -/* WARNING: HACKY STUFF HERE - - The Now Playing page is designed to "switch" between these two sub-pages, - using a QStackedWidget. This *could* be the best way to do this, but this - feels very very stupid and I really don't like it */ +#include "anitomy/anitomy.h" + namespace NowPlayingPages { class Default : public QWidget { @@ -29,7 +26,7 @@ public: Playing(QWidget* parent = nullptr); - void SetPlayingAnime(const Anime::Anime& anime, const std::unordered_map& info); + void SetPlayingAnime(const Anime::Anime& anime, const anitomy::Elements& info); int GetPlayingAnime(); private: @@ -89,11 +86,11 @@ return _id; } -void Playing::SetPlayingAnime(const Anime::Anime& anime, const std::unordered_map& info) { - if (_id == anime.GetId() && std::to_string(_episode) == info.at("episode")) +void Playing::SetPlayingAnime(const Anime::Anime& anime, const anitomy::Elements& info) { + if (_id == anime.GetId() && _episode == Strings::ToInt(Strings::ToUtf8String(info.get(anitomy::kElementEpisodeNumber)))) return; _id = anime.GetId(); - _episode = Strings::ToInt(info.at("episode")); + _episode = Strings::ToInt(Strings::ToUtf8String(info.get(anitomy::kElementEpisodeNumber))); _title->SetText(Strings::ToQString(anime.GetUserPreferredTitle())); _info->SetAnime(anime); _poster->SetAnime(anime); @@ -126,7 +123,7 @@ return reinterpret_cast(stack->widget(1))->GetPlayingAnime(); } -void NowPlayingPage::SetPlaying(const Anime::Anime& anime, const std::unordered_map& info) { +void NowPlayingPage::SetPlaying(const Anime::Anime& anime, const anitomy::Elements& info) { reinterpret_cast(stack->widget(1))->SetPlayingAnime(anime, info); stack->setCurrentIndex(1); updateGeometry(); diff -r bd439dd6ffc5 -r d43d68408d3c src/gui/pages/torrents.cc --- a/src/gui/pages/torrents.cc Wed Nov 15 13:28:18 2023 -0500 +++ b/src/gui/pages/torrents.cc Wed Nov 15 14:14:17 2023 -0500 @@ -17,6 +17,8 @@ #include #include +#include "anitomy/anitomy.h" + /* This file is very, very similar to the anime list page. It differs from Taiga in that it uses tabs instead of @@ -71,12 +73,16 @@ TorrentModelItem torrent; torrent.SetFilename(item.child_value("title")); /* "title" == filename */ { - /* Use Anitomy to parse the file's elements (we should *really* not be doing this this way!) */ - std::unordered_map elements = Track::Media::GetFileElements(torrent.GetFilename()); - torrent.SetTitle(elements["title"]); - torrent.SetEpisode(Strings::RemoveLeadingChars(elements["episode"], '0')); - torrent.SetGroup(elements["group"]); - torrent.SetResolution(elements["resolution"]); + anitomy::Anitomy anitomy; + anitomy.Parse(Strings::ToWstring(torrent.GetFilename())); + + const auto& elements = anitomy.elements(); + + /* todo: patch Anitomy so that it doesn't use wide strings */ + torrent.SetTitle(Strings::ToUtf8String(elements.get(anitomy::kElementAnimeTitle))); + torrent.SetEpisode(Strings::RemoveLeadingChars(Strings::ToUtf8String(elements.get(anitomy::kElementEpisodeNumber)), '0')); + torrent.SetGroup(Strings::ToUtf8String(elements.get(anitomy::kElementReleaseGroup))); + torrent.SetResolution(Strings::ToUtf8String(elements.get(anitomy::kElementVideoResolution))); } torrent.SetDescription(Strings::TextifySynopsis(item.child_value("description"))); { diff -r bd439dd6ffc5 -r d43d68408d3c src/gui/window.cc --- a/src/gui/window.cc Wed Nov 15 13:28:18 2023 -0500 +++ b/src/gui/window.cc Wed Nov 15 14:14:17 2023 -0500 @@ -17,6 +17,8 @@ #include "services/services.h" #include "track/media.h" +#include "anitomy/anitomy.h" + #include #include #include @@ -76,9 +78,12 @@ /* this should really be more intertwined with anitomy */ for (const auto& file : files) { - std::filesystem::path path(file); // in the future it will not be guaranteed this is a path! - std::unordered_map elements = Track::Media::GetFileElements(path.filename().string()); - int id = Anime::db.GetAnimeFromTitle(elements["title"]); + anitomy::Anitomy anitomy; + anitomy.Parse(Strings::ToWstring(file)); + + const auto& elements = anitomy.elements(); + + int id = Anime::db.GetAnimeFromTitle(Strings::ToUtf8String(elements.get(anitomy::kElementAnimeTitle))); if (id <= 0) continue; diff -r bd439dd6ffc5 -r d43d68408d3c src/track/media.cc --- a/src/track/media.cc Wed Nov 15 13:28:18 2023 -0500 +++ b/src/track/media.cc Wed Nov 15 14:14:17 2023 -0500 @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include @@ -42,11 +42,11 @@ for (const auto& media : result.media) { for (const auto& info : media.information) { switch (info.type) { - case + case animia::MediaInfoType::File: + case animia::MediaInfoType::Title: + vec.push_back(std::filesystem::path(info.value).filename().string()); + success |= true; } - std::cout << static_cast(info.type) << ": " << info.value << std::endl; - vec.push_back(info.value); - success |= true; } } }