Updated SoX binary to v14.4.2-Git (2014-10-06), compiled with ICL 15.0 and MSVC 12.0.
[LameXP.git] / src / Thread_DiskObserver.cpp
blobb5efa8134e6c8d016165811fada91a2655e92831
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2014 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
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"
25 #include "Global.h"
26 #include "Model_Progress.h"
28 #include <QDir>
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!");
54 try
56 observe();
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!");
63 catch(...)
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 = 0ui64;
76 bool ok = false;
78 forever
80 freeSpace = lamexp_free_diskspace(m_path, &ok);
81 if(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 / 1048576ui64)), QUTF8(QString::number(freeSpace / 1048576ui64)));
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 / 1048576ui64)), 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)
101 QDir dir(baseDir);
103 if(!dir.exists())
105 return baseDir;
108 bool success = true;
110 while(success)
112 success = dir.cdUp();
115 return dir.canonicalPath();
118 ////////////////////////////////////////////////////////////
119 // SLOTS
120 ////////////////////////////////////////////////////////////
122 /*NONE*/
124 ////////////////////////////////////////////////////////////
125 // EVENTS
126 ////////////////////////////////////////////////////////////
128 /*NONE*/