LibPkg
boot_options_file.h
Go to the documentation of this file.
1 // This file is part of LibPkg.
2 // Copyright � 2003-2005 Graham Shaw.
3 // Copyright � 2013 Alan Buckley
4 // Distribution and use are subject to the GNU Lesser General Public License,
5 // a copy of which may be found in the file !LibPkg.Copyright.
6 
7 #ifndef LIBPKG_BOOT_OPTIONS_FILE
8 #define LIBPKG_BOOT_OPTIONS_FILE
9 
10 #include <string>
11 #include <vector>
12 #include <stdexcept>
13 
14 
15 namespace pkg {
16 
21 {
22 public:
23  class commit_error;
24 
25 private:
26  std::string _read_pathname;
27  std::string _write_pathname;
28  const char *_section_prefix;
29  const char *_section_version;
30  const char *_section_suffix;
31  const char *_command;
32  const char *_command2;
33  char *_file_contents;
34  char *_section;
35  char *_end_section;
36  std::vector<std::string> _apps;
37  std::string _boot_drive;
38  bool _modified;
39 
40 public:
41  boot_options_file(const char *file_name, const char *section_prefix, const char *section_version, const char *section_suffix, const char *command, const char *command2 = 0);
42  virtual ~boot_options_file();
43 
44  void rollback();
45  void commit();
46 
47  bool contains(const std::string &app) const;
48  bool add(const std::string &app);
49  bool remove(const std::string &app);
50  bool replace(const std::string &was_app, const std::string &app);
51 
56  const std::string &read_pathname() const {return _read_pathname;}
61  const std::string &write_pathname() const {return _write_pathname;}
62 
63  void use_test_pathname(const std::string &pathname);
64  bool has_section() const;
65  bool modified() const {return _modified;}
66  bool contains_raw(const std::string &app) const;
67 
68  void dump_apps() const;
69 
70 protected:
71  virtual char *find_insert_section() = 0;
72  char *find_section(const char *name, const char *suffix);
73  void parse_section();
74  bool parse_word(char *&pos, std::string &word) const;
75  char *find_section_end(char *section) const;
76  char *next_line(char *line) const;
77  std::string name_in_section(const std::string &app) const;
78 };
79 
82  public std::runtime_error
83 {
84 public:
86  commit_error();
87 };
88 
93 {
94 public:
96  look_at_options() : boot_options_file("Desktop", "RISCOS BootBoot", "0.01", "Boot","Filer_Boot") {}
97  virtual ~look_at_options() {}
98 protected:
99  virtual char *find_insert_section()
100  {
101  char *found = find_section("Acorn BootBoot", "Boot");
102  if (!found) found = find_section("RISCOS !Boot", "Auto tasks");
103  return found;
104  };
105 };
106 
111 {
112 public:
114  run_options() : boot_options_file("Desktop", "RISCOS BootRun", "0.01", "Run", "Filer_Boot", "Filer_Run") {}
115  virtual ~run_options() {}
116 
117 protected:
118  virtual char *find_insert_section()
119  {
120  char *found = find_section("Acorn BootRun", "Run");
121  if (!found) found = find_section("RISCOS BootBoot", "Boot");
122  if (!found) found = find_section("RISCOS !Boot", "Auto tasks");
123  return found;
124  }
125 
126 };
127 
132 {
133 public:
135  add_to_apps_options() : boot_options_file("PreDesktop","RISCOS BootApps","0.01","ResApps","AddApp") {}
136 
137 protected:
138  virtual char *find_insert_section()
139  {
140  char *found = find_section("Acorn BootApps", "ResApps");
141  if (!found) found = find_section("RISCOS !Boot", "ResApps");
142  return found;
143  }
144 };
145 
146 } // end of namespace
147 
148 #endif
virtual char * find_insert_section()=0
void rollback()
Discard any changes and reload the file.
Definition: boot_options_file.cc:125
An exception class for reporting failure to commit a boot options file.
Definition: boot_options_file.h:81
bool modified() const
Definition: boot_options_file.h:65
Base class to manipulate the RISC OS boot options files in Choices.
Definition: boot_options_file.h:20
virtual char * find_insert_section()
Definition: boot_options_file.h:118
add_to_apps_options()
Constructor sets up base class with the correct values for the look at options.
Definition: boot_options_file.h:135
The namespace used to hold the package management library.
Definition: auto_dir.cc:12
void use_test_pathname(const std::string &pathname)
Change the path name for read or write.
Definition: boot_options_file.cc:265
std::string name_in_section(const std::string &app) const
Generate the name used in the file.
Definition: boot_options_file.cc:546
bool parse_word(char *&pos, std::string &word) const
Parse a single word from the given location.
Definition: boot_options_file.cc:450
const std::string & read_pathname() const
The path name to the location of the PreDesk file that contains the look at declarations for reading...
Definition: boot_options_file.h:56
Class to configure the add to apps option section in the PreDeskop file.
Definition: boot_options_file.h:131
bool add(const std::string &app)
Add application to up section.
Definition: boot_options_file.cc:301
virtual ~boot_options_file()
Definition: boot_options_file.cc:115
char * find_section_end(char *section) const
Find the end of the section.
Definition: boot_options_file.cc:511
bool has_section() const
See if file has the section defined.
Definition: boot_options_file.cc:274
Class to configure the run options in the Desktop file.
Definition: boot_options_file.h:110
void dump_apps() const
Dump apps array to cout - debugging helper.
Definition: boot_options_file.cc:566
char * find_section(const char *name, const char *suffix)
Find section in the file.
Definition: boot_options_file.cc:472
const std::string & write_pathname() const
The path name to the location of the PreDesk file that any changes to the look at declarations will b...
Definition: boot_options_file.h:61
char * next_line(char *line) const
Return adress of start of next line.
Definition: boot_options_file.cc:530
void commit()
Commit any changes to the file.
Definition: boot_options_file.cc:153
virtual ~run_options()
Definition: boot_options_file.h:115
look_at_options()
Constructor sets up base class with the correct values for the look at options.
Definition: boot_options_file.h:96
void parse_section()
Parse section we are interested into C++ structures.
Definition: boot_options_file.cc:381
bool contains(const std::string &app) const
Check if application is contained in the look ups.
Definition: boot_options_file.cc:285
virtual char * find_insert_section()
Definition: boot_options_file.h:99
bool replace(const std::string &was_app, const std::string &app)
Replace an application.
Definition: boot_options_file.cc:344
run_options()
Constructor sets up base class with the correct values for the look at options.
Definition: boot_options_file.h:114
virtual ~look_at_options()
Definition: boot_options_file.h:97
virtual char * find_insert_section()
Definition: boot_options_file.h:138
Class to configure the look at options file in the Desktop file.
Definition: boot_options_file.h:92
bool contains_raw(const std::string &app) const
Check if exact name is contained in the look ups.
Definition: boot_options_file.cc:369
boot_options_file(const char *file_name, const char *section_prefix, const char *section_version, const char *section_suffix, const char *command, const char *command2=0)
Construct boot_options_file object by setting parameters for the options file it will edit...
Definition: boot_options_file.cc:97

Reference Manual LibPkg Version 0.6.1 (28 Jan 2015)