Add Folder check and Folder creation
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
#include "RTSPRecorder.h"
|
||||
#include "Util.h"
|
||||
#include "Util/Util.h"
|
||||
#include <HttpClient.h>
|
||||
#include <Logging.h>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
namespace CameraRecorder {
|
||||
@@ -21,7 +22,28 @@ std::string RTSPRecorder::Snapshot(ctpl::thread_pool* pThreadPool, const std::st
|
||||
{
|
||||
Logging::Log(Logging::Severity::Debug, "RTSPRecorder Snapshot");
|
||||
|
||||
std::string dateTimeString = GetDateTimeString();
|
||||
std::string folderName = GetFolderName(m_settings);
|
||||
if (!Util::FolderExists(folderName))
|
||||
{
|
||||
try
|
||||
{
|
||||
Util::CreateFolder(folderName);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
std::cerr << "Exception caught" << std::endl;
|
||||
|
||||
std::stringstream ss;
|
||||
ss << "Type : " << typeid(e).name() << std::endl;
|
||||
ss << "ERROR: " << e.what() << std::endl;
|
||||
|
||||
Logging::Log(Logging::Severity::Error, ss.str());
|
||||
|
||||
return std::string();
|
||||
}
|
||||
}
|
||||
|
||||
std::string dateTimeString = Util::GetDateTimeString();
|
||||
std::string fileName = GetFileName(m_settings, "jpg", dateTimeString, 0);
|
||||
|
||||
Http::HttpClient* pHttpClient = m_pHttpClient;
|
||||
@@ -35,7 +57,28 @@ std::string RTSPRecorder::MultiSnapshot(ctpl::thread_pool* pThreadPool, const st
|
||||
{
|
||||
Logging::Log(Logging::Severity::Debug, "RTSPRecorder MultiSnapshot");
|
||||
|
||||
std::string dateTimeString = GetDateTimeString();
|
||||
std::string folderName = GetFolderName(m_settings);
|
||||
if (!Util::FolderExists(folderName))
|
||||
{
|
||||
try
|
||||
{
|
||||
Util::CreateFolder(folderName);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
std::cerr << "Exception caught" << std::endl;
|
||||
|
||||
std::stringstream ss;
|
||||
ss << "Type : " << typeid(e).name() << std::endl;
|
||||
ss << "ERROR: " << e.what() << std::endl;
|
||||
|
||||
Logging::Log(Logging::Severity::Error, ss.str());
|
||||
|
||||
return std::string();
|
||||
}
|
||||
}
|
||||
|
||||
std::string dateTimeString = Util::GetDateTimeString();
|
||||
std::string fileName = GetFileName(m_settings, "jpg", dateTimeString, 0);
|
||||
|
||||
Http::HttpClient* pHttpClient = m_pHttpClient;
|
||||
@@ -52,7 +95,28 @@ std::string RTSPRecorder::Video(ctpl::thread_pool* pThreadPool, const std::strin
|
||||
std::stringstream url;
|
||||
url << "rtsp://" << m_settings.Username << ":" << m_settings.Password << "@" << m_settings.IpAddress << ":" << m_settings.Port << m_settings.URL;
|
||||
|
||||
std::string dateTimeString = GetDateTimeString();
|
||||
std::string folderName = GetFolderName(m_settings);
|
||||
if (!Util::FolderExists(folderName))
|
||||
{
|
||||
try
|
||||
{
|
||||
Util::CreateFolder(folderName);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
std::cerr << "Exception caught" << std::endl;
|
||||
|
||||
std::stringstream ss;
|
||||
ss << "Type : " << typeid(e).name() << std::endl;
|
||||
ss << "ERROR: " << e.what() << std::endl;
|
||||
|
||||
Logging::Log(Logging::Severity::Error, ss.str());
|
||||
|
||||
return std::string();
|
||||
}
|
||||
}
|
||||
|
||||
std::string dateTimeString = Util::GetDateTimeString();
|
||||
std::string fileName = GetFileName(m_settings, "mp4", dateTimeString, 0);
|
||||
|
||||
std::stringstream command;
|
||||
@@ -65,12 +129,19 @@ std::string RTSPRecorder::Video(ctpl::thread_pool* pThreadPool, const std::strin
|
||||
return fileName;
|
||||
}
|
||||
|
||||
std::string RTSPRecorder::GetFileName(const Settings& settings, const std::string& extension, const std::string& dateTimeString, int imageIndex)
|
||||
std::string RTSPRecorder::GetFolderName(const Settings& settings)
|
||||
{
|
||||
filesystem::path fileLocation(settings.Path);
|
||||
fileLocation = fileLocation / filesystem::path(settings.IpAddress);
|
||||
|
||||
std::string fileName = std::string(dateTimeString).append(".").append(extension);
|
||||
return fileLocation.str();
|
||||
}
|
||||
|
||||
std::string RTSPRecorder::GetFileName(const Settings& settings, const std::string& extension, const std::string& dateTimeString, int imageIndex)
|
||||
{
|
||||
filesystem::path fileLocation(GetFolderName(settings));
|
||||
|
||||
std::string fileName = std::string(dateTimeString).append("_").append(std::to_string(imageIndex)).append(".").append(extension);
|
||||
filesystem::path fullFileName = fileLocation / filesystem::path(fileName);
|
||||
|
||||
return fullFileName.str();
|
||||
|
||||
Reference in New Issue
Block a user