Skip to content

Commit

Permalink
rename ds => fs for FileState*
Browse files Browse the repository at this point in the history
  • Loading branch information
kjk committed Aug 10, 2024
1 parent 89d34c2 commit 7e0fe80
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 33 deletions.
56 changes: 28 additions & 28 deletions src/FileThumbnails.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ void DeleteThumbnailForFile(const char* filePath) {
logf("DeleteThumbnailForFile: file::Remove('%s') %s\n", thumbPath, status);
}

RenderedBitmap* LoadThumbnail(FileState* ds) {
if (ds->thumbnail) {
return ds->thumbnail;
RenderedBitmap* LoadThumbnail(FileState* fs) {
if (fs->thumbnail) {
return fs->thumbnail;
}
TempStr bmpPath = GetThumbnailPathTemp(ds->filePath);
TempStr bmpPath = GetThumbnailPathTemp(fs->filePath);
if (!bmpPath) {
return nullptr;
}
Expand All @@ -77,73 +77,73 @@ RenderedBitmap* LoadThumbnail(FileState* ds) {
return nullptr;
}

ds->thumbnail = bmp;
return ds->thumbnail;
fs->thumbnail = bmp;
return fs->thumbnail;
}

bool HasThumbnail(FileState* ds) {
bool HasThumbnail(FileState* fs) {
// TODO: optimize, LoadThumbnail() is probably not necessary
if (!ds->thumbnail && !LoadThumbnail(ds)) {
if (!fs->thumbnail && !LoadThumbnail(fs)) {
return false;
}

TempStr bmpPath = GetThumbnailPathTemp(ds->filePath);
TempStr bmpPath = GetThumbnailPathTemp(fs->filePath);
if (!bmpPath) {
return true;
}
FILETIME bmpTime = file::GetModificationTime(bmpPath);
FILETIME fileTime = file::GetModificationTime(ds->filePath);
FILETIME fileTime = file::GetModificationTime(fs->filePath);
// delete the thumbnail if the file is newer than the thumbnail
if (FileTimeDiffInSecs(fileTime, bmpTime) > 0) {
delete ds->thumbnail;
ds->thumbnail = nullptr;
delete fs->thumbnail;
fs->thumbnail = nullptr;
}

return ds->thumbnail != nullptr;
return fs->thumbnail != nullptr;
}

// takes ownership of bmp
void SetThumbnail(FileState* ds, RenderedBitmap* bmp) {
void SetThumbnail(FileState* fs, RenderedBitmap* bmp) {
ReportIf(bmp && bmp->GetSize().IsEmpty());
if (!ds || !bmp || bmp->GetSize().IsEmpty()) {
if (!fs || !bmp || bmp->GetSize().IsEmpty()) {
delete bmp;
return;
}
delete ds->thumbnail;
ds->thumbnail = bmp;
SaveThumbnail(ds);
delete fs->thumbnail;
fs->thumbnail = bmp;
SaveThumbnail(fs);
}

void SaveThumbnail(FileState* ds) {
if (!ds->thumbnail) {
void SaveThumbnail(FileState* fs) {
if (!fs->thumbnail) {
return;
}

TempStr thumbnailPath = GetThumbnailPathTemp(ds->filePath);
TempStr thumbnailPath = GetThumbnailPathTemp(fs->filePath);
if (!thumbnailPath) {
return;
}
if (!dir::CreateForFile(thumbnailPath)) {
logf("SaveThumbnail: dir::CreateForFile('%s') failed, file path: '%s'\n", thumbnailPath, ds->filePath);
logf("SaveThumbnail: dir::CreateForFile('%s') failed, file path: '%s'\n", thumbnailPath, fs->filePath);
ReportIfQuick(true);
}
ReportIfQuick(!str::EndsWithI(thumbnailPath, ".png"));

Gdiplus::Bitmap bmp(ds->thumbnail->GetBitmap(), nullptr);
Gdiplus::Bitmap bmp(fs->thumbnail->GetBitmap(), nullptr);
CLSID tmpClsid = GetEncoderClsid(L"image/png");
TempWStr pathW = ToWStrTemp(thumbnailPath);
bmp.Save(pathW, &tmpClsid, nullptr);
}

void RemoveThumbnail(FileState* ds) {
if (!HasThumbnail(ds)) {
void RemoveThumbnail(FileState* fs) {
if (!HasThumbnail(fs)) {
return;
}

char* bmpPath = GetThumbnailPathTemp(ds->filePath);
char* bmpPath = GetThumbnailPathTemp(fs->filePath);
if (bmpPath) {
file::Delete(bmpPath);
}
delete ds->thumbnail;
ds->thumbnail = nullptr;
delete fs->thumbnail;
fs->thumbnail = nullptr;
}
10 changes: 5 additions & 5 deletions src/FileThumbnails.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
constexpr int kThumbnailDx = 212;
constexpr int kThumbnailDy = 150;

RenderedBitmap* LoadThumbnail(FileState* ds);
bool HasThumbnail(FileState* ds);
void SetThumbnail(FileState* ds, RenderedBitmap* bmp);
void SaveThumbnail(FileState* ds);
void RemoveThumbnail(FileState* ds);
RenderedBitmap* LoadThumbnail(FileState* fs);
bool HasThumbnail(FileState* fs);
void SetThumbnail(FileState* fs, RenderedBitmap* bmp);
void SaveThumbnail(FileState* fs);
void RemoveThumbnail(FileState* fs);

TempStr GetThumbnailCacheDirTemp();
char* GetThumbnailPathTemp(const char* filePath);
Expand Down

0 comments on commit 7e0fe80

Please sign in to comment.