1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2020 LoRd_MuldeR <MuldeR2@GMX.de>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU GENERAL PUBLIC LICENSE as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version; always including the non-optional
9 // LAMEXP GNU GENERAL PUBLIC LICENSE ADDENDUM. See "License.txt" file!
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this program; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 // http://www.gnu.org/licenses/gpl-2.0.txt
21 ///////////////////////////////////////////////////////////////////////////////
23 #include "Thread_DiskObserver.h"
27 #include "Model_Progress.h"
30 #include <MUtils/Global.h>
31 #include <MUtils/OSSupport.h>
32 #include <MUtils/Exception.h>
37 #define MIN_DISKSPACE 104857600ui64 //100 MB
39 ////////////////////////////////////////////////////////////
40 // Constructor & Destructor
41 ////////////////////////////////////////////////////////////
43 DiskObserverThread::DiskObserverThread(const QString
&path
)
45 m_path(makeRootDir(path
))
49 DiskObserverThread::~DiskObserverThread(void)
53 ////////////////////////////////////////////////////////////
54 // Protected functions
55 ////////////////////////////////////////////////////////////
57 void DiskObserverThread::run(void)
59 qDebug("DiskSpace observer started!");
65 catch(const std::exception
&error
)
67 MUTILS_PRINT_ERROR("\nGURU MEDITATION !!!\n\nException error:\n%s\n", error
.what());
68 MUtils::OS::fatal_exit(L
"Unhandeled C++ exception error, application will exit!");
72 MUTILS_PRINT_ERROR("\nGURU MEDITATION !!!\n\nUnknown exception error!\n");
73 MUtils::OS::fatal_exit(L
"Unhandeled C++ exception error, application will exit!");
76 while(m_semaphore
.available()) m_semaphore
.tryAcquire();
79 void DiskObserverThread::observe(void)
81 quint64 minimumSpace
= MIN_DISKSPACE
;
82 quint64 previousSpace
= quint64(-1);
86 quint64 freeSpace
= 0ui
64;
87 if(MUtils::OS::free_diskspace(m_path
, freeSpace
))
89 if(freeSpace
< minimumSpace
)
91 qWarning("Free diskspace on '%s' dropped below %s MB, only %s MB free!", MUTILS_UTF8(m_path
), MUTILS_UTF8(QString::number(minimumSpace
/ 1048576ui
64)), MUTILS_UTF8(QString::number(freeSpace
/ 1048576ui
64)));
92 emit
messageLogged(tr("Low diskspace on drive '%1' detected (only %2 MB are free), problems can occur!").arg(QDir::toNativeSeparators(m_path
), QString::number(freeSpace
/ 1048576ui
64)), ProgressModel::SysMsg_Warning
);
93 minimumSpace
= qMin(freeSpace
, (minimumSpace
>> 1));
95 if(freeSpace
!= previousSpace
)
97 emit
freeSpaceChanged(freeSpace
);
98 previousSpace
= freeSpace
;
101 if(m_semaphore
.tryAcquire(1, 2000)) break;
105 QString
DiskObserverThread::makeRootDir(const QString
&baseDir
)
118 success
= dir
.cdUp();
121 return dir
.canonicalPath();
124 ////////////////////////////////////////////////////////////
126 ////////////////////////////////////////////////////////////
130 ////////////////////////////////////////////////////////////
132 ////////////////////////////////////////////////////////////