27#include <wx/filename.h>
35#include "androidUTIL.h"
38static std::string cache_path() {
41 path.AppendDir(
"plugins");
42 path.AppendDir(
"cache");
43 return path.GetFullPath().ToStdString();
46static std::string tarball_path(
const char* basename,
bool create =
false) {
47 wxFileName dirs(cache_path());
48 dirs.AppendDir(
"tarballs");
50 dirs.Mkdir(wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL);
52 static const auto kSeparator = wxFileName::GetPathSeparator();
53 wxFileName path(dirs.GetFullPath() + kSeparator + wxString(basename));
54 return path.GetFullPath().ToStdString();
57static bool copy_file(
const char* src_path,
const char* dest_path) {
59 return AndroidSecureCopyFile(src_path, dest_path);
61 return wxCopyFile(src_path, dest_path);
65static std::string get_basename(
const char* path) {
66 wxString sep(wxFileName::GetPathSeparator());
70 return parts[parts.size() - 1];
75static std::string metadata_path(
const char* basename,
bool create =
false) {
76 wxFileName dirs(cache_path());
77 dirs.AppendDir(
"metadata");
79 dirs.Mkdir(wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL);
81 wxFileName path(dirs.GetFullPath(), wxString(basename));
82 return path.GetFullPath().ToStdString();
86 auto name = get_basename(path);
87 std::string dest = metadata_path(name.c_str(),
true);
89 wxLogDebug(
"Storing metadata %s at %s: %s", path, dest.c_str(),
96 name =
"ocpn-plugins.xml";
98 auto path = metadata_path(name);
103 std::string dest = tarball_path(basename,
true);
105 wxLogDebug(
"Storing tarball %s at %s: %s", path, dest.c_str(),
111 std::string basename = get_basename(uri);
112 std::string path = tarball_path(basename.c_str());
117 wxFileName dirs(cache_path());
118 dirs.AppendDir(
"tarballs");
119 if (!dirs.DirExists()) {
122 wxDir dir(dirs.GetFullPath());
125 bool cont = dir.GetFirst(&file);
128 cont = dir.GetNext(&file);
134 wxFileName dirs(cache_path());
135 dirs.AppendDir(
"tarballs");
136 if (!dirs.DirExists()) {
139 wxDir dir(dirs.GetFullPath());
141 wxULongLong total = 0;
142 bool cont = dir.GetFirst(&file);
144 dirs.SetFullName(file);
145 wxFileName fn(dirs.GetFullPath());
146 if (fn.FileExists()) {
148 auto size = fn.GetSize();
149 if (size == wxInvalidSize) {
150 wxLogMessage(
"Cannot stat file %s",
151 dirs.GetFullPath().ToStdString().c_str());
157 cont = dir.GetNext(&file);
159 total /= (1024 * 1024);
160 return total.ToULong();
165 wxFileName dirs(cache_path());
166 dirs.AppendDir(
"tarballs");
167 if (!dirs.DirExists()) {
170 wxDir dir(dirs.GetFullPath());
172 bool cont = dir.GetFirst(&file);
174 dirs.SetFullName(file);
175 wxRemoveFile(dirs.GetFullPath());
177 cont = dir.GetNext(&file);
Standard, mostly strings utilities.
std::string lookup_tarball(const char *uri)
Get path to tarball in cache for given filename.
std::string lookup_metadata(const char *name)
Get metadata path for a given name defaulting to ocpn-plugins.xml)
bool startswith(const std::string &str, const std::string &prefix)
Return true if s starts with given prefix.
std::vector< std::string > split(const char *token_string, const std::string &delimiter)
Return vector of items in s separated by delimiter.
void cache_clear()
Remove all files in cache:
void copy_file(const std::string &src_path, const std::string &dest_path)
Copy file contents in path src_path to dest_path.
unsigned cache_file_count()
Return number of files in cache.
bool exists(const std::string &name)
bool store_metadata(const char *path)
Store metadata in metadata cache, return success/fail.
bool store_tarball(const char *path, const char *basename)
Store a tarball in tarball cache, return success/fail.
unsigned long cache_size()
Return total size of files in cache in kbytes.
Miscellaneous utilities, many of which string related.
Downloaded plugins cache.