MCPcopy Create free account
hub / github.com/Universal-Team/Universal-Updater / copyFile

Method copyFile

source/utils/scriptUtils.cpp:92–133  ·  view source on GitHub ↗

Copy. */

Source from the content-addressed store, hash-verified

90
91/* Copy. */
92Result 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. */
136Result ScriptUtils::renameFile(const std::string &oldName, const std::string &newName, bool isARG) {

Callers

nothing calls this directly

Calls 7

makeDirsFunction · 0.85
fcopyFunction · 0.85
archPathMethod · 0.80
_3dsxPathMethod · 0.80
_3dsxInFolderMethod · 0.80
ndsPathMethod · 0.80
firmPathMethod · 0.80

Tested by

no test coverage detected