store: Fixed more download issues when some folders don't have write perms
This commit is contained in:
parent
2847098020
commit
5a02c38fcd
@ -56,7 +56,7 @@ namespace hex {
|
|||||||
void setSize(u64 size);
|
void setSize(u64 size);
|
||||||
|
|
||||||
void flush();
|
void flush();
|
||||||
void remove();
|
bool remove();
|
||||||
|
|
||||||
auto getHandle() { return this->m_file; }
|
auto getHandle() { return this->m_file; }
|
||||||
const fs::path &getPath() { return this->m_path; }
|
const fs::path &getPath() { return this->m_path; }
|
||||||
|
@ -44,6 +44,7 @@ namespace hex {
|
|||||||
std::string encodeByteString(const std::vector<u8> &bytes);
|
std::string encodeByteString(const std::vector<u8> &bytes);
|
||||||
std::vector<u8> decodeByteString(const std::string &string);
|
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) {
|
[[nodiscard]] constexpr inline u64 extract(u8 from, u8 to, const hex::unsigned_integral auto &value) {
|
||||||
if (from < to) std::swap(from, to);
|
if (from < to) std::swap(from, to);
|
||||||
|
@ -122,9 +122,9 @@ namespace hex {
|
|||||||
fflush(this->m_file);
|
fflush(this->m_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
void File::remove() {
|
bool File::remove() {
|
||||||
this->close();
|
this->close();
|
||||||
std::remove(this->m_path.string().c_str());
|
return std::remove(this->m_path.string().c_str()) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -23,6 +23,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <hex/helpers/logger.hpp>
|
#include <hex/helpers/logger.hpp>
|
||||||
|
#include <hex/helpers/file.hpp>
|
||||||
|
|
||||||
namespace hex {
|
namespace hex {
|
||||||
|
|
||||||
@ -393,6 +394,23 @@ namespace hex {
|
|||||||
return result;
|
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) {
|
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();
|
NFD::Init();
|
||||||
|
@ -8,8 +8,6 @@
|
|||||||
#include "init/splash_window.hpp"
|
#include "init/splash_window.hpp"
|
||||||
#include "init/tasks.hpp"
|
#include "init/tasks.hpp"
|
||||||
|
|
||||||
#include <hex/helpers/file.hpp>
|
|
||||||
|
|
||||||
int main(int argc, char **argv, char **envp) {
|
int main(int argc, char **argv, char **envp) {
|
||||||
using namespace hex;
|
using namespace hex;
|
||||||
ImHexApi::System::impl::setProgramArguments(argc, argv, envp);
|
ImHexApi::System::impl::setProgramArguments(argc, argv, envp);
|
||||||
|
@ -110,7 +110,7 @@ namespace hex::plugin::builtin {
|
|||||||
|
|
||||||
downloadDoneCallback(entry);
|
downloadDoneCallback(entry);
|
||||||
} else
|
} else
|
||||||
log::error("Download failed!");
|
log::error("Download failed! HTTP Code {}", response.code);
|
||||||
|
|
||||||
|
|
||||||
this->m_download = {};
|
this->m_download = {};
|
||||||
@ -186,7 +186,7 @@ namespace hex::plugin::builtin {
|
|||||||
|
|
||||||
auto path = folder / fs::path(storeEntry.fileName);
|
auto path = folder / fs::path(storeEntry.fileName);
|
||||||
|
|
||||||
if (fs::exists(path)) {
|
if (fs::exists(path) && hex::isPathWritable(folder)) {
|
||||||
storeEntry.installed = true;
|
storeEntry.installed = true;
|
||||||
|
|
||||||
std::ifstream file(path, std::ios::in | std::ios::binary);
|
std::ifstream file(path, std::ios::in | std::ios::binary);
|
||||||
@ -237,7 +237,11 @@ namespace hex::plugin::builtin {
|
|||||||
bool ViewStore::download(ImHexPath pathType, const std::string &fileName, const std::string &url, bool update) {
|
bool ViewStore::download(ImHexPath pathType, const std::string &fileName, const std::string &url, bool update) {
|
||||||
bool downloading = false;
|
bool downloading = false;
|
||||||
for (const auto &path : hex::getPath(pathType)) {
|
for (const auto &path : hex::getPath(pathType)) {
|
||||||
|
if (!hex::isPathWritable(path))
|
||||||
|
continue;
|
||||||
|
|
||||||
auto fullPath = path / fs::path(fileName);
|
auto fullPath = path / fs::path(fileName);
|
||||||
|
|
||||||
if (!update || fs::exists(fullPath)) {
|
if (!update || fs::exists(fullPath)) {
|
||||||
downloading = true;
|
downloading = true;
|
||||||
this->m_downloadPath = fullPath;
|
this->m_downloadPath = fullPath;
|
||||||
@ -257,8 +261,10 @@ namespace hex::plugin::builtin {
|
|||||||
bool ViewStore::remove(ImHexPath pathType, const std::string &fileName) {
|
bool ViewStore::remove(ImHexPath pathType, const std::string &fileName) {
|
||||||
bool removed = false;
|
bool removed = false;
|
||||||
for (const auto &path : hex::getPath(pathType)) {
|
for (const auto &path : hex::getPath(pathType)) {
|
||||||
bool removedFile = fs::remove(path / fs::path(fileName));
|
std::error_code error;
|
||||||
bool removedFolder = fs::remove(path / fs::path(fileName).stem());
|
|
||||||
|
bool removedFile = fs::remove(path / fs::path(fileName), error);
|
||||||
|
bool removedFolder = fs::remove(path / fs::path(fileName).stem(), error);
|
||||||
|
|
||||||
removed = removed || removedFile || removedFolder;
|
removed = removed || removedFile || removedFolder;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user