Skip to content
This repository was archived by the owner on Sep 2, 2021. It is now read-only.

Commit fa15f22

Browse files
committed
Merge pull request #349 from adobe/couzteau/preview-images-with-size
add file size to file stat
2 parents e2a1a7c + 6942510 commit fa15f22

6 files changed

Lines changed: 23 additions & 17 deletions

appshell/appshell_extensions.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ class ProcessMessageDelegate : public ClientHandler::ProcessMessageDelegate {
237237
error = Rename(oldName, newName);
238238
}
239239
// No additional response args for this function
240-
} else if (message_name == "GetFileModificationTime") {
240+
} else if (message_name == "GetFileInfo") {
241241
// Parameters:
242242
// 0: int32 - callback id
243243
// 1: string - filename
@@ -249,13 +249,15 @@ class ProcessMessageDelegate : public ClientHandler::ProcessMessageDelegate {
249249
if (error == NO_ERROR) {
250250
ExtensionString filename = argList->GetString(1);
251251
uint32 modtime;
252+
double size;
252253
bool isDir;
253254

254-
error = GetFileModificationTime(filename, modtime, isDir);
255+
error = GetFileInfo(filename, modtime, isDir, size);
255256

256257
// Set response args for this function
257258
responseArgs->SetInt(2, modtime);
258259
responseArgs->SetBool(3, isDir);
260+
responseArgs->SetInt(4, size);
259261
}
260262
} else if (message_name == "ReadFile") {
261263
// Parameters:

appshell/appshell_extensions.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,17 +267,18 @@ if (!appshell.app) {
267267
*
268268
* @return None. This is an asynchronous call that sends all return information to the callback.
269269
*/
270-
native function GetFileModificationTime();
270+
native function GetFileInfo();
271271
appshell.fs.stat = function (path, callback) {
272-
GetFileModificationTime(function (err, modtime, isDir) {
272+
GetFileInfo(function (err, modtime, isDir, size) {
273273
callback(err, {
274274
isFile: function () {
275275
return !isDir;
276276
},
277277
isDirectory: function () {
278278
return isDir;
279279
},
280-
mtime: new Date(modtime * 1000) // modtime is seconds since 1970, convert to ms
280+
mtime: new Date(modtime * 1000), // modtime is seconds since 1970, convert to ms
281+
size: new Number(size)
281282
});
282283
}, path);
283284
};

appshell/appshell_extensions_gtk.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,14 +286,15 @@ int Rename(ExtensionString oldName, ExtensionString newName)
286286
}
287287
}
288288

289-
int GetFileModificationTime(ExtensionString filename, uint32& modtime, bool& isDir)
289+
int GetFileInfo(ExtensionString filename, uint32& modtime, bool& isDir, double& size)
290290
{
291291
struct stat buf;
292292
if(stat(filename.c_str(),&buf)==-1)
293293
return ConvertLinuxErrorCode(errno);
294294

295295
modtime = buf.st_mtime;
296296
isDir = S_ISDIR(buf.st_mode);
297+
size = (double)buf.st_size;
297298

298299
return NO_ERROR;
299300
}

appshell/appshell_extensions_mac.mm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ int32 Rename(ExtensionString oldName, ExtensionString newName)
432432
return ConvertNSErrorCode(error, false);
433433
}
434434

435-
int32 GetFileModificationTime(ExtensionString filename, uint32& modtime, bool& isDir)
435+
int32 GetFileInfo(ExtensionString filename, uint32& modtime, bool& isDir, double& size)
436436
{
437437
NSString* path = [NSString stringWithUTF8String:filename.c_str()];
438438
BOOL isDirectory;
@@ -447,7 +447,8 @@ int32 GetFileModificationTime(ExtensionString filename, uint32& modtime, bool& i
447447
NSDictionary* fileAttribs = [[NSFileManager defaultManager] attributesOfItemAtPath:path error:&error];
448448
NSDate *modDate = [fileAttribs valueForKey:NSFileModificationDate];
449449
modtime = [modDate timeIntervalSince1970];
450-
450+
NSNumber *filesize = [fileAttribs valueForKey:NSFileSize];
451+
size = [filesize doubleValue];
451452
return ConvertNSErrorCode(error, true);
452453
}
453454

appshell/appshell_extensions_platform.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ int32 MakeDir(ExtensionString path, int32 mode);
9595

9696
int32 Rename(ExtensionString oldName, ExtensionString newName);
9797

98-
int32 GetFileModificationTime(ExtensionString filename, uint32& modtime, bool& isDir);
98+
int32 GetFileInfo(ExtensionString filename, uint32& modtime, bool& isDir, double& size);
9999

100100
int32 ReadFile(ExtensionString filename, ExtensionString encoding, std::string& contents);
101101

appshell/appshell_extensions_win.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -654,23 +654,24 @@ int32 Rename(ExtensionString oldName, ExtensionString newName)
654654
return NO_ERROR;
655655
}
656656

657-
int32 GetFileModificationTime(ExtensionString filename, uint32& modtime, bool& isDir)
657+
int32 GetFileInfo(ExtensionString filename, uint32& modtime, bool& isDir, double& size)
658658
{
659-
DWORD dwAttr = GetFileAttributes(filename.c_str());
660-
661-
if (dwAttr == INVALID_FILE_ATTRIBUTES) {
662-
return ConvertWinErrorCode(GetLastError());
663-
}
664-
665-
isDir = ((dwAttr & FILE_ATTRIBUTE_DIRECTORY) != 0);
666659

667660
WIN32_FILE_ATTRIBUTE_DATA fad;
668661
if (!GetFileAttributesEx(filename.c_str(), GetFileExInfoStandard, &fad)) {
669662
return ConvertWinErrorCode(GetLastError());
670663
}
671664

665+
DWORD dwAttr = fad.dwFileAttributes;
666+
isDir = ((dwAttr & FILE_ATTRIBUTE_DIRECTORY) != 0);
667+
672668
modtime = FiletimeToTime(fad.ftLastWriteTime);
673669

670+
LARGE_INTEGER size_tmp;
671+
size_tmp.HighPart = fad.nFileSizeHigh;
672+
size_tmp.LowPart = fad.nFileSizeLow;
673+
size = size_tmp.QuadPart;
674+
674675
return NO_ERROR;
675676
}
676677

0 commit comments

Comments
 (0)