reapack

Package manager for REAPER
Log | Files | Refs | Submodules | README | LICENSE

config.hpp (2400B)


      1 /* ReaPack: Package manager for REAPER
      2  * Copyright (C) 2015-2025  Christian Fillion
      3  *
      4  * This program is free software: you can redistribute it and/or modify
      5  * it under the terms of the GNU Lesser General Public License as published by
      6  * the Free Software Foundation, either version 3 of the License, or
      7  * (at your option) any later version.
      8  *
      9  * This program is distributed in the hope that it will be useful,
     10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12  * GNU Lesser General Public License for more details.
     13  *
     14  * You should have received a copy of the GNU Lesser General Public License
     15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
     16  */
     17 
     18 #ifndef REAPACK_CONFIG_HPP
     19 #define REAPACK_CONFIG_HPP
     20 
     21 #include "remote.hpp"
     22 
     23 #include <string>
     24 
     25 class Path;
     26 
     27 struct WindowState {
     28   std::string about;
     29   std::string browser;
     30   std::string manager;
     31 };
     32 
     33 struct InstallOpts {
     34   bool autoInstall;
     35   bool bleedingEdge;
     36   bool promptObsolete;
     37 };
     38 
     39 struct NetworkOpts {
     40   enum StaleThreshold {
     41     NoThreshold = 0,
     42     OneWeekThreshold = 7 * 24 * 3600,
     43   };
     44 
     45   std::string proxy;
     46   bool verifyPeer;
     47   time_t staleThreshold;
     48 };
     49 
     50 struct FilterOpts {
     51   bool expandSynonyms;
     52 };
     53 
     54 class Config {
     55 public:
     56   Config(const Path &);
     57   Config(const Config &) = delete;
     58   ~Config();
     59 
     60   void read();
     61   void write();
     62 
     63   void resetOptions();
     64   void restoreDefaultRemotes();
     65 
     66   bool isFirstRun() const { return m_isFirstRun; }
     67 
     68   InstallOpts install;
     69   NetworkOpts network;
     70   FilterOpts  filter;
     71   WindowState windowState;
     72 
     73   RemoteList remotes;
     74 
     75 private:
     76   std::string getString(const char *g, const char *k, const std::string &fallback = {}) const;
     77   void setString(const char *g, const char *k, const std::string &v) const;
     78 
     79   bool getBool(const char *g, const char *k, bool fallback = false) const;
     80   unsigned int getUInt(const char *g, const char *k, unsigned int fallback = 0) const;
     81   void setUInt(const char *g, const char *k, unsigned int v) const;
     82 
     83   void deleteKey(const char *g, const char *k) const;
     84   void cleanupArray(const char *g, const char *k, unsigned int begin, unsigned int end) const;
     85 
     86   void migrate();
     87 
     88   std::string m_path;
     89   bool m_isFirstRun;
     90   unsigned int m_version;
     91 
     92   void readRemotes();
     93   void restoreSelfRemote();
     94   void writeRemotes();
     95   unsigned int m_remotesIniSize;
     96 };
     97 
     98 #endif