store: Fixed more download issues when some folders don't have write perms

This commit is contained in:
WerWolv
2022-02-28 23:10:04 +01:00
parent 2847098020
commit 5a02c38fcd
6 changed files with 32 additions and 9 deletions

View File

@@ -56,7 +56,7 @@ namespace hex {
void setSize(u64 size);
void flush();
void remove();
bool remove();
auto getHandle() { return this->m_file; }
const fs::path &getPath() { return this->m_path; }

View File

@@ -44,6 +44,7 @@ namespace hex {
std::string encodeByteString(const std::vector<u8> &bytes);
std::vector<u8> decodeByteString(const std::string &string);
bool isPathWritable(fs::path path);
[[nodiscard]] constexpr inline u64 extract(u8 from, u8 to, const hex::unsigned_integral auto &value) {
if (from < to) std::swap(from, to);

View File

@@ -122,9 +122,9 @@ namespace hex {
fflush(this->m_file);
}
void File::remove() {
bool File::remove() {
this->close();
std::remove(this->m_path.string().c_str());
return std::remove(this->m_path.string().c_str()) == 0;
}
}

View File

@@ -23,6 +23,7 @@
#endif
#include <hex/helpers/logger.hpp>
#include <hex/helpers/file.hpp>
namespace hex {
@@ -393,6 +394,23 @@ namespace hex {
return result;
}
bool isPathWritable(fs::path path) {
constexpr static auto TestFileName = "__imhex__tmp__";
{
File file(path / TestFileName, File::Mode::Read);
if (file.isValid()) {
if (!file.remove())
return false;
}
}
File file(path / TestFileName, File::Mode::Create);
bool result = file.isValid();
if (!file.remove())
return false;
return result;
}
bool openFileBrowser(const std::string &title, DialogMode mode, const std::vector<nfdfilteritem_t> &validExtensions, const std::function<void(fs::path)> &callback, const std::string &defaultPath) {
NFD::Init();