[refactor] reorganize platform and wire sources

This commit is contained in:
dijunkun
2026-09-01 01:29:30 +08:00
parent fb0ab4f14e
commit 90184f5251
354 changed files with 2837 additions and 2456 deletions
@@ -0,0 +1,60 @@
#include "path_manager.h"
#include "platform/path_backend.h"
#ifndef CROSSDESK_PORTABLE
#define CROSSDESK_PORTABLE 0
#endif
namespace {
#if CROSSDESK_PORTABLE
std::filesystem::path GetPortableRootPath() {
std::filesystem::path executable_dir =
crossdesk::platform::GetExecutableDirectory();
if (!executable_dir.empty()) return executable_dir;
std::error_code error;
const std::filesystem::path current =
std::filesystem::current_path(error);
return error ? std::filesystem::path(".") : current;
}
#endif
} // namespace
namespace crossdesk {
PathManager::PathManager(const std::string& app_name) : app_name_(app_name) {}
std::filesystem::path PathManager::GetConfigPath() {
#if CROSSDESK_PORTABLE
return GetPortableRootPath() / "data";
#else
return platform::GetConfigPath(app_name_);
#endif
}
std::filesystem::path PathManager::GetCachePath() {
#if CROSSDESK_PORTABLE
return GetPortableRootPath() / "data";
#else
return platform::GetCachePath(app_name_);
#endif
}
std::filesystem::path PathManager::GetLogPath() {
#if CROSSDESK_PORTABLE
return GetPortableRootPath() / "logs";
#else
return platform::GetLogPath(app_name_);
#endif
}
bool PathManager::CreateDirectories(const std::filesystem::path& path) {
std::error_code error;
const bool created = std::filesystem::create_directories(path, error);
return !error && (created || std::filesystem::exists(path));
}
} // namespace crossdesk
@@ -0,0 +1,31 @@
/*
* @Author: DI JUNKUN
* @Date: 2025-07-16
* Copyright (c) 2025 by DI JUNKUN, All Rights Reserved.
*/
#ifndef _PATH_MANAGER_H_
#define _PATH_MANAGER_H_
#include <filesystem>
#include <string>
namespace crossdesk {
class PathManager {
public:
explicit PathManager(const std::string& app_name);
std::filesystem::path GetConfigPath();
std::filesystem::path GetCachePath();
std::filesystem::path GetLogPath();
bool CreateDirectories(const std::filesystem::path& p);
private:
std::string app_name_;
};
} // namespace crossdesk
#endif