Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/supermerill/SuperSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/libslic3r/AppConfig.cpp10
-rw-r--r--src/libslic3r/Utils.hpp3
-rw-r--r--src/libslic3r/utils.cpp5
-rw-r--r--src/slic3r/GUI/GalleryDialog.cpp16
4 files changed, 25 insertions, 9 deletions
diff --git a/src/libslic3r/AppConfig.cpp b/src/libslic3r/AppConfig.cpp
index cf7bf21d1..7bc749643 100644
--- a/src/libslic3r/AppConfig.cpp
+++ b/src/libslic3r/AppConfig.cpp
@@ -655,6 +655,7 @@ void AppConfig::init_ui_layout() {
//copy all resources that aren't in datadir or newer
std::string current_name = get("ui_layout");
bool find_current = false;
+ std::string error_message;
for (const auto& layout : resources_map) {
auto it_datadir_layout = datadir_map.find(layout.first);
if (it_datadir_layout != datadir_map.end()) {
@@ -665,7 +666,8 @@ void AppConfig::init_ui_layout() {
boost::filesystem::remove_all(file.path());
}
for (boost::filesystem::directory_entry& file : boost::filesystem::directory_iterator(layout.second.path)) {
- boost::filesystem::copy_file(file.path(), it_datadir_layout->second.path / file.path().filename());
+ if (copy_file_inner(file.path(), it_datadir_layout->second.path / file.path().filename(), error_message))
+ throw FileIOError(error_message);
}
//update for saving
it_datadir_layout->second.version = layout.second.version;
@@ -679,7 +681,8 @@ void AppConfig::init_ui_layout() {
std::time_t datadir_last_mod = boost::filesystem::last_write_time(datadir_path);
if (datadir_last_mod < resources_last_mod) {
boost::filesystem::remove_all(datadir_path);
- boost::filesystem::copy_file(resources_file.path(), datadir_path);
+ if (copy_file_inner(resources_file.path(), datadir_path, error_message))
+ throw FileIOError(error_message);
}
}
@@ -688,7 +691,8 @@ void AppConfig::init_ui_layout() {
// Doesn't exists, copy
boost::filesystem::create_directory(data_dir_path / layout.second.path.filename());
for (boost::filesystem::directory_entry& file : boost::filesystem::directory_iterator(layout.second.path)) {
- boost::filesystem::copy_file(file.path(), data_dir_path / layout.second.path.filename() / file.path().filename());
+ if (copy_file_inner(file.path(), data_dir_path / layout.second.path.filename() / file.path().filename(), error_message))
+ throw FileIOError(error_message);
}
//update for saving
datadir_map[layout.first] = layout.second;
diff --git a/src/libslic3r/Utils.hpp b/src/libslic3r/Utils.hpp
index 8862951a8..7d7422240 100644
--- a/src/libslic3r/Utils.hpp
+++ b/src/libslic3r/Utils.hpp
@@ -93,7 +93,8 @@ enum CopyFileResult {
FAIL_CHECK_TARGET_NOT_OPENED
};
// Copy a file, adjust the access attributes, so that the target is writable.
-CopyFileResult copy_file_inner(const std::string &from, const std::string &to, std::string& error_message);
+CopyFileResult copy_file_inner(const std::string& from, const std::string& to, std::string& error_message);
+CopyFileResult copy_file_inner(const boost::filesystem::path& from, const boost::filesystem::path& to, std::string& error_message);
// Copy file to a temp file first, then rename it to the final file name.
// If with_check is true, then the content of the copied file is compared to the content
// of the source file before renaming.
diff --git a/src/libslic3r/utils.cpp b/src/libslic3r/utils.cpp
index a17e9ab06..e90871d79 100644
--- a/src/libslic3r/utils.cpp
+++ b/src/libslic3r/utils.cpp
@@ -678,6 +678,11 @@ CopyFileResult copy_file_inner(const std::string& from, const std::string& to, s
{
const boost::filesystem::path source(from);
const boost::filesystem::path target(to);
+ return copy_file_inner(source, target, error_message);
+}
+
+CopyFileResult copy_file_inner(const boost::filesystem::path& source, const boost::filesystem::path& target, std::string& error_message)
+{
static const auto perms = boost::filesystem::owner_read | boost::filesystem::owner_write | boost::filesystem::group_read | boost::filesystem::others_read; // aka 644
// Make sure the file has correct permission both before and after we copy over it.
diff --git a/src/slic3r/GUI/GalleryDialog.cpp b/src/slic3r/GUI/GalleryDialog.cpp
index 9178eef13..ad9ad2aa7 100644
--- a/src/slic3r/GUI/GalleryDialog.cpp
+++ b/src/slic3r/GUI/GalleryDialog.cpp
@@ -473,7 +473,9 @@ void GalleryDialog::change_thumbnail()
png_path.replace_extension("png");
fs::path current = fs::path(into_u8(input_files.Item(0)));
- fs::copy_file(current, png_path, fs::copy_option::overwrite_if_exists);
+ std::string error_msg;
+ if (copy_file_inner(current, png_path, error_msg))
+ throw FileIOError(error_msg);
}
catch (fs::filesystem_error const& e) {
std::cerr << e.what() << '\n';
@@ -560,9 +562,11 @@ bool GalleryDialog::load_files(const wxArrayString& input_files)
try {
fs::path current = fs::path(input_file);
- if (!fs::exists(dest_dir / current.filename()))
- fs::copy_file(current, dest_dir / current.filename());
- else {
+ if (!fs::exists(dest_dir / current.filename())) {
+ std::string error_msg;
+ if (copy_file_inner(current, dest_dir / current.filename(), error_msg))
+ throw FileIOError(error_msg);
+ } else {
std::string filename = current.stem().string();
int file_idx = 0;
@@ -584,7 +588,9 @@ bool GalleryDialog::load_files(const wxArrayString& input_files)
}
if (file_idx > 0) {
filename += " (" + std::to_string(file_idx) + ")." + (is_gallery_file(input_file, ".stl") ? "stl" : "obj");
- fs::copy_file(current, dest_dir / filename);
+ std::string error_msg;
+ if (copy_file_inner(current, dest_dir / filename, error_msg))
+ throw FileIOError(error_msg);
}
}
}