2012-06-25 17:59:17 +00:00
|
|
|
// * This file is part of the COLOBOT source code
|
|
|
|
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
|
|
|
|
// * Copyright (C) 2012, Polish Portal of Colobot (PPC)
|
|
|
|
// *
|
|
|
|
// * This program is free software: you can redistribute it and/or modify
|
|
|
|
// * it under the terms of the GNU General Public License as published by
|
|
|
|
// * the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// * (at your option) any later version.
|
|
|
|
// *
|
|
|
|
// * This program is distributed in the hope that it will be useful,
|
|
|
|
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// * GNU General Public License for more details.
|
|
|
|
// *
|
|
|
|
// * You should have received a copy of the GNU General Public License
|
|
|
|
// * along with this program. If not, see http://www.gnu.org/licenses/.
|
|
|
|
|
|
|
|
|
|
|
|
#include "app/system.h"
|
|
|
|
|
|
|
|
#include "common/config.h"
|
|
|
|
|
2012-07-15 17:17:49 +00:00
|
|
|
|
2012-06-25 17:59:17 +00:00
|
|
|
#if defined(PLATFORM_WINDOWS)
|
2013-03-23 23:03:37 +00:00
|
|
|
#include "app/system_windows.h"
|
2012-06-25 17:59:17 +00:00
|
|
|
#elif defined(PLATFORM_LINUX)
|
2013-03-23 23:03:37 +00:00
|
|
|
#include "app/system_linux.h"
|
2013-10-30 16:27:05 +00:00
|
|
|
#elif defined(PLATFORM_MACOSX)
|
|
|
|
#include "app/system_macosx.h"
|
2012-06-25 17:59:17 +00:00
|
|
|
#else
|
2013-03-23 23:03:37 +00:00
|
|
|
#include "app/system_other.h"
|
2012-06-25 17:59:17 +00:00
|
|
|
#endif
|
|
|
|
|
2012-07-15 17:17:49 +00:00
|
|
|
#include <cassert>
|
2013-03-23 23:03:37 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
|
|
template<>
|
|
|
|
CSystemUtils* CSingleton<CSystemUtils>::m_instance = nullptr;
|
2012-06-25 17:59:17 +00:00
|
|
|
|
|
|
|
|
2013-03-23 23:03:37 +00:00
|
|
|
CSystemUtils::CSystemUtils()
|
2012-06-25 17:59:17 +00:00
|
|
|
{
|
2013-03-23 23:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CSystemUtils* CSystemUtils::Create()
|
|
|
|
{
|
|
|
|
assert(m_instance == nullptr);
|
2012-07-15 17:17:49 +00:00
|
|
|
#if defined(PLATFORM_WINDOWS)
|
2013-03-23 23:03:37 +00:00
|
|
|
m_instance = new CSystemUtilsWindows();
|
2012-07-15 17:17:49 +00:00
|
|
|
#elif defined(PLATFORM_LINUX)
|
2013-03-23 23:03:37 +00:00
|
|
|
m_instance = new CSystemUtilsLinux();
|
2013-10-30 16:27:05 +00:00
|
|
|
#elif defined(PLATFORM_MACOSX)
|
|
|
|
m_instance = new CSystemUtilsMacOSX();
|
2012-07-15 17:17:49 +00:00
|
|
|
#else
|
2013-03-23 23:03:37 +00:00
|
|
|
m_instance = new CSystemUtilsOther();
|
2012-07-15 17:17:49 +00:00
|
|
|
#endif
|
2013-03-23 23:03:37 +00:00
|
|
|
return m_instance;
|
2012-06-25 17:59:17 +00:00
|
|
|
}
|
|
|
|
|
2013-03-23 23:03:37 +00:00
|
|
|
SystemDialogResult CSystemUtils::ConsoleSystemDialog(SystemDialogType type, const std::string& title, const std::string& message)
|
2012-06-25 17:59:17 +00:00
|
|
|
{
|
2013-03-23 23:03:37 +00:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case SDT_INFO:
|
|
|
|
std::cout << "INFO: ";
|
|
|
|
break;
|
|
|
|
case SDT_WARNING:
|
|
|
|
std::cout << "WARNING:";
|
|
|
|
break;
|
|
|
|
case SDT_ERROR:
|
|
|
|
std::cout << "ERROR: ";
|
|
|
|
break;
|
|
|
|
case SDT_YES_NO:
|
|
|
|
case SDT_OK_CANCEL:
|
|
|
|
std::cout << "QUESTION: ";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cout << message << std::endl;
|
|
|
|
|
|
|
|
std::string line;
|
|
|
|
|
|
|
|
SystemDialogResult result = SDR_OK;
|
|
|
|
|
|
|
|
bool done = false;
|
|
|
|
while (!done)
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case SDT_INFO:
|
|
|
|
case SDT_WARNING:
|
|
|
|
case SDT_ERROR:
|
|
|
|
std::cout << "Press ENTER to continue";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SDT_YES_NO:
|
|
|
|
std::cout << "Type 'Y' for Yes or 'N' for No";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SDT_OK_CANCEL:
|
|
|
|
std::cout << "Type 'O' for OK or 'C' for Cancel";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::getline(std::cin, line);
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case SDT_INFO:
|
|
|
|
case SDT_WARNING:
|
|
|
|
case SDT_ERROR:
|
|
|
|
done = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SDT_YES_NO:
|
|
|
|
if (line == "Y" || line == "y")
|
|
|
|
{
|
|
|
|
result = SDR_YES;
|
|
|
|
done = true;
|
|
|
|
}
|
|
|
|
else if (line == "N" || line == "n")
|
|
|
|
{
|
|
|
|
result = SDR_NO;
|
|
|
|
done = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SDT_OK_CANCEL:
|
|
|
|
if (line == "O" || line == "o")
|
|
|
|
{
|
|
|
|
done = true;
|
|
|
|
result = SDR_OK;
|
|
|
|
}
|
|
|
|
else if (line == "C" || line == "c")
|
|
|
|
{
|
|
|
|
done = true;
|
|
|
|
result = SDR_CANCEL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2012-06-25 17:59:17 +00:00
|
|
|
}
|
|
|
|
|
2013-03-23 23:03:37 +00:00
|
|
|
SystemTimeStamp* CSystemUtils::CreateTimeStamp()
|
2012-06-25 17:59:17 +00:00
|
|
|
{
|
2013-03-23 23:03:37 +00:00
|
|
|
return new SystemTimeStamp();
|
2012-06-25 17:59:17 +00:00
|
|
|
}
|
|
|
|
|
2013-03-23 23:03:37 +00:00
|
|
|
void CSystemUtils::DestroyTimeStamp(SystemTimeStamp *stamp)
|
2012-06-25 17:59:17 +00:00
|
|
|
{
|
2013-03-23 23:03:37 +00:00
|
|
|
delete stamp;
|
2012-06-25 17:59:17 +00:00
|
|
|
}
|
|
|
|
|
2013-03-23 23:03:37 +00:00
|
|
|
void CSystemUtils::CopyTimeStamp(SystemTimeStamp *dst, SystemTimeStamp *src)
|
2012-07-15 17:17:49 +00:00
|
|
|
{
|
2013-03-23 23:03:37 +00:00
|
|
|
*dst = *src;
|
2012-07-15 17:17:49 +00:00
|
|
|
}
|
2012-06-25 17:59:17 +00:00
|
|
|
|
2013-03-23 23:03:37 +00:00
|
|
|
float CSystemUtils::GetTimeStampResolution(SystemTimeUnit unit)
|
2012-06-25 17:59:17 +00:00
|
|
|
{
|
2013-03-23 23:03:37 +00:00
|
|
|
unsigned long long exact = GetTimeStampExactResolution();
|
2012-07-15 17:17:49 +00:00
|
|
|
float result = 0.0f;
|
|
|
|
if (unit == STU_SEC)
|
|
|
|
result = exact * 1e-9;
|
|
|
|
else if (unit == STU_MSEC)
|
|
|
|
result = exact * 1e-6;
|
|
|
|
else if (unit == STU_USEC)
|
|
|
|
result = exact * 1e-3;
|
|
|
|
else
|
|
|
|
assert(false);
|
2013-03-23 23:03:37 +00:00
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
return result;
|
2012-06-25 17:59:17 +00:00
|
|
|
}
|
|
|
|
|
2013-03-23 23:03:37 +00:00
|
|
|
float CSystemUtils::TimeStampDiff(SystemTimeStamp *before, SystemTimeStamp *after, SystemTimeUnit unit)
|
2012-07-15 17:17:49 +00:00
|
|
|
{
|
2013-03-23 23:03:37 +00:00
|
|
|
long long exact = TimeStampExactDiff(before, after);
|
2012-06-25 17:59:17 +00:00
|
|
|
|
2012-07-15 17:17:49 +00:00
|
|
|
float result = 0.0f;
|
|
|
|
if (unit == STU_SEC)
|
|
|
|
result = exact * 1e-9;
|
|
|
|
else if (unit == STU_MSEC)
|
|
|
|
result = exact * 1e-6;
|
|
|
|
else if (unit == STU_USEC)
|
|
|
|
result = exact * 1e-3;
|
|
|
|
else
|
|
|
|
assert(false);
|
|
|
|
|
2013-03-23 23:03:37 +00:00
|
|
|
return result;
|
2012-07-15 17:17:49 +00:00
|
|
|
}
|
2013-03-27 09:20:06 +00:00
|
|
|
|
2013-05-26 15:47:54 +00:00
|
|
|
std::string CSystemUtils::GetProfileFileLocation()
|
2013-03-27 09:20:06 +00:00
|
|
|
{
|
2013-05-26 15:47:54 +00:00
|
|
|
return std::string("colobot.ini");
|
2013-03-27 09:20:06 +00:00
|
|
|
}
|
|
|
|
|
2013-05-26 15:47:54 +00:00
|
|
|
std::string CSystemUtils::GetSavegameDirectoryLocation()
|
2013-03-27 09:20:06 +00:00
|
|
|
{
|
2013-05-26 15:47:54 +00:00
|
|
|
return std::string("savegame");
|
2013-03-27 09:20:06 +00:00
|
|
|
}
|
2013-05-26 15:47:54 +00:00
|
|
|
|