mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-16 21:42:43 +00:00
fix: resolve relative input paths given on the command line (#14803)
Opening a model with a relative path, for example `orca-slicer ./some.3mf`, failed with "Loading of a model file failed." and "The file does not contain any geometry data.", while the same file opened by an absolute path or by drag and drop worked. GUI_App::init_app_config() changes the working directory to <data_dir>/log, and it runs from the GUI_App constructor because the app config is needed early for instance checking. The input files are opened much later, in post_init(), so a path still relative at that point resolved against the log directory instead of the directory OrcaSlicer was started from, and the 3MF reader failed to open it. Resolve the input paths in CLI::setup(), which runs before GUI_App is constructed and therefore before the working directory moves. Absolute paths are returned unchanged, so the forms that open today are unaffected, and custom open protocol URLs are passed through since post_init() hands those to the downloader rather than the file loader. The working directory change is left alone. It was added in #3248 so the TUTK logs land in the data directory instead of the working directory (#3209).
This commit is contained in:
@@ -176,4 +176,22 @@ inline void write_debug_stream([[maybe_unused]] const std::string &name, [[maybe
|
||||
#endif
|
||||
}
|
||||
|
||||
// Changes the working directory and restores the previous one on scope exit, including when an
|
||||
// assertion throws. It is process wide state shared with every other test.
|
||||
class ScopedWorkingDirectory
|
||||
{
|
||||
public:
|
||||
explicit ScopedWorkingDirectory(const boost::filesystem::path &dir)
|
||||
: m_previous(boost::filesystem::current_path())
|
||||
{
|
||||
boost::filesystem::current_path(dir);
|
||||
}
|
||||
~ScopedWorkingDirectory() { boost::system::error_code ec; boost::filesystem::current_path(m_previous, ec); }
|
||||
ScopedWorkingDirectory(const ScopedWorkingDirectory &) = delete;
|
||||
ScopedWorkingDirectory &operator=(const ScopedWorkingDirectory &) = delete;
|
||||
|
||||
private:
|
||||
boost::filesystem::path m_previous;
|
||||
};
|
||||
|
||||
#endif // SLIC3R_TEST_UTILS
|
||||
|
||||
Reference in New Issue
Block a user