mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-06 07:06:54 +08:00
Combined file info functions
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
#include "filesystem.h"
|
#include "filesystem.h"
|
||||||
|
#include <sstream>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
namespace alpr
|
namespace alpr
|
||||||
{
|
{
|
||||||
@@ -146,41 +148,51 @@ namespace alpr
|
|||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
// Stub out these functions on Windows. They're used for the daemon anyway, which isn't supported on Windows.
|
// Stub out these functions on Windows. They're used for the daemon anyway, which isn't supported on Windows.
|
||||||
|
|
||||||
int64_t getFileSize(std::string filename) { return 0; }
|
static int makeDir(const char *path, mode_t mode) { return 0; }
|
||||||
static int makeDir(char *path, mode_t mode) { return 0; }
|
bool makePath(const char* path, mode_t mode) {
|
||||||
bool makePath(char* path, mode_t mode) { return true; }
|
std::stringstream pathstream;
|
||||||
int64_t getFileCreationTime(std::string filename) { return 0; }
|
pathstream << "mkdir " << path;
|
||||||
|
std::string candidate_path = pathstream.str();
|
||||||
|
std::replace(candidate_path.begin(), candidate_path.end(), '/', '\\');
|
||||||
|
|
||||||
|
system(candidate_path.c_str());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
FileInfo getFileInfo(std::string filename) {
|
||||||
|
FileInfo response;
|
||||||
|
response.creation_time = 0;
|
||||||
|
response.size = 0;
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
int64_t getFileSize(std::string filename)
|
FileInfo getFileInfo(std::string filename)
|
||||||
{
|
{
|
||||||
|
FileInfo response;
|
||||||
|
|
||||||
struct stat stat_buf;
|
struct stat stat_buf;
|
||||||
int rc = stat(filename.c_str(), &stat_buf);
|
int rc = stat(filename.c_str(), &stat_buf);
|
||||||
//return rc == 0 ? stat_buf.st_size : -1;
|
//return rc == 0 ? stat_buf.st_size : -1;
|
||||||
|
|
||||||
// 512 bytes is the standard block size
|
// 512 bytes is the standard block size
|
||||||
if (rc == 0)
|
if (rc == 0)
|
||||||
return 512 * stat_buf.st_blocks;
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int64_t getFileCreationTime(std::string filename)
|
|
||||||
{
|
{
|
||||||
struct stat stat_buf;
|
|
||||||
int rc = stat(filename.c_str(), &stat_buf);
|
|
||||||
|
|
||||||
if (rc != 0)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
double milliseconds = (stat_buf.st_ctimespec.tv_sec * 1000) + (((double) stat_buf.st_ctimespec.tv_nsec) / 1000000.0);
|
double milliseconds = (stat_buf.st_ctimespec.tv_sec * 1000) + (((double) stat_buf.st_ctimespec.tv_nsec) / 1000000.0);
|
||||||
#else
|
#else
|
||||||
double milliseconds = (stat_buf.st_ctim.tv_sec * 1000) + (((double) stat_buf.st_ctim.tv_nsec) / 1000000.0);
|
double milliseconds = (stat_buf.st_ctim.tv_sec * 1000) + (((double) stat_buf.st_ctim.tv_nsec) / 1000000.0);
|
||||||
#endif
|
#endif
|
||||||
|
response.size = 512 * stat_buf.st_blocks;
|
||||||
|
response.creation_time = (int64_t) milliseconds;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
response.creation_time = 0;
|
||||||
|
response.size = 0;
|
||||||
|
}
|
||||||
|
|
||||||
return (int64_t) milliseconds;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int makeDir(const char *path, mode_t mode)
|
static int makeDir(const char *path, mode_t mode)
|
||||||
|
@@ -25,14 +25,19 @@ typedef int mode_t;
|
|||||||
namespace alpr
|
namespace alpr
|
||||||
{
|
{
|
||||||
|
|
||||||
|
struct FileInfo
|
||||||
|
{
|
||||||
|
int64_t size;
|
||||||
|
int64_t creation_time;
|
||||||
|
};
|
||||||
|
|
||||||
bool startsWith(std::string const &fullString, std::string const &prefix);
|
bool startsWith(std::string const &fullString, std::string const &prefix);
|
||||||
bool hasEnding (std::string const &fullString, std::string const &ending);
|
bool hasEnding (std::string const &fullString, std::string const &ending);
|
||||||
bool hasEndingInsensitive(const std::string& fullString, const std::string& ending);
|
bool hasEndingInsensitive(const std::string& fullString, const std::string& ending);
|
||||||
|
|
||||||
std::string filenameWithoutExtension(std::string filename);
|
std::string filenameWithoutExtension(std::string filename);
|
||||||
|
|
||||||
int64_t getFileSize(std::string filename);
|
FileInfo getFileInfo(std::string filename);
|
||||||
int64_t getFileCreationTime(std::string filename);
|
|
||||||
|
|
||||||
bool DirectoryExists( const char* pzPath );
|
bool DirectoryExists( const char* pzPath );
|
||||||
bool fileExists( const char* pzPath );
|
bool fileExists( const char* pzPath );
|
||||||
|
Reference in New Issue
Block a user