|
|
@@ -28,16 +28,20 @@ COMMAND_FLAGS filefunctions::operator|(filefunctions::COMMAND_FLAGS a, filefunct
|
|
|
|
|
|
time_t filetime_to_unixtime(FILETIME const &t)
|
|
|
{
|
|
|
+ //FILETIME t;
|
|
|
+ //FileTimeToLocalFileTime(&utc_t, &t);
|
|
|
LARGE_INTEGER big_time;
|
|
|
time_t unix_time;
|
|
|
|
|
|
big_time.HighPart = t.dwHighDateTime;
|
|
|
big_time.LowPart = t.dwLowDateTime;
|
|
|
unix_time = big_time.QuadPart/10000000-11644473600;
|
|
|
+ unix_time += 3600; // UTC+1
|
|
|
+ DEBUG("__FILETIME__ " << big_time.QuadPart);
|
|
|
return unix_time;
|
|
|
}
|
|
|
|
|
|
-tm* get_exif_time(std::string path)
|
|
|
+tm* get_exif_time(std::string path, long file_size)
|
|
|
{
|
|
|
FILE *filen = fopen(path.c_str(), "rb");
|
|
|
if (filen == nullptr)
|
|
|
@@ -46,7 +50,7 @@ tm* get_exif_time(std::string path)
|
|
|
return nullptr;
|
|
|
}
|
|
|
DEBUG("__GET_EXIF_TIME__ Opened file: " << path);
|
|
|
-
|
|
|
+/*
|
|
|
fseek(filen, 0, SEEK_END);
|
|
|
unsigned long file_size = ftell(filen);
|
|
|
rewind(filen);
|
|
|
@@ -61,22 +65,41 @@ tm* get_exif_time(std::string path)
|
|
|
fclose(filen);
|
|
|
return nullptr;
|
|
|
}
|
|
|
+ fclose(filen);*/
|
|
|
+
|
|
|
+ DEBUG("__GET_EXIF_TIME__ File size: " << file_size);
|
|
|
+ unsigned int shortened = file_size > 0x10000 ? 0x10000 : file_size;
|
|
|
+ DEBUG("__GET_EXIF_TIME__ Shortened size: " << shortened);
|
|
|
+ unsigned char *buf = new unsigned char[shortened];
|
|
|
+
|
|
|
+ if (fread(buf, 1, shortened, filen) != shortened)
|
|
|
+ {
|
|
|
+ delete[] buf;
|
|
|
+ fclose(filen);
|
|
|
+ ASSERT("__GET_EXIF_TIME__ Could not read file");
|
|
|
+ return nullptr;
|
|
|
+ }
|
|
|
fclose(filen);
|
|
|
|
|
|
easyexif::EXIFInfo exif;
|
|
|
- if(exif.parseFrom(buf, file_size))
|
|
|
+ if(exif.parseFrom(buf, shortened))
|
|
|
{
|
|
|
- DEBUG("__GET_EXIF_TIME__ Could not parse file");
|
|
|
delete[] buf;
|
|
|
+ ASSERT("__GET_EXIF_TIME__ Could not parse file");
|
|
|
return nullptr;
|
|
|
}
|
|
|
delete[] buf;
|
|
|
|
|
|
DEBUG("__GET_EXIF_TIME__ File parsed!");
|
|
|
+ if(exif.DateTimeOriginal.size()==0)
|
|
|
+ {
|
|
|
+ DEBUG("__GET_EXIF_TIME__ No original datetime found!");
|
|
|
+ delete[] buf;
|
|
|
+ return nullptr;
|
|
|
+ }
|
|
|
|
|
|
tm *result = new tm;
|
|
|
//tm *result = (tm*)malloc(sizeof(tm));
|
|
|
- int bajs;
|
|
|
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);
|
|
|
|
|
|
DEBUG("__GET_EXIF_TIME__ DateTime: " << exif.DateTimeOriginal.c_str());
|
|
|
@@ -91,7 +114,9 @@ tm* get_exif_time(std::string path)
|
|
|
result->tm_year -= 1900;
|
|
|
result->tm_mon -= 1;
|
|
|
|
|
|
+ tm dont_touch_my_time = *result;
|
|
|
time_t unix_time = mktime(result);
|
|
|
+ *result = dont_touch_my_time;
|
|
|
DEBUG("__GET_EXIF_TIME__ Time: " << unix_time);
|
|
|
|
|
|
// Sort of a sanity check
|
|
|
@@ -175,7 +200,7 @@ STATUS_CODE filefunctions::mv(std::string const &src_arg, std::string const &des
|
|
|
return SC_DOES_NOT_EXIST;
|
|
|
}
|
|
|
|
|
|
- if(mkdir(dest.substr(0,dest.find_last_of('/\\'))))
|
|
|
+ if(mkdir(dest.substr(0,dest.find_last_of("/\\"))))
|
|
|
{
|
|
|
DEBUG("__MV__ Could not determine destination directory");
|
|
|
return SC_INVALID_DESTINATION;
|
|
|
@@ -225,7 +250,7 @@ STATUS_CODE filefunctions::mkdir(std::string const &arg_path, COMMAND_FLAGS flag
|
|
|
return SC_IS_NOT_DIRECTORY;
|
|
|
}
|
|
|
|
|
|
- size_t parent_separator = path.find_last_of('/\\');
|
|
|
+ size_t parent_separator = path.find_last_of("/\\");
|
|
|
if(parent_separator == std::string::npos)
|
|
|
{
|
|
|
DEBUG("__MKDIR__ Invalid path");
|
|
|
@@ -340,7 +365,7 @@ STATUS_CODE filefunctions::ls(std::string path_arg, std::queue<File_Struct> &con
|
|
|
else
|
|
|
{
|
|
|
temp.modified = new tm;
|
|
|
- memcpy(temp.modified, localtime(&unix_time), sizeof(tm));
|
|
|
+ memcpy(temp.modified, gmtime(&unix_time), sizeof(tm));
|
|
|
}
|
|
|
|
|
|
temp.file_ending = temp.path.substr(temp.path.find_last_of('.')+1);
|
|
|
@@ -349,8 +374,21 @@ STATUS_CODE filefunctions::ls(std::string path_arg, std::queue<File_Struct> &con
|
|
|
|
|
|
if(temp.file_ending == "jpeg" || temp.file_ending == "jpg")
|
|
|
{
|
|
|
+ temp.file_ending = "jpg";
|
|
|
DEBUG("__LS__ Found JPEG-file, decoding EXIF");
|
|
|
- temp.taken = get_exif_time(temp.path);
|
|
|
+ LARGE_INTEGER dryg;
|
|
|
+ dryg.HighPart = file_data.nFileSizeHigh;
|
|
|
+ dryg.LowPart = file_data.nFileSizeLow;
|
|
|
+ temp.taken = get_exif_time(temp.path, dryg.QuadPart);
|
|
|
+ if(temp.taken)
|
|
|
+ {
|
|
|
+ DEBUG("__LS__ year: " << temp.taken->tm_year);
|
|
|
+ DEBUG("__LS__ month: " << temp.taken->tm_mon);
|
|
|
+ DEBUG("__LS__ date: " << temp.taken->tm_mday);
|
|
|
+ DEBUG("__LS__ hour: " << temp.taken->tm_hour);
|
|
|
+ DEBUG("__LS__ minute: " << temp.taken->tm_min);
|
|
|
+ DEBUG("__LS__ second: " << temp.taken->tm_sec);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
content.push(temp);
|
|
|
@@ -365,5 +403,5 @@ STATUS_CODE filefunctions::ls(std::string path_arg, std::queue<File_Struct> &con
|
|
|
|
|
|
#else
|
|
|
// Fail?
|
|
|
- Hård fail som fan!
|
|
|
+ HÃ¥rd fail som fan!
|
|
|
#endif // __linux__
|