1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2012 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.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
22 #include "Thread_DiskObserver.h"
25 #include "Model_Progress.h"
29 #define MIN_DISKSPACE 104857600ui64 //100 MB
31 ////////////////////////////////////////////////////////////
32 // Constructor & Destructor
33 ////////////////////////////////////////////////////////////
35 DiskObserverThread::DiskObserverThread(const QString &path)
37 m_path(makeRootDir(path))
41 DiskObserverThread::~DiskObserverThread(void)
45 ////////////////////////////////////////////////////////////
46 // Protected functions
47 ////////////////////////////////////////////////////////////
49 void DiskObserverThread::run(void)
51 qDebug("DiskSpace observer started!");
61 fprintf(stderr, "\nGURU MEDITATION !!!\n");
62 FatalAppExit(0, L"Unhandeled exception error, application will exit!");
63 TerminateProcess(GetCurrentProcess(), -1);
66 while(m_semaphore.available()) m_semaphore.tryAcquire();
69 void DiskObserverThread::observe(void)
71 unsigned __int64 minimumSpace = MIN_DISKSPACE;
72 unsigned __int64 freeSpace, previousSpace = 0ui64;
77 freeSpace = lamexp_free_diskspace(m_path, &ok);
80 if(freeSpace < minimumSpace)
82 qWarning("Free diskspace on '%s' dropped below %s MB, only %s MB free!", m_path.toUtf8().constData(), QString::number(minimumSpace / 1048576ui64).toUtf8().constData(), QString::number(freeSpace / 1048576ui64).toUtf8().constData());
83 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);
84 minimumSpace = qMin(freeSpace, (minimumSpace >> 1));
86 if(freeSpace != previousSpace)
88 emit freeSpaceChanged(freeSpace);
89 previousSpace = freeSpace;
92 if(m_semaphore.tryAcquire(1, 2000)) break;
96 QString DiskObserverThread::makeRootDir(const QString &baseDir)
109 success = dir.cdUp();
112 return dir.canonicalPath();
115 ////////////////////////////////////////////////////////////
117 ////////////////////////////////////////////////////////////
121 ////////////////////////////////////////////////////////////
123 ////////////////////////////////////////////////////////////