Route startup storage paths through platform services

This commit is contained in:
2026-06-03 04:59:23 +02:00
parent beb7f717f1
commit 578b1f6082
10 changed files with 170 additions and 93 deletions

View File

@@ -8,6 +8,7 @@
#include "app_core/document_recording.h"
#include "app_core/document_route.h"
#include "app_core/document_session.h"
#include "platform_api/platform_services.h"
#include "renderer_gl/opengl_capabilities.h"
#ifdef __APPLE__
@@ -16,13 +17,6 @@
#endif
#include "settings.h"
#ifdef __LINUX__
std::string linux_home_path();
int mkpath(const std::string& dir, mode_t mode = DEFFILEMODE);
#elif __WEB__
#include <unistd.h>
#endif
App* App::I = nullptr; // singleton
std::deque<AppTask> App::render_tasklist;
@@ -295,78 +289,16 @@ void App::initAssets()
void App::initLog()
{
#if defined(__IOS__)
[ios_view init_dirs];
#elif defined(__OSX__)
[osx_app init_dirs];
#elif defined(_WIN32)
//CHAR my_documents[MAX_PATH];
//HRESULT result = SHGetFolderPathA(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, my_documents);
//HMODULE hModule = GetModuleHandle(NULL);
//CHAR path[MAX_PATH];
//GetModuleFileNameA(hModule, path, MAX_PATH);
//CHAR out_drive[MAX_PATH];
//CHAR out_path[MAX_PATH];
//_splitpath(path, out_drive, out_path, nullptr, nullptr);
//sprintf_s(path, "%s%s", out_drive, out_path);
//data_path = path;
CHAR my_documents[MAX_PATH];
HRESULT result = SHGetFolderPathA(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, my_documents);
if (SUCCEEDED(result))
{
std::string path = std::string(my_documents) + "\\PanoPainter";
if (!PathFileExistsA(path.c_str()))
CreateDirectoryA(path.c_str(), NULL);
data_path = path;
}
else
{
CHAR path[MAX_PATH];
GetCurrentDirectoryA(sizeof(path), path);
data_path = path;
}
rec_path = data_path + "\\frames";
if (!PathFileExistsA(rec_path.c_str()))
CreateDirectoryA(rec_path.c_str(), NULL);
if (!PathFileExistsA((data_path + "\\brushes").c_str()))
CreateDirectoryA((data_path + "\\brushes").c_str(), NULL);
if (!PathFileExistsA((data_path + "\\brushes\\thumbs").c_str()))
CreateDirectoryA((data_path + "\\brushes\\thumbs").c_str(), NULL);
if (!PathFileExistsA((data_path + "\\patterns").c_str()))
CreateDirectoryA((data_path + "\\patterns").c_str(), NULL);
if (!PathFileExistsA((data_path + "\\patterns\\thumbs").c_str()))
CreateDirectoryA((data_path + "\\patterns\\thumbs").c_str(), NULL);
if (!PathFileExistsA((data_path + "\\settings").c_str()))
CreateDirectoryA((data_path + "\\settings").c_str(), NULL);
#elif __LINUX__
data_path = linux_home_path() + "/PanoPainter";
mkpath(data_path + "/brushes");
mkpath(data_path + "/brushes/thumbs");
mkpath(data_path + "/patterns");
mkpath(data_path + "/patterns/thumbs");
mkpath(data_path + "/settings");
mkpath(data_path + "/frames");
#elif __WEB__
data_path = "/PanoPainter";
mkdir(data_path.c_str(), 0777);
mkdir((data_path + "/brushes").c_str(), 0777);
mkdir((data_path + "/brushes/thumbs").c_str(), 0777);
mkdir((data_path + "/patterns").c_str(), 0777);
mkdir((data_path + "/patterns/thumbs").c_str(), 0777);
mkdir((data_path + "/settings").c_str(), 0777);
mkdir((data_path + "/frames").c_str(), 0777);
#endif
const auto paths = prepare_storage_paths();
if (!paths.data_path.empty())
data_path = paths.data_path;
if (!paths.recording_path.empty())
rec_path = paths.recording_path;
if (!paths.temporary_path.empty())
tmp_path = paths.temporary_path;
// TODO: save this path somewhere in the settings, don't overwrite every start
work_path = data_path;
work_path = paths.work_path.empty() ? data_path : paths.work_path;
//LogRemote::I.start();
LogRemote::I.file_init();

View File

@@ -28,6 +28,7 @@
namespace pp::platform {
class PlatformServices;
struct PlatformStoragePaths;
}
#if defined(__OBJC__) && defined(__IOS__)
@@ -205,6 +206,7 @@ public:
std::function<void(const std::string& path, bool saved)> callback);
void set_platform_services(pp::platform::PlatformServices* services) noexcept;
[[nodiscard]] pp::platform::PlatformServices* platform_services() const noexcept;
[[nodiscard]] pp::platform::PlatformStoragePaths prepare_storage_paths();
void showKeyboard();
void hideKeyboard();
void initLog();

View File

@@ -56,6 +56,11 @@ pp::platform::PlatformServices* App::platform_services() const noexcept
return platform_services_;
}
pp::platform::PlatformStoragePaths App::prepare_storage_paths()
{
return active_platform_services().prepare_storage_paths();
}
std::string App::clipboard_get_text()
{
if (pp::app::plan_clipboard_read() != pp::app::ClipboardReadAction::read_text)

View File

@@ -10,10 +10,18 @@ namespace pp::platform {
using PickedPathCallback = std::function<void(std::string path)>;
using PreparedFileCallback = std::function<void(std::string path, bool saved)>;
struct PlatformStoragePaths {
std::string data_path;
std::string work_path;
std::string recording_path;
std::string temporary_path;
};
class PlatformServices {
public:
virtual ~PlatformServices() = default;
[[nodiscard]] virtual PlatformStoragePaths prepare_storage_paths() = 0;
[[nodiscard]] virtual std::string clipboard_text() = 0;
[[nodiscard]] virtual bool set_clipboard_text(std::string_view text) = 0;
virtual void set_cursor_visible(bool visible) = 0;

View File

@@ -18,6 +18,8 @@ bool android_set_clipboard(const std::string& s);
#elif __APPLE__
#elif __LINUX__
#include <tinyfiledialogs.h>
std::string linux_home_path();
int mkpath(const std::string& dir, mode_t mode = DEFFILEMODE);
void linux_update_fps(int frames);
#elif __WEB__
void webgl_pick_file(std::function<void(std::string)> callback);
@@ -41,6 +43,63 @@ void invoke_picked_path_if_selected(
// DEBT-0017: fallback for platforms that do not inject PlatformServices yet.
class LegacyPlatformServices final : public pp::platform::PlatformServices {
public:
[[nodiscard]] pp::platform::PlatformStoragePaths prepare_storage_paths() override
{
#if defined(__IOS__)
[App::I->ios_view init_dirs];
return {
App::I->data_path,
App::I->work_path,
App::I->rec_path,
App::I->tmp_path,
};
#elif defined(__OSX__)
[App::I->osx_app init_dirs];
return {
App::I->data_path,
App::I->work_path,
App::I->rec_path,
App::I->tmp_path,
};
#elif __LINUX__
const std::string data_path = linux_home_path() + "/PanoPainter";
mkpath(data_path + "/brushes");
mkpath(data_path + "/brushes/thumbs");
mkpath(data_path + "/patterns");
mkpath(data_path + "/patterns/thumbs");
mkpath(data_path + "/settings");
mkpath(data_path + "/frames");
return {
data_path,
data_path,
data_path + "/frames",
{},
};
#elif __WEB__
const std::string data_path = "/PanoPainter";
mkdir(data_path.c_str(), 0777);
mkdir((data_path + "/brushes").c_str(), 0777);
mkdir((data_path + "/brushes/thumbs").c_str(), 0777);
mkdir((data_path + "/patterns").c_str(), 0777);
mkdir((data_path + "/patterns/thumbs").c_str(), 0777);
mkdir((data_path + "/settings").c_str(), 0777);
mkdir((data_path + "/frames").c_str(), 0777);
return {
data_path,
data_path,
data_path + "/frames",
{},
};
#else
return {
App::I->data_path,
App::I->work_path,
App::I->rec_path,
App::I->tmp_path,
};
#endif
}
[[nodiscard]] std::string clipboard_text() override
{
#if __IOS__

View File

@@ -134,6 +134,12 @@ void invoke_selected_path(
callback(path);
}
void ensure_directory(const std::string& path)
{
if (!PathFileExistsA(path.c_str()))
CreateDirectoryA(path.c_str(), NULL);
}
std::string build_supported_files_filter(const std::vector<std::string>& types)
{
std::string filter = "Supported Files (";
@@ -157,6 +163,38 @@ std::string build_supported_files_filter(const std::vector<std::string>& types)
class WindowsPlatformServices final : public pp::platform::PlatformServices {
public:
[[nodiscard]] pp::platform::PlatformStoragePaths prepare_storage_paths() override
{
std::string data_path;
CHAR my_documents[MAX_PATH];
HRESULT result = SHGetFolderPathA(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, my_documents);
if (SUCCEEDED(result))
{
data_path = std::string(my_documents) + "\\PanoPainter";
ensure_directory(data_path);
}
else
{
CHAR path[MAX_PATH];
GetCurrentDirectoryA(sizeof(path), path);
data_path = path;
}
ensure_directory(data_path + "\\frames");
ensure_directory(data_path + "\\brushes");
ensure_directory(data_path + "\\brushes\\thumbs");
ensure_directory(data_path + "\\patterns");
ensure_directory(data_path + "\\patterns\\thumbs");
ensure_directory(data_path + "\\settings");
return {
data_path,
data_path,
data_path + "\\frames",
{},
};
}
[[nodiscard]] std::string clipboard_text() override
{
return ::clipboard_text();