Fixed a typo, thanks to Rub3n CT for reporting.
[LameXP.git] / src / Thread_DiskObserver.cpp
blob564521bdf8781b0326d6d058d794b351b4907163
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2011 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.
9 //
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"
24 #include "Global.h"
26 #include <QDir>
28 #define MIN_DISKSPACE 104857600LL //100 MB
30 ////////////////////////////////////////////////////////////
31 // Constructor & Destructor
32 ////////////////////////////////////////////////////////////
34 DiskObserverThread::DiskObserverThread(const QString &path)
36 m_path(makeRootDir(path))
38 m_terminated = false;
41 DiskObserverThread::~DiskObserverThread(void)
45 ////////////////////////////////////////////////////////////
46 // Protected functions
47 ////////////////////////////////////////////////////////////
49 void DiskObserverThread::run(void)
51 qDebug("DiskSpace observer started!");
53 try
55 observe();
57 catch(...)
59 fflush(stdout);
60 fflush(stderr);
61 fprintf(stderr, "\nGURU MEDITATION !!!\n");
62 FatalAppExit(0, L"Unhandeled exception error, application will exit!");
63 TerminateProcess(GetCurrentProcess(), -1);
67 void DiskObserverThread::observe(void)
69 __int64 freeSpace, minimumSpace = MIN_DISKSPACE;
71 while(!m_terminated)
73 freeSpace = lamexp_free_diskspace(m_path);
74 if(freeSpace < minimumSpace)
76 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());
77 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)), true);
78 minimumSpace = min(freeSpace, (minimumSpace >> 1));
80 Sleep(1000);
84 QString DiskObserverThread::makeRootDir(const QString &baseDir)
86 QDir dir(baseDir);
88 if(!dir.exists())
90 return baseDir;
93 bool success = true;
95 while(success)
97 success = dir.cdUp();
100 return dir.canonicalPath();
103 ////////////////////////////////////////////////////////////
104 // SLOTS
105 ////////////////////////////////////////////////////////////
107 /*NONE*/
109 ////////////////////////////////////////////////////////////
110 // EVENTS
111 ////////////////////////////////////////////////////////////
113 /*NONE*/