Add correct paths for 'data' and 'cache' directories
This commit is contained in:
parent
b0e32b6717
commit
828de30570
5 changed files with 19 additions and 11 deletions
|
@ -3,6 +3,7 @@
|
|||
#include <mutex>
|
||||
#include <vector>
|
||||
#include <optional>
|
||||
#include "evalyte-cpp-common/evalyte.h"
|
||||
#include "rei-json/Field.h"
|
||||
#include "rei-json/Object.h"
|
||||
#include "ui.h"
|
||||
|
@ -85,11 +86,12 @@ public:
|
|||
}
|
||||
|
||||
void loadDataFromDisk() {
|
||||
std::filesystem::create_directories("./imgs");
|
||||
evalyte::createRequiredDirectories("lali");
|
||||
std::filesystem::create_directories(imageDirectory);
|
||||
|
||||
std::ifstream file("./save.json");
|
||||
std::ifstream file(saveFilePath);
|
||||
if (!file.is_open()) {
|
||||
std::println(std::cerr, "can't open file");
|
||||
std::println(std::cerr, "can't open file {}", saveFilePath);
|
||||
json = rei::json::JsonObject{};
|
||||
json.set("version", 1);
|
||||
json.addArray("lists", rei::json::JsonArray{});
|
||||
|
@ -107,11 +109,6 @@ public:
|
|||
ui->global<ui::State>().set_lists(listsSlint);
|
||||
|
||||
animesSlint = std::make_shared<slint::VectorModel<ui::Anime>>();
|
||||
ui->global<ui::State>().set_current_list({
|
||||
.index = 0,
|
||||
.name = "ok",
|
||||
.animes = animesSlint
|
||||
});
|
||||
|
||||
auto& lists = json.getArray("lists");
|
||||
|
||||
|
@ -285,7 +282,7 @@ public:
|
|||
|
||||
slint::Image getAnimeImage(int animeId, std::string imageUrl) {
|
||||
//std::println("Get image for anime {}", animeId);
|
||||
std::string imagePath = "./imgs/" + std::to_string(animeId);
|
||||
std::string imagePath = imageDirectory + "/" + std::to_string(animeId);
|
||||
|
||||
if (imageUrl.ends_with(".jpg") || imageUrl.ends_with(".jpeg")) {
|
||||
imagePath += ".jpg";
|
||||
|
@ -328,7 +325,7 @@ public:
|
|||
}
|
||||
|
||||
void save() {
|
||||
std::ofstream save("./save.json");
|
||||
std::ofstream save(saveFilePath);
|
||||
if (!save.is_open()) {
|
||||
throw std::runtime_error("Can't save data");
|
||||
}
|
||||
|
@ -348,4 +345,7 @@ private:
|
|||
std::mutex continueAnimeLock[THREAD_COUNT];
|
||||
bool shouldStopLoadingImages[THREAD_COUNT] = {false};
|
||||
std::thread thread_object[THREAD_COUNT];
|
||||
|
||||
const std::string imageDirectory = evalyte::cacheDirectoryPath("lali") + "/images";
|
||||
const std::string saveFilePath = evalyte::dataDirectoryPath("lali") + "/save.json";
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue