diff --git a/src/api/webDAV.cpp b/src/api/webDAV.cpp index 7af05ee..817fb43 100644 --- a/src/api/webDAV.cpp +++ b/src/api/webDAV.cpp @@ -57,16 +57,16 @@ std::vector WebDAV::login(const string &Url, const string &Username, uuid = Username; } auto tempPath = NEXTCLOUD_ROOT_PATH + uuid + "/"; - Util::accessConfig( Action::IWriteString, "storageLocation", "/mnt/ext1/nextcloud"); + Util::accessConfig( Action::IWriteString, "storageLocation", "/mnt/ext1/nextcloud"); std::vector tempItems = getDataStructure(tempPath); if (!tempItems.empty()) { if (iv_access(CONFIG_PATH.c_str(), W_OK) != 0) iv_buildpath(CONFIG_PATH.c_str()); - Util::accessConfig( Action::IWriteString, "url", _url); - Util::accessConfig( Action::IWriteString, "username", _username); - Util::accessConfig( Action::IWriteString, "UUID", uuid); - Util::accessConfig( Action::IWriteSecret, "password", _password); + Util::accessConfig( Action::IWriteString, "url", _url); + Util::accessConfig( Action::IWriteString, "username", _username); + Util::accessConfig( Action::IWriteString, "UUID", uuid); + Util::accessConfig( Action::IWriteSecret, "password", _password); } else { diff --git a/src/handler/eventHandler.cpp b/src/handler/eventHandler.cpp index 5292985..40a88aa 100644 --- a/src/handler/eventHandler.cpp +++ b/src/handler/eventHandler.cpp @@ -36,11 +36,12 @@ EventHandler::EventHandler() if (iv_access(CONFIG_PATH.c_str(), W_OK) == 0) { //for backwards compatibilty - if (Util::accessConfig(Action::IReadString, "storageLocation",{}).empty()) - Util::accessConfig(Action::IWriteString, "storageLocation", "/mnt/ext1/nextcloud"); + if (Util::accessConfig(Action::IReadString, "storageLocation",{}).compare("error") == 0) + Util::accessConfig(Action::IWriteString, "storageLocation", "/mnt/ext1/nextcloud"); if (iv_access(Util::accessConfig(Action::IReadString, "storageLocation",{}).c_str(), W_OK) != 0) iv_mkdir(Util::accessConfig(Action::IReadString, "storageLocation",{}).c_str(), 0777); + std::vector currentWebDAVItems; string path = NEXTCLOUD_ROOT_PATH + Util::accessConfig(Action::IReadString,"UUID",{}) + '/'; @@ -188,10 +189,10 @@ void EventHandler::mainMenuHandler(const int index) switch (dialogResult) { case 1: - Util::accessConfig(Action::IWriteInt, "sortBy", 1); + Util::accessConfig(Action::IWriteInt, "sortBy", 1); break; case 2: - Util::accessConfig(Action::IWriteInt, "sortBy", 2); + Util::accessConfig(Action::IWriteInt, "sortBy", 2); break; default: return; @@ -203,13 +204,16 @@ void EventHandler::mainMenuHandler(const int index) case 104: { - _currentPath =+ (_currentPath.back() != '/') ? "/nextcloud" : "nextcloud"; + _currentPath = _currentPath + ((_currentPath.back() != '/') ? "/nextcloud" : "nextcloud"); if (iv_mkdir(_currentPath.c_str(), 0777) != 0) + { + Log::writeErrorLog("choosen part " + _currentPath + " could not be created as permission are not sufficient."); Message(ICON_ERROR, "Error", "The permissions are not sufficient.", 1000); + } else { - Util::accessConfig(Action::IWriteString, "storageLocation", _currentPath); + Util::accessConfig(Action::IWriteString, "storageLocation", _currentPath); std::vector currentWebDAVItems = _webDAV.getDataStructure(NEXTCLOUD_ROOT_PATH + Util::accessConfig(Action::IReadString,"UUID",{}) + '/'); if (currentWebDAVItems.empty()) { @@ -377,11 +381,11 @@ int EventHandler::pointerHandler(const int type, const int par1, const int par2) else { int dialogResult = DialogSynchro(ICON_QUESTION, "Action", "Do you want to choose your own storage path or use the default one. \n (/mnt/ext1/nextcloud/)", "Choose my own path", "Choose standard path", NULL); - auto path = "/mnt/ext1"; switch (dialogResult) { case 1: { + auto path = "/mnt/ext1"; FileBrowser fileBrowser = FileBrowser(false); vector currentFolder = fileBrowser.getFileStructure(path); _currentPath = path; @@ -390,7 +394,10 @@ int EventHandler::pointerHandler(const int type, const int par1, const int par2) _fileView = std::unique_ptr(new FileView(_menu->getContentRect(), currentFolder,1)); } break; + case 2: default: + if (iv_access(Util::accessConfig(Action::IReadString, "storageLocation",{}).c_str(), W_OK) != 0) + iv_mkdir(Util::accessConfig(Action::IReadString, "storageLocation",{}).c_str(), 0777); updateItems(currentWebDAVItems); drawWebDAVItems(currentWebDAVItems); break; @@ -549,6 +556,7 @@ int EventHandler::keyHandler(const int type, const int par1, const int par2) } +//TODO use Filebrowser void EventHandler::getLocalFileStructure(vector &items) { //get local files, https://stackoverflow.com/questions/306533/how-do-i-get-a-list-of-files-in-a-directory-in-c @@ -694,18 +702,19 @@ void EventHandler::updateItems(vector &items) { for(auto &item : items) { + //ICloud if is not found item.state = _sqllite.getState(item.path); if (item.type == Itemtype::IFILE) { - if(iv_access(item.localPath.c_str(), W_OK) != 0) + if (iv_access(item.localPath.c_str(), W_OK) != 0) item.state = FileState::ICLOUD; else item.state = FileState::ISYNCED; } else { - if(iv_access(item.localPath.c_str(), W_OK) != 0) + if (iv_access(item.localPath.c_str(), W_OK) != 0) iv_mkdir(item.localPath.c_str(), 0777); } diff --git a/src/ui/webDAVView/webDAVView.cpp b/src/ui/webDAVView/webDAVView.cpp index 9247593..ab42922 100644 --- a/src/ui/webDAVView/webDAVView.cpp +++ b/src/ui/webDAVView/webDAVView.cpp @@ -47,7 +47,7 @@ WebDAVView::WebDAVView(const irect &contentRect, vector &items, int sort(begin, items.end(), []( WebDAVItem &w1, WebDAVItem &w2) -> bool { - if(Util::accessConfig(Action::IReadInt, "sortBy", 0) == 2) + if(Util::accessConfig(Action::IReadInt, "sortBy", 0) == 2) { //sort by lastmodified time_t t1 = mktime(&w1.lastEditDate); diff --git a/src/util/util.h b/src/util/util.h index bcb9a5e..2f37d2f 100644 --- a/src/util/util.h +++ b/src/util/util.h @@ -12,6 +12,7 @@ #include "inkview.h" #include "eventHandler.h" +#include "log.h" #include enum class Action @@ -65,9 +66,6 @@ public: iconfig *config = OpenConfig(CONFIG_PATH.c_str(), temp); T returnValue; - if constexpr(std::is_same::value) - { - } if constexpr(std::is_same::value) { switch (action) @@ -77,14 +75,14 @@ public: returnValue = {}; break; case Action::IReadSecret: - returnValue = ReadSecret(config, name.c_str(), ""); + returnValue = ReadSecret(config, name.c_str(), "error"); break; case Action::IWriteString: WriteString(config, name.c_str(), value.c_str()); returnValue = {}; break; case Action::IReadString: - returnValue = ReadString(config, name.c_str(), ""); + returnValue = ReadString(config, name.c_str(), "error"); break; default: break;