139 |
|
return isDouble; |
140 |
|
} |
141 |
|
|
142 |
< |
//Copied from here: http://stackoverflow.com/questions/2536524/copy-directory-using-qt (ty roop) |
143 |
< |
bool cpDir(const QString &srcPath, const QString &dstPath) |
142 |
> |
// from here: https://gzeki.com/blog/view/Recursive_copy_files_from_one_directory_to_another_in_C++_(Qt_5) |
143 |
> |
bool copyDir(QString from_dir, QString to_dir, bool replace_on_conflit) |
144 |
|
{ |
145 |
< |
rmDir(dstPath); |
145 |
> |
QDir dir; |
146 |
> |
dir.setPath(from_dir); |
147 |
|
|
148 |
< |
QDir parentDstDir(QFileInfo(dstPath).path()); |
149 |
< |
if (!parentDstDir.mkdir(QFileInfo(dstPath).fileName())) |
150 |
< |
return false; |
151 |
< |
|
152 |
< |
QDir srcDir(srcPath); |
153 |
< |
foreach(const QFileInfo &info, srcDir.entryInfoList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot)) { |
154 |
< |
QString srcItemPath = srcPath + "/" + info.fileName(); |
155 |
< |
QString dstItemPath = dstPath + "/" + info.fileName(); |
156 |
< |
if (info.isDir()) { |
157 |
< |
if (!cpDir(srcItemPath, dstItemPath)) { |
158 |
< |
return false; |
148 |
> |
from_dir += QDir::separator(); |
149 |
> |
to_dir += QDir::separator(); |
150 |
> |
|
151 |
> |
foreach (QString copy_file, dir.entryList(QDir::Files)) |
152 |
> |
{ |
153 |
> |
QString from = from_dir + copy_file; |
154 |
> |
QString to = to_dir + copy_file; |
155 |
> |
|
156 |
> |
if (QFile::exists(to)) |
157 |
> |
{ |
158 |
> |
if (replace_on_conflit) |
159 |
> |
{ |
160 |
> |
if (QFile::remove(to) == false) |
161 |
> |
{ |
162 |
> |
return false; |
163 |
> |
} |
164 |
|
} |
165 |
< |
} else if (info.isFile()) { |
166 |
< |
if (!QFile::copy(srcItemPath, dstItemPath)) { |
167 |
< |
return false; |
165 |
> |
else |
166 |
> |
{ |
167 |
> |
continue; |
168 |
|
} |
169 |
< |
} else { |
170 |
< |
qDebug("Unhandled item" + info.filePath().toUtf8() + "in cpDir"); |
169 |
> |
} |
170 |
> |
|
171 |
> |
if (QFile::copy(from, to) == false) |
172 |
> |
{ |
173 |
> |
return false; |
174 |
|
} |
175 |
|
} |
176 |
+ |
|
177 |
+ |
foreach (QString copy_dir, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) |
178 |
+ |
{ |
179 |
+ |
QString from = from_dir + copy_dir; |
180 |
+ |
QString to = to_dir + copy_dir; |
181 |
+ |
|
182 |
+ |
if (dir.mkpath(to) == false) |
183 |
+ |
{ |
184 |
+ |
return false; |
185 |
+ |
} |
186 |
+ |
|
187 |
+ |
if (copyDir(from, to, replace_on_conflit) == false) |
188 |
+ |
{ |
189 |
+ |
return false; |
190 |
+ |
} |
191 |
+ |
} |
192 |
+ |
|
193 |
|
return true; |
194 |
|
} |
195 |
|
|
212 |
|
return parentDir.rmdir(QFileInfo(dirPath).fileName()); |
213 |
|
} |
214 |
|
|
215 |
+ |
|
216 |
|
QString fullTrim(QString str) { |
217 |
|
|
218 |
|
str = str.simplified(); //convert all invisible chars in normal whitespaces |
222 |
|
} |
223 |
|
|
224 |
|
void openLogFile(){ |
225 |
< |
QDesktopServices::openUrl(QUrl("file:///"+QDir::currentPath()+"/"+GlobalVars::AppLogName)); |
225 |
> |
QDesktopServices::openUrl(QUrl("file:///"+Util::getAppPath()+"/"+GlobalVars::AppLogName)); |
226 |
|
} |
227 |
|
|
228 |
|
//Searches for the QString "toSearch" in the "myString" variable backward |
276 |
|
return widget.availableGeometry(widget.primaryScreen()); // or screenGeometry(), depending on your needs |
277 |
|
} |
278 |
|
|
279 |
+ |
/** |
280 |
+ |
Gets application directory. In mac os gets the .app directory |
281 |
+ |
**/ |
282 |
+ |
QString getOSIndependentAppPath(){ |
283 |
+ |
#ifdef Q_OS_MAC |
284 |
+ |
QDir dir = QDir(QCoreApplication::applicationDirPath()); |
285 |
+ |
if(dir.absolutePath().contains(".app")){ // include bundle, but we don't want it |
286 |
+ |
dir.cdUp(); |
287 |
+ |
dir.cdUp(); |
288 |
+ |
dir.cdUp(); |
289 |
+ |
} |
290 |
+ |
return dir.absolutePath(); |
291 |
+ |
#else |
292 |
+ |
return QDir::currentPath(); |
293 |
+ |
#endif |
294 |
+ |
} |
295 |
+ |
|
296 |
+ |
QString getAppPath(){ |
297 |
+ |
return getOSIndependentAppPath(); |
298 |
+ |
} |
299 |
+ |
|
300 |
+ |
QString getOniSplitExeName(){ |
301 |
+ |
|
302 |
+ |
#ifdef Q_OS_MAC |
303 |
+ |
return getMonoExecutablePath() + " " + GlobalVars::OniSplitString; |
304 |
+ |
#elif |
305 |
+ |
return GlobalVars::OniSplitString; |
306 |
+ |
#endif |
307 |
+ |
} |
308 |
+ |
|
309 |
+ |
QString getXmlToolsExeName(){ |
310 |
+ |
|
311 |
+ |
#ifdef Q_OS_MAC |
312 |
+ |
return getMonoExecutablePath() + " " + GlobalVars::XmlToolsString; |
313 |
+ |
#elif |
314 |
+ |
return GlobalVars::XmlToolsString; |
315 |
+ |
#endif |
316 |
+ |
} |
317 |
+ |
|
318 |
+ |
#ifdef Q_OS_MAC |
319 |
+ |
QString getMonoExecutablePath(){ |
320 |
+ |
|
321 |
+ |
// Only way that I found to get mono working in 10.11 |
322 |
+ |
QString possibleMonoDir = "/usr/local/bin/mono"; |
323 |
+ |
QFileInfo checkFile(possibleMonoDir); |
324 |
+ |
|
325 |
+ |
if (checkFile.exists() && checkFile.isFile()) { |
326 |
+ |
return possibleMonoDir; |
327 |
+ |
} else { |
328 |
+ |
return "mono"; |
329 |
+ |
} |
330 |
+ |
|
331 |
+ |
} |
332 |
+ |
#endif |
333 |
+ |
|
334 |
|
} |