Skip to content

Commit

Permalink
in_vgm: fix
Browse files Browse the repository at this point in the history
I'm now reloading the file if the "last write time" has changed.
  • Loading branch information
ValleyBell committed Dec 23, 2018
1 parent 725f7ba commit e4ba7ed
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions VGMPlay/VGMPlay_Updates.txt
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,4 @@ Updates since 0.4.0u8 (16.04.2017)
- fixed SN76496 variant being incorrectly called NCR7496 instead of NCR8496
- [in_vgm] made "Tag fallback" option work (finally, after 5 years!)
- [in_vgm] made "disable file information cache" option selectable via configuration
- [in_vgm] fix VGM information dialog using cached data even if file was changed
26 changes: 25 additions & 1 deletion in_vgm/dlg_fileinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ typedef struct fileinfo_data
wchar_t* FileName;
bool ForceReload;

FILETIME FileTime;
UINT32 FileSize;
VGM_HEADER Head;
GD3_TAG Tag;
Expand Down Expand Up @@ -238,14 +239,33 @@ static bool LoadInfoA(const char* FileName, FINF_DATA* FileInf)

static bool LoadInfoW(const wchar_t* FileName, FINF_DATA* FileInf)
{
HANDLE hFile;
FILETIME fileWrtTime;
VGM_HEADER* FH;
UINT32 StrSize;
INT32 TempSLng;

hFile = CreateFileW(FileName, 0, FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, NULL);
if (hFile != INVALID_HANDLE_VALUE)
{
GetFileTime(hFile, NULL, NULL, &fileWrtTime);
CloseHandle(hFile); hFile = NULL;
}
else
{
fileWrtTime.dwLowDateTime = 0x00;
fileWrtTime.dwHighDateTime = 0x00;
}

if (! FileInf->ForceReload && ! Options.NoInfoCache)
{
if (FileInf->FileName != NULL && ! _wcsicmp(FileInf->FileName, FileName))
return true; // I just loaded that file.
{
// We just loaded that file.
if (CompareFileTime(&fileWrtTime, &FileInf->FileTime) == 0)
return true; // The file wasn't changed, so don't reload.
}
}
FileInf->ForceReload = false;

Expand All @@ -268,6 +288,7 @@ static bool LoadInfoW(const wchar_t* FileName, FINF_DATA* FileInf)

// copy all info from PlayVGMInfo to current structure
// (advanced caching) ;)
FileInf->FileTime = PlayVGMInfo.FileTime;
FileInf->FileSize = PlayVGMInfo.FileSize;
FileInf->Head = PlayVGMInfo.Head;
CopyTagData(&FileInf->Tag, &PlayVGMInfo.Tag);
Expand All @@ -292,6 +313,8 @@ static bool LoadInfoW(const wchar_t* FileName, FINF_DATA* FileInf)

if (! FileInf->FileSize)
{
FileInf->FileTime.dwLowDateTime = 0x00;
FileInf->FileTime.dwHighDateTime = 0x00;
FileInf->FileSize = 0x00;
memset(&FileInf->Head, 0x00, sizeof(VGM_HEADER));
memset(&FileInf->Tag, 0x00, sizeof(GD3_TAG));
Expand All @@ -310,6 +333,7 @@ static bool LoadInfoW(const wchar_t* FileName, FINF_DATA* FileInf)
wcscpy(FileInf->Tag.strNotes, L"File invalid!");
return false;
}
FileInf->FileTime = fileWrtTime;

FH = &FileInf->Head;
FileInf->TrackLen = CalcSampleMSecExt(FH->lngTotalSamples, 0x02, FH);
Expand Down

0 comments on commit e4ba7ed

Please sign in to comment.