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,8 +1,9 @@
#include "VStarCamRecorder.h"
#include "Util.h"
#include "Util/Util.h"
#include <HttpClient.h>
#include <Logging.h>
#include <fstream>
#include <iostream>
#include <sstream>
@@ -23,7 +24,28 @@ std::string VStarCamRecorder::Snapshot(ctpl::thread_pool* pThreadPool, const std
{
Logging::Log(Logging::Severity::Debug, "VStarCamRecorder Snapshot");
std::string dateTimeString = GetDateTimeString(true);
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(true);
std::string fileName = GetFileName(m_settings, "jpg", dateTimeString, 0);
Http::HttpClient* pHttpClient = m_pHttpClient;
@@ -37,7 +59,28 @@ std::string VStarCamRecorder::MultiSnapshot(ctpl::thread_pool* pThreadPool, cons
{
Logging::Log(Logging::Severity::Debug, "VStarCamRecorder MultiSnapshot");
std::string dateTimeString = GetDateTimeString(true);
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(true);
std::string fileName = GetFileName(m_settings, "jpg", dateTimeString, 0);
Http::HttpClient* pHttpClient = m_pHttpClient;
@@ -55,7 +98,28 @@ std::string VStarCamRecorder::Video(ctpl::thread_pool* pThreadPool, const std::s
std::stringstream url;
url << "rtsp://" << m_settings.Username << ":" << m_settings.Password << "@" << m_settings.IpAddress << ":" << port << "/udp/av0_0";
std::string dateTimeString = GetDateTimeString(true);
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(true);
std::string fileName = GetFileName(m_settings, "mp4", dateTimeString, 0);
std::stringstream command;
@@ -68,11 +132,18 @@ std::string VStarCamRecorder::Video(ctpl::thread_pool* pThreadPool, const std::s
return fileName;
}
std::string VStarCamRecorder::GetFileName(const Settings& settings, const std::string& extension, const std::string& dateTimeString, int imageIndex)
std::string VStarCamRecorder::GetFolderName(const Settings& settings)
{
filesystem::path fileLocation(settings.Path);
fileLocation = fileLocation / filesystem::path(settings.IpAddress);
return fileLocation.str();
}
std::string VStarCamRecorder::GetFileName(const Settings& settings, const std::string& extension, const std::string& dateTimeString, int imageIndex)
{
filesystem::path fileLocation(GetFolderName(settings));
std::string fileName = std::string("VSTA000000XXXXX_0_").append(dateTimeString).append("_").append(std::to_string(imageIndex)).append(".").append(extension);
filesystem::path fullFileName = fileLocation / filesystem::path(fileName);