|
|
@@ -75,19 +75,32 @@ tm* get_exif_time(std::string path)
|
|
|
DEBUG("__GET_EXIF_TIME__ File parsed!");
|
|
|
|
|
|
tm *result = new tm;
|
|
|
+ //tm *result = (tm*)malloc(sizeof(tm));
|
|
|
int bajs;
|
|
|
- sscanf(exif.DateTimeOriginal.c_str(), "%i:%i:%i %i:%i:%i", &result->tm_year, &result->tm_mon, &result->tm_mday, &result->tm_hour, &result->tm_min, &result->tm_sec);
|
|
|
+ sscanf(exif.DateTimeOriginal.c_str(), "%d:%d:%d %d:%d:%d", &result->tm_year, &result->tm_mon, &result->tm_mday, &result->tm_hour, &result->tm_min, &result->tm_sec);
|
|
|
|
|
|
- // Coarse sanity check to avoid very invalid dates
|
|
|
- if(result->tm_year < 70 || result->tm_yday > 200)
|
|
|
- {
|
|
|
- delete result;
|
|
|
- return nullptr;
|
|
|
- }
|
|
|
+ DEBUG("__GET_EXIF_TIME__ DateTime: " << exif.DateTimeOriginal.c_str());
|
|
|
+
|
|
|
+ DEBUG("__GET_EXIF_TIME__ year: " << result->tm_year);
|
|
|
+ DEBUG("__GET_EXIF_TIME__ month: " << result->tm_mon);
|
|
|
+ DEBUG("__GET_EXIF_TIME__ date: " << result->tm_mday);
|
|
|
+ DEBUG("__GET_EXIF_TIME__ hour: " << result->tm_hour);
|
|
|
+ DEBUG("__GET_EXIF_TIME__ minute: " << result->tm_min);
|
|
|
+ DEBUG("__GET_EXIF_TIME__ second: " << result->tm_sec);
|
|
|
|
|
|
result->tm_year -= 1900;
|
|
|
result->tm_mon -= 1;
|
|
|
|
|
|
+ time_t unix_time = mktime(result);
|
|
|
+ DEBUG("__GET_EXIF_TIME__ Time: " << unix_time);
|
|
|
+
|
|
|
+ // Sort of a sanity check
|
|
|
+ if(unix_time == -1)
|
|
|
+ {
|
|
|
+ delete result;
|
|
|
+ return nullptr;
|
|
|
+ }//*/
|
|
|
+
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@@ -122,7 +135,7 @@ STATUS_CODE filefunctions::cd(std::string const &path_arg, COMMAND_FLAGS flags)
|
|
|
DEBUG("__CD__ Path: " << path);
|
|
|
DEBUG("__CD__ Attr: " << std::hex << attr);
|
|
|
|
|
|
- if(attr == FILE_ATTRIBUTE_DIRECTORY)
|
|
|
+ if(attr != INVALID_FILE_ATTRIBUTES && attr&FILE_ATTRIBUTE_DIRECTORY)
|
|
|
{
|
|
|
filefunctions_wd = path;
|
|
|
return SC_SUCCESS;
|
|
|
@@ -201,7 +214,7 @@ STATUS_CODE filefunctions::mkdir(std::string const &arg_path, COMMAND_FLAGS flag
|
|
|
|
|
|
DWORD attr = GetFileAttributes(path.c_str());
|
|
|
|
|
|
- if(attr == FILE_ATTRIBUTE_DIRECTORY)
|
|
|
+ if(attr != INVALID_FILE_ATTRIBUTES && attr&FILE_ATTRIBUTE_DIRECTORY)
|
|
|
{
|
|
|
DEBUG("__MKDIR__ SUCCESS Attr: " << attr);
|
|
|
return SC_SUCCESS;
|
|
|
@@ -265,7 +278,7 @@ STATUS_CODE filefunctions::ls(std::string path_arg, std::queue<File_Struct> &con
|
|
|
DEBUG("__LS__ ls(" << path << ")");
|
|
|
|
|
|
DWORD attr = GetFileAttributes(path.c_str());
|
|
|
- if(attr != FILE_ATTRIBUTE_DIRECTORY)
|
|
|
+ if(attr != INVALID_FILE_ATTRIBUTES && !(attr&FILE_ATTRIBUTE_DIRECTORY))
|
|
|
return SC_IS_NOT_DIRECTORY;
|
|
|
|
|
|
std::string path_joker = path + "\\*";
|
|
|
@@ -282,6 +295,10 @@ STATUS_CODE filefunctions::ls(std::string path_arg, std::queue<File_Struct> &con
|
|
|
do
|
|
|
{
|
|
|
File_Struct temp;
|
|
|
+ temp.modified = nullptr;
|
|
|
+ temp.taken = nullptr;
|
|
|
+ temp.file_ending = "";
|
|
|
+
|
|
|
temp.path = path + "\\" + file_data.cFileName;
|
|
|
|
|
|
if (file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
|
|
@@ -297,7 +314,7 @@ STATUS_CODE filefunctions::ls(std::string path_arg, std::queue<File_Struct> &con
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- DEBUG("__LS__ Which is not . or ..\nGoing in!\n");
|
|
|
+ INFO("__LS__ Found directory. Going in!\n");
|
|
|
ls(temp.path, content, CF_RECURSIVE);
|
|
|
}
|
|
|
}
|
|
|
@@ -309,14 +326,22 @@ STATUS_CODE filefunctions::ls(std::string path_arg, std::queue<File_Struct> &con
|
|
|
else
|
|
|
{
|
|
|
DEBUG("__LS__ Found file!");
|
|
|
- DEBUG("__LS__ File: \"" << temp.path << "\"");
|
|
|
+ INFO("__LS__ File: \"" << temp.path << "\"");
|
|
|
time_t unix_time = filetime_to_unixtime(file_data.ftLastWriteTime);
|
|
|
|
|
|
|
|
|
DEBUG("__LS__ Modified time: " << std::dec << unix_time);
|
|
|
|
|
|
- temp.modified = new tm;
|
|
|
- memcpy(temp.modified, localtime(&unix_time), sizeof(tm));
|
|
|
+ if(unix_time < 800000000 || unix_time > 3500000000)
|
|
|
+ {
|
|
|
+ delete temp.modified;
|
|
|
+ temp.modified = nullptr;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ temp.modified = new tm;
|
|
|
+ memcpy(temp.modified, localtime(&unix_time), sizeof(tm));
|
|
|
+ }
|
|
|
|
|
|
temp.file_ending = temp.path.substr(temp.path.find_last_of('.')+1);
|
|
|
std::transform(temp.file_ending.begin(), temp.file_ending.end(), temp.file_ending.begin(), ::tolower);
|