LibPkg
boot_options_file.h
Go to the documentation of this file.
1 // This file is part of the LibPkg.
2 //
3 // Copyright 2003-2020 Graham Shaw
4 // Copyright 2013-2020 Alan Buckley
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 // You may obtain a copy of the License at
9 //
10 // http://www.apache.org/licenses/LICENSE-2.0
11 //
12 // Unless required by applicable law or agreed to in writing, software
13 // distributed under the License is distributed on an "AS IS" BASIS,
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 // See the License for the specific language governing permissions and
16 // limitations under the License.
17 
18 
19 #ifndef LIBPKG_BOOT_OPTIONS_FILE
20 #define LIBPKG_BOOT_OPTIONS_FILE
21 
22 #include <string>
23 #include <vector>
24 #include <stdexcept>
25 
26 
27 namespace pkg {
28 
33 {
34 public:
35  class commit_error;
36 
37 private:
38  std::string _read_pathname;
39  std::string _write_pathname;
40  const char *_section_prefix;
41  const char *_section_version;
42  const char *_section_suffix;
43  const char *_command;
44  const char *_command2;
45  char *_file_contents;
46  char *_section;
47  char *_end_section;
48  std::vector<std::string> _apps;
49  std::string _boot_drive;
50  bool _modified;
51 
52 public:
53  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);
54  virtual ~boot_options_file();
55 
56  void rollback();
57  void commit();
58 
59  bool contains(const std::string &app) const;
60  bool add(const std::string &app);
61  bool remove(const std::string &app);
62  bool replace(const std::string &was_app, const std::string &app);
63 
68  const std::string &read_pathname() const {return _read_pathname;}
73  const std::string &write_pathname() const {return _write_pathname;}
74 
75  void use_test_pathname(const std::string &pathname);
76  bool has_section() const;
77  bool modified() const {return _modified;}
78  bool contains_raw(const std::string &app) const;
79 
80  void dump_apps() const;
81 
82 protected:
83  virtual char *find_insert_section() = 0;
84  char *find_section(const char *name, const char *suffix);
85  void parse_section();
86  bool parse_word(char *&pos, std::string &word) const;
87  char *find_section_end(char *section) const;
88  char *next_line(char *line) const;
89  std::string name_in_section(const std::string &app) const;
90 };
91 
94  public std::runtime_error
95 {
96 public:
98  commit_error();
99 };
100 
105 {
106 public:
108  look_at_options() : boot_options_file("Desktop", "RISCOS BootBoot", "0.01", "Boot","Filer_Boot") {}
109  virtual ~look_at_options() {}
110 protected:
111  virtual char *find_insert_section()
112  {
113  char *found = find_section("Acorn BootBoot", "Boot");
114  if (!found) found = find_section("RISCOS !Boot", "Auto tasks");
115  return found;
116  };
117 };
118 
123 {
124 public:
126  run_options() : boot_options_file("Desktop", "RISCOS BootRun", "0.01", "Run", "Filer_Boot", "Filer_Run") {}
127  virtual ~run_options() {}
128 
129 protected:
130  virtual char *find_insert_section()
131  {
132  char *found = find_section("Acorn BootRun", "Run");
133  if (!found) found = find_section("RISCOS BootBoot", "Boot");
134  if (!found) found = find_section("RISCOS !Boot", "Auto tasks");
135  return found;
136  }
137 
138 };
139 
144 {
145 public:
147  add_to_apps_options() : boot_options_file("PreDesktop","RISCOS BootApps","0.01","ResApps","AddApp") {}
148 
149 protected:
150  virtual char *find_insert_section()
151  {
152  char *found = find_section("Acorn BootApps", "ResApps");
153  if (!found) found = find_section("RISCOS !Boot", "ResApps");
154  return found;
155  }
156 };
157 
158 } // end of namespace
159 
160 #endif
virtual char * find_insert_section()=0
void rollback()
Discard any changes and reload the file.
Definition: boot_options_file.cc:135
An exception class for reporting failure to commit a boot options file.
Definition: boot_options_file.h:93
bool modified() const
Definition: boot_options_file.h:77
Base class to manipulate the RISC OS boot options files in Choices.
Definition: boot_options_file.h:32
virtual char * find_insert_section()
Definition: boot_options_file.h:130
add_to_apps_options()
Constructor sets up base class with the correct values for the look at options.
Definition: boot_options_file.h:147
The namespace used to hold the package management library.
Definition: auto_dir.cc:23
void use_test_pathname(const std::string &pathname)
Change the path name for read or write.
Definition: boot_options_file.cc:275
std::string name_in_section(const std::string &app) const
Generate the name used in the file.
Definition: boot_options_file.cc:556
bool parse_word(char *&pos, std::string &word) const
Parse a single word from the given location.
Definition: boot_options_file.cc:460
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:68
Class to configure the add to apps option section in the PreDeskop file.
Definition: boot_options_file.h:143
bool add(const std::string &app)
Add application to up section.
Definition: boot_options_file.cc:311
virtual ~boot_options_file()
Definition: boot_options_file.cc:125
char * find_section_end(char *section) const
Find the end of the section.
Definition: boot_options_file.cc:521
bool has_section() const
See if file has the section defined.
Definition: boot_options_file.cc:284
Class to configure the run options in the Desktop file.
Definition: boot_options_file.h:122
void dump_apps() const
Dump apps array to cout - debugging helper.
Definition: boot_options_file.cc:576
char * find_section(const char *name, const char *suffix)
Find section in the file.
Definition: boot_options_file.cc:482
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:73
char * next_line(char *line) const
Return adress of start of next line.
Definition: boot_options_file.cc:540
void commit()
Commit any changes to the file.
Definition: boot_options_file.cc:163
virtual ~run_options()
Definition: boot_options_file.h:127
look_at_options()
Constructor sets up base class with the correct values for the look at options.
Definition: boot_options_file.h:108
void parse_section()
Parse section we are interested into C++ structures.
Definition: boot_options_file.cc:391
bool contains(const std::string &app) const
Check if application is contained in the look ups.
Definition: boot_options_file.cc:295
virtual char * find_insert_section()
Definition: boot_options_file.h:111
bool replace(const std::string &was_app, const std::string &app)
Replace an application.
Definition: boot_options_file.cc:354
run_options()
Constructor sets up base class with the correct values for the look at options.
Definition: boot_options_file.h:126
virtual ~look_at_options()
Definition: boot_options_file.h:109
virtual char * find_insert_section()
Definition: boot_options_file.h:150
Class to configure the look at options file in the Desktop file.
Definition: boot_options_file.h:104
bool contains_raw(const std::string &app) const
Check if exact name is contained in the look ups.
Definition: boot_options_file.cc:379
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:107

Reference Manual LibPkg Version 0.9.0 (4 Sep 2020)