mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-23 00:31:11 -06:00
New C++ class AppConfig for maintaining the config.ini
New helper function for generating a unified "generated by slic3r" header.
This commit is contained in:
parent
835e5b71a8
commit
1fee3633a0
11 changed files with 107 additions and 51 deletions
|
@ -1,6 +1,6 @@
|
|||
#include "Config.hpp"
|
||||
#include "Utils.hpp"
|
||||
#include <assert.h>
|
||||
#include <ctime>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <exception> // std::runtime_error
|
||||
|
@ -422,13 +422,7 @@ void ConfigBase::save(const std::string &file) const
|
|||
{
|
||||
boost::nowide::ofstream c;
|
||||
c.open(file, std::ios::out | std::ios::trunc);
|
||||
{
|
||||
std::time_t now;
|
||||
time(&now);
|
||||
char buf[sizeof "0000-00-00 00:00:00"];
|
||||
strftime(buf, sizeof(buf), "%F %T", gmtime(&now));
|
||||
c << "# generated by Slic3r " << SLIC3R_VERSION << " on " << buf << std::endl;
|
||||
}
|
||||
c << "# " << Slic3r::header_slic3r_generated() << std::endl;
|
||||
for (const std::string &opt_key : this->keys())
|
||||
c << opt_key << " = " << this->serialize(opt_key) << std::endl;
|
||||
c.close();
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "Geometry.hpp"
|
||||
#include "GCode/PrintExtents.hpp"
|
||||
#include "GCode/WipeTowerPrusaMM.hpp"
|
||||
#include "Utils.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
|
@ -11,7 +12,6 @@
|
|||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/algorithm/string/find.hpp>
|
||||
#include <boost/date_time/local_time/local_time.hpp>
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
#include <boost/nowide/iostream.hpp>
|
||||
|
@ -462,15 +462,7 @@ bool GCode::_do_export(Print &print, FILE *file)
|
|||
m_enable_extrusion_role_markers = (bool)m_pressure_equalizer;
|
||||
|
||||
// Write information on the generator.
|
||||
{
|
||||
const auto now = boost::posix_time::second_clock::local_time();
|
||||
const auto date = now.date();
|
||||
fprintf(file, "; generated by Slic3r %s on %04d-%02d-%02d at %02d:%02d:%02d\n\n",
|
||||
SLIC3R_VERSION,
|
||||
// Local date in an ANSII format.
|
||||
int(now.date().year()), int(now.date().month()), int(now.date().day()),
|
||||
int(now.time_of_day().hours()), int(now.time_of_day().minutes()), int(now.time_of_day().seconds()));
|
||||
}
|
||||
fprintf(file, "# %s\n\n", Slic3r::header_slic3r_generated().c_str());
|
||||
// Write notes (content of the Print Settings tab -> Notes)
|
||||
{
|
||||
std::list<std::string> lines;
|
||||
|
|
|
@ -30,6 +30,12 @@ extern std::string encode_path(const char *src);
|
|||
extern std::string decode_path(const char *src);
|
||||
extern std::string normalize_utf8_nfc(const char *src);
|
||||
|
||||
// Timestamp formatted for header_slic3r_generated().
|
||||
extern std::string timestamp_str();
|
||||
// Standard "generated by Slic3r version xxx timestamp xxx" header string,
|
||||
// to be placed at the top of Slic3r generated files.
|
||||
inline std::string header_slic3r_generated() { return std::string("generated by Slic3r " SLIC3R_VERSION " on ") + timestamp_str(); }
|
||||
|
||||
// Compute the next highest power of 2 of 32-bit v
|
||||
// http://graphics.stanford.edu/~seander/bithacks.html
|
||||
template<typename T>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <locale>
|
||||
#include <ctime>
|
||||
|
||||
#include <boost/log/core.hpp>
|
||||
#include <boost/log/trivial.hpp>
|
||||
|
@ -7,6 +8,7 @@
|
|||
#include <boost/locale.hpp>
|
||||
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <boost/date_time/local_time/local_time.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/nowide/integration/filesystem.hpp>
|
||||
#include <boost/nowide/convert.hpp>
|
||||
|
@ -233,4 +235,24 @@ std::string normalize_utf8_nfc(const char *src)
|
|||
return boost::locale::normalize(src, boost::locale::norm_nfc, locale_utf8);
|
||||
}
|
||||
|
||||
std::string timestamp_str()
|
||||
{
|
||||
#if 1
|
||||
std::time_t now;
|
||||
time(&now);
|
||||
char buf[sizeof "0000-00-00 00:00:00"];
|
||||
strftime(buf, sizeof(buf), "%F %T", gmtime(&now));
|
||||
#else
|
||||
const auto now = boost::posix_time::second_clock::local_time();
|
||||
const auto date = now.date();
|
||||
char buf[2048];
|
||||
sprintf(buf, "on %04d-%02d-%02d at %02d:%02d:%02d",
|
||||
SLIC3R_VERSION,
|
||||
// Local date in an ANSII format.
|
||||
int(now.date().year()), int(now.date().month()), int(now.date().day()),
|
||||
int(now.time_of_day().hours()), int(now.time_of_day().minutes()), int(now.time_of_day().seconds()));
|
||||
#endif
|
||||
return buf;
|
||||
}
|
||||
|
||||
}; // namespace Slic3r
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue