Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Application: Add HOME support and improve filesystem usage #1833

Merged
merged 28 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
5fd1d6d
output/reference: Add proper collapse support
mwestphal Dec 27, 2024
955c9fc
input: Support HOME
mwestphal Dec 28, 2024
b256c98
config: Add HOME support
mwestphal Dec 28, 2024
6869935
engine: Update loadPlugin for new utils
mwestphal Dec 30, 2024
44add4c
load-plugins: Test HOME
mwestphal Dec 28, 2024
243c769
screenshot-filename: doc relative path behavior
mwestphal Dec 28, 2024
526c2b9
fixup tests
mwestphal Dec 28, 2024
1fbe671
Add .cache to .gitignore
mwestphal Dec 28, 2024
010673d
colormap-file: precise documentation
mwestphal Dec 28, 2024
025be4f
interaction-test: Add HOME support
mwestphal Jan 2, 2025
a9a382d
fixup ref/output
mwestphal Dec 28, 2024
faaf414
fixup app/output test
mwestphal Dec 28, 2024
079d1a4
fixup again
mwestphal Dec 28, 2024
800df07
fixup template
mwestphal Dec 28, 2024
091c823
Adding supports for screenshot filename
mwestphal Dec 28, 2024
136033b
colormapfile: Support HOME
mwestphal Dec 28, 2024
473585d
screenshot-file test
mwestphal Dec 28, 2024
0474c4f
command-script: Add HOME support
mwestphal Dec 28, 2024
98a169c
fixup testing
mwestphal Dec 28, 2024
9e59c64
FIxup colormap
mwestphal Jan 2, 2025
49b78f1
Improve path management
mwestphal Jan 2, 2025
97ce32f
fixup homecommand test
mwestphal Jan 2, 2025
f32e100
fixup testing
mwestphal Jan 2, 2025
56e7c0a
fixup testing
mwestphal Jan 2, 2025
0e6aaef
fixup testing again
mwestphal Jan 2, 2025
af31fd4
fixup
mwestphal Jan 3, 2025
bbfd150
fixup
mwestphal Jan 3, 2025
881d1af
better testing
mwestphal Jan 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ _version.py

# wasm process related
node_modules

# testing related
.cache
62 changes: 35 additions & 27 deletions application/F3DColorMapTools.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -4,63 +4,71 @@

#include "image.h"
#include "log.h"
#include "utils.h"

#include <filesystem>

namespace fs = std::filesystem;

namespace F3DColorMapTools
{
std::string Find(const std::string& str)
fs::path Find(const std::string& str)
{
if (fs::exists(str))
try
{
fs::path resolved = fs::canonical(str);
if (fs::is_regular_file(resolved))
fs::path fullPath(f3d::utils::collapsePath(str));
if (fs::exists(fullPath))
{
// already full path
return resolved.string();
if (fs::is_regular_file(fullPath))
{
// already full path
return fullPath;
}
}
}

std::vector<fs::path> dirsToCheck{ F3DSystemTools::GetUserConfigFileDirectory() / "colormaps",
std::vector<fs::path> dirsToCheck{ F3DSystemTools::GetUserConfigFileDirectory() / "colormaps",
#ifdef __APPLE__
"/usr/local/etc/f3d/colormaps",
"/usr/local/etc/f3d/colormaps",
#endif
#ifdef __linux__
"/etc/f3d/colormaps", "/usr/share/f3d/colormaps",
"/etc/f3d/colormaps", "/usr/share/f3d/colormaps",
#endif
F3DSystemTools::GetBinaryResourceDirectory() / "colormaps" };
F3DSystemTools::GetBinaryResourceDirectory() / "colormaps" };

for (const fs::path& dir : dirsToCheck)
{
// If the string is a stem, try adding supported extensions
if (fs::path(str).stem() == str)
for (const fs::path& dir : dirsToCheck)
{
for (const std::string& ext : f3d::image::getSupportedFormats())
// If the string is a stem, try adding supported extensions
if (fs::path(str).stem() == str)
{
fs::path cmPath = dir / (str + ext);
if (fs::exists(cmPath))
for (const std::string& ext : f3d::image::getSupportedFormats())
{
return cmPath.string();
fs::path cmPath = dir / (str + ext);
if (fs::exists(cmPath))
{
return cmPath;
}
}
}
}
else
{
// If not, use directly
fs::path cmPath = dir / str;
if (fs::exists(cmPath))
else
{
return cmPath.string();
// If not, use directly
fs::path cmPath = dir / str;
if (fs::exists(cmPath))
{
return cmPath;
}
}
}
}
catch (const fs::filesystem_error& ex)
{
f3d::log::error("Unable to look for color map ", str, ": ", ex.what());
}

return {};
}

std::vector<double> Read(const std::string& path)
std::vector<double> Read(const fs::path& path)
{
try
{
Expand Down
5 changes: 3 additions & 2 deletions application/F3DColorMapTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
#ifndef F3DColorMapReader_h
#define F3DColorMapReader_h

#include <filesystem>
#include <string>
#include <vector>

namespace F3DColorMapTools
{
std::string Find(const std::string& str);
std::vector<double> Read(const std::string& path);
std::filesystem::path Find(const std::string& str);
std::vector<double> Read(const std::filesystem::path& path);
}

#endif
8 changes: 5 additions & 3 deletions application/F3DConfigFileTools.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "nlohmann/json.hpp"

#include "log.h"
#include "utils.h"

#include <filesystem>
#include <fstream>
Expand All @@ -21,7 +22,7 @@ namespace
*/
std::vector<fs::path> GetConfigPaths(const std::string& configSearch)
{
std::vector<std::filesystem::path> paths;
std::vector<fs::path> paths;

fs::path configPath;
std::vector<fs::path> dirsToCheck = {
Expand Down Expand Up @@ -111,7 +112,8 @@ F3DConfigFileTools::ReadConfigFiles(const std::string& userConfig)
}
else
{
configPaths.emplace_back(userConfig);
// Collapse full path into an absolute path
configPaths.emplace_back(f3d::utils::collapsePath(userConfig));
}

// Recover actual individual config file paths
Expand All @@ -133,7 +135,7 @@ F3DConfigFileTools::ReadConfigFiles(const std::string& userConfig)
if (fs::is_directory(configPath))
{
f3d::log::debug("Using config directory ", configPath.string());
for (auto& entry : std::filesystem::directory_iterator(configPath))
for (auto& entry : fs::directory_iterator(configPath))
{
actualConfigFilePaths.emplace(entry);
}
Expand Down
Loading
Loading