#include <addon.hpp>
Public Member Functions | |
std::string | get_md5 () const |
Get MD5, based either on installed file's contents or stored value. | |
void | parse (const Reader &lisp) |
Read additional information from given contents of a (supertux-addoninfo . | |
void | parse (std::string fname) |
Read additional information from given file. | |
void | write (Writer &writer) const |
Writes out Add-on metainformation to a Lisp Writer. | |
void | write (std::string fname) const |
Writes out Add-on metainformation to a file. | |
bool | operator== (Addon addon2) const |
Checks if Add-on is the same as given one. | |
Public Attributes | |
std::string | kind |
std::string | title |
std::string | author |
std::string | license |
std::string | http_url |
std::string | suggested_filename |
filename suggested by addon author, e.g. | |
std::string | installed_physfs_filename |
PhysFS filename on disk, e.g. | |
std::string | installed_absolute_filename |
complete path and filename on disk, e.g. | |
std::string | stored_md5 |
bool | installed |
bool | loaded |
Protected Member Functions | |
Addon () | |
Protected Attributes | |
std::string | calculated_md5 |
Friends | |
class | AddonManager |
a level set
Definition at line 28 of file addon.hpp.
Addon::Addon | ( | ) | [inline, protected] |
Definition at line 82 of file addon.hpp.
00082 : 00083 kind(), 00084 title(), 00085 author(), 00086 license(), 00087 http_url(), 00088 suggested_filename(), 00089 installed_physfs_filename(), 00090 installed_absolute_filename(), 00091 stored_md5(), 00092 installed(), 00093 loaded(), 00094 calculated_md5() 00095 {}; };
std::string Addon::get_md5 | ( | ) | const |
Get MD5, based either on installed file's contents or stored value.
Definition at line 30 of file addon.cpp.
References calculated_md5, MD5::hex_digest(), installed, installed_physfs_filename, log_debug, log_warning, stored_md5, title, and MD5::update().
Referenced by AddonManager::install(), and operator==().
00031 { 00032 if (!installed) { 00033 if (stored_md5 == "") log_warning << "Add-on not installed and no stored MD5 available" << std::endl; 00034 return stored_md5; 00035 } 00036 00037 if (calculated_md5 != "") return calculated_md5; 00038 00039 if (installed_physfs_filename == "") throw std::runtime_error("Tried to calculate MD5 of Add-on with unknown filename"); 00040 00041 // TODO: this does not work as expected for some files -- IFileStream seems to not always behave like an ifstream. 00042 //IFileStream ifs(installed_physfs_filename); 00043 //std::string md5 = MD5(ifs).hex_digest(); 00044 00045 MD5 md5; 00046 PHYSFS_file* file; 00047 file = PHYSFS_openRead(installed_physfs_filename.c_str()); 00048 unsigned char buffer[1024]; 00049 while (true) { 00050 PHYSFS_sint64 len = PHYSFS_read(file, buffer, 1, sizeof(buffer)); 00051 if (len <= 0) break; 00052 md5.update(buffer, len); 00053 } 00054 PHYSFS_close(file); 00055 00056 calculated_md5 = md5.hex_digest(); 00057 log_debug << "MD5 of " << title << ": " << calculated_md5 << std::endl; 00058 00059 return calculated_md5; 00060 }
void Addon::parse | ( | const Reader & | lisp | ) |
Read additional information from given contents of a (supertux-addoninfo .
..) block
Definition at line 63 of file addon.cpp.
References author, lisp::Lisp::get(), http_url, kind, license, stored_md5, suggested_filename, and title.
Referenced by AddonManager::load_addons(), and parse().
00064 { 00065 try { 00066 lisp.get("kind", kind); 00067 lisp.get("title", title); 00068 lisp.get("author", author); 00069 lisp.get("license", license); 00070 lisp.get("http-url", http_url); 00071 lisp.get("file", suggested_filename); 00072 lisp.get("md5", stored_md5); 00073 } catch(std::exception& e) { 00074 std::stringstream msg; 00075 msg << "Problem when parsing addoninfo: " << e.what(); 00076 throw std::runtime_error(msg.str()); 00077 } 00078 }
void Addon::parse | ( | std::string | fname | ) |
Read additional information from given file.
Definition at line 81 of file addon.cpp.
References lisp::Lisp::get_lisp(), parse(), and lisp::Parser::parse().
00082 { 00083 try { 00084 lisp::Parser parser; 00085 const lisp::Lisp* root = parser.parse(fname); 00086 const lisp::Lisp* addon = root->get_lisp("supertux-addoninfo"); 00087 if(!addon) throw std::runtime_error("file is not a supertux-addoninfo file."); 00088 parse(*addon); 00089 } catch(std::exception& e) { 00090 std::stringstream msg; 00091 msg << "Problem when reading addoninfo '" << fname << "': " << e.what(); 00092 throw std::runtime_error(msg.str()); 00093 } 00094 }
void Addon::write | ( | Writer & | writer | ) | const |
Writes out Add-on metainformation to a Lisp Writer.
Definition at line 97 of file addon.cpp.
References author, lisp::Writer::end_list(), http_url, kind, license, lisp::Writer::start_list(), stored_md5, suggested_filename, title, and lisp::Writer::write().
Referenced by write().
00098 { 00099 writer.start_list("supertux-addoninfo"); 00100 if (kind != "") writer.write("kind", kind); 00101 if (title != "") writer.write("title", title); 00102 if (author != "") writer.write("author", author); 00103 if (license != "") writer.write("license", license); 00104 if (http_url != "") writer.write("http-url", http_url); 00105 if (suggested_filename != "") writer.write("file", suggested_filename); 00106 if (stored_md5 != "") writer.write("md5", stored_md5); 00107 writer.end_list("supertux-addoninfo"); 00108 }
void Addon::write | ( | std::string | fname | ) | const |
Writes out Add-on metainformation to a file.
Definition at line 111 of file addon.cpp.
References write().
00112 { 00113 lisp::Writer writer(fname); 00114 write(writer); 00115 }
bool Addon::operator== | ( | Addon | addon2 | ) | const |
Checks if Add-on is the same as given one.
If available, checks MD5 sum, else relies on kind, author and title alone.
Definition at line 118 of file addon.cpp.
References author, get_md5(), kind, and title.
00119 { 00120 std::string s1 = this->get_md5(); 00121 std::string s2 = addon2.get_md5(); 00122 00123 if ((s1 != "") && (s2 != "")) return (s1 == s2); 00124 00125 if (this->title != addon2.title) return false; 00126 if (this->author != addon2.author) return false; 00127 if (this->kind != addon2.kind) return false; 00128 return true; 00129 }
friend class AddonManager [friend] |
std::string Addon::kind |
std::string Addon::title |
Definition at line 32 of file addon.hpp.
Referenced by generate_addons_menu_sorter(), get_md5(), operator==(), parse(), and write().
std::string Addon::author |
std::string Addon::license |
std::string Addon::http_url |
Definition at line 35 of file addon.hpp.
Referenced by AddonManager::install(), parse(), and write().
std::string Addon::suggested_filename |
filename suggested by addon author, e.g.
"pak0.zip"
Definition at line 37 of file addon.hpp.
Referenced by AddonManager::install(), parse(), and write().
std::string Addon::installed_physfs_filename |
PhysFS filename on disk, e.g.
"pak0.zip"
Definition at line 39 of file addon.hpp.
Referenced by AddonManager::disable(), AddonManager::enable(), get_md5(), AddonManager::install(), AddonManager::load_addons(), and AddonManager::remove().
std::string Addon::installed_absolute_filename |
complete path and filename on disk, e.g.
"/home/sommer/.supertux2/pak0.zip"
Definition at line 41 of file addon.hpp.
Referenced by AddonManager::install(), AddonManager::load(), AddonManager::load_addons(), AddonManager::remove(), and AddonManager::unload().
std::string Addon::stored_md5 |
bool Addon::installed |
Definition at line 43 of file addon.hpp.
Referenced by get_md5(), AddonManager::install(), AddonManager::load(), AddonManager::load_addons(), AddonManager::remove(), and AddonManager::unload().
bool Addon::loaded |
Definition at line 44 of file addon.hpp.
Referenced by AddonManager::install(), AddonManager::load(), AddonManager::load_addons(), and AddonManager::unload().
std::string Addon::calculated_md5 [mutable, protected] |