Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 22 additions & 2 deletions src/libslic3r/PresetBundle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,11 @@ void PresetBundle::reset(bool delete_files)

void PresetBundle::setup_directories()
{
#ifdef WIN32
boost::filesystem::path data_dir = boost::filesystem::path(boost::nowide::widen(Slic3r::data_dir()));
#else
boost::filesystem::path data_dir = boost::filesystem::path(Slic3r::data_dir());
#endif
//BBS: change directoties by design
std::initializer_list<boost::filesystem::path> paths = {
data_dir,
Expand Down Expand Up @@ -370,21 +374,31 @@ static void copy_dir(const boost::filesystem::path& from_dir, const boost::files
if (!boost::filesystem::is_directory(to_dir))
boost::filesystem::create_directory(to_dir);
for (auto& dir_entry : boost::filesystem::directory_iterator(from_dir)) {
const boost::filesystem::path dest_child = to_dir / dir_entry.path().filename();
if (!boost::filesystem::is_directory(dir_entry.path())) {
std::string em;
CopyFileResult cfr = copy_file(dir_entry.path().string(), (to_dir / dir_entry.path().filename()).string(), em, false);
#ifdef WIN32
CopyFileResult cfr = copy_file(boost::nowide::narrow(dir_entry.path().wstring()),
boost::nowide::narrow(dest_child.wstring()), em, false);
#else
CopyFileResult cfr = copy_file(dir_entry.path().string(), dest_child.string(), em, false);
#endif
if (cfr != SUCCESS) {
BOOST_LOG_TRIVIAL(error) << "Error when copying files from " << from_dir << " to " << to_dir << ": " << em;
}
} else {
copy_dir(dir_entry.path(), to_dir / dir_entry.path().filename());
copy_dir(dir_entry.path(), dest_child);
}
}
}

void PresetBundle::copy_files(const std::string& from)
{
#ifdef WIN32
boost::filesystem::path data_dir = boost::filesystem::path(boost::nowide::widen(Slic3r::data_dir()));
#else
boost::filesystem::path data_dir = boost::filesystem::path(Slic3r::data_dir());
#endif
// list of searched paths based on current directory system in setup_directories()
// do not copy cache and snapshots
boost::filesystem::path from_data_dir = boost::filesystem::path(from);
Expand Down Expand Up @@ -1403,9 +1417,15 @@ std::pair<PresetsConfigSubstitutions, std::string> PresetBundle::load_system_pre

// Here the vendor specific read only Config Bundles are stored.
//BBS: change directory by design
#ifdef WIN32
boost::filesystem::path dir = (boost::filesystem::path(boost::nowide::widen(data_dir())) / PRESET_SYSTEM_DIR).make_preferred();
if (validation_mode)
dir = boost::filesystem::path(boost::nowide::widen(data_dir())).make_preferred();
#else
boost::filesystem::path dir = (boost::filesystem::path(data_dir()) / PRESET_SYSTEM_DIR).make_preferred();
if (validation_mode)
dir = (boost::filesystem::path(data_dir())).make_preferred();
#endif

PresetsConfigSubstitutions substitutions;
std::string errors_cummulative;
Expand Down
17 changes: 14 additions & 3 deletions src/libslic3r/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1535,16 +1535,27 @@ bool copy_directory_recursively(const boost::filesystem::path &source, const boo

std::string error_message;
for (auto &dir_entry : boost::filesystem::directory_iterator(source)) {
const std::string name = dir_entry.path().filename().string();
const boost::filesystem::path child_name = dir_entry.path().filename();
const boost::filesystem::path dest_child = target / child_name;

if (boost::filesystem::is_directory(dir_entry)) {
if (!copy_directory_recursively(dir_entry, target / name, filter))
if (!copy_directory_recursively(dir_entry.path(), dest_child, filter))
return false;
} else {
#ifdef WIN32
const std::string name = boost::nowide::narrow(child_name.wstring());
#else
const std::string name = child_name.string();
#endif
if (filter && filter(name))
continue;
#ifdef WIN32
const std::string source_file = boost::nowide::narrow(dir_entry.path().wstring());
const std::string target_file = boost::nowide::narrow(dest_child.wstring());
#else
const std::string source_file = dir_entry.path().string();
const std::string target_file = (target / name).string();
const std::string target_file = dest_child.string();
#endif
const CopyFileResult cfr = copy_file(source_file, target_file, error_message, false);
if (cfr != CopyFileResult::SUCCESS) {
BOOST_LOG_TRIVIAL(error) << "Copying failed(" << static_cast<int>(cfr) << "): " << error_message
Expand Down
17 changes: 14 additions & 3 deletions src/slic3r/GUI/GUI_App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2270,7 +2270,11 @@ bool GUI_App::check_older_app_config(Semver current_version, bool backup)
void GUI_App::copy_web_resources() {
StartupProfiler profiler("GUI_App::copy_web_resources");

#ifdef WIN32
auto data_web_path = boost::filesystem::path(boost::nowide::widen(data_dir())) / "web";
#else
auto data_web_path = boost::filesystem::path(data_dir()) / "web";
#endif
if (!boost::filesystem::exists(data_web_path / "flutter_web")) {
copy_bundled_flutter_web(false);
profiler.mark("copy flutter_web (missing target)");
Expand All @@ -2282,10 +2286,13 @@ void GUI_App::copy_web_resources() {
boost::property_tree::ptree source_config, target_config;
boost::property_tree::read_json(source_version_file.string(), source_config);
boost::property_tree::read_json(target_version_file.string(), target_config);
std::string source_build_number_str = source_config.get<std::string>("build_number", "0");
std::string target_build_number_str = target_config.get<std::string>("build_number", "0");
std::string source_version_str = source_config.get<std::string>("version", "0");
std::string target_version_str = target_config.get<std::string>("version", "0");

Semver source_version(source_version_str);
Semver target_version(target_version_str);

if (source_build_number_str > target_build_number_str) {
if (target_version < source_version) {
copy_bundled_flutter_web(true);
profiler.mark("copy flutter_web (version upgrade)");
} else {
Expand All @@ -2301,7 +2308,11 @@ void GUI_App::copy_web_resources() {
bool GUI_App::copy_bundled_flutter_web(bool upgrade)
{
auto source_path = boost::filesystem::path(resources_dir()) / "web" / "flutter_web";
#ifdef WIN32
auto target_path = boost::filesystem::path(boost::nowide::widen(data_dir())) / "web" / "flutter_web";
#else
auto target_path = boost::filesystem::path(data_dir()) / "web" / "flutter_web";
#endif
if (copy_directory_recursively(source_path, target_path))
return true;

Expand Down
64 changes: 54 additions & 10 deletions src/slic3r/Utils/PresetUpdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,12 @@ void copy_file_fix(const fs::path &source, const fs::path &target)
BOOST_LOG_TRIVIAL(debug) << format("PresetUpdater: Copying %1% -> %2%", source, target);
std::string error_message;
//CopyFileResult cfr = Slic3r::GUI::copy_file_gui(source.string(), target.string(), error_message, false);
#ifdef WIN32
CopyFileResult cfr = copy_file(boost::nowide::narrow(source.wstring()),
boost::nowide::narrow(target.wstring()), error_message, false);
#else
CopyFileResult cfr = copy_file(source.string(), target.string(), error_message, false);
#endif
if (cfr != CopyFileResult::SUCCESS) {
BOOST_LOG_TRIVIAL(error) << "Copying failed(" << cfr << "): " << error_message;
throw Slic3r::CriticalException(GUI::format(
Expand Down Expand Up @@ -317,9 +322,15 @@ struct PresetUpdater::priv

//BBS: change directories by design
PresetUpdater::priv::priv()
#ifdef WIN32
: cache_path(fs::path(boost::nowide::widen(Slic3r::data_dir())) / "ota")
, rsrc_path(fs::path(resources_dir()) / "profiles")
, vendor_path(fs::path(boost::nowide::widen(Slic3r::data_dir())) / PRESET_SYSTEM_DIR)
#else
: cache_path(fs::path(Slic3r::data_dir()) / "ota")
, rsrc_path(fs::path(resources_dir()) / "profiles")
, vendor_path(fs::path(Slic3r::data_dir()) / PRESET_SYSTEM_DIR)
#endif
, cancel(false)
{
//BBS: refine preset updater logic
Expand Down Expand Up @@ -1002,7 +1013,11 @@ void PresetUpdater::priv::sync_update_flutter_resource(bool isAuto_check)
auto reservedData2 = dataObj.value("reserved_2", "");

auto localProfilesjson = cache_path / "flutter_web/version.json";
std::string json_path = data_dir() + "/web/flutter_web/version.json";
#ifdef WIN32
std::string json_path = boost::nowide::narrow((boost::filesystem::path(boost::nowide::widen(data_dir())) / "web" / "flutter_web" / "version.json").wstring());
#else
std::string json_path = (boost::filesystem::path(data_dir()) / "web" / "flutter_web" / "version.json").string();
#endif
// Use a unique filename per version to avoid deleting a zip that may still be in use (Windows file locks / concurrent UI import).
std::string fileName = (cache_profile_path / ("flutter_web_" + fileVersion + ".zip")).string();
Semver currentPresetVersion = get_version_from_json(json_path);
Expand Down Expand Up @@ -1134,7 +1149,11 @@ void PresetUpdater::priv::sync_config(bool isAuto_check)
currentPresetVersion =
GUI::wxGetApp().preset_bundle->get_vendor_profile_version(PresetBundle::SM_BUNDLE);
else
currentPresetVersion = get_version_from_json(data_dir() + "/system/Snapmaker.json");
#ifdef WIN32
currentPresetVersion = get_version_from_json(boost::nowide::narrow((boost::filesystem::path(boost::nowide::widen(data_dir())) / "system" / "Snapmaker.json").wstring()));
#else
currentPresetVersion = get_version_from_json((boost::filesystem::path(data_dir()) / "system" / "Snapmaker.json").string());
#endif

std::regex matcher("[0-9]+\\.[0-9]+(\\.[0-9]+)*(-[A-Za-z0-9]+)?(\\+[A-Za-z0-9]+)?");

Expand Down Expand Up @@ -1232,7 +1251,11 @@ void PresetUpdater::priv::sync_tooltip(std::string http_url, std::string languag
try {
std::string common_version = "00.00.00.00";
std::string language_version = "00.00.00.00";
#ifdef WIN32
fs::path cache_root = fs::path(boost::nowide::widen(data_dir())) / "resources/tooltip";
#else
fs::path cache_root = fs::path(data_dir()) / "resources/tooltip";
#endif
try {
auto vf = cache_root / "common" / "version";
if (fs::exists(vf)) Slic3r::load_string_file(vf, common_version);
Expand Down Expand Up @@ -1260,8 +1283,11 @@ void PresetUpdater::priv::sync_tooltip(std::string http_url, std::string languag
// return true means there are plugins files
bool PresetUpdater::priv::get_cached_plugins_version(std::string& cached_version, bool &force)
{
std::string data_dir_str = data_dir();
boost::filesystem::path data_dir_path(data_dir_str);
#ifdef WIN32
boost::filesystem::path data_dir_path(boost::nowide::widen(data_dir()));
#else
boost::filesystem::path data_dir_path(data_dir());
#endif
auto cache_folder = data_dir_path / "ota";
std::string network_library, player_library, live555_library;
bool has_plugins = false;
Expand Down Expand Up @@ -1346,8 +1372,11 @@ void PresetUpdater::priv::sync_plugins(std::string http_url, std::string plugin_
}

if (need_delete_cache) {
std::string data_dir_str = data_dir();
boost::filesystem::path data_dir_path(data_dir_str);
#if defined(_MSC_VER) || defined(_WIN32)
boost::filesystem::path data_dir_path(boost::nowide::widen(data_dir()));
#else
boost::filesystem::path data_dir_path(data_dir());
#endif
auto cache_folder = data_dir_path / "ota";

#if defined(_MSC_VER) || defined(_WIN32)
Expand Down Expand Up @@ -1460,8 +1489,11 @@ void PresetUpdater::priv::sync_printer_config(std::string http_url)
std::string using_version = curr_version.substr(0, 6) + "00.00";

std::string cached_version;
std::string data_dir_str = data_dir();
boost::filesystem::path data_dir_path(data_dir_str);
#ifdef WIN32
boost::filesystem::path data_dir_path(boost::nowide::widen(data_dir()));
#else
boost::filesystem::path data_dir_path(data_dir());
#endif
auto config_folder = data_dir_path / "printers";
auto cache_folder = data_dir_path / "ota" / "printers";

Expand Down Expand Up @@ -1649,9 +1681,13 @@ void PresetUpdater::priv::check_installed_vendor_profiles() const

Updates PresetUpdater::priv::get_printer_config_updates(bool update) const
{
std::string data_dir_str = data_dir();
boost::filesystem::path data_dir_path(data_dir_str);
#ifdef WIN32
boost::filesystem::path data_dir_path(boost::nowide::widen(data_dir()));
boost::filesystem::path resc_dir_path(boost::nowide::widen(resources_dir()));
#else
boost::filesystem::path data_dir_path(data_dir());
boost::filesystem::path resc_dir_path(resources_dir());
#endif
auto config_folder = data_dir_path / "printers";
auto resc_folder = (update ? cache_path : resc_dir_path) / "printers";
std::string curr_version;
Expand Down Expand Up @@ -2191,7 +2227,11 @@ void PresetUpdater::load_flutter_web(const std::string& resource_path, bool serv
std::string ori_version_str = "0";
std::string ori_build_number_str = "0";

#ifdef WIN32
auto ori_version_file = boost::filesystem::path(boost::nowide::widen(data_dir())) / "web" / "flutter_web" / "version.json";
#else
auto ori_version_file = boost::filesystem::path(data_dir()) / "web" / "flutter_web" / "version.json";
#endif
boost::property_tree::ptree ori_config;
boost::property_tree::read_json(ori_version_file.string(), ori_config);
ori_version_str = ori_config.get<std::string>("version", "0");
Expand All @@ -2209,7 +2249,11 @@ void PresetUpdater::load_flutter_web(const std::string& resource_path, bool serv

if (current_version < online_version) {
auto source_folder_path = flutter_root;
#ifdef WIN32
auto target_folder_path = (boost::filesystem::path(boost::nowide::widen(data_dir())) / "web" / "flutter_web");
#else
auto target_folder_path = (boost::filesystem::path(data_dir()) / "web" / "flutter_web");
#endif

Version version;
version.config_version = online_version;
Expand Down
Loading