diff --git a/src/audio/audio_downloader.h b/src/audio/audio_downloader.h index 8c8b8d6..3a6eba7 100644 --- a/src/audio/audio_downloader.h +++ b/src/audio/audio_downloader.h @@ -27,17 +27,17 @@ namespace radiantwave::audio { // honored, anything else falls back to the Hz parsed from the filename, so // the file's own name is always the safety net. struct AudioManifestEntry { - std::string filename; - std::string display_name; - int solfeggio_frequency_hz = 0; - std::string md5; + std::string filename; + std::string display_name; + int solfeggio_frequency_hz = 0; + std::string md5; }; // Downloads audio assets from files.radiantwavetech.com in the background // and keeps the database's audio_files table in sync with what is actually // on disk. // -// Fetches checksums.md5, compares each entry against the local file's MD5, +// Fetches new_checksums.md5, compares each entry against the local file's MD5, // and re-downloads anything that is missing or whose checksum differs. // Files present on disk but absent from the manifest are deleted, and the // audio_files table is reconciled on every pass (and after each individual @@ -50,45 +50,49 @@ struct AudioManifestEntry { // checksums are picked up while running. class AudioDownloader { public: - AudioDownloader() = default; - ~AudioDownloader(); + AudioDownloader() = default; + ~AudioDownloader(); - AudioDownloader(const AudioDownloader&) = delete; - AudioDownloader& operator=(const AudioDownloader&) = delete; + AudioDownloader(const AudioDownloader &) = delete; + AudioDownloader &operator=(const AudioDownloader &) = delete; - // Spawns the background thread. Safe to call repeatedly; only one worker - // runs at a time. The manifest is reconciled against `db` on every pass. - void start(db::DatabaseManager& db); + // Spawns the background thread. Safe to call repeatedly; only one worker + // runs at a time. The manifest is reconciled against `db` on every pass. + void start(db::DatabaseManager &db); - // Signals the worker to stop and joins the thread. - void shutdown(); + // Signals the worker to stop and joins the thread. + void shutdown(); - // Returns the current human-readable status for display (e.g. footer). - std::string statusString() const; + // Returns the current human-readable status for display (e.g. footer). + std::string statusString() const; - static constexpr const char* AUDIO_BASE_URL = "https://files.radiantwavetech.com/audio/"; - static constexpr const char* MANIFEST_FILENAME = "checksums.md5"; + static constexpr const char *AUDIO_BASE_URL = + "https://files.radiantwavetech.com/audio/"; + static constexpr const char *MANIFEST_FILENAME = "new_checksums.md5"; private: - void run(); - bool fetchManifest(std::vector& out); - bool downloadAndVerify(const std::string& filename, const std::string& expectedMd5, const std::string& displayName); + void run(); + bool fetchManifest(std::vector &out); + bool downloadAndVerify(const std::string &filename, + const std::string &expectedMd5, + const std::string &displayName); - void setStatus(const std::string& msg); - void wait(std::chrono::seconds seconds); + void setStatus(const std::string &msg); + void wait(std::chrono::seconds seconds); - mutable std::mutex mutex_; - std::condition_variable cv_; - std::thread worker_; - std::atomic stop_{false}; - std::string status_; - db::DatabaseManager* db_ = nullptr; + mutable std::mutex mutex_; + std::condition_variable cv_; + std::thread worker_; + std::atomic stop_{false}; + std::string status_; + db::DatabaseManager *db_ = nullptr; }; -// Parses checksums.md5 manifest text into entries. Blank lines and lines +// Parses new_checksums.md5 manifest text into entries. Blank lines and lines // starting with '#' are ignored. Lines that don't match a known format are // skipped. Returns false if no valid entries were found. -bool parseManifest(const std::string& text, std::vector& out); +bool parseManifest(const std::string &text, + std::vector &out); // Maps a frequency value in Hz to its internal solfeggio frequency id using // the same table the color palettes are seeded from (174/285->1, 396->2, @@ -100,9 +104,9 @@ int frequencyIdForHz(int hz); // "396Hz.wav" -> 396. Requires the digits to be followed by "Hz" // (case-insensitive); returns 0 when the name has no frequency (e.g. // "AlphaWaves.wav", "OriginalAudio.wav"). -int hzFromFilename(const std::string& filename); +int hzFromFilename(const std::string &filename); // Computes the lowercase MD5 hex of a file, or an empty string on failure. -std::string computeFileMd5(const std::string& path); +std::string computeFileMd5(const std::string &path); } // namespace radiantwave::audio