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
+76 -5
View File
@@ -1,10 +1,11 @@
#include "WatchBotRecorder.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 <vector>
@@ -26,7 +27,28 @@ std::string WatchBotRecorder::Snapshot(ctpl::thread_pool* pThreadPool, const std
{
Logging::Log(Logging::Severity::Debug, "WatchBotRecorder 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);
Http::HttpClient* pHttpClient = m_pHttpClient;
@@ -40,7 +62,28 @@ std::string WatchBotRecorder::MultiSnapshot(ctpl::thread_pool* pThreadPool, cons
{
Logging::Log(Logging::Severity::Debug, "WatchBotRecorder 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;
@@ -57,7 +100,28 @@ std::string WatchBotRecorder::Video(ctpl::thread_pool* pThreadPool, const std::s
std::stringstream url;
url << "http://" << m_settings.IpAddress << ":" << m_settings.Port << "/videostream.asf?user=" << m_settings.Username << "&pwd=" << m_settings.Password;
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;
@@ -70,11 +134,18 @@ std::string WatchBotRecorder::Video(ctpl::thread_pool* pThreadPool, const std::s
return fileName;
}
std::string WatchBotRecorder::GetFileName(const Settings& settings, const std::string& extension, const std::string& dateTimeString)
std::string WatchBotRecorder::GetFolderName(const Settings& settings)
{
filesystem::path fileLocation(settings.Path);
fileLocation = fileLocation / filesystem::path(settings.IpAddress);
return fileLocation.str();
}
std::string WatchBotRecorder::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);