Rename / Move a file. */
| 134 | |
| 135 | /* Rename / Move a file. */ |
| 136 | Result ScriptUtils::renameFile(const std::string &oldName, const std::string &newName, bool isARG) { |
| 137 | Result ret = NONE; |
| 138 | if (access(oldName.c_str(), F_OK) != 0) return MOVE_ERROR; |
| 139 | |
| 140 | std::string old, _new; |
| 141 | old = std::regex_replace(oldName, std::regex("%ARCHIVE_DEFAULT%"), config->archPath()); |
| 142 | old = std::regex_replace(old, std::regex("%3DSX%/(.*)\\.(.*)"), config->_3dsxPath() + (config->_3dsxInFolder() ? "/$1/$1.$2" : "/$1.$2")); |
| 143 | old = std::regex_replace(old, std::regex("%3DSX%"), config->_3dsxPath()); |
| 144 | old = std::regex_replace(old, std::regex("%NDS%"), config->ndsPath()); |
| 145 | old = std::regex_replace(old, std::regex("%FIRM%"), config->firmPath()); |
| 146 | |
| 147 | _new = std::regex_replace(newName, std::regex("%ARCHIVE_DEFAULT%"), config->archPath()); |
| 148 | _new = std::regex_replace(_new, std::regex("%3DSX%/(.*)\\.(.*)"), config->_3dsxPath() + (config->_3dsxInFolder() ? "/$1/$1.$2" : "/$1.$2")); |
| 149 | _new = std::regex_replace(_new, std::regex("%3DSX%"), config->_3dsxPath()); |
| 150 | _new = std::regex_replace(_new, std::regex("%NDS%"), config->ndsPath()); |
| 151 | _new = std::regex_replace(_new, std::regex("%FIRM%"), config->firmPath()); |
| 152 | |
| 153 | /* TODO: Kinda avoid that? */ |
| 154 | makeDirs(_new.c_str()); |
| 155 | rename(old.c_str(), _new.c_str()); |
| 156 | return ret; |
| 157 | } |
| 158 | |
| 159 | /* Download from GitHub Release. */ |
| 160 | Result ScriptUtils::downloadRelease(const std::string &repo, const std::string &file, const std::string &output, bool includePrereleases, const std::string &message, bool isARG) { |