From a7126f42d2c39d005e790bb9cab90bc4d0b12969 Mon Sep 17 00:00:00 2001 From: lordmulder Date: Sun, 30 Oct 2011 21:41:00 +0100 Subject: [PATCH] Display "N/A" if CPU usage cannot be determined (as on Win2k). --- etc/Translation/Blank.ts | 40 +++++++++++------------ etc/Translation/LameXP_PL.ts | 40 +++++++++++------------ gui/ProcessingDialog.ui | 4 +-- src/Config.h | 2 +- src/Dialog_Processing.cpp | 8 +++-- src/Thread_CPUObserver.cpp | 76 +++++++++++++++++++++++--------------------- 6 files changed, 87 insertions(+), 83 deletions(-) diff --git a/etc/Translation/Blank.ts b/etc/Translation/Blank.ts index a018c88a..e94d8006 100644 --- a/etc/Translation/Blank.ts +++ b/etc/Translation/Blank.ts @@ -2653,94 +2653,94 @@ - + Encoding files, please wait... - + Multi-threading enabled: Running %1 instances in parallel! - + Aborted! Waiting for running jobs to terminate... - + Encoding: %1 files of %2 completed so far, please wait... - + Creating the playlist file, please wait... - + Process was aborted by the user after %1 file(s)! - + Process was aborted prematurely by the user! - + LameXP - Aborted - + Process was aborted by the user. - + Error: %1 of %2 files failed. Double-click failed items for detailed information! - + LameXP - Error - + At least one file has failed! - - + + All files completed successfully. - + LameXP - Done - + Playlist creation failed - + The playlist file could not be created: - + Warning: Computer will shutdown in %1 seconds... - - + + Cancel Shutdown diff --git a/etc/Translation/LameXP_PL.ts b/etc/Translation/LameXP_PL.ts index 59fc2ce3..edd5d250 100644 --- a/etc/Translation/LameXP_PL.ts +++ b/etc/Translation/LameXP_PL.ts @@ -2653,94 +2653,94 @@ Twoje pliki są właśnie kompresowane, prosze być cierpliwy... - + Encoding files, please wait... Kompresowanie plików, prosze czekać... - + Multi-threading enabled: Running %1 instances in parallel! Wielowątkowosć włączona: Równolegle wykonywanych jest %1 kodowań! - + Aborted! Waiting for running jobs to terminate... Przerwano! Czekanie na wyłączenie procesu... - + Encoding: %1 files of %2 completed so far, please wait... Kompresja: Prosze czekać, jak dotąd wykonano %1 z %2 plików... - + Creating the playlist file, please wait... Tworzenie pliku playlisty, prosze czekać... - + Process was aborted by the user after %1 file(s)! Proces został przerwany przez użytkownika po wykonaniu %1 plików! - + Process was aborted prematurely by the user! Proces został przedwcześnie zakończony przez użytkownika! - + LameXP - Aborted LameXP - Przerwano - + Process was aborted by the user. Proces został przerwany przez użytkownika. - + Error: %1 of %2 files failed. Double-click failed items for detailed information! Błąd: %1 z %2 plików nie zostało skompresowanych. Kliknij dwukrotnie na plik aby zobaczyć szczegóły! - + LameXP - Error LameXP - Błąd - + At least one file has failed! Przynajmniej jeden plik nie został skompresowany! - - + + All files completed successfully. Kompresja wszystkich plików zakończona powodzeniem. - + LameXP - Done LameXP - Zrobione - + Playlist creation failed Tworzenie playlisty zakończone niepowodzeniem - + The playlist file could not be created: Playlista nie mogła zostać utworzona: - + Warning: Computer will shutdown in %1 seconds... Ostrzeżenie: Komputer zostanie zamknięty za %1 sekund/y... - - + + Cancel Shutdown Anuluj wyłączenie komputera diff --git a/gui/ProcessingDialog.ui b/gui/ProcessingDialog.ui index c99d5d95..57d2055b 100644 --- a/gui/ProcessingDialog.ui +++ b/gui/ProcessingDialog.ui @@ -416,7 +416,7 @@ QFrame::VLine - QFrame::Raised + QFrame::Sunken @@ -495,7 +495,7 @@ QFrame::VLine - QFrame::Raised + QFrame::Sunken diff --git a/src/Config.h b/src/Config.h index a0e96179..8cddad14 100644 --- a/src/Config.h +++ b/src/Config.h @@ -30,7 +30,7 @@ #define VER_LAMEXP_MINOR_LO 3 #define VER_LAMEXP_TYPE RC #define VER_LAMEXP_PATCH 3 -#define VER_LAMEXP_BUILD 762 +#define VER_LAMEXP_BUILD 763 /////////////////////////////////////////////////////////////////////////////// // Tools versions diff --git a/src/Dialog_Processing.cpp b/src/Dialog_Processing.cpp index 89f34e0f..89a1bd27 100644 --- a/src/Dialog_Processing.cpp +++ b/src/Dialog_Processing.cpp @@ -244,6 +244,8 @@ ProcessingDialog::~ProcessingDialog(void) void ProcessingDialog::showEvent(QShowEvent *event) { + static const char *NA = " N/A"; + setCloseButtonEnabled(false); button_closeDialog->setEnabled(false); button_AbortProcess->setEnabled(false); @@ -254,9 +256,9 @@ void ProcessingDialog::showEvent(QShowEvent *event) SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); } - ramUsageHasChanged(0.0); - cpuUsageHasChanged(0.0); - diskUsageHasChanged(0ui64); + label_cpu->setText(NA); + label_disk->setText(NA); + label_ram->setText(NA); QTimer::singleShot(1000, this, SLOT(initEncoding())); } diff --git a/src/Thread_CPUObserver.cpp b/src/Thread_CPUObserver.cpp index dacc247b..209f0111 100644 --- a/src/Thread_CPUObserver.cpp +++ b/src/Thread_CPUObserver.cpp @@ -74,63 +74,65 @@ ULONGLONG CPUObserverThread::filetime2ulonglong(const void *ftime) void CPUObserverThread::observe(void) { - ULONGLONG sys[2], usr[2], idl[2]; - FILETIME sysTime, usrTime, idlTime; QLibrary kernel32("kernel32.dll"); GetSystemTimesPtr getSystemTimes = NULL; - bool first = true; - double previous = -1.0; if(kernel32.load()) { getSystemTimes = reinterpret_cast(kernel32.resolve("GetSystemTimes")); } - if(getSystemTimes == NULL) + if(getSystemTimes != NULL) { - qWarning("GetSystemTimes() ist not available on this system!"); - return; - } - - for(size_t i = 0; i < 2; i++) - { - sys[i] = 0; usr[i] = 0; idl[i] = 0; - } + bool first = true; + double previous = -1.0; + FILETIME sysTime, usrTime, idlTime; + ULONGLONG sys[2], usr[2], idl[2]; - while(!m_terminated) - { - if(getSystemTimes(&idlTime, &sysTime, &usrTime)) + for(size_t i = 0; i < 2; i++) { - sys[1] = sys[0]; sys[0] = filetime2ulonglong(&sysTime); - usr[1] = usr[0]; usr[0] = filetime2ulonglong(&usrTime); - idl[1] = idl[0]; idl[0] = filetime2ulonglong(&idlTime); + sys[i] = 0; usr[i] = 0; idl[i] = 0; + } - if(first) + while(!m_terminated) + { + if(getSystemTimes(&idlTime, &sysTime, &usrTime)) { - first = false; - emit currentUsageChanged(1.0); - msleep(250); - continue; - } + sys[1] = sys[0]; sys[0] = filetime2ulonglong(&sysTime); + usr[1] = usr[0]; usr[0] = filetime2ulonglong(&usrTime); + idl[1] = idl[0]; idl[0] = filetime2ulonglong(&idlTime); - ULONGLONG timeIdl = (idl[0] - idl[1]); //Idle time only - ULONGLONG timeSys = (sys[0] - sys[1]); //Kernel mode time (incl. Idle time!) - ULONGLONG timeUsr = (usr[0] - usr[1]); //User mode time only + if(first) + { + first = false; + emit currentUsageChanged(1.0); + msleep(250); + continue; + } + + ULONGLONG timeIdl = (idl[0] - idl[1]); //Idle time only + ULONGLONG timeSys = (sys[0] - sys[1]); //Kernel mode time (incl. Idle time!) + ULONGLONG timeUsr = (usr[0] - usr[1]); //User mode time only - ULONGLONG timeSum = timeUsr + timeSys; //Overall CPU time that has elapsed - ULONGLONG timeWrk = timeSum - timeIdl; //Time the CPU spent working + ULONGLONG timeSum = timeUsr + timeSys; //Overall CPU time that has elapsed + ULONGLONG timeWrk = timeSum - timeIdl; //Time the CPU spent working - if((timeSum > 0) || (timeWrk > 0)) - { - double current = static_cast(timeWrk) / static_cast(timeSum); - if(current != previous) + if(timeSum > 0) { - emit currentUsageChanged(current); - previous = current; + double current = static_cast(timeWrk) / static_cast(timeSum); + if(current != previous) + { + emit currentUsageChanged(current); + previous = current; + } } } + msleep(1000); } - msleep(1000); + } + else + { + qWarning("GetSystemTimes() ist not available on this system!"); } } -- 2.11.0