mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-16 20:26:00 +08:00
rename token file, delete old dat file
This commit is contained in:
parent
b037da1126
commit
8042b4f905
@ -136,6 +136,40 @@ bool load_secret(const std::string& opt, std::string& usr, std::string& psswd)
|
|||||||
return false;
|
return false;
|
||||||
#endif // wxUSE_SECRETSTORE
|
#endif // wxUSE_SECRETSTORE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __linux__
|
||||||
|
void load_refresh_token_linux(std::string& refresh_token)
|
||||||
|
{
|
||||||
|
// Load refresh token from UserAccount.dat
|
||||||
|
boost::filesystem::path source(boost::filesystem::path(Slic3r::data_dir()) / "UserAccount.dat") ;
|
||||||
|
// since there was for a short period different file in use, if present, load it and delete it.
|
||||||
|
boost::system::error_code ec;
|
||||||
|
bool delete_after_read = false;
|
||||||
|
if (!boost::filesystem::exists(source, ec) || ec) {
|
||||||
|
source = boost::filesystem::path(Slic3r::data_dir()) / "UserAcountData.dat";
|
||||||
|
ec.clear();
|
||||||
|
if (!boost::filesystem::exists(source, ec) || ec) {
|
||||||
|
BOOST_LOG_TRIVIAL(error) << "UserAccount: Failed to read token - no datafile found.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
delete_after_read = true;
|
||||||
|
}
|
||||||
|
boost::nowide::ifstream stream(source.generic_string(), std::ios::in | std::ios::binary);
|
||||||
|
if (!stream) {
|
||||||
|
BOOST_LOG_TRIVIAL(error) << "UserAccount: Failed to read token from " << source;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
std::getline(stream, refresh_token);
|
||||||
|
stream.close();
|
||||||
|
if (delete_after_read) {
|
||||||
|
ec.clear();
|
||||||
|
if (!boost::filesystem::remove(source, ec) || ec) {
|
||||||
|
BOOST_LOG_TRIVIAL(error) << "UserAccount: Failed to remove file " << source;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif //__linux__
|
||||||
}
|
}
|
||||||
|
|
||||||
UserAccountCommunication::UserAccountCommunication(wxEvtHandler* evt_handler, AppConfig* app_config)
|
UserAccountCommunication::UserAccountCommunication(wxEvtHandler* evt_handler, AppConfig* app_config)
|
||||||
@ -168,15 +202,7 @@ UserAccountCommunication::UserAccountCommunication(wxEvtHandler* evt_handler, Ap
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
// Load refresh token from UserAcountData.txt
|
load_refresh_token_linux(refresh_token);
|
||||||
boost::filesystem::path source(boost::filesystem::path(Slic3r::data_dir()) / "UserAcountData.dat") ;
|
|
||||||
boost::nowide::ifstream stream(source.generic_string(), std::ios::in | std::ios::binary);
|
|
||||||
if (stream) {
|
|
||||||
std::getline(stream, refresh_token);
|
|
||||||
stream.close();
|
|
||||||
} else {
|
|
||||||
BOOST_LOG_TRIVIAL(error) << "UserAccount: Failed to read token from " << source;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
long long next = next_timeout.empty() ? 0 : std::stoll(next_timeout);
|
long long next = next_timeout.empty() ? 0 : std::stoll(next_timeout);
|
||||||
@ -229,7 +255,7 @@ void UserAccountCommunication::set_username(const std::string& username)
|
|||||||
else {
|
else {
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
// If we can't store the tokens in secret store, store them in file with chmod 600
|
// If we can't store the tokens in secret store, store them in file with chmod 600
|
||||||
boost::filesystem::path target(boost::filesystem::path(Slic3r::data_dir()) / "UserAcountData.dat") ;
|
boost::filesystem::path target(boost::filesystem::path(Slic3r::data_dir()) / "UserAccount.dat") ;
|
||||||
std::string data = m_session->get_refresh_token();
|
std::string data = m_session->get_refresh_token();
|
||||||
FILE* file;
|
FILE* file;
|
||||||
static const auto perms = boost::filesystem::owner_read | boost::filesystem::owner_write; // aka 600
|
static const auto perms = boost::filesystem::owner_read | boost::filesystem::owner_write; // aka 600
|
||||||
|
Loading…
x
Reference in New Issue
Block a user