Add Folder check and Folder creation

This commit is contained in:
2023-03-16 13:41:53 +01:00
parent 5f3d3d78b7
commit c26e48e43c
13 changed files with 376 additions and 61 deletions
+78 -5
View File
@@ -1,10 +1,11 @@
#include "FoscamRecorder.h"
#include "Util.h"
#include "Util/Util.h"
#include <HttpClient.h>
#include <JpegImageCollection.h>
#include <Logging.h>
#include <filesystem/path.h>
#include <fstream>
#include <iostream>
#include <sstream>
#include <thread>
@@ -26,7 +27,31 @@ std::string FoscamRecorder::Snapshot(ctpl::thread_pool* pThreadPool, const std::
{
Logging::Log(Logging::Severity::Debug, "FoscamRecorder 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();
}
}
//if (m_pRecorderMutex->IsRecording(m_settings.IpAddress))
// return std::string();
std::string dateTimeString = Util::GetDateTimeString();
std::string fileName = GetFileName(m_settings, "jpg", dateTimeString);
Http::HttpClient* pHttpClient = m_pHttpClient;
@@ -40,7 +65,27 @@ std::string FoscamRecorder::MultiSnapshot(ctpl::thread_pool* pThreadPool, const
{
Logging::Log(Logging::Severity::Debug, "FoscamRecorder 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);
Http::HttpClient* pHttpClient = m_pHttpClient;
@@ -58,7 +103,28 @@ std::string FoscamRecorder::Video(ctpl::thread_pool* pThreadPool, const std::str
std::stringstream url;
url << "rtsp://" << m_settings.Username << ":" << m_settings.Password << "@" << m_settings.IpAddress << ":" << port << "/videoSub";
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);
std::stringstream command;
@@ -71,11 +137,18 @@ std::string FoscamRecorder::Video(ctpl::thread_pool* pThreadPool, const std::str
return fileName;
}
std::string FoscamRecorder::GetFileName(const Settings& settings, const std::string& extension, const std::string& dateTimeString)
std::string FoscamRecorder::GetFolderName(const Settings& settings)
{
filesystem::path fileLocation(settings.Path);
fileLocation = fileLocation / filesystem::path(settings.IpAddress);
return fileLocation.str();
}
std::string FoscamRecorder::GetFileName(const Settings& settings, const std::string& extension, const std::string& dateTimeString)
{
filesystem::path fileLocation(GetFolderName(settings));
std::string fileName = std::string(dateTimeString).append(".").append(extension);
filesystem::path fullFileName = fileLocation / filesystem::path(fileName);