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() {return find_section("RISCOS !Boot", "Auto tasks");};
100 
101 };
102 
107 {
108 public:
110  run_options() : boot_options_file("Desktop", "RISCOS BootRun", "0.01", "Run", "Filer_Boot", "Filer_Run") {}
111  virtual ~run_options() {}
112 
113 protected:
114  virtual char *find_insert_section()
115  {
116  char *found = find_section("RISCOS BootBoot", "Boot");
117  if (!found) found = find_section("RISCOS !Boot", "Auto tasks");
118  return found;
119  }
120 
121 };
122 
127 {
128 public:
130  add_to_apps_options() : boot_options_file("PreDesktop","RISCOS BootApps","0.01","ResApps","AddApp") {}
131 
132 protected:
133  virtual char *find_insert_section() {return find_section("RISCOS !Boot", "ResApps");}
134 };
135 
136 } // end of namespace
137 
138 #endif
virtual char * find_insert_section()=0
void rollback()
Discard any changes and reload the file.
Definition: boot_options_file.cc:120
An exception class for reporting failure to commit a boot options file.
Definition: boot_options_file.h:81
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:114
add_to_apps_options()
Constructor sets up base class with the correct values for the look at options.
Definition: boot_options_file.h:130
bool contains_raw(const std::string &app) const
Check if exact name is contained in the look ups.
Definition: boot_options_file.cc:364
std::string name_in_section(const std::string &app) const
Generate the name used in the file.
Definition: boot_options_file.cc:541
void use_test_pathname(const std::string &pathname)
Change the path name for read or write.
Definition: boot_options_file.cc:260
commit_error()
Construct commit error.
Definition: boot_options_file.cc:569
char * find_section_end(char *section) const
Find the end of the section.
Definition: boot_options_file.cc:506
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
char * next_line(char *line) const
Return adress of start of next line.
Definition: boot_options_file.cc:525
bool parse_word(char *&pos, std::string &word) const
Parse a single word from the given location.
Definition: boot_options_file.cc:445
bool modified() const
Definition: boot_options_file.h:65
Class to configure the add to apps option section in the PreDeskop file.
Definition: boot_options_file.h:126
bool contains(const std::string &app) const
Check if application is contained in the look ups.
Definition: boot_options_file.cc:280
bool add(const std::string &app)
Add application to up section.
Definition: boot_options_file.cc:296
virtual ~boot_options_file()
Definition: boot_options_file.cc:110
bool has_section() const
See if file has the section defined.
Definition: boot_options_file.cc:269
Class to configure the run options in the Desktop file.
Definition: boot_options_file.h:106
char * find_section(const char *name, const char *suffix)
Find section in the file.
Definition: boot_options_file.cc:467
void commit()
Commit any changes to the file.
Definition: boot_options_file.cc:148
virtual ~run_options()
Definition: boot_options_file.h:111
look_at_options()
Constructor sets up base class with the correct values for the look at options.
Definition: boot_options_file.h:96
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
void parse_section()
Parse section we are interested into C++ structures.
Definition: boot_options_file.cc:376
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:339
run_options()
Constructor sets up base class with the correct values for the look at options.
Definition: boot_options_file.h:110
virtual ~look_at_options()
Definition: boot_options_file.h:97
virtual char * find_insert_section()
Definition: boot_options_file.h:133
Class to configure the look at options file in the Desktop file.
Definition: boot_options_file.h:92
void dump_apps() const
Dump apps array to cout - debugging helper.
Definition: boot_options_file.cc:561
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:92

Reference Manual LibPkg Version 0.6.1 (28 Jan 2015)