diff options
Diffstat (limited to 'rbutil/rbutilqt/base/utils.cpp')
-rw-r--r-- | rbutil/rbutilqt/base/utils.cpp | 65 |
1 files changed, 33 insertions, 32 deletions
diff --git a/rbutil/rbutilqt/base/utils.cpp b/rbutil/rbutilqt/base/utils.cpp index 1aeea7f18c..6a817e86da 100644 --- a/rbutil/rbutilqt/base/utils.cpp +++ b/rbutil/rbutilqt/base/utils.cpp | |||
@@ -21,6 +21,7 @@ | |||
21 | #include "system.h" | 21 | #include "system.h" |
22 | #include "rbsettings.h" | 22 | #include "rbsettings.h" |
23 | #include "systeminfo.h" | 23 | #include "systeminfo.h" |
24 | #include "Logger.h" | ||
24 | 25 | ||
25 | #ifdef UNICODE | 26 | #ifdef UNICODE |
26 | #define _UNICODE | 27 | #define _UNICODE |
@@ -125,7 +126,7 @@ QString Utils::resolvePathCase(QString path) | |||
125 | else | 126 | else |
126 | return QString(""); | 127 | return QString(""); |
127 | } | 128 | } |
128 | qDebug() << "[Utils] resolving path" << path << "->" << realpath; | 129 | LOG_INFO() << "resolving path" << path << "->" << realpath; |
129 | return realpath; | 130 | return realpath; |
130 | } | 131 | } |
131 | 132 | ||
@@ -179,7 +180,7 @@ QString Utils::filesystemName(QString path) | |||
179 | } while(result == noErr); | 180 | } while(result == noErr); |
180 | #endif | 181 | #endif |
181 | 182 | ||
182 | qDebug() << "[Utils] Volume name of" << path << "is" << name; | 183 | LOG_INFO() << "Volume name of" << path << "is" << name; |
183 | return name; | 184 | return name; |
184 | } | 185 | } |
185 | 186 | ||
@@ -190,7 +191,7 @@ QString Utils::filesystemName(QString path) | |||
190 | qulonglong Utils::filesystemFree(QString path) | 191 | qulonglong Utils::filesystemFree(QString path) |
191 | { | 192 | { |
192 | qulonglong size = filesystemSize(path, FilesystemFree); | 193 | qulonglong size = filesystemSize(path, FilesystemFree); |
193 | qDebug() << "[Utils] free disk space for" << path << size; | 194 | LOG_INFO() << "free disk space for" << path << size; |
194 | return size; | 195 | return size; |
195 | } | 196 | } |
196 | 197 | ||
@@ -198,7 +199,7 @@ qulonglong Utils::filesystemFree(QString path) | |||
198 | qulonglong Utils::filesystemTotal(QString path) | 199 | qulonglong Utils::filesystemTotal(QString path) |
199 | { | 200 | { |
200 | qulonglong size = filesystemSize(path, FilesystemTotal); | 201 | qulonglong size = filesystemSize(path, FilesystemTotal); |
201 | qDebug() << "[Utils] total disk space for" << path << size; | 202 | LOG_INFO() << "total disk space for" << path << size; |
202 | return size; | 203 | return size; |
203 | } | 204 | } |
204 | 205 | ||
@@ -206,7 +207,7 @@ qulonglong Utils::filesystemTotal(QString path) | |||
206 | qulonglong Utils::filesystemClusterSize(QString path) | 207 | qulonglong Utils::filesystemClusterSize(QString path) |
207 | { | 208 | { |
208 | qulonglong size = filesystemSize(path, FilesystemClusterSize); | 209 | qulonglong size = filesystemSize(path, FilesystemClusterSize); |
209 | qDebug() << "[Utils] cluster size for" << path << size; | 210 | LOG_INFO() << "cluster size for" << path << size; |
210 | return size; | 211 | return size; |
211 | } | 212 | } |
212 | 213 | ||
@@ -273,7 +274,7 @@ QString Utils::findExecutable(QString name) | |||
273 | #elif defined(Q_OS_WIN) | 274 | #elif defined(Q_OS_WIN) |
274 | QStringList path = QString(getenv("PATH")).split(";", QString::SkipEmptyParts); | 275 | QStringList path = QString(getenv("PATH")).split(";", QString::SkipEmptyParts); |
275 | #endif | 276 | #endif |
276 | qDebug() << "[Utils] system path:" << path; | 277 | LOG_INFO() << "system path:" << path; |
277 | for(int i = 0; i < path.size(); i++) | 278 | for(int i = 0; i < path.size(); i++) |
278 | { | 279 | { |
279 | QString executable = QDir::fromNativeSeparators(path.at(i)) + "/" + name; | 280 | QString executable = QDir::fromNativeSeparators(path.at(i)) + "/" + name; |
@@ -284,11 +285,11 @@ QString Utils::findExecutable(QString name) | |||
284 | #endif | 285 | #endif |
285 | if(QFileInfo(executable).isExecutable()) | 286 | if(QFileInfo(executable).isExecutable()) |
286 | { | 287 | { |
287 | qDebug() << "[Utils] findExecutable: found" << executable; | 288 | LOG_INFO() << "findExecutable: found" << executable; |
288 | return QDir::toNativeSeparators(executable); | 289 | return QDir::toNativeSeparators(executable); |
289 | } | 290 | } |
290 | } | 291 | } |
291 | qDebug() << "[Utils] findExecutable: could not find" << name; | 292 | LOG_INFO() << "findExecutable: could not find" << name; |
292 | return ""; | 293 | return ""; |
293 | } | 294 | } |
294 | 295 | ||
@@ -299,7 +300,7 @@ QString Utils::findExecutable(QString name) | |||
299 | */ | 300 | */ |
300 | QString Utils::checkEnvironment(bool permission) | 301 | QString Utils::checkEnvironment(bool permission) |
301 | { | 302 | { |
302 | qDebug() << "[Utils] checking environment"; | 303 | LOG_INFO() << "checking environment"; |
303 | QString text = ""; | 304 | QString text = ""; |
304 | 305 | ||
305 | // check permission | 306 | // check permission |
@@ -338,7 +339,7 @@ QString Utils::checkEnvironment(bool permission) | |||
338 | */ | 339 | */ |
339 | int Utils::compareVersionStrings(QString s1, QString s2) | 340 | int Utils::compareVersionStrings(QString s1, QString s2) |
340 | { | 341 | { |
341 | qDebug() << "[Utils] comparing version strings" << s1 << "and" << s2; | 342 | LOG_INFO() << "comparing version strings" << s1 << "and" << s2; |
342 | QString a = s1.trimmed(); | 343 | QString a = s1.trimmed(); |
343 | QString b = s2.trimmed(); | 344 | QString b = s2.trimmed(); |
344 | // if strings are identical return 0. | 345 | // if strings are identical return 0. |
@@ -418,7 +419,7 @@ int Utils::compareVersionStrings(QString s1, QString s2) | |||
418 | */ | 419 | */ |
419 | QString Utils::resolveDevicename(QString path) | 420 | QString Utils::resolveDevicename(QString path) |
420 | { | 421 | { |
421 | qDebug() << "[Utils] resolving device name" << path; | 422 | LOG_INFO() << "resolving device name" << path; |
422 | #if defined(Q_OS_LINUX) | 423 | #if defined(Q_OS_LINUX) |
423 | FILE *mn = setmntent("/etc/mtab", "r"); | 424 | FILE *mn = setmntent("/etc/mtab", "r"); |
424 | if(!mn) | 425 | if(!mn) |
@@ -434,7 +435,7 @@ QString Utils::resolveDevicename(QString path) | |||
434 | && (QString(ent->mnt_type).contains("vfat", Qt::CaseInsensitive) | 435 | && (QString(ent->mnt_type).contains("vfat", Qt::CaseInsensitive) |
435 | || QString(ent->mnt_type).contains("hfs", Qt::CaseInsensitive))) { | 436 | || QString(ent->mnt_type).contains("hfs", Qt::CaseInsensitive))) { |
436 | endmntent(mn); | 437 | endmntent(mn); |
437 | qDebug() << "[Utils] device name is" << ent->mnt_fsname; | 438 | LOG_INFO() << "device name is" << ent->mnt_fsname; |
438 | return QString(ent->mnt_fsname); | 439 | return QString(ent->mnt_fsname); |
439 | } | 440 | } |
440 | } | 441 | } |
@@ -453,7 +454,7 @@ QString Utils::resolveDevicename(QString path) | |||
453 | if(QString(mntinf->f_mntonname) == path | 454 | if(QString(mntinf->f_mntonname) == path |
454 | && (QString(mntinf->f_fstypename).contains("msdos", Qt::CaseInsensitive) | 455 | && (QString(mntinf->f_fstypename).contains("msdos", Qt::CaseInsensitive) |
455 | || QString(mntinf->f_fstypename).contains("hfs", Qt::CaseInsensitive))) { | 456 | || QString(mntinf->f_fstypename).contains("hfs", Qt::CaseInsensitive))) { |
456 | qDebug() << "[Utils] device name is" << mntinf->f_mntfromname; | 457 | LOG_INFO() << "device name is" << mntinf->f_mntfromname; |
457 | return QString(mntinf->f_mntfromname); | 458 | return QString(mntinf->f_mntfromname); |
458 | } | 459 | } |
459 | mntinf++; | 460 | mntinf++; |
@@ -471,17 +472,17 @@ QString Utils::resolveDevicename(QString path) | |||
471 | h = CreateFile(uncpath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, | 472 | h = CreateFile(uncpath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, |
472 | NULL, OPEN_EXISTING, 0, NULL); | 473 | NULL, OPEN_EXISTING, 0, NULL); |
473 | if(h == INVALID_HANDLE_VALUE) { | 474 | if(h == INVALID_HANDLE_VALUE) { |
474 | //qDebug() << "error getting extents for" << uncpath; | 475 | //LOG_INFO() << "error getting extents for" << uncpath; |
475 | return ""; | 476 | return ""; |
476 | } | 477 | } |
477 | // get the extents | 478 | // get the extents |
478 | if(DeviceIoControl(h, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, | 479 | if(DeviceIoControl(h, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, |
479 | NULL, 0, extents, sizeof(buffer), &written, NULL)) { | 480 | NULL, 0, extents, sizeof(buffer), &written, NULL)) { |
480 | if(extents->NumberOfDiskExtents > 1) { | 481 | if(extents->NumberOfDiskExtents > 1) { |
481 | qDebug() << "[Utils] resolving device name: volume spans multiple disks!"; | 482 | LOG_INFO() << "resolving device name: volume spans multiple disks!"; |
482 | return ""; | 483 | return ""; |
483 | } | 484 | } |
484 | qDebug() << "[Utils] device name is" << extents->Extents[0].DiskNumber; | 485 | LOG_INFO() << "device name is" << extents->Extents[0].DiskNumber; |
485 | return QString("%1").arg(extents->Extents[0].DiskNumber); | 486 | return QString("%1").arg(extents->Extents[0].DiskNumber); |
486 | } | 487 | } |
487 | #endif | 488 | #endif |
@@ -496,7 +497,7 @@ QString Utils::resolveDevicename(QString path) | |||
496 | */ | 497 | */ |
497 | QString Utils::resolveMountPoint(QString device) | 498 | QString Utils::resolveMountPoint(QString device) |
498 | { | 499 | { |
499 | qDebug() << "[Utils] resolving mountpoint:" << device; | 500 | LOG_INFO() << "resolving mountpoint:" << device; |
500 | 501 | ||
501 | #if defined(Q_OS_LINUX) | 502 | #if defined(Q_OS_LINUX) |
502 | FILE *mn = setmntent("/etc/mtab", "r"); | 503 | FILE *mn = setmntent("/etc/mtab", "r"); |
@@ -511,11 +512,11 @@ QString Utils::resolveMountPoint(QString device) | |||
511 | QString result; | 512 | QString result; |
512 | if(QString(ent->mnt_type).contains("vfat", Qt::CaseInsensitive) | 513 | if(QString(ent->mnt_type).contains("vfat", Qt::CaseInsensitive) |
513 | || QString(ent->mnt_type).contains("hfs", Qt::CaseInsensitive)) { | 514 | || QString(ent->mnt_type).contains("hfs", Qt::CaseInsensitive)) { |
514 | qDebug() << "[Utils] resolved mountpoint is:" << ent->mnt_dir; | 515 | LOG_INFO() << "resolved mountpoint is:" << ent->mnt_dir; |
515 | result = QString(ent->mnt_dir); | 516 | result = QString(ent->mnt_dir); |
516 | } | 517 | } |
517 | else { | 518 | else { |
518 | qDebug() << "[Utils] mountpoint is wrong filesystem!"; | 519 | LOG_INFO() << "mountpoint is wrong filesystem!"; |
519 | } | 520 | } |
520 | endmntent(mn); | 521 | endmntent(mn); |
521 | return result; | 522 | return result; |
@@ -536,11 +537,11 @@ QString Utils::resolveMountPoint(QString device) | |||
536 | if(QString(mntinf->f_mntfromname) == device) { | 537 | if(QString(mntinf->f_mntfromname) == device) { |
537 | if(QString(mntinf->f_fstypename).contains("msdos", Qt::CaseInsensitive) | 538 | if(QString(mntinf->f_fstypename).contains("msdos", Qt::CaseInsensitive) |
538 | || QString(mntinf->f_fstypename).contains("hfs", Qt::CaseInsensitive)) { | 539 | || QString(mntinf->f_fstypename).contains("hfs", Qt::CaseInsensitive)) { |
539 | qDebug() << "[Utils] resolved mountpoint is:" << mntinf->f_mntonname; | 540 | LOG_INFO() << "resolved mountpoint is:" << mntinf->f_mntonname; |
540 | return QString(mntinf->f_mntonname); | 541 | return QString(mntinf->f_mntonname); |
541 | } | 542 | } |
542 | else { | 543 | else { |
543 | qDebug() << "[Utils] mountpoint is wrong filesystem!"; | 544 | LOG_INFO() << "mountpoint is wrong filesystem!"; |
544 | return QString(); | 545 | return QString(); |
545 | } | 546 | } |
546 | } | 547 | } |
@@ -556,14 +557,14 @@ QString Utils::resolveMountPoint(QString device) | |||
556 | for(letter = 'A'; letter <= 'Z'; letter++) { | 557 | for(letter = 'A'; letter <= 'Z'; letter++) { |
557 | if(resolveDevicename(QString(letter)).toUInt() == driveno) { | 558 | if(resolveDevicename(QString(letter)).toUInt() == driveno) { |
558 | result = letter; | 559 | result = letter; |
559 | qDebug() << "[Utils] resolved mountpoint is:" << result; | 560 | LOG_INFO() << "resolved mountpoint is:" << result; |
560 | break; | 561 | break; |
561 | } | 562 | } |
562 | } | 563 | } |
563 | if(!result.isEmpty()) | 564 | if(!result.isEmpty()) |
564 | return result + ":/"; | 565 | return result + ":/"; |
565 | #endif | 566 | #endif |
566 | qDebug() << "[Utils] resolving mountpoint failed!"; | 567 | LOG_INFO() << "resolving mountpoint failed!"; |
567 | return QString(""); | 568 | return QString(""); |
568 | } | 569 | } |
569 | 570 | ||
@@ -589,11 +590,11 @@ QStringList Utils::mountpoints(enum MountpointsFilter type) | |||
589 | QString fstype = QString::fromWCharArray(t); | 590 | QString fstype = QString::fromWCharArray(t); |
590 | if(type == MountpointsAll || supported.contains(fstype)) { | 591 | if(type == MountpointsAll || supported.contains(fstype)) { |
591 | tempList << list.at(i).absolutePath(); | 592 | tempList << list.at(i).absolutePath(); |
592 | qDebug() << "[Utils] Added:" << list.at(i).absolutePath() | 593 | LOG_INFO() << "Added:" << list.at(i).absolutePath() |
593 | << "type" << fstype; | 594 | << "type" << fstype; |
594 | } | 595 | } |
595 | else { | 596 | else { |
596 | qDebug() << "[Utils] Ignored:" << list.at(i).absolutePath() | 597 | LOG_INFO() << "Ignored:" << list.at(i).absolutePath() |
597 | << "type" << fstype; | 598 | << "type" << fstype; |
598 | } | 599 | } |
599 | } | 600 | } |
@@ -607,11 +608,11 @@ QStringList Utils::mountpoints(enum MountpointsFilter type) | |||
607 | while(num--) { | 608 | while(num--) { |
608 | if(type == MountpointsAll || supported.contains(mntinf->f_fstypename)) { | 609 | if(type == MountpointsAll || supported.contains(mntinf->f_fstypename)) { |
609 | tempList << QString(mntinf->f_mntonname); | 610 | tempList << QString(mntinf->f_mntonname); |
610 | qDebug() << "[Utils] Added:" << mntinf->f_mntonname | 611 | LOG_INFO() << "Added:" << mntinf->f_mntonname |
611 | << "is" << mntinf->f_mntfromname << "type" << mntinf->f_fstypename; | 612 | << "is" << mntinf->f_mntfromname << "type" << mntinf->f_fstypename; |
612 | } | 613 | } |
613 | else { | 614 | else { |
614 | qDebug() << "[Utils] Ignored:" << mntinf->f_mntonname | 615 | LOG_INFO() << "Ignored:" << mntinf->f_mntonname |
615 | << "is" << mntinf->f_mntfromname << "type" << mntinf->f_fstypename; | 616 | << "is" << mntinf->f_mntfromname << "type" << mntinf->f_fstypename; |
616 | } | 617 | } |
617 | mntinf++; | 618 | mntinf++; |
@@ -626,11 +627,11 @@ QStringList Utils::mountpoints(enum MountpointsFilter type) | |||
626 | while((ent = getmntent(mn))) { | 627 | while((ent = getmntent(mn))) { |
627 | if(type == MountpointsAll || supported.contains(ent->mnt_type)) { | 628 | if(type == MountpointsAll || supported.contains(ent->mnt_type)) { |
628 | tempList << QString(ent->mnt_dir); | 629 | tempList << QString(ent->mnt_dir); |
629 | qDebug() << "[Utils] Added:" << ent->mnt_dir | 630 | LOG_INFO() << "Added:" << ent->mnt_dir |
630 | << "is" << ent->mnt_fsname << "type" << ent->mnt_type; | 631 | << "is" << ent->mnt_fsname << "type" << ent->mnt_type; |
631 | } | 632 | } |
632 | else { | 633 | else { |
633 | qDebug() << "[Utils] Ignored:" << ent->mnt_dir | 634 | LOG_INFO() << "Ignored:" << ent->mnt_dir |
634 | << "is" << ent->mnt_fsname << "type" << ent->mnt_type; | 635 | << "is" << ent->mnt_fsname << "type" << ent->mnt_type; |
635 | } | 636 | } |
636 | } | 637 | } |
@@ -658,13 +659,13 @@ QStringList Utils::findRunningProcess(QStringList names) | |||
658 | 659 | ||
659 | hdl = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); | 660 | hdl = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); |
660 | if(hdl == INVALID_HANDLE_VALUE) { | 661 | if(hdl == INVALID_HANDLE_VALUE) { |
661 | qDebug() << "[Utils] CreateToolhelp32Snapshot failed."; | 662 | LOG_ERROR() << "CreateToolhelp32Snapshot failed."; |
662 | return found; | 663 | return found; |
663 | } | 664 | } |
664 | entry.dwSize = sizeof(PROCESSENTRY32); | 665 | entry.dwSize = sizeof(PROCESSENTRY32); |
665 | entry.szExeFile[0] = '\0'; | 666 | entry.szExeFile[0] = '\0'; |
666 | if(!Process32First(hdl, &entry)) { | 667 | if(!Process32First(hdl, &entry)) { |
667 | qDebug() << "[Utils] Process32First failed."; | 668 | LOG_ERROR() << "Process32First failed."; |
668 | return found; | 669 | return found; |
669 | } | 670 | } |
670 | 671 | ||
@@ -721,7 +722,7 @@ QStringList Utils::findRunningProcess(QStringList names) | |||
721 | found.append(processlist.at(index)); | 722 | found.append(processlist.at(index)); |
722 | } | 723 | } |
723 | } | 724 | } |
724 | qDebug() << "[Utils] Found listed processes running:" << found; | 725 | LOG_INFO() << "Found listed processes running:" << found; |
725 | return found; | 726 | return found; |
726 | } | 727 | } |
727 | 728 | ||