Make naming convention consistent, and synchronize code
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
#include "genericModel.h"
|
||||
|
||||
bool GenericModel::first = true;
|
||||
GenericModel::GenericModel(const std::string &url, const std::string& storepath, const std::string &id, int index) : url(url), id(id), storepath(("opfs/" + storepath)), GenericObj(index) {
|
||||
bool genericModel::first = true;
|
||||
genericModel::genericModel(const std::string &url, const std::string& storepath, const std::string &id, int index) : url(url), id(id), genericObj(index) {
|
||||
fs::current_path(storepath);
|
||||
if(first) {
|
||||
vosk_set_log_level(-1);
|
||||
vosk_set_log_level(0);
|
||||
int res{};
|
||||
std::thread t{[&res](){
|
||||
res = wasmfs_create_directory("opfs",0777,wasmfs_create_opfs_backend());
|
||||
@@ -16,8 +17,8 @@ GenericModel::GenericModel(const std::string &url, const std::string& storepath,
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
bool GenericModel::checkId(const std::string& path, const std::string& id) {
|
||||
std::ifstream file {(path + "/id"), std::ifstream::binary};
|
||||
bool genericModel::checkId(const std::string& id) {
|
||||
std::ifstream file {"id", std::ifstream::binary};
|
||||
if(!file.is_open()) {
|
||||
return false;
|
||||
};
|
||||
@@ -27,36 +28,36 @@ bool GenericModel::checkId(const std::string& path, const std::string& id) {
|
||||
file.read(&oldid[0], size);
|
||||
return id.compare(oldid) == 0 ? true : false;
|
||||
}
|
||||
bool GenericModel::loadModel() {
|
||||
if(!checkModel(storepath) || !checkId(storepath, id)) {
|
||||
if(emscripten_wget(url.c_str(), "opfs/model.tzst") == 1) {
|
||||
bool genericModel::loadModel() {
|
||||
if(!checkModel() || !checkId(id)) {
|
||||
if(emscripten_wget(url.c_str(),"opfs/model.tzst") == 1) {
|
||||
fireEv("error", "Unable to fetch model");
|
||||
return false;
|
||||
}
|
||||
if(!extractModel("opfs/model.tzst", storepath)) {
|
||||
if(!extractModel("opfs/model.tzst", ".")) {
|
||||
fireEv("error", "Unable to extract model");
|
||||
}
|
||||
fs::remove("opfs/model.tzst");
|
||||
if(!checkModel(storepath)) {
|
||||
if(!checkModel()) {
|
||||
fireEv("error", "Model URL contains invalid model files");
|
||||
}
|
||||
std::ofstream idFile((storepath + "/id"));
|
||||
std::ofstream idFile("id");
|
||||
if(!idFile.is_open()) {
|
||||
fireEv("error", "Unable to write new id");
|
||||
fs::remove_all(storepath);
|
||||
fs::remove_all(".");
|
||||
return false;
|
||||
}
|
||||
idFile << id;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool GenericModel::extractModel(const char* target, const std::string& dest) {
|
||||
bool genericModel::extractModel(const char* target, const std::string& dest) {
|
||||
std::string path{};
|
||||
archive* src {archive_read_new()};
|
||||
archive_entry* entry {};
|
||||
archive_read_support_filter_all(src);
|
||||
archive_read_support_format_all(src);
|
||||
archive_read_open_filename(src, target,22480);
|
||||
archive_read_open_filename(src, ".",10240);
|
||||
if(archive_errno(src) != 0) return false;
|
||||
while (archive_read_next_header(src, &entry) == ARCHIVE_OK) {
|
||||
path = archive_entry_pathname(entry);
|
||||
|
||||
Reference in New Issue
Block a user