Copy. */
| 90 | |
| 91 | /* Copy. */ |
| 92 | Result ScriptUtils::copyFile(const std::string &source, const std::string &destination, const std::string &message, bool isARG) { |
| 93 | Result ret = NONE; |
| 94 | if (access(source.c_str(), F_OK) != 0) return COPY_ERROR; |
| 95 | |
| 96 | std::string _source, _dest; |
| 97 | _source = std::regex_replace(source, std::regex("%ARCHIVE_DEFAULT%"), config->archPath()); |
| 98 | _source = std::regex_replace(_source, std::regex("%3DSX%/(.*)\\.(.*)"), config->_3dsxPath() + (config->_3dsxInFolder() ? "/$1/$1.$2" : "/$1.$2")); |
| 99 | _source = std::regex_replace(_source, std::regex("%3DSX%"), config->_3dsxPath()); |
| 100 | _source = std::regex_replace(_source, std::regex("%NDS%"), config->ndsPath()); |
| 101 | _source = std::regex_replace(_source, std::regex("%FIRM%"), config->firmPath()); |
| 102 | |
| 103 | _dest = std::regex_replace(destination, std::regex("%ARCHIVE_DEFAULT%"), config->archPath()); |
| 104 | _dest = std::regex_replace(_dest, std::regex("%3DSX%/(.*)\\.(.*)"), config->_3dsxPath() + (config->_3dsxInFolder() ? "/$1/$1.$2" : "/$1.$2")); |
| 105 | _dest = std::regex_replace(_dest, std::regex("%3DSX%"), config->_3dsxPath()); |
| 106 | _dest = std::regex_replace(_dest, std::regex("%NDS%"), config->ndsPath()); |
| 107 | _dest = std::regex_replace(_dest, std::regex("%FIRM%"), config->firmPath()); |
| 108 | |
| 109 | if (isARG) { |
| 110 | snprintf(progressBarMsg, sizeof(progressBarMsg), message.c_str()); |
| 111 | showProgressBar = true; |
| 112 | progressbarType = ProgressBar::Copying; |
| 113 | |
| 114 | s32 prio = 0; |
| 115 | svcGetThreadPriority(&prio, CUR_THREAD_HANDLE); |
| 116 | thread = threadCreate((ThreadFunc)Animation::displayProgressBar, NULL, 64 * 1024, prio - 1, -2, false); |
| 117 | } |
| 118 | |
| 119 | /* If destination does not exist, create dirs. */ |
| 120 | if (access(_dest.c_str(), F_OK) != 0) makeDirs(_dest.c_str()); |
| 121 | ret = fcopy(_source.c_str(), _dest.c_str()); |
| 122 | |
| 123 | if (ret == -1) ret = COPY_ERROR; |
| 124 | else if (ret == 1) ret = NONE; |
| 125 | |
| 126 | if (isARG) { |
| 127 | showProgressBar = false; |
| 128 | threadJoin(thread, U64_MAX); |
| 129 | threadFree(thread); |
| 130 | } |
| 131 | |
| 132 | return ret; |
| 133 | } |
| 134 | |
| 135 | /* Rename / Move a file. */ |
| 136 | Result ScriptUtils::renameFile(const std::string &oldName, const std::string &newName, bool isARG) { |