1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2014 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, but always including the *additional*
9 // restrictions defined in the "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"
26 #include "Model_Progress.h"
30 #define MIN_DISKSPACE 104857600ui64 //100 MB
32 ////////////////////////////////////////////////////////////
33 // Constructor & Destructor
34 ////////////////////////////////////////////////////////////
36 DiskObserverThread::DiskObserverThread(const QString
&path
)
38 m_path(makeRootDir(path
))
42 DiskObserverThread::~DiskObserverThread(void)
46 ////////////////////////////////////////////////////////////
47 // Protected functions
48 ////////////////////////////////////////////////////////////
50 void DiskObserverThread::run(void)
52 qDebug("DiskSpace observer started!");
58 catch(const std::exception
&error
)
60 PRINT_ERROR("\nGURU MEDITATION !!!\n\nException error:\n%s\n", error
.what());
61 lamexp_fatal_exit("Unhandeled C++ exception error, application will exit!");
65 PRINT_ERROR("\nGURU MEDITATION !!!\n\nUnknown exception error!\n");
66 lamexp_fatal_exit("Unhandeled C++ exception error, application will exit!");
69 while(m_semaphore
.available()) m_semaphore
.tryAcquire();
72 void DiskObserverThread::observe(void)
74 unsigned __int64 minimumSpace
= MIN_DISKSPACE
;
75 unsigned __int64 freeSpace
, previousSpace
= 0ui
64;
80 freeSpace
= lamexp_free_diskspace(m_path
, &ok
);
83 if(freeSpace
< minimumSpace
)
85 qWarning("Free diskspace on '%s' dropped below %s MB, only %s MB free!", QUTF8(m_path
), QUTF8(QString::number(minimumSpace
/ 1048576ui
64)), QUTF8(QString::number(freeSpace
/ 1048576ui
64)));
86 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
);
87 minimumSpace
= qMin(freeSpace
, (minimumSpace
>> 1));
89 if(freeSpace
!= previousSpace
)
91 emit
freeSpaceChanged(freeSpace
);
92 previousSpace
= freeSpace
;
95 if(m_semaphore
.tryAcquire(1, 2000)) break;
99 QString
DiskObserverThread::makeRootDir(const QString
&baseDir
)
112 success
= dir
.cdUp();
115 return dir
.canonicalPath();
118 ////////////////////////////////////////////////////////////
120 ////////////////////////////////////////////////////////////
124 ////////////////////////////////////////////////////////////
126 ////////////////////////////////////////////////////////////