clang-tidy
This commit is contained in:
@@ -1,27 +1,29 @@
|
||||
#include "system_utils.h"
|
||||
#include <iostream>
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <cerrno>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#include <shlobj.h>
|
||||
#include <direct.h>
|
||||
// Evitar conflictos con macros de Windows
|
||||
#ifdef ERROR_ALREADY_EXISTS
|
||||
#undef ERROR_ALREADY_EXISTS
|
||||
#endif
|
||||
#include <direct.h>
|
||||
#include <shlobj.h>
|
||||
#include <windows.h>
|
||||
// Evitar conflictos con macros de Windows
|
||||
#ifdef ERROR_ALREADY_EXISTS
|
||||
#undef ERROR_ALREADY_EXISTS
|
||||
#endif
|
||||
#else
|
||||
#include <pwd.h>
|
||||
#include <unistd.h>
|
||||
#include <pwd.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
namespace SystemUtils {
|
||||
|
||||
// Función auxiliar para crear una carpeta individual
|
||||
// Función auxiliar para crear una carpeta individual
|
||||
auto createSingleFolder(const std::string& path, int permissions) -> Result {
|
||||
struct stat st = {0};
|
||||
struct stat st = {.st_dev = 0};
|
||||
|
||||
// Verificar si ya existe
|
||||
if (stat(path.c_str(), &st) == 0) {
|
||||
@@ -31,28 +33,28 @@ auto createSingleFolder(const std::string& path, int permissions) -> Result {
|
||||
// Intentar crear la carpeta
|
||||
int result;
|
||||
#ifdef _WIN32
|
||||
result = _mkdir(path.c_str());
|
||||
result = _mkdir(path.c_str());
|
||||
#else
|
||||
result = mkdir(path.c_str(), permissions);
|
||||
result = mkdir(path.c_str(), permissions);
|
||||
#endif
|
||||
|
||||
if (result == -1) {
|
||||
switch (errno) {
|
||||
case EACCES:
|
||||
return Result::PERMISSION_DENIED;
|
||||
case EEXIST:
|
||||
return Result::ALREADY_EXISTS;
|
||||
case ENAMETOOLONG:
|
||||
return Result::PATH_TOO_LONG;
|
||||
default:
|
||||
return Result::UNKNOWN_ERROR;
|
||||
}
|
||||
if (result == -1) {
|
||||
switch (errno) {
|
||||
case EACCES:
|
||||
return Result::PERMISSION_DENIED;
|
||||
case EEXIST:
|
||||
return Result::ALREADY_EXISTS;
|
||||
case ENAMETOOLONG:
|
||||
return Result::PATH_TOO_LONG;
|
||||
default:
|
||||
return Result::UNKNOWN_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
return Result::SUCCESS;
|
||||
return Result::SUCCESS;
|
||||
}
|
||||
|
||||
// Función auxiliar para crear carpetas padre recursivamente
|
||||
// Función auxiliar para crear carpetas padre recursivamente
|
||||
auto createParentFolders(const std::string& path, int permissions) -> Result {
|
||||
size_t pos = 0;
|
||||
|
||||
@@ -108,29 +110,29 @@ auto createFolder(const std::string& path, const FolderConfig& config) -> Result
|
||||
|
||||
auto getApplicationDataPath(const std::string& app_name) -> std::string {
|
||||
#ifdef _WIN32
|
||||
char* appdata = getenv("APPDATA");
|
||||
if (appdata) {
|
||||
return std::string(appdata) + "/" + app_name;
|
||||
}
|
||||
return "C:/Users/Default/AppData/Roaming/" + app_name;
|
||||
char* appdata = getenv("APPDATA");
|
||||
if (appdata) {
|
||||
return std::string(appdata) + "/" + app_name;
|
||||
}
|
||||
return "C:/Users/Default/AppData/Roaming/" + app_name;
|
||||
|
||||
#elif __APPLE__
|
||||
std::string home = getHomeDirectory();
|
||||
return home + "/Library/Application Support/" + app_name;
|
||||
std::string home = getHomeDirectory();
|
||||
return home + "/Library/Application Support/" + app_name;
|
||||
|
||||
#elif __linux__
|
||||
std::string home = getHomeDirectory();
|
||||
return home + "/.config/" + app_name;
|
||||
std::string home = getHomeDirectory();
|
||||
return home + "/.config/" + app_name;
|
||||
|
||||
#else
|
||||
// Fallback genérico
|
||||
std::string home = getHomeDirectory();
|
||||
return home + "/." + app_name;
|
||||
// Fallback genérico
|
||||
std::string home = getHomeDirectory();
|
||||
return home + "/." + app_name;
|
||||
#endif
|
||||
}
|
||||
|
||||
auto folderExists(const std::string& path) -> bool {
|
||||
struct stat st = {0};
|
||||
struct stat st = {.st_dev = 0};
|
||||
return (stat(path.c_str(), &st) == 0 && S_ISDIR(st.st_mode));
|
||||
}
|
||||
|
||||
@@ -155,36 +157,36 @@ auto resultToString(Result result) -> const char* {
|
||||
|
||||
auto getHomeDirectory() -> std::string {
|
||||
#ifdef _WIN32
|
||||
char* userprofile = getenv("USERPROFILE");
|
||||
if (userprofile) {
|
||||
return std::string(userprofile);
|
||||
}
|
||||
return "C:/Users/Default";
|
||||
char* userprofile = getenv("USERPROFILE");
|
||||
if (userprofile) {
|
||||
return std::string(userprofile);
|
||||
}
|
||||
return "C:/Users/Default";
|
||||
#else
|
||||
struct passwd *pw = getpwuid(getuid());
|
||||
if ((pw != nullptr) && (pw->pw_dir != nullptr)) {
|
||||
return std::string(pw->pw_dir);
|
||||
}
|
||||
struct passwd* pw = getpwuid(getuid());
|
||||
if ((pw != nullptr) && (pw->pw_dir != nullptr)) {
|
||||
return {pw->pw_dir};
|
||||
}
|
||||
|
||||
// Fallback
|
||||
char* home = getenv("HOME");
|
||||
if (home != nullptr) {
|
||||
return std::string(home);
|
||||
}
|
||||
return "/tmp";
|
||||
// Fallback
|
||||
char* home = getenv("HOME");
|
||||
if (home != nullptr) {
|
||||
return {home};
|
||||
}
|
||||
return "/tmp";
|
||||
#endif
|
||||
}
|
||||
|
||||
auto getTempDirectory() -> std::string {
|
||||
#ifdef _WIN32
|
||||
char* temp = getenv("TEMP");
|
||||
if (temp) {
|
||||
return std::string(temp);
|
||||
}
|
||||
return "C:/Windows/Temp";
|
||||
char* temp = getenv("TEMP");
|
||||
if (temp) {
|
||||
return std::string(temp);
|
||||
}
|
||||
return "C:/Windows/Temp";
|
||||
#else
|
||||
return "/tmp";
|
||||
return "/tmp";
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace SystemUtils
|
||||
} // namespace SystemUtils
|
||||
Reference in New Issue
Block a user